def get_main_group(): """ Return the main resource Group that will be used on all pages """ # UnPackaged external libraries font_awesome_css = get_resource("css/font-awesome.min.css") underscore = get_resource("js/vendors/underscore.js", minified="js/vendors/underscore-min.js") main_js = get_resource("js/main.js", depends=[ui_dialog, ui_sortable, underscore]) main_css = get_resource("css/main.css", depends=[ bootstrap, jqueryui_bootstrap_theme, font_awesome_css, ]) _date = get_resource("js/date.js", depends=[timepicker_js]) _dom = get_resource("js/dom.js", depends=[jquery]) _math = get_resource("js/math.js") js_tools = Group([_dom, _math, _date]) return Group([ main_js, main_css, js_tools, jquery_form, ui_datepicker_fr, ])
def get_main_group(): """ Return the main resource Group that will be used on all pages """ # UnPackaged external libraries underscore = get_resource("js/vendors/underscore.js", minified="js/vendors/underscore-min.js") main_js = get_resource("js/main.js", depends=[ ui_dialog, ui_sortable, underscore, timepicker_js, bootstrap, _math, ]) js_tools = Group([main_js, _dom, _math, _date, select2]) return Group([ main_css, js_tools, jquery_form, ui_datepicker_fr, ])
def test_convenience_group_resource_need(): foo = Library('foo', '') x1 = Resource(foo, 'a.js') x2 = Resource(foo, 'b.css') y1 = Resource(foo, 'c.js') group = Group([x1, x2, y1]) needed = init_needed() assert get_needed() == needed assert get_needed().resources() == [] group.need() assert get_needed().resources() == [x2, x1, y1]
def get_module_group(): """ Return main libraries used in custom modules (backbone marionette and handlebar stuff) NB : depends on the main_group """ handlebar = get_resource("js/vendors/handlebars.runtime.js") backbone = get_resource( "js/vendors/backbone.js", minified="js/vendors/backbone-min.js", depends=[main_group], ) backbone_marionnette = get_resource( "js/vendors/backbone.marionette.js", minified="js/vendors/backbone.marionette.min.js", depends=[backbone] ) # Bootstrap form validation stuff backbone_validation = get_resource( "js/vendors/backbone-validation.js", minified="js/vendors/backbone-validation-min.js", depends=[backbone] ) backbone_validation_bootstrap = get_resource( "js/backbone-validation-bootstrap.js", depends=[backbone_validation] ) # Popup object backbone_popup = get_resource( "js/backbone-popup.js", depends=[backbone_marionnette] ) # Some specific tuning backbone_tuning = get_resource( "js/backbone-tuning.js", depends=[backbone_marionnette, handlebar] ) # The main templates main_templates = get_resource( "js/template.js", depends=[handlebar] ) # Messages message_js = get_resource( "js/message.js", depends=[handlebar] ) return Group( [ backbone_marionnette, backbone_validation_bootstrap, backbone_tuning, backbone_popup, main_templates, effects_highlight, effects_shake, message_js, ] )
def test_depend_on_group(): foo = Library('foo', '') a = Resource(foo, 'a.js') b = Resource(foo, 'b.js') g = Group([a, b]) c = Resource(foo, 'c.js', depends=[g]) g2 = Group([g]) g3 = Group([g, g2]) assert c.depends == set([a, b]) assert g2.depends == set([a, b]) assert g3.depends == set([a, b]) needed = NeededResources() needed.need(c) assert needed.resources() == [a, b, c]
def test_add_dependency_group_to_resource(): foo = Library('foo', '') a1 = Resource(foo, 'a1.js') b1 = Resource(foo, 'b1.js', depends=[a1]) c1 = Resource(foo, 'c1.js', depends=[b1]) assert a1.depends == set([]) assert a1.resources == set([a1]) assert b1.depends == set([a1]) assert b1.resources == set([a1, b1]) assert c1.depends == set([b1]) assert c1.resources == set([a1, b1, c1]) a2 = Resource(foo, 'a2.js') a3 = Group([a1, a2]) b1.add_dependency(a3) assert b1.depends == set([a1, a3]) assert b1.resources == set([a1, a2, b1]) assert c1.depends == set([b1]) assert c1.resources == set([a1, a2, b1, c1]) # Adding it twice does not change anything. b1.add_dependency(a3) assert b1.depends == set([a1, a3]) assert b1.resources == set([a1, a2, b1]) assert c1.depends == set([b1]) assert c1.resources == set([a1, a2, b1, c1])
def group(self, name, items): items = [ self.resources[i] if isinstance(i, basestring) else i for i in items ] group = self.resources[name] = Group(items) return group
def get_test_resource(): res = [] for i in ('math', 'date', 'dom'): res.append( get_resource("js/tests/test_%s.js" % i, depends=(jquery_qunit, main_group))) return Group(res)
def test_group_resource(): foo = Library('foo', '') x1 = Resource(foo, 'a.js') x2 = Resource(foo, 'b.css') group = Group([x1, x2]) needed = NeededResources() needed.need(group) assert group.resources == set([x1, x2]) more_stuff = Resource(foo, 'more_stuff.js', depends=[group]) assert more_stuff.resources == set([x1, x2, more_stuff])
def get_fanstatic_resources(request): global olimgpath_js olimgpath = request.static_url('c2cgeoportal:static/lib/openlayers/img/') def olimgpath_renderer(url): return '<script>OpenLayers.ImgPath="%s";</script>' % olimgpath if olimgpath_js is None: olimgpath_js = Resource( fanstatic_lib, 'whatever.js', renderer=olimgpath_renderer, depends=[admin_js]) return Group([admin_js, olimgpath_js, admin_css])
def bootstrap_select_i18n_js(lang=None): if lang in ALL_LANGS: return Resource( library, 'js/i18n/defaults-%s.js' % lang, minified='js/i18n/defaults-%s.min.js' % lang, depends=[bootstrap_select_js,]) else: all_langs = [ Resource( library, 'js/i18n/defaults-%s.js' % l, minified='js/i18n/defaults-%s.min.js' % l, depends=[bootstrap_select_js, ]) for l in ALL_LANGS ] return Group(all_langs)
# -*- coding: utf-8 -*- """ Created on 2016-06-15 :author: Oshane Bailey ([email protected]) """ from __future__ import absolute_import from fanstatic import Group from fanstatic import Library from fanstatic import Resource library = Library("kotti_controlpanel", "static") css = Resource(library, "styles.css", minified="styles.min.css") js = Resource(library, "scripts.js", minified="scripts.min.js") css_and_js = Group([css, js])
blueimp_gallery_js = Resource( library, 'blueimp-gallery/js/blueimp-gallery.js', minified='blueimp-gallery/js/blueimp-gallery.min.js', depends=[ jquery, ]) jquery_blueimp_gallery_js = Resource( library, 'blueimp-gallery/js/jquery.blueimp-gallery.js', minified='blueimp-gallery/js/jquery.blueimp-gallery.min.js', depends=[ blueimp_gallery_js, ]) bootstrap_image_gallery_js = Resource( library, 'blueimp-bootstrap-image-gallery/js/bootstrap-image-gallery.js', minified= 'blueimp-bootstrap-image-gallery/js/bootstrap-image-gallery.min.js', # noqa depends=[ bootstrap_js, jquery_blueimp_gallery_js, ]) # BW COMPAT gallery_css = bootstrap_image_gallery_css gallery_js = bootstrap_image_gallery_js # THE "ALL IN ONE" RESOURCE gallery = Group([bootstrap_image_gallery_css, bootstrap_image_gallery_js])
from fanstatic import Resource, Group, Library library = Library('dummy', '.') library.need = lambda: 'No, sorry, that is a Library.' resource = Resource(library, 'fanstatic_dummy_resource.css') resource.need = lambda: 'needed resource' group = Group([resource]) group.need = lambda: 'needed group'
# -*- coding: utf-8 -*- from fanstatic import Group from js.ui_bootstrap import ui_bootstrap from js.angular import angular, angular_sanitize, angular_route from js.momentjs import moment_timezone_with_data from js.underscore import underscore from js.fontawesome import fontawesome __author__ = 'viruzzz-kun' group = Group([ ui_bootstrap, angular, angular_sanitize, angular_route, moment_timezone_with_data, underscore, fontawesome ])
"deform", "static") library = Library( "deform", deform_dir) deform_js = Resource( library, "scripts/deform.js", depends=[jquery, ]) deform_form_css = Resource( library, "css/form.css") deform_css = Group([deform_form_css, ]) deform_basic = Group([deform_form_css, deform_js, ]) deform = Group([deform_css, deform_js, ]) modernizr = Resource( library, 'scripts/modernizr.custom.input-types-and-atts.js') typeahead_js = Resource( library, 'scripts/typeahead.min.js', depends=[jquery, ]) typeahead_css = Resource( library, 'css/typeahead.css')
from fanstatic import Library, Resource, Group from js.jquery import jquery from js.jqueryui import jqueryui library = Library("fileupload", "resource_library") ui_css = Resource(library, "jquery.fileupload-ui.css") js = Resource(library, "jquery.fileupload.js", depends=[jquery]) ui_js = Resource(library, "jquery.fileupload-ui.js", depends=[js, ui_css, jqueryui]) transport = Resource(library, "jquery.iframe-transport.js") fileupload_resources = Group([ui_css, ui_js, js, transport])
social_privacy_css = Resource( library, "socialshareprivacy/socialshareprivacy.css", minified='socialshareprivacy/socialshareprivacy.min.css', bottom=True ) social_privacy_js = Resource( library, "socialshareprivacy/jquery.socialshareprivacy.js", minified='socialshareprivacy/jquery.socialshareprivacy.min.js', depends=[social_privacy_css], bottom=True ) social_privacy_en_js = Resource( library, "socialshareprivacy/jquery.socialshareprivacy.en.js", minified='socialshareprivacy/jquery.socialshareprivacy.en.min.js', depends=[social_privacy_js], bottom=True ) social_privacy_de_js = Resource( library, "socialshareprivacy/jquery.socialshareprivacy.de.js", minified='socialshareprivacy/jquery.socialshareprivacy.de.min.js', depends=[social_privacy_js], bottom=True ) view_css_and_js = Group([social_privacy_css, social_privacy_js])
from fanstatic import Library, Group, Resource, init_needed # external libraries from js.jquery import jquery from js.jquery_joyride import joyride from js.socialshareprivacy import socialshareprivacy # --[ yaml ]---------------------------------------------------------------- yaml_library = Library('yaml', 'yaml', version="3.2.1") yaml_base = Resource(yaml_library, 'core/base.css') yaml_print = Resource(yaml_library, 'print/print_draft.css', depends=[yaml_base]) yaml = Group([yaml_base, yaml_print]) # --[ twitter bootstrap ]--------------------------------------------------- bootstrap_library = Library('bootstrap', 'bootstrap', version="2.1.1") bootstrap_js = Resource(bootstrap_library, 'js/bootstrap.js', minified='js/bootstrap.min.js', depends=[jquery]) bootstrap_css = Resource(bootstrap_library, 'css/bootstrap.css', minified='css/bootstrap.min.css', depends=[yaml]) # include it after yaml bootstrap = Group([bootstrap_js, bootstrap_css]) # --[ stylesheets ]--------------------------------------------------------- stylesheets_library = Library('stylesheets', 'stylesheets')
from fanstatic import Group from fanstatic import Library from fanstatic import Resource from js.angular import angular library = Library('angularui', 'resources') angular_ui_css = Resource(library, 'angular-ui.css', minified='angular-ui.min.css') angular_ui_js = Resource(library, 'angular-ui.js', minified='angular-ui.min.js', depends=[angular]) angular_ui_ieshiv_js = Resource(library, 'angular-ui-ieshiv.js', minified='angular-ui-ieshiv.min.js', depends=[angular_ui_js]) angular_ui = Group([angular_ui_css, angular_ui_js]) angular_ui_ieshiv = Group([angular_ui_css, angular_ui_ieshiv_js])
from js.angular import angular from js.bootstrap import bootstrap_js from js.bootstrap import bootstrap_css from js.html5shiv import html5shiv from js.fineuploader import fineuploader from js.jquery import jquery from js.jquery_form import jquery_form from js.jquery_tablednd import jquery_tablednd from js.jqueryui import bootstrap as jqueryui_bootstrap_theme from js.jqueryui_tagit import tagit as ui_tagit # This is needed until ``kotti.views.form.deferred_tag_it_widget`` is converted # to a class with a ``requirements`` attribute (that would be auto_needed by # ``js.deform[_bootstrap]``). tagit = Group([ui_tagit, jqueryui_bootstrap_theme]) # Kotti's resources lib_kotti = Library("kotti", "static") contents_view_js = Resource( lib_kotti, "contents.js", depends=[jquery_tablednd, ], minified="contents.min.js", bottom=True) base_css = Resource( lib_kotti, "base.css", depends=[bootstrap_css], minified="base.min.css", dont_bundle=True)
from __future__ import absolute_import from fanstatic import Group from fanstatic import Library from fanstatic import Resource from js.jquery import jquery library = Library("kotti_quiz", "static") kotti_quiz_css = Resource(library, "style.css") kotti_quiz_js = Resource(library, "quiz.js", depends=[jquery]) kotti_quiz_group = Group([kotti_quiz_css, kotti_quiz_js])
def need(self): # pragma: no cover # this is tested in fanstatic itself; we should add browser tests # for `view_needed` and `edit_needed` (see below) Group(self.resources).need()
cbs = Resource(library, 'jasny-bootstrap.css') bootstrap_css = Resource(library, 'bootstrap_bundle.css', compiler='less', source='bootstrap_bundle.less') siguv_css = Resource(library, 'siguv.css', compiler='less', source='siguv.less') maincss = Resource(library, 'main.css', depends=[bootstrap_css, siguv_css]) mainjs = Resource(library, 'main.js', bottom=True) #siguvcss = Resource(library, 'siguvtheme.css') tune = Group([maincss, cbs, jbs, mainjs, jsbs]) datepicker_css = Resource(library, path.join('datepicker', 'bootstrap-datepicker.css')) datepicker = Resource(library, path.join('datepicker', 'bootstrap-datepicker.js'), depends=[datepicker_css]) datepicker_de = Resource(library, path.join('datepicker', 'locales', 'bootstrap-datepicker.de.js'), depends=[datepicker]) datepicker_fr = Resource(library, path.join('datepicker', 'locales',
return Group([ main_css, js_tools, jquery_form, ui_datepicker_fr, ]) main_group = get_main_group() opa_group = get_opa_group() jstree_js = get_resource("js/vendors/jstree.js", minified="js/vendors/jstree.min.js", depends=[main_group]) jstree_css = get_resource("css/jstree_themes/default/style.css") jstree = Group([jstree_js, jstree_css]) def get_module_group(): """ Return main libraries used in custom modules (backbone marionette and handlebar stuff) NB : depends on the main_group """ handlebar = get_resource("js/vendors/handlebars.runtime.js") backbone = get_resource( "js/vendors/backbone.js", minified="js/vendors/backbone-min.js", depends=[main_group], )
from __future__ import absolute_import from fanstatic import Group from fanstatic import Library from fanstatic import Resource library = Library("kotti_mb", "static") kotti_mb_css = Resource(library, "css/styles.css") kotti_mb_js_holder = Resource(library, "assets/js/holder.js") kotti_mb_js = Resource(library, "assets/js/bootstrap.min.js") kotti_mb_group = Group([kotti_mb_css])
jqgrid_i18n_gl = Resource(library, 'js/i18n/grid.locale-gl.js') jqgrid_i18n_he = Resource(library, 'js/i18n/grid.locale-he.js') jqgrid_i18n_hr = Resource(library, 'js/i18n/grid.locale-hr.js') jqgrid_i18n_hr1250 = Resource(library, 'js/i18n/grid.locale-hr1250.js') jqgrid_i18n_hu = Resource(library, 'js/i18n/grid.locale-hu.js') jqgrid_i18n_is = Resource(library, 'js/i18n/grid.locale-is.js') jqgrid_i18n_it = Resource(library, 'js/i18n/grid.locale-it.js') jqgrid_i18n_ja = Resource(library, 'js/i18n/grid.locale-ja.js') jqgrid_i18n_kr = Resource(library, 'js/i18n/grid.locale-kr.js') jqgrid_i18n_lt = Resource(library, 'js/i18n/grid.locale-lt.js') jqgrid_i18n_mne = Resource(library, 'js/i18n/grid.locale-mne.js') jqgrid_i18n_nl = Resource(library, 'js/i18n/grid.locale-nl.js') jqgrid_i18n_no = Resource(library, 'js/i18n/grid.locale-no.js') jqgrid_i18n_pl = Resource(library, 'js/i18n/grid.locale-pl.js') jqgrid_i18n_pt_br = Resource(library, 'js/i18n/grid.locale-pt-br.js') jqgrid_i18n_pt = Resource(library, 'js/i18n/grid.locale-pt.js') jqgrid_i18n_ro = Resource(library, 'js/i18n/grid.locale-ro.js') jqgrid_i18n_ru = Resource(library, 'js/i18n/grid.locale-ru.js') jqgrid_i18n_sk = Resource(library, 'js/i18n/grid.locale-sk.js') jqgrid_i18n_sr = Resource(library, 'js/i18n/grid.locale-sr.js') jqgrid_i18n_sr_latin = Resource(library, 'js/i18n/grid.locale-sr-latin.js') jqgrid_i18n_sv = Resource(library, 'js/i18n/grid.locale-sv.js') jqgrid_i18n_th = Resource(library, 'js/i18n/grid.locale-th.js') jqgrid_i18n_tr = Resource(library, 'js/i18n/grid.locale-tr.js') jqgrid_i18n_tw = Resource(library, 'js/i18n/grid.locale-tw.js') jqgrid_i18n_ua = Resource(library, 'js/i18n/grid.locale-ua.js') jqgrid_css = Resource(library, 'css/ui.jqgrid.css') jqgrid = Group([jqgrid_js, jqgrid_css])
from __future__ import absolute_import from fanstatic import Group from fanstatic import Library from fanstatic import Resource from js.jquery import jquery library = Library('kotti_grid', 'static') css = Resource(library, 'css/style.css', minified='css/style.min.css') js = Resource(library, "js/script.js", minified="js/script.min.js", depends=[jquery]) kotti_grid = Group([ css, js, ])
from __future__ import absolute_import from fanstatic import Group from fanstatic import Library from fanstatic import Resource library = Library('kotti_navigation', 'static') css = Resource(library, 'css/style.css', minified='css/style.min.css') kotti_navigation = Group([ css, ])
def create_library(name, path, depend_base=True): ''' Creates a fanstatic library `name` with the contents of a directory `path` using resource.config if found.''' def get_resource(lib_name, resource_name): ''' Attempt to get the resource from the current lib or if not try assume it is a fully qualified resource name. ''' try: res = getattr(module, '%s/%s' % (lib_name, resource_name)) except AttributeError: res = getattr(module, '%s' % resource_name) return res def create_resource(path, lib_name, count, inline=False): ''' create the fanstatic Resource ''' renderer = None kw = {} if not inline: # resource_name is name of the file without the .js/.css rel_path, filename = os.path.split(path) filename = os.path.join(rel_path, filename) path_min = min_path(os.path.join(resource_path, filename)) if os.path.exists(path_min): kw['minified'] = min_path(filename) if filename.endswith('.js'): renderer = core.render_js if path not in force_top: kw['bottom'] = True if filename.endswith('.css'): renderer = core.render_css core.set_resource_file_existence_checking(True) else: # This doesn't exist so stop fanstatic checking the filesystem if path not in force_top: kw['bottom'] = True core.set_resource_file_existence_checking(False) dependencies = [] if path in depends: for dependency in depends[path]: dependencies.append(get_resource(name, dependency)) if depend_base: dependencies.append(getattr(module, 'base/main')) if dependencies: kw['depends'] = dependencies if path in dont_bundle: kw['dont_bundle'] = True # IE conditionals condition = None other_browsers = False if path in IE_conditionals: other_browsers = ('others' in IE_conditionals[path]) condition = IE_conditionals[path][0] if inline or condition: kw['renderer'] = fanstatic_extensions.CkanCustomRenderer( condition=condition, script=inline, renderer=renderer, other_browsers=other_browsers) resource = Resource(library, path, **kw) # Add our customised ordering if path in custom_render_order: resource.order = custom_render_order[path] resource.custom_order = count # Update the attributes of the minified version of the resource to # that of the parents as fanstatic does not pass these on. update_attributes = [ 'custom_order', 'order', 'bottom', 'depends', 'dont_bundle', 'renderer' ] if 'minified' in resource.modes: min_res = resource.modes['minified'] for attribute in update_attributes: setattr(min_res, attribute, getattr(resource, attribute)) # add the resource to this module fanstatic_name = '%s/%s' % (lib_name, path) #log.debug('create resource %s' % fanstatic_name) setattr(module, fanstatic_name, resource) return resource resource_path = os.path.join(os.path.dirname(__file__), path) library = Library(name, path) module = sys.modules[__name__] # config options order = [] dont_bundle = [] force_top = [] depends = {} groups = {} IE_conditionals = {} custom_render_order = {} inline_scripts = {} # parse the resource.config file if it exists config_path = os.path.join(resource_path, 'resource.config') if os.path.exists(config_path): config = ConfigParser.RawConfigParser() config.read(config_path) if config.has_option('main', 'order'): order = config.get('main', 'order').split() if config.has_option('main', 'dont_bundle'): dont_bundle = config.get('main', 'dont_bundle').split() if config.has_option('main', 'force_top'): force_top = config.get('main', 'force_top').split() if config.has_section('depends'): items = config.items('depends') depends = dict((n, v.split()) for (n, v) in items) if config.has_section('groups'): items = config.items('groups') groups = dict((n, v.split()) for (n, v) in items) if config.has_section('custom render order'): items = config.items('custom render order') custom_render_order = dict((n, int(v)) for (n, v) in items) if config.has_section('inline scripts'): items = config.items('inline scripts') inline_scripts = dict((n, v) for (n, v) in items) if config.has_section('IE conditional'): items = config.items('IE conditional') for (n, v) in items: files = v.split() for f in files: if f not in IE_conditionals: IE_conditionals[f] = [] IE_conditionals[f].append(n) # add dependencies for resources in groups for group in groups: if group in depends: for resource in groups[group]: if resource not in depends: depends[resource] = [] for dep in depends[group]: if dep not in depends[resource]: depends[resource].append(dep) # process each .js/.css file found resource_list = [] for dirname, dirnames, filenames in os.walk(resource_path): for f in filenames: rel_path = dirname[len(path):] if rel_path: rel_path = rel_path[1:] filepath = os.path.join(rel_path, f) filename_only, extension = os.path.splitext(f) if extension in ('.css', '.js') and (not filename_only.endswith('.min')): resource_list.append(filepath) # if groups are defined make sure the order supplied there is honored for group in groups: for resource in groups[group]: if resource not in order: # make sure any dependencies are met when we get to creating # the resource if resource in depends: for dep in depends[resource]: if dep not in order: order.append(dep) order.append(resource) # add inline scripts for inline in inline_scripts: resource_list.append(inline) if inline not in custom_render_order: custom_render_order[inline] = 20 # order resource_list so that resources are created in the correct order for resource_name in reversed(order): if resource_name in resource_list: resource_list.remove(resource_name) resource_list.insert(0, resource_name) # create the resources and keep them ordered as we define them. count = 0 for resource_name in resource_list: if resource_name in inline_scripts: inline = inline_scripts[resource_name].strip() else: inline = None create_resource(resource_name, name, count, inline=inline) count += 1 # add groups for group_name in groups: members = [] for member in groups[group_name]: fanstatic_name = '%s/%s' % (name, member) members.append(getattr(module, fanstatic_name)) group = Group(members) fanstatic_name = '%s/%s' % (name, group_name) setattr(module, fanstatic_name, group) # finally add the library to this module setattr(module, name, library) # add to fanstatic registry = get_library_registry() registry.add(library)
def get_opa_group(): """ Return the resources used on one page applications pages """ # js_tools = Group([_date]) return Group([main_css, opa_css, opa_vendor_js, base_setup_js])