Add folder name suggestions
[cds-indico.git] / indico / web / assets / bundles.py
blob1db0701baceca639b4cef7b6e370c8ff4608a6d9
1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
18 """
19 This file declares all core JS/CSS assets used by Indico
20 """
22 # stdlib imports
23 import os
24 from urlparse import urlparse
26 # 3rd party libs
27 from markupsafe import Markup
28 from webassets import Bundle, Environment
30 # legacy imports
31 from indico.core.config import Config
34 def configure_pyscss(environment):
35 config = Config.getInstance()
36 base_url_path = urlparse(config.getBaseURL()).path
37 environment.config['PYSCSS_DEBUG_INFO'] = environment.debug and config.getSCSSDebugInfo()
38 environment.config['PYSCSS_STATIC_URL'] = '{0}/static/'.format(base_url_path)
39 environment.config['PYSCSS_LOAD_PATHS'] = [
40 os.path.join(config.getHtdocsDir(), 'sass', 'lib', 'compass'),
41 os.path.join(config.getHtdocsDir(), 'sass')
45 class IndicoEnvironment(Environment):
46 def __init__(self):
47 config = Config.getInstance()
48 url_path = urlparse(config.getBaseURL()).path
49 output_dir = os.path.join(config.getHtdocsDir(), 'static', 'assets')
50 url = '{0}/static/assets/'.format(url_path)
52 super(IndicoEnvironment, self).__init__(output_dir, url)
53 self.debug = config.getDebug()
54 configure_pyscss(self)
56 self.append_path(config.getHtdocsDir(), '/')
57 self.append_path(os.path.join(config.getHtdocsDir(), 'css'), '{0}/css'.format(url_path))
58 self.append_path(os.path.join(config.getHtdocsDir(), 'js'), '{0}/js'.format(url_path))
61 def namespace(dir_ns, *list_files):
62 return [os.path.join(dir_ns, f) for f in list_files]
65 def include_js_assets(bundle_name):
66 """Jinja template function to generate HTML tags for a JS asset bundle."""
67 return Markup('\n'.join('<script src="{}"></script>'.format(url) for url in core_env[bundle_name].urls()))
70 def include_css_assets(bundle_name):
71 """Jinja template function to generate HTML tags for a CSS asset bundle."""
72 return Markup('\n'.join('<link rel="stylesheet" type="text/css" href="{}">'.format(url)
73 for url in core_env[bundle_name].urls()))
76 def rjs_bundle(name, *files):
77 return Bundle(*files, filters='rjsmin', output='js/{}_%(version)s.min.js'.format(name))
80 indico_core = rjs_bundle(
81 'indico_core',
82 *namespace('js/indico/Core',
84 'Presentation.js',
85 'Data.js',
86 'Components.js',
87 'Auxiliar.js',
88 'Buttons.js',
89 'Effects.js',
90 'Interaction/Base.js',
91 'Widgets/Base.js',
92 'Widgets/Inline.js',
93 'Widgets/DateTime.js',
94 'Widgets/Menu.js',
95 'Widgets/RichText.js',
96 'Widgets/Navigation.js',
97 'Widgets/UserList.js',
98 'Dialogs/Popup.js',
99 'Dialogs/PopupWidgets.js',
100 'Dialogs/Base.js',
101 'Dialogs/Util.js',
102 'Dialogs/Users.js',
103 'Dialogs/PopupWidgets.js',
104 'Browser.js',
105 'Services.js',
106 'Util.js',
107 'Login.js',
108 'Dragndrop.js',
109 'keymap.js'))
111 indico_management = rjs_bundle(
112 'indico_management',
113 *namespace('js/indico/Management',
115 'ConfModifDisplay.js',
116 'RoomBooking.js',
117 'eventCreation.js',
118 'Timetable.js',
119 'AbstractReviewing.js',
120 'NotificationTPL.js',
121 'Registration.js',
122 'Contributions.js',
123 'Sessions.js',
124 'CFA.js',
125 'RoomBookingMapOfRooms.js',
126 'EventUsers.js'))
128 indico_room_booking = rjs_bundle(
129 'indico_room_booking',
130 'js/lib/rrule.js',
131 *namespace('js/indico/RoomBooking',
133 'util.js',
134 'MapOfRooms.js',
135 'BookingForm.js',
136 'RoomBookingCalendar.js',
137 'roomselector.js',
138 'validation.js'))
140 indico_admin = rjs_bundle(
141 'indico_admin',
142 *namespace('js/indico/Admin',
144 'News.js',
145 'Upcoming.js'))
147 indico_timetable = rjs_bundle(
148 'indico_timetable',
149 *namespace('js/indico/Timetable',
151 'Filter.js',
152 'Layout.js',
153 'Undo.js',
154 'Base.js',
155 'DragAndDrop.js',
156 'Draw.js',
157 'Management.js'))
159 indico_legacy = rjs_bundle(
160 'indico_legacy',
161 *namespace('js/indico/Legacy',
163 'Widgets.js',
164 'Dialogs.js',
165 'Util.js'))
167 indico_common = rjs_bundle(
168 'indico_common',
169 *namespace('js/indico/Common',
170 'Export.js',
171 'TimezoneSelector.js',
172 'Social.js',
173 'htmlparser.js'))
175 indico_materialeditor = rjs_bundle('indico_materialeditor', 'js/indico/MaterialEditor/Editor.js')
177 indico_display = rjs_bundle('indico_display', 'js/indico/Display/Dialogs.js')
179 indico_jquery = rjs_bundle(
180 'indico_jquery',
181 *namespace('js/indico/jquery',
182 'defaults.js',
183 'global.js',
184 'errors.js',
185 'ajaxcheckbox.js',
186 'ajaxdialog.js',
187 'clearableinput.js',
188 'actioninput.js',
189 'fieldarea.js',
190 'multiselect.js',
191 'principalfield.js',
192 'realtimefilter.js',
193 'scrollblocker.js',
194 'timerange.js',
195 'tooltips.js',
196 'nullableselector.js'))
198 indico_jquery_authors = rjs_bundle('indico_jquery_authors', 'js/indico/jquery/authors.js')
200 indico_badges_js = rjs_bundle('indico_badges', 'js/indico/Management/ConfModifBadgePosterPrinting.js')
202 indico_badges_css = Bundle('css/badges.css',
203 filters='cssmin', output='css/indico_badges_%(version)s.min.css')
205 indico_regform = rjs_bundle(
206 'indico_regform',
207 *namespace('js/indico/RegistrationForm',
208 'registrationform.js',
209 'section.js',
210 'field.js',
211 'sectiontoolbar.js',
212 'table.js'))
214 angular = rjs_bundle(
215 'angular',
216 'js/lib/angular.js',
217 'js/lib/angular-resource.js',
218 'js/lib/angular-sanitize.js',
219 'js/lib/sortable.js',
220 'js/indico/angular/app.js',
221 'js/indico/angular/directives.js',
222 'js/indico/angular/filters.js',
223 'js/indico/angular/services.js')
225 zero_clipboard_js = rjs_bundle('zero_clipboard_js',
226 'js/lib/zeroclipboard/ZeroClipboard.js',
227 'js/custom/zeroclipboard.js')
229 dropzone_js = rjs_bundle('dropzone_js',
230 'js/lib/dropzone.js/dropzone.js')
232 dropzone_css = Bundle('css/lib/dropzone.js/dropzone.css',
233 'sass/custom/_dropzone.scss',
234 filters=('pyscss', 'cssmin'), output='css/dropzone_css_%(version)s.min.css')
236 jquery = rjs_bundle('jquery', *filter(None, [
237 'js/lib/underscore.js',
238 'js/lib/jquery.js',
239 'js/lib/jquery.qtip.js',
240 'js/jquery/jquery-ui.js',
241 'js/lib/jquery.multiselect.js',
242 'js/lib/jquery.multiselect.filter.js',
243 'js/lib/jquery.typeahead.js',
244 'js/jquery/jquery-migrate-silencer.js' if not Config.getInstance().getDebug() else None] +
245 namespace('js/jquery',
247 'jquery-migrate.js',
248 'jquery.form.js',
249 'jquery.custom.js',
250 'jquery.daterange.js',
251 'jquery.dttbutton.js',
252 'jquery.colorbox.js',
253 'jquery.menu.js',
254 'date.js',
255 'jquery.colorpicker.js',
256 'jquery-extra-selectors.js',
257 'jquery.typewatch.js',
258 'jstorage.js',
259 'jquery.placeholder.js')))
261 utils = rjs_bundle('utils', *namespace('js/utils', 'routing.js', 'i18n.js', 'misc.js', 'forms.js'))
262 calendar = rjs_bundle('calendar', *namespace('js/calendar', 'calendar.js', 'calendar-setup.js'))
264 presentation = rjs_bundle(
265 'presentation',
266 *namespace('js/presentation',
268 'Core/Primitives.js',
269 'Core/Iterators.js',
270 'Core/Tools.js',
271 'Core/String.js',
272 'Core/Type.js',
273 'Core/Interfaces.js',
274 'Core/Commands.js',
275 'Core/MathEx.js',
276 'Data/Bag.js',
277 'Data/Watch.js',
278 'Data/WatchValue.js',
279 'Data/WatchList.js',
280 'Data/WatchObject.js',
281 'Data/Binding.js',
282 'Data/Logic.js',
283 'Data/Json.js',
284 'Data/Remote.js',
285 'Data/DateTime.js',
286 'Ui/MimeTypes.js',
287 'Ui/XElement.js',
288 'Ui/Html.js',
289 'Ui/Dom.js',
290 'Ui/Style.js',
291 'Ui/Extensions/Lookup.js',
292 'Ui/Extensions/Layout.js',
293 'Ui/Text.js',
294 'Ui/Styles/SimpleStyles.js',
295 'Ui/Widgets/WidgetBase.js',
296 'Ui/Widgets/WidgetPage.js',
297 'Ui/Widgets/WidgetComponents.js',
298 'Ui/Widgets/WidgetControl.js',
299 'Ui/Widgets/WidgetEditor.js',
300 'Ui/Widgets/WidgetTable.js',
301 'Ui/Widgets/WidgetField.js',
302 'Ui/Widgets/WidgetEditable.js',
303 'Ui/Widgets/WidgetMenu.js',
304 'Ui/Widgets/WidgetGrid.js'))
306 ie_compatibility = rjs_bundle('ie_compatibility', 'js/selectivizr.js')
308 jed = rjs_bundle('jed', 'js/lib/jed.js')
309 moment = rjs_bundle('moment', *namespace('js/moment', 'moment.js', 'locale/es.js', 'locale/fr.js'))
311 jqplot_js = rjs_bundle('jqplot',
312 *namespace('js/lib/jqplot',
313 'core/jqplot.core.js',
314 'core/jqplot.linearTickGenerator.js',
315 'core/jqplot.linearAxisRenderer.js',
316 'core/jqplot.axisTickRenderer.js',
317 'core/jqplot.axisLabelRenderer.js',
318 'core/jqplot.tableLegendRenderer.js',
319 'core/jqplot.lineRenderer.js',
320 'core/jqplot.markerRenderer.js',
321 'core/jqplot.divTitleRenderer.js',
322 'core/jqplot.canvasGridRenderer.js',
323 'core/jqplot.linePattern.js',
324 'core/jqplot.shadowRenderer.js',
325 'core/jqplot.shapeRenderer.js',
326 'core/jqplot.sprintf.js',
327 'core/jsdate.js',
328 'core/jqplot.themeEngine.js',
329 'core/jqplot.toImage.js',
330 'core/jqplot.effects.core.js',
331 'core/jqplot.effects.blind.js',
332 # hardcoded list since globbing doesn't have a fixed order across machines
333 'plugins/axis/jqplot.canvasAxisLabelRenderer.js',
334 'plugins/axis/jqplot.canvasAxisTickRenderer.js',
335 'plugins/axis/jqplot.categoryAxisRenderer.js',
336 'plugins/axis/jqplot.dateAxisRenderer.js',
337 'plugins/axis/jqplot.logAxisRenderer.js',
338 'plugins/bar/jqplot.barRenderer.js',
339 'plugins/cursor/jqplot.cursor.js',
340 'plugins/highlighter/jqplot.highlighter.js',
341 'plugins/points/jqplot.pointLabels.js',
342 'plugins/text/jqplot.canvasTextRenderer.js'))
344 jqplot_css = Bundle(
345 'css/lib/jquery.jqplot.css',
346 filters='cssmin', output='css/jqplot_%(version)s.min.css'
349 mathjax_js = rjs_bundle('mathjax', 'js/lib/mathjax/MathJax.js', 'js/custom/pagedown_mathjax.js')
350 contributions_js = rjs_bundle('contributions', 'js/indico/Display/contributions.js')
352 abstracts_js = rjs_bundle(
353 'abstracts',
354 contributions_js,
355 'js/indico/Management/abstracts.js',
356 *namespace('js/lib/pagedown',
357 'Markdown.Converter.js',
358 'Markdown.Editor.js',
359 'Markdown.Sanitizer.js'))
361 base_js = Bundle(jquery, angular, jed, utils, presentation, calendar, indico_jquery, moment,
362 indico_core, indico_legacy, indico_common)
364 module_js = {
365 'vc': rjs_bundle('modules_vc', 'js/indico/modules/vc.js'),
366 'event_display': rjs_bundle('modules_event_display', 'js/indico/modules/eventdisplay.js'),
367 'attachments': rjs_bundle('modules_attachments', 'js/indico/modules/attachments.js')
370 SASS_BASE_MODULES = ["sass/*.scss",
371 "sass/base/*.scss",
372 "sass/custom/*.scss",
373 "sass/partials/*.scss"]
376 def sass_module_bundle(module_name, depends=[]):
377 return Bundle('sass/modules/_{0}.scss'.format(module_name),
378 filters=("pyscss", "cssrewrite", "cssmin"),
379 output="sass/{0}_%(version)s.min.css".format(module_name),
380 depends = SASS_BASE_MODULES + ['sass/modules/{0}/*.scss'.format(module_name)] + depends)
382 agreements_sass = sass_module_bundle('agreements')
383 attachments_sass = sass_module_bundle('attachments')
384 contributions_sass = sass_module_bundle('contributions')
385 registrationform_sass = sass_module_bundle('registrationform')
386 roombooking_sass = sass_module_bundle('roombooking')
387 dashboard_sass = sass_module_bundle('dashboard')
388 category_sass = sass_module_bundle('category')
389 admin_sass = sass_module_bundle('admin')
390 eventservices_sass = sass_module_bundle('eventservices')
391 event_display_sass = sass_module_bundle('event_display')
392 event_management_sass = sass_module_bundle('event_management')
393 overviews_sass = sass_module_bundle('overviews')
394 vc_sass = sass_module_bundle('vc')
395 news_sass = sass_module_bundle('news')
396 users_sass = sass_module_bundle('users')
397 auth_sass = sass_module_bundle('auth')
399 screen_sass = Bundle('sass/screen.scss',
400 filters=("pyscss", "cssrewrite", "cssmin"),
401 output="sass/screen_sass_%(version)s.css",
402 depends=SASS_BASE_MODULES)
405 def register_all_js(env):
406 env.register('jquery', jquery)
407 env.register('utils', utils)
408 env.register('presentation', presentation)
409 env.register('indico_core', indico_core)
410 env.register('indico_management', indico_management)
411 env.register('indico_roombooking', indico_room_booking)
412 env.register('indico_admin', indico_admin)
413 env.register('indico_timetable', indico_timetable)
414 env.register('indico_legacy', indico_legacy)
415 env.register('indico_common', indico_common)
416 env.register('indico_materialeditor', indico_materialeditor)
417 env.register('indico_display', indico_display)
418 env.register('indico_jquery', indico_jquery)
419 env.register('indico_authors', indico_jquery_authors)
420 env.register('indico_badges_js', indico_badges_js)
421 env.register('indico_regform', indico_regform)
422 env.register('base_js', base_js)
423 env.register('ie_compatibility', ie_compatibility)
424 env.register('abstracts_js', abstracts_js)
425 env.register('contributions_js', contributions_js)
426 env.register('mathjax_js', mathjax_js)
427 env.register('jqplot_js', jqplot_js)
428 env.register('zero_clipboard_js', zero_clipboard_js)
429 env.register('dropzone_js', dropzone_js)
431 for key, bundle in module_js.iteritems():
432 env.register('modules_{}_js'.format(key), bundle)
435 def register_all_css(env, main_css_file):
437 base_css = Bundle(
438 *namespace('css',
439 main_css_file,
440 'calendar-blue.css',
441 'jquery-ui.css',
442 'lib/angular.css',
443 'lib/jquery.qtip.css',
444 'lib/jquery.multiselect.css',
445 'lib/jquery.multiselect.filter.css',
446 'lib/jquery.typeahead.css',
447 'jquery.colorbox.css',
448 'jquery-ui-custom.css',
449 'jquery.qtip-custom.css',
450 'jquery.colorpicker.css'),
451 filters=("cssmin", "cssrewrite"),
452 output='css/base_%(version)s.min.css')
454 env.register('base_css', base_css)
455 env.register('indico_badges_css', indico_badges_css)
456 env.register('jqplot_css', jqplot_css)
457 env.register('dropzone_css', dropzone_css)
459 # SASS/SCSS
460 env.register('agreements_sass', agreements_sass)
461 env.register('attachments_sass', attachments_sass)
462 env.register('registrationform_sass', registrationform_sass)
463 env.register('roombooking_sass', roombooking_sass)
464 env.register('contributions_sass', contributions_sass)
465 env.register('dashboard_sass', dashboard_sass)
466 env.register('category_sass', category_sass)
467 env.register('admin_sass', admin_sass)
468 env.register('screen_sass', screen_sass)
469 env.register('eventservices_sass', eventservices_sass)
470 env.register('event_display_sass', event_display_sass)
471 env.register('event_management_sass', event_management_sass)
472 env.register('overviews_sass', overviews_sass)
473 env.register('vc_sass', vc_sass)
474 env.register('news_sass', news_sass)
475 env.register('users_sass', users_sass)
476 env.register('auth_sass', auth_sass)
479 core_env = IndicoEnvironment()