-
Notifications
You must be signed in to change notification settings - Fork 3
/
static_content.html
271 lines (240 loc) · 9.23 KB
/
static_content.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<%page expression_filter="h"/>
<%!
import logging
import json
from django.contrib.staticfiles.storage import staticfiles_storage
from common.djangoapps.pipeline_mako import compressed_css, compressed_js
from common.djangoapps.pipeline_mako.helpers.studiofrontend import load_sfe_i18n_messages
from django.utils.translation import get_language_bidi
from mako.exceptions import TemplateLookupException
from common.djangoapps.edxmako.shortcuts import marketing_link
from openedx.core.djangolib.js_utils import js_escaped_string, dump_js_escaped_json
from openedx.core.djangolib.markup import HTML
from openedx.core.djangoapps.site_configuration.helpers import (
page_title_breadcrumbs,
get_value,
)
from openedx.core.djangoapps.theming.helpers import (
get_template_path,
is_request_in_themed_site,
)
from lms.djangoapps.certificates.api import get_asset_url_by_slug
from webpack_loader.templatetags.webpack_loader import render_bundle
logger = logging.getLogger(__name__)
%>
<%def name="marketing_link(name)"><%
link = marketing_link(name)
return "/" if link == "#" else link
%></%def>
<%def name='url(file, raw=False)'><%
try:
url = staticfiles_storage.url(file)
except:
url = file
## HTML-escaping must be handled by caller
%>${url | n, decode.utf8}${"?raw" if raw else ""}</%def>
<%def name='certificate_asset_url(slug)'><%
try:
url = get_asset_url_by_slug(slug)
except:
url = ''
## HTML-escaping must be handled by caller
%>${url | n, decode.utf8}</%def>
<%def name='css(group, raw=False)'>
<%
rtl_group = '{}-rtl'.format(group)
if get_language_bidi() and rtl_group in settings.PIPELINE['STYLESHEETS']:
group = rtl_group
%>
% if settings.PIPELINE['PIPELINE_ENABLED']:
${compressed_css(group, raw=raw) | n, decode.utf8}
% else:
% for filename in settings.PIPELINE['STYLESHEETS'][group]['source_filenames']:
<link rel="stylesheet" href="${staticfiles_storage.url(filename.replace('.scss', '.css'))}${"?raw" if raw else ""}" type="text/css" media="all" / >
% endfor
%endif
</%def>
<%def name='js(group)'>
% if settings.PIPELINE['PIPELINE_ENABLED']:
${compressed_js(group) | n, decode.utf8}
% else:
% for filename in settings.PIPELINE['JAVASCRIPT'][group]['source_filenames']:
<script type="text/javascript" src="${staticfiles_storage.url(filename.replace('.coffee', '.js'))}"></script>
% endfor
%endif
</%def>
## A language-direction indicator, suitable for use in class="" attributes,
## for example:
##
## <body class="${dir_rtl()}">
##
<%def name="dir_rtl()"><%
return 'rtl' if get_language_bidi() else 'ltr'
%></%def>
<%def name="include(path)"><%
from django.conf import settings
from django.template.engine import Engine
from django.template import TemplateDoesNotExist
from django.template.loaders.filesystem import Loader
from openedx.core.djangoapps.theming.helpers import get_current_theme
dirs = settings.DEFAULT_TEMPLATE_ENGINE['DIRS']
theme = get_current_theme()
if theme:
dirs = list(dirs)
dirs.append(theme.path / 'templates')
engine = Engine(dirs=dirs)
loader = Loader(engine)
source = None
for origin in loader.get_template_sources(path):
try:
source = loader.get_contents(origin)
except TemplateDoesNotExist:
pass
if not source:
raise TemplateDoesNotExist(path)
%>${source | n, decode.utf8}</%def>
<%def name="studiofrontend(entry)">
<%doc>
Loads a studio-frontend page, with the necessary context. Context is expected
as a dictionary in the body of this tag.
</%doc>
<%
body = capture(caller.body)
body_dict = json.loads(body)
locale = body_dict['lang']
messages = load_sfe_i18n_messages(locale)
%>
<script type="application/json" id="SFE_i18n_data">
{
"locale": "${ locale | n, decode.utf8}",
"messages": ${ messages | n, decode.utf8}
}
</script>
<script type="application/javascript" id='courseContext'>
var studioContext = ${ body | n, decode.utf8};
</script>
<div id="root" class="SFE"></div>
% if settings.STUDIO_FRONTEND_CONTAINER_URL:
<script type="text/javascript" src="${settings.STUDIO_FRONTEND_CONTAINER_URL}/${entry}.js"></script>
% else:
<script type="text/javascript" src="${url('common/js/vendor/runtime.min.js')}"></script>
<script type="text/javascript" src="${url('common/js/vendor/common.min.js')}"></script>
<script type="text/javascript" src="${url('common/js/vendor/{}.min.js'.format(entry))}"></script>
% endif
</%def>
<%def name="webpack(entry, extension=None, config='DEFAULT', attrs='')">
<%doc>
Loads Javascript onto your page from a Webpack-generated bundle.
Uses the Django template engine because our webpack loader only provides template tags for Jinja and Django.
</%doc>
<%
body = capture(caller.body)
%>
${HTML(render_bundle(entry, extension=None, config='DEFAULT', attrs=attrs))}
% if body:
<script type="text/javascript">
${body | n, decode.utf8}
</script>
% endif
</%def>
<%def name="renderReact(component, id, props={})">
<%doc>
Wrapper function to load a React component via webpack() and render
it onto the page, passing an optional context object via props.
component: (string) The component to render, as specified by the name
of its Webpack entry point.
id: (string) A unique id to apply to the component's container div.
props: (dict, optional) An object containing data to pass into the
component as props.
</%doc>
${HTML(render_bundle(component))}
${HTML(render_bundle('ReactRenderer'))}
<div id="${id}"></div>
<script type="text/javascript">
var c;
try { c = ${component | n, decode.utf8}; } catch (e) { c = null; }
new ReactRenderer({
component: c,
selector: '#${id | n, decode.utf8}',
componentName: '${component | n, js_escaped_string}',
props: ${props | n, dump_js_escaped_json}
});
</script>
</%def>
<%def name="require_module(module_name, class_name)">
<%doc>
Loads Javascript onto your page synchronously.
Uses RequireJS in development and a plain script tag in production.
Use this form of require_module for all new code.
</%doc>
% if not settings.REQUIRE_DEBUG:
<script type="text/javascript" src="${staticfiles_storage.url(module_name + '.js') + '?raw'}"></script>
% endif
<script type="text/javascript">
(function (require) {
require(['${module_name | n, js_escaped_string}'], function (${class_name | n, decode.utf8}) {
${caller.body() | n, decode.utf8}
});
}).call(this, require || RequireJS.require);
</script>
</%def>
<%def name="require_module_async(module_name, class_name)">
<%doc>
Legacy mode of require_module that operates asynchronously, required for certain edge cases
(notably where Javascript is required outside of a <%block name="js_extra" or "headextra").
Do not use for any new code; instead create a factory and use require_module above.
</%doc>
<script type="text/javascript">
(function (require) {
% if settings.REQUIRE_DEBUG:
(function (require) {
require(['${module_name | n, js_escaped_string}'], function (${class_name | n, decode.utf8}) {
${caller.body() | n, decode.utf8}
});
}).call(this, require || RequireJS.require);
% else:
## The "raw" parameter is specified to avoid the URL from being further maninpulated by
## static_replace calls (as would happen if require_module is used within courseware).
## Without specifying "raw", a call to static_replace would result in the MD5 hash being
## being appended more than once, causing the import to fail in production environments.
require(['${staticfiles_storage.url(module_name + ".js") + "?raw" | n, js_escaped_string}'], function () {
require(['${module_name | n, js_escaped_string}'], function (${class_name | n, decode.utf8}) {
${caller.body() | n, decode.utf8}
});
});
% endif
}).call(this, require || RequireJS.require);
</script>
</%def>
<%def name="optional_include_mako(file, is_theming_enabled=False)"><%
# http://stackoverflow.com/q/21219531
if is_theming_enabled:
file = get_template_path(file)
try:
tmpl = self.get_template(file)
except TemplateLookupException:
pass
else:
tmpl.render_context(context)
%></%def>
<%def name="get_page_title_breadcrumbs(*args)"><%
return page_title_breadcrumbs(*args)
%></%def>
<%def name="get_platform_name()"><%
return get_value('platform_name', settings.PLATFORM_NAME)
%></%def>
<%def name="get_value(val_name, default=None, **kwargs)"><%
return get_value(val_name, default=default, **kwargs)
%></%def>
<%def name="get_template_path(relative_path, **kwargs)"><%
return get_template_path(relative_path, **kwargs)
%></%def>
<%def name="is_request_in_themed_site()"><%
return is_request_in_themed_site()
%></%def>
<%def name="get_tech_support_email_address()"><%
return get_value('email_from_address', settings.TECH_SUPPORT_EMAIL)
%></%def>
<%def name="get_contact_email_address()"><%
return get_value('email_from_address', settings.CONTACT_EMAIL)
%></%def>