def test_convenience_need(): foo = Library('foo', '') x1 = Resource(foo, 'a.js') x2 = Resource(foo, 'b.css') y1 = Resource(foo, 'c.js', depends=[x1, x2]) needed = init_needed() assert get_needed() == needed assert get_needed().resources() == [] y1.need() assert get_needed().resources() == [x2, x1, y1]
def test_resource_need_should_pass_slots_to_needed(): import fanstatic lib = Library("lib", "") c = Resource(lib, "c.js") slot = Slot(lib, ".js", depends=[c]) a = Resource(lib, "a.js", depends=[slot]) b = Resource(lib, "b.js", depends=[c]) needed = fanstatic.init_needed() try: a.need({slot: c}) finally: fanstatic.del_needed() assert slot in needed._slots
def test_convenience_clear(): foo = Library('foo', '') x1 = Resource(foo, 'a.js') x2 = Resource(foo, 'b.css') y1 = Resource(foo, 'c.js', depends=[x1, x2]) z1 = Resource(foo, 'd.js') z2 = Resource(foo, 'e.js', depends=[z1, x1]) needed = init_needed(resources=[y1]) assert sort_resources(needed.resources()) == [x2, x1, y1] # For some reason,for example an error page needs to be rendered, # the currently needed resources need to be cleared. clear_needed() assert len(needed.resources()) == 0 z2.need() assert sort_resources(needed.resources()) == [x1, z1, z2]
class TestUnicodeError(unittest.TestCase): _custom_config = { 'fanstatic.publisher_signature': 'custom_sign', } def setUp(self): from fanstatic import Library, Resource from fanstatic import set_resource_file_existence_checking set_resource_file_existence_checking(False) self.lib = Library('foo', '') # When the resources contains an unicode string fanstatic may break # if the HTML is only str. self.resource = Resource(self.lib, u'resource.js') self.config = testing.setUp() self.config.registry.settings.update(self._custom_config) self.config.include("pyramid_fanstatic") self.config.add_route('home', '/') self.config.add_view(route_name='home', view=self.home) self.app = TestApp(self.config.make_wsgi_app()) def home(self, request): resp = request.response resp.content_type = 'text/html; charset=utf-8' resp.body = '''\ <html> <head> </head> <body> <p>Voil\xc3\xa0 !</p> </body> </html> ''' self.resource.need() return resp def test_unicode_error_should_not_be_raised(self): self.app.get('/') def tearDown(self): from fanstatic import set_resource_file_existence_checking testing.tearDown() set_resource_file_existence_checking(True)
def test_logging_when_compiling(tmpdir, compilers, caplog): class WhiteSpaceRemover(fanstatic.compiler.Compiler): """A silly minifier, to showcase logging.""" name = 'whitespace' source_extension = '.frop' def process(self, source, target): with open(target, 'wb') as output: output.write(compat.as_bytestring( open(source, 'r').read().replace(' ', ''))) compilers.add_compiler(WhiteSpaceRemover()) lib = Library('lib', str(tmpdir)) tmpdir.join('a.frop').write(' foo bar baz ') a = Resource(lib, 'a.js', compiler='whitespace') assert len(caplog.records()) == 0 a.compile() assert len(caplog.records()) == 1 assert "Compiling <Resource 'a.js' in library 'lib'> in" in caplog.text() # The 'compiler' really worked! assert tmpdir.join('a.js').read() == 'foobarbaz'
def setUp(self): from fanstatic import Library, Resource from fanstatic import set_resource_file_existence_checking set_resource_file_existence_checking(False) self.lib = Library('foo', '') # When the resources contains an unicode string fanstatic may break # if the HTML is only str. self.resource = Resource(self.lib, u'resource.js') self.config = testing.setUp() self.config.registry.settings.update(self._custom_config) self.config.include("pyramid_fanstatic") self.config.add_route('home', '/') self.config.add_view(route_name='home', view=self.home) self.app = TestApp(self.config.make_wsgi_app())
# -*- coding: utf-8 -*- from fanstatic import Library from fanstatic import Resource from js.jquery import jquery library = Library('mediaelement.js', 'resources') mediaelement_js = Resource(library, 'mediaelement.js', minified="mediaelement.min.js") mediaelementplayer_css = Resource(library, 'mediaelementplayer.css', minified="mediaelementplayer.min.css") mediaelementplayer_js = Resource(library, 'mediaelementplayer.js', minified="mediaelementplayer.min.js", depends=[ jquery, ]) mediaelementandplayer = Resource(library, 'mediaelement-and-player.js', minified="mediaelement-and-player.min.js", depends=[ jquery, mediaelementplayer_css, ])
def R(path, *args, **kwargs): minified = os.path.join(fa_library.path, 'min', path) if os.path.isfile(minified): kwargs['minified'] = 'min/%s' % path return Resource(fa_library, path, *args, **kwargs)
from fanstatic import Library, Resource, Group from js.jquery import jquery from js.jquery_cookie import cookie library = Library('foundation', 'resources') # 3rd party modernizr = Resource(library, 'js/modernizr.foundation.js') placeholder = Resource(library, 'js/jquery.placeholder.js') # initialize plugins app = Resource(library, 'js/app.js', depends=[jquery, modernizr], bottom=True) app.order = 10000 # Push this to the bottom so plugins are all loaded beforehand # foundation.min.js includes all foundation js along with modernizr and jquery foundation_js = Resource(library, 'js/foundation.min.js', depends=[jquery, modernizr, app], bottom=True) foundation_css = Resource(library, 'css/app.css', minified='css/app.min.css') foundation = Group([foundation_js, foundation_css]) # Foundation accordion = Resource(library, 'js/jquery.foundation.accordion.js', depends=[jquery, modernizr], bottom=True) alerts = Resource(library, 'js/jquery.foundation.alerts.js', depends=[jquery], bottom=True) buttons = Resource(library, 'js/jquery.foundation.buttons.js', depends=[jquery], bottom=True) clearing = Resource(library, 'js/jquery.foundation.clearing.js', depends=[jquery], bottom=True) forms = Resource(library, 'js/jquery.foundation.forms.js', depends=[jquery], bottom=True) joyride = Resource(library, 'js/jquery.foundation.joyride.js', depends=[jquery, modernizr, cookie], bottom=True) magellan = Resource(library, 'js/jquery.foundation.magellan.js', depends=[jquery], bottom=True) mediaQueryToggle = Resource(library, 'js/jquery.foundation.mediaQueryToggle.js', depends=[jquery], bottom=True) navigation = Resource(library, 'js/jquery.foundation.navigation.js', depends=[jquery, modernizr], bottom=True) orbit = Resource(library, 'js/jquery.foundation.orbit.js', depends=[jquery], bottom=True) reveal = Resource(library, 'js/jquery.foundation.reveal.js', depends=[jquery], bottom=True)
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
# -*- coding: utf-8 -*- from fanstatic import Library, Resource from js.jquery import jquery library = Library('remote_wsgi', 'assets') js = Resource(library, 'menu.js', depends=[jquery]) css = Resource(library, 'menu.css')
from fanstatic import Library from fanstatic import Resource library = Library('fontawesome', 'resources') # CSS fontawesome = Resource( library, 'css/font-awesome.css', minified='css/font-awesome.min.css', )
def test_minifier_target_transforms_extension_if_no_name_given(): lib = Library('lib', '/foo') a = Resource(lib, 'a.js') minifier = Minifier() minifier.target_extension = '.min.js' assert minifier.target_path(a) == '/foo/a.min.js'
from fanstatic import Library from fanstatic import Resource library = Library('momentjs', 'resources') moment = Resource(library, 'moment.js') moment_with_locales = Resource( library, 'moment-with-locales.js', ) moment_timezone = Resource(library, 'moment-timezone.js', depends=[moment]) moment_timezone_with_data = Resource(library, 'moment-timezone-with-data.js', depends=[moment]) moment_timezone_with_data_2010_2020 = Resource( library, 'moment-timezone-with-data-2010-2020.js', depends=[moment])
def test_minifier_source_is_full_resource_path(): lib = Library('lib', '/foo') a = Resource(lib, 'a.js') minifier = Minifier() assert minifier.source_path(a) == '/foo/a.js'
def test_minifier_uses_minified_if_given_on_resource(): lib = Library('lib', '/foo') a = Resource(lib, 'a.js', minified='a.min.js') minifier = Minifier() assert minifier.target_path(a) == '/foo/a.min.js'
def test_compiler_source_transforms_extension_if_no_source_given(): lib = Library('lib', '/foo') a = Resource(lib, 'a.js') compiler = Compiler() compiler.source_extension = '.source' assert compiler.source_path(a) == '/foo/a.source'
def test_compiler_uses_source_if_given_on_resource(): lib = Library('lib', '/foo') a = Resource(lib, 'a.js', source='a.source') compiler = Compiler() assert compiler.source_path(a) == '/foo/a.source'
def test_compiler_target_is_full_resource_path(): lib = Library('lib', '/foo') a = Resource(lib, 'a.js') compiler = Compiler() assert compiler.target_path(a) == '/foo/a.js'
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) edit_css = Resource( lib_kotti, "edit.css", depends=[base_css], minified="edit.min.css") view_css = Resource( lib_kotti,
def test_minifier_available_and_minified_not_a_string_should_raise(compilers): compilers.add_minifier(MockMinifier()) lib = Library('lib', '') minified = Resource(lib, 'a.min.js') with pytest.raises(fanstatic.ConfigurationError) as exc: a = Resource(lib, 'a.js', minifier='mock', minified=minified)
def test_slot_with_default_can_not_set_required_explicitly(): lib = Library('lib', '') a = Resource(lib, 'a.js') with pytest.raises(ValueError): slot = Slot(lib, '.js', default=a, required=True)
import os from fanstatic import Library, Group, Resource library = Library('uni_form', 'resources') pth = library.path fnames = lambda subp, ext: [ fn for fn in os.listdir(library.path + os.sep + subp) if fn.endswith(ext) ] css_resources = [ Resource(library, 'css' + os.sep + fn) for fn in fnames('css', 'css') ] js_resources = [ Resource(library, 'js' + os.sep + fn) for fn in fnames('js', 'js') ] i18n_resources = [ Resource(library, 'localization' + os.sep + fn) for fn in fnames('localization', 'js') ] css = Group(css_resources) js = Group(js_resources) i18n = Group(i18n_resources) uni_form = Group([css, js, i18n])
# All rights reserved. # # This is free software; you can redistribute it and/or modify it under # the terms of the LICENCE attached in the distribution package. # # Created on 2013-05-27 from __future__ import (division as _py3_division, print_function as _py3_print, unicode_literals as _py3_unicode, absolute_import as _py3_abs_imports) from fanstatic import Library, Resource from js.jquery import jquery __author__ = "Manuel Vázquez Acosta <*****@*****.**>" __date__ = "Mon May 27 15:50:02 2013" lib = Library('js.typeahead', 'resources') typeahead_css = Resource(lib, 'css/typeahead.css', minified='css/typeahead.min.css') typeahead_bootstrap_css = Resource(lib, 'css/typeahead.js-bootstrap.css', depends=[typeahead_css]) typeahead_js = Resource(lib, 'js/typeahead.js', minified='js/typeahead.min.js', depends=[jquery])
from fanstatic import Group, Library, Resource from js.jquery import jquery library = Library('uploadify', 'resources') uploadify_css = Resource( library, 'uploadify.css', ) uploadify_js = Resource( library, 'jquery.uploadify.js', minified='jquery.uploadify.min.js', depends=[ jquery, uploadify_css, ], ) uploadify = Group([uploadify_js, uploadify_css])
from fanstatic import Library, Resource library = Library('partybuilder', 'static') bootstrap = Resource(library, 'bootstrap/bootstrap.css') style = Resource(library, 'style.css') jquery = Resource(library, 'jquery/jquery-3.2.1.min.js') js_utils = Resource(library, 'utils.js', depends=[jquery])
from fanstatic import Library, Group, Resource # 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 Library from fanstatic import Resource from js.deform import resource_mapping from kotti.resources import Content from kotti.resources import File from kotti.resources import Image from kotti.util import _ from kotti.util import title_to_name from pyramid.httpexceptions import HTTPFound from pyramid.response import Response from pyramid.view import view_config from pyramid.view import view_defaults library = Library('kotti_tinymce', 'static') tinymce = Resource(library, "tinymce.js", minified="tinymce.min.js") kotti_tinymce = Resource(library, "kotti_tinymce.js", minified="kotti_tinymce.min.js", depends=[ tinymce, ]) codemirror_plugin = Resource(library, "codemirror/plugin.js", depends=[ tinymce, ]) kottiimage_plugin = Resource(library, "kottiimage_plugin.js", minified="kottiimage_plugin.min.js", depends=[
from fanstatic import Group from fanstatic import Library from fanstatic import Resource from css.pure import pure from js.jquery import jquery library = Library('yoshimi_admin', 'static', minifiers={'.js': 'jsmin'}) js = Group([ jquery, Resource(library, 'js/lib/tree.jquery.js'), Resource(library, 'js/admin.js'), ]) css = Group([ pure, Resource(library, 'css/main.css', compiler='sass', source='css/main.scss'), ])
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 -*- # Copyright (c) 2007-2010 NovaReto GmbH # [email protected] from js.jquery import jquery from fanstatic import Resource, Library, Group widget_library = Library('uvc.widgets', 'static') dpcss = Resource(widget_library, 'bootstrap-datepicker.standalone.min.css') dpdecss = Resource(widget_library, 'bootstrap-datepicker.de.min.js') dpjs = Resource(widget_library, 'bootstrap-datepicker.min.js') bootstrapdatepicker = Group((dpcss, dpdecss, dpjs)) optchoice = Resource(widget_library, 'choice.js', depends=[jquery]) double = Resource(widget_library, 'double.js', depends=[jquery]) masked_input = Resource(widget_library, 'jquery.maskedinput.js', depends=[jquery]) # Achtung JQuery 1.9 #masked_input = Resource(widget_library, 'jquery.maskedinput-1.3.js', depends=[jquery]) datepicker = Resource(widget_library, 'bsdp.js', depends=[bootstrapdatepicker]) plz_select = Resource(widget_library, 'plz_select.js', depends=[jquery]) lov = Resource(widget_library, 'lov.js', depends=[jquery]) limit_js = Resource(widget_library, 'limit.js', depends=[jquery])
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) setattr(module, fanstatic_name, resource) return resource
from fanstatic import Library, Resource library = Library('angularjs', 'resources') angular = Resource(library, 'angular.js', minified='angular.min.js') angular_cookies = Resource(library, 'angular-cookies.js', minified='angular-cookies.min.js', depends=[angular]) angular_loader = Resource(library, 'angular-loader.js', minified='angular-loader.min.js') angular_mobile = Resource(library, 'angular-mobile.js', minified='angular-mobile.min.js', depends=[angular]) angular_mocks = Resource(library, 'angular-mocks.js', depends=[angular]) angular_resource = Resource(library, 'angular-resource.js', minified='angular-resource.min.js', depends=[angular]) angular_sanitize = Resource(library, 'angular-sanitize.js', minified='angular-sanitize.min.js', depends=[angular]) angular_scenario = Resource(library, 'angular-scenario.js') _langs = [ 'af', 'af-na', 'af-za',
from fanstatic import Group from fanstatic import Library from fanstatic import Resource from fanstatic.core import render_print_css from js.jquery import jquery from js.momentjs import moment library = Library('js.fullcalendar', 'resources') fullcalendar_css = Resource( library, 'fullcalendar.css', minified='fullcalendar.min.css') fullcalendar_print_css = Resource( library, 'fullcalendar.print.css', depends=[fullcalendar_css, ], renderer=render_print_css) css = Group([fullcalendar_css, fullcalendar_print_css, ]) fullcalendar_js = Resource( library, 'fullcalendar.js', depends=[jquery, moment], minified='fullcalendar.min.js') lang_all_js = Resource( library,
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) setattr(module, fanstatic_name, resource) return resource
from js.jquery import jquery from js.jquery_joyride import joyride from js.socialshareprivacy import socialshareprivacy from adhocracy.i18n import LOCALES js_i18n = dict() static_path = os.path.dirname(os.path.abspath(__file__)) # --[ 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 = Group([bootstrap_js]) # --[ stylesheets ]--------------------------------------------------------- stylesheets_library = Library('stylesheets', 'stylesheets') style = Resource(stylesheets_library, 'adhocracy.css', minified='min/adhocracy.css') stylesheets = Group([style]) instance_stylesheets = {} instance_themes = {}
# -*- coding: utf-8 -*- """ Created on 2013-02-18 :author: Andreas Kaiser (disko) """ from __future__ import absolute_import from fanstatic import Library from fanstatic import Resource from js.bootstrap_image_gallery import gallery library = Library( 'kotti_gallery', 'static') kotti_gallery = Resource( library, 'kotti_gallery.css', minified='kotti_gallery.min.css', depends=[gallery, ] )