fix: style, script, assets_url jinja helpers
Jinja helpers to load js, css assets
This commit is contained in:
parent
b0329faa7a
commit
63771417a2
3 changed files with 26 additions and 11 deletions
|
|
@ -37,8 +37,8 @@ app_include_js = [
|
|||
"frappe/public/js/report.bundle.js",
|
||||
]
|
||||
app_include_css = [
|
||||
"/assets/css/desk.min.css",
|
||||
"/assets/css/report.min.css",
|
||||
"frappe/public/scss/desk.bundle.scss",
|
||||
"frappe/public/scss/report.bundle.scss",
|
||||
]
|
||||
|
||||
doctype_js = {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ def get_jenv():
|
|||
'inspect': inspect,
|
||||
'web_blocks': web_blocks,
|
||||
'web_block': web_block,
|
||||
'js_asset': js_asset
|
||||
'script': script,
|
||||
'style': style,
|
||||
'assets_url': assets_url
|
||||
})
|
||||
|
||||
frappe.local.jenv = jenv
|
||||
|
|
@ -230,8 +232,23 @@ def web_blocks(blocks):
|
|||
|
||||
return html
|
||||
|
||||
def js_asset(path):
|
||||
import frappe
|
||||
if not frappe.local.dev_server or True:
|
||||
path = path.replace('frappe/public/', '/assets/frappe/build/')
|
||||
def script(path):
|
||||
path = assets_url(path)
|
||||
if '/public/' in path:
|
||||
path = path.replace('/public/', '/build/')
|
||||
return f'<script type="text/javascript" src="{path}"></script>'
|
||||
|
||||
def style(path):
|
||||
path = assets_url(path)
|
||||
if '/public/' in path:
|
||||
path = path.replace('/public/', '/build/')
|
||||
if path.endswith(('.scss', '.sass', '.less', '.styl')):
|
||||
path = path.rsplit('.', 1)[0] + '.css'
|
||||
return f'<link type="text/css" rel="stylesheet" href="{path}">'
|
||||
|
||||
def assets_url(path):
|
||||
if not path.startswith('/'):
|
||||
path = '/' + path
|
||||
if not path.startswith('/assets'):
|
||||
path = '/assets' + path
|
||||
return path
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
<link rel="icon"
|
||||
href="{{ favicon or "/assets/frappe/images/frappe-favicon.svg" }}" type="image/x-icon">
|
||||
{% for include in include_css -%}
|
||||
<link type="text/css" rel="stylesheet" href="{{ include }}?ver={{ build_version }}">
|
||||
{{ style(include) }}
|
||||
{%- endfor -%}
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -53,11 +53,9 @@
|
|||
</script>
|
||||
|
||||
{% for include in include_js %}
|
||||
{{ js_asset(include) }}
|
||||
{{ script(include) }}
|
||||
{% endfor %}
|
||||
|
||||
{{ js_asset('frappe/public/js/test.bundle.js') }}
|
||||
|
||||
{% include "templates/includes/app_analytics/google_analytics.html" %}
|
||||
{% include "templates/includes/app_analytics/mixpanel_analytics.html" %}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue