Esempio n. 1
0
def test_no_output_but_filters():
    """If a container specifies filters, those filters are applied to
    the sub-bundles.
    """
    jl = bundle_to_joblist(
        Bundle(Bundle('s1', output='foo'),
               Bundle('s2', output='bar', filters=[js]),
               filters=[css]))
    assert jl['foo'][0][0] == [css]
    assert jl['foo'][0][1] == ['s1']
    assert jl['bar'][0][0] == [js, css]
    assert jl['bar'][0][1] == ['s2']
Esempio n. 2
0
def test_filter_assign():
    """Test the different ways we can assign filters to the bundle.
    """

    class TestFilter(Filter):
        pass

    def _assert(list, length):
        """Confirm that everything in the list is a filter instance, and
        that the list as the required length."""
        assert len(list) == length
        assert bool([f for f in list if isinstance(f, Filter)])

    # Comma-separated string.
    b = Bundle(filters='jsmin,cssutils')
    _assert(b.filters, 2)

    # List of strings.
    b = Bundle(filters=['jsmin', 'cssutils'])
    _assert(b.filters, 2)
    # Strings inside a list may not be further comma separated
    assert_raises(ValueError, Bundle, filters=['jsmin,cssutils'])

    # A single or multiple classes may be given
    b = Bundle(filters=TestFilter)
    _assert(b.filters, 1)
    b = Bundle(filters=[TestFilter, TestFilter, TestFilter])
    _assert(b.filters, 3)

    # A single or multiple instance may be given
    b = Bundle(filters=TestFilter())
    _assert(b.filters, 1)
    b = Bundle(filters=[TestFilter(), TestFilter(), TestFilter()])
    _assert(b.filters, 3)

    # You can mix instances and classes
    b = Bundle(filters=[TestFilter, TestFilter()])
    _assert(b.filters, 2)

    # If something is wrong, an error is raised right away.
    assert_raises(ValueError, Bundle, filters='notreallyafilter')
    assert_raises(ValueError, Bundle, filters=object())

    # [bug] Specifically test that we can assign ``None``.
    Bundle().filters = None

    # Changing filters after bundle creation is no problem, either.
    b = Bundle()
    assert b.filters is None
    b.filters = TestFilter
    _assert(b.filters, 1)

    # Assigning the own filter list should change nothing.
    old_filters = b.filters
    b.filters = b.filters
    assert b.filters == old_filters
Esempio n. 3
0
def test_filter_merge():
    """Test that filter lists in a nested bundle structure are
    properly merged.
    """
    b = Bundle('s1',
               Bundle('s2', Bundle('s3', filters=[css, sass]), filters=[js]),
               output='foo')
    jl = bundle_to_joblist(b)
    assert jl['foo'][0][0] == []
    assert jl['foo'][0][1] == ['s1']
    assert jl['foo'][1][0] == [js]
    assert jl['foo'][1][1] == ['s2']
    assert jl['foo'][2][0] == [css, sass, js]
    assert jl['foo'][2][1] == ['s3']
Esempio n. 4
0
def test_single_bundle():
    """Test registering a single ``Bundle`` object.
    """

    b = Bundle()
    register('foo', b)
    assert _get() == b
Esempio n. 5
0
def test_duplicate():
    """Test name clashes.
    """

    b1 = Bundle()
    b2 = Bundle()

    register('foo', b1)

    # Multiple calls with the same name are ignored if the given bundle
    # is the same as originally passed.
    register('foo', b1)
    assert len(_REGISTRY) == 1

    # Otherwise, an error is raised.
    assert_raises(RegistryError, register, 'foo', b2)
    assert_raises(RegistryError, register, 'foo', 's1', 's2', 's3')
Esempio n. 6
0
def test_flat():
    """If the bundle structure is already flat, we don't have to do much.
    """
    b = Bundle('s1', 'a2', output='foo')
    jl = bundle_to_joblist(b)
    assert len(jl) == 1
    assert jl.keys()[0] == 'foo'
    assert len(jl['foo']) == 1
    assert len(jl['foo'][0][1]) == 2
Esempio n. 7
0
def test_debug_inheritance():
    """Test the bundle ``debug`` setting in a nested scenario.
    """
    sub2 = Bundle('s4', filters=[js], output="bar")
    sub1 = Bundle('s3', sub2, debug='merge', output='foo', filters=[css])
    b = Bundle('s1', 's2', sub1, filters=[js])

    jl = bundle_to_joblist(b)
    assert len(jl) == 3
    assert 's1' in jl and 's2' in jl
    assert jl['foo'][0][0] == []
    assert jl['foo'][1][0] == []

    sub2.debug = True
    jl = bundle_to_joblist(b)
    assert len(jl) == 4
    assert 's1' in jl and 's2' in jl and 's4' in jl
    assert jl['foo'][0][0] == []
Esempio n. 8
0
def test_unmergable():
    """A subbundle that is unmergable will be pulled into a separate job.
    """
    b = Bundle('s1',
               's2',
               Bundle('s3', debug=False, filters=css, output="bar"),
               output='foo',
               filters=js)
    jl = bundle_to_joblist(b)
    assert len(jl) == 3
    assert 's1' in jl and 's2' in jl
    assert jl['bar'][0][0] == [css]
    assert 's3' in jl['bar'][0][1]

    # However, the bundle that is pulled up needs to have it's own output
    # target, or we can't continue.
    assert_raises(BundleError, bundle_to_joblist,
                  Bundle('s1', Bundle('s2', debug=False), output='foo'))
Esempio n. 9
0
def test_debug_merge_only():
    """Test the 'merge only' debug option (no filters).
    """
    sub = Bundle('s3', filters=[css], output="bar")
    b = Bundle('s1', 's2', sub, output='foo', filters=[js])
    jl = bundle_to_joblist(b)
    assert len(jl) == 1
    assert jl['foo'][0][0] == []
    assert jl['foo'][1][0] == []

    sub.debug = False
    jl = bundle_to_joblist(b)
    assert len(jl) == 1
    assert jl['foo'][0][0] == []
    assert jl['foo'][1][0] == [css]

    sub.debug = True
    jl = bundle_to_joblist(b)
    assert len(jl) == 2
    assert jl['foo'][0][0] == []
Esempio n. 10
0
def test_no_output():
    """Each file in a bundle needs an output target if it is supposed
    to be merged. An error is raised if no target is available.
    """

    # The root bundle is lacking an output option.
    assert_raises(BundleError, bundle_to_joblist, Bundle('s1', 's2'))

    # Also, if the output is missing merely in a subtree, that's ok.
    bundle_to_joblist(Bundle('s1', Bundle('s2'), output='foo'))

    # If the root bundle is merely a container, that's ok, as long as
    # all the sub-bundles have their own output target.
    bundle_to_joblist(
        Bundle(Bundle('s1', output='foo'), Bundle('s2', output='bar')))
    assert_raises(BundleError, bundle_to_joblist,
                  Bundle(Bundle('s1', output='foo'), Bundle('s2')))
    def setup(self):
        test_instance = self
        class MockBundle(Bundle):
            urls_to_fake = ['foo']
            def __init__(self, *a, **kw):
                Bundle.__init__(self, *a, **kw)
                # Kind of hacky, but gives us access to the last Bundle
                # instance used by our Django template tag.
                test_instance.the_bundle = self
            def _urls(self, *a, **kw):
                return self.urls_to_fake
        # Inject our mock bundle class
        self._old_bundle_class = AssetsNode.BundleClass
        AssetsNode.BundleClass = self.BundleClass = MockBundle

        # Reset the Django asset environment, init it with some
        # dummy bundles.
        django_env_reset()
        self.foo_bundle = Bundle()
        self.bar_bundle = Bundle()
        django_env_register('foo_bundle', self.foo_bundle)
        django_env_register('bar_bundle', self.bar_bundle)
Esempio n. 12
0
 def _recurse_node(node_to_search):
     for node in node_to_search.iter_child_nodes():
         if isinstance(node, jinja2.nodes.Call):
             if isinstance(node.node, jinja2.nodes.ExtensionAttribute)\
                and node.node.identifier == AssetsExtension.identifier:
                 filter, output, files = node.args
                 bundle = Bundle(
                     *files.as_const(), **{
                         'output': output.as_const(),
                         'filters': filter.as_const()})
                 result.append(bundle)
         else:
             _recurse_node(node)
Esempio n. 13
0
    def get_merged_bundles(self):
        files_by_ext = self.get_files_by_ext()

        for js_or_css in files_by_ext.values():
            for ext_files in js_or_css.values():
                ext_files["files"] = self._clean_duplicates(ext_files.get("files", []))
                ext_files["filters"] = self._clean_duplicates(ext_files.get("filters", []))

        css_bundles = []
        js_bundles = []

        for js_or_css, js_or_css_files in files_by_ext.items():
            bundles = css_bundles if js_or_css == "css" else js_bundles
            for ext, js_css in js_or_css_files.items():
                if js_css["filters"] is None:
                    raise ImproperlyConfigured('You need to specify ASSETS_DEFAULT_CSS_FILTERS in your Django settings file')
                elif js_css["filters"] == '':
                    bundles.append(Bundle(*js_css["files"], output="%s/js/%s_%s.%s" % (self.path, self.name, ext, js_or_css), debug=self.debug))
                else:
                    bundles.append(Bundle(*js_css["files"], filters=js_css["filters"], output="%s/js/%s_%s.%s" % (self.path, self.name, ext, js_or_css), debug=self.debug))

        return css_bundles, js_bundles
Esempio n. 14
0
def test_new_bundle():
    """Test registering a new bundle on the fly.
    """

    b = Bundle()
    register('foo', b, 's2', 's3')
    assert b in _get('foo').contents

    # Special case of using only a single, non-bundle source argument.
    register('footon', 's1')
    assert 's1' in _get('footon').contents

    # Special case of specifying only a single bundle as a source, but
    # additional options - this also creates a wrapping bundle.
    register('foofighters', b, output="bar")
    assert b in _get('foofighters').contents
Esempio n. 15
0
"""
try:
    from django_assets import Bundle, register
except ImportError:
    DJANGO_ASSETS_INSTALLED = False
else:
    DJANGO_ASSETS_INSTALLED = True

if DJANGO_ASSETS_INSTALLED:
    from djangocodemirror import settings_local
    from djangocodemirror.config import ConfigManager

    # Build all Bundles from available editor settings
    for settings_name, settings_values in settings_local.CODEMIRROR_SETTINGS.items(
    ):
        config = ConfigManager(config_name=settings_name)

        css_options = settings_local.BUNDLES_CSS_OPTIONS.copy()
        css_options['output'] = css_options['output'].format(
            settings_name=settings_name)
        js_options = settings_local.BUNDLES_JS_OPTIONS.copy()
        js_options['output'] = js_options['output'].format(
            settings_name=settings_name)

        css_contents, js_contents = config.find_assets()

        register(config.settings['css_bundle_name'],
                 Bundle(*css_contents, **css_options))
        register(config.settings['js_bundle_name'],
                 Bundle(*js_contents, **js_options))
Esempio n. 16
0
# -*- coding: utf-8 -*-
from django.utils.translation import ugettext_lazy as _
from django_assets import Bundle, register

test_main_css = Bundle(
    'css/jquery-ui.min.css',
    'css/base.css',
    filters='cssmin',
    output='css/test_main_css.css'
)
register('test_main_all_css', test_main_css)

test_main_js = Bundle(
    'js/jquery-1.11.1.min.js',
    'js/jquery-ui.min.js',
    'js/base.js',
    filters='jsmin',
    output='js/test_main_js.js'
)
register('test_main_all_js', test_main_js)
Esempio n. 17
0
from django_assets import Bundle, register

# SCSS

scss_custom_bootstrap = Bundle(
    "scss/custom_bootstrap.scss",
    filters="scss",
    output="css/custom_bootstrap.css",
)
scss_atelier_soude = Bundle("scss/ateliersoude.scss",
                            filters="scss",
                            output="css/ateliersoude.css")
scss_places = Bundle(
    "scss/lib/leaflet.scss",
    "scss/places/leaflet_custom.scss",
    "scss/places/custom.scss",
    filters="scss",
    output="css/leaflet_custom.css",
)
scss_detail_place = Bundle(
    "scss/lib/leaflet.scss",
    "scss/places/leaflet_custom.scss",
    filters="scss",
    output="css/detail_place.css",
)
scss_auto_complete = Bundle(
    "scss/lib/auto-complete.scss",
    filters="scss",
    output="css/auto-complete.css",
)
scss_detail_event = Bundle(
Esempio n. 18
0
from django.conf import settings

from django_assets import Bundle, register
from webassets.filter import get_filter

libsass = get_filter("libsass", style="compressed")

css_libs = Bundle(settings.BASE_DIR + "/assets/styles/css/libs/normalize.css",
                  filters="cssutils",
                  output="css/libs.css")

css_custom = Bundle(
    settings.BASE_DIR + "/assets/styles/sass/base.sass",
    filters=libsass,
    output="css/style.css",
    depends="/**/*.sass",
)

register("css_libs", css_libs)
register("css_custom", css_custom)
Esempio n. 19
0
from django_assets import Bundle, register

# Assets for the landing pages
css_landing = Bundle('bootstrap/dist/css/bootstrap.css',
                     'css/landing-page.css',
                     filters=(
                         'cssrewrite',
                         'yui_css',
                     ),
                     output='compiled-assets/gen/css_landing.%(version)s.css')

register('css_landing', css_landing)

js_landing = Bundle('jquery/dist/jquery.js',
                    'bootstrap/dist/js/bootstrap.js',
                    filters='closure_js',
                    output='compiled-assets/gen/js_landing.%(version)s.js')

register('js_landing', js_landing)

# Assets for the application
css_main = Bundle('bootstrap/dist/css/bootstrap.css',
                  'djng/css/styles.css',
                  'font-awesome/css/font-awesome.css',
                  'css/datasets.css',
                  filters=(
                      'cssrewrite',
                      'yui_css',
                  ),
                  output='compiled-assets/gen/css_main.%(version)s.css')
Esempio n. 20
0
#
# Copyright (C) Pootle contributors.
#
# This file is a part of the Pootle project. It is distributed under the GPL3
# or later license. See the LICENSE file for a copy of the license and the
# AUTHORS file for copyright and authorship information.

from django_assets import Bundle, register


# <Webpack>
# These are handled by webpack and therefore have no filters applied
# They're kept here so hash-based cache invalidation can be used

js_vendor = Bundle(
    'js/vendor.bundle.js',
    output='js/vendor.min.%(version)s.js')
register('js_vendor', js_vendor)

js_common = Bundle(
    'js/common/app.bundle.js',
    output='js/common/app.min.%(version)s.js')
register('js_common', js_common)

js_admin_general_app = Bundle(
    'js/admin/general/app.bundle.js',
    output='js/admin/general/app.min.%(version)s.js')
register('js_admin_general_app', js_admin_general_app)

js_admin_app = Bundle(
    'js/admin/app.bundle.js',
Esempio n. 21
0
from django_assets import Bundle, register

bower_js = Bundle("jslib/parser/parser.js",
                  "lib/jquery/dist/jquery.min.js",
                  "lib/angular/angular.js",
                  "lib/angular-resource/angular-resource.js",
                  "lib/angular-cookies/angular-cookies.js",
                  "lib/angular-sanitize/angular-sanitize.js",
                  "lib/angular-aria/angular-aria.js",
                  "lib/angular-route/angular-route.js",
                  "lib/ng-file-upload/angular-file-upload.js",
                  "lib/ngDialog/js/ngDialog.min.js",
                  "lib/angular-ui-router/release/angular-ui-router.js",
                  "lib/angular-order-object-by/src/ng-order-object-by.js",
                  "lib/base64/base64.min.js",
                  "lib/bigfoot/dist/bigfoot.min.js",
                  filters="jsmin",
                  output="js/bower.min.%(version)s.js")

angular_js = Bundle("js/app.js",
                    "js/filters/truncate.js",
                    "js/directives/workflow.js",
                    "js/directives/topic.js",
                    "js/directives/pagination.js",
                    "js/directives/backbutton.js",
                    "js/directives/jargon.js",
                    "js/directives/header.js",
                    "js/directives/footer.js",
                    "js/directives/elements/str.js",
                    "js/directives/elements/text.js",
                    "js/directives/elements/bool.js",
Esempio n. 22
0
from django_assets import Bundle, register

# =============================================================================
# Announcement forms
# =============================================================================

announcement_forms_css = Bundle('announce/styles/announce.css',
                                'js/datetimepicker/datepicker.css',
                                filters='cssutils',
                                output='announce/styles/forms_packed.css')
register('announcement_forms_css', announcement_forms_css)

announcement_forms_js = Bundle('js/datetimepicker/Locale.en-US.DatePicker.js',
                               'js/datetimepicker/Picker.js',
                               'js/datetimepicker/Picker.Attach.js',
                               'js/datetimepicker/Picker.Date.js',
                               'js/loadingOverlay.js',
                               filters='jsmin',
                               output='announce/scripts/forms_packed.js')
register('announcement_forms_js', announcement_forms_js)
Esempio n. 23
0
from django_assets import Bundle, register
from webassets.filter import get_filter

thirdparty_path = os.path.join(settings.BASE_DIR, "node_modules")
sass = get_filter("scss",
                  style="compressed",
                  load_paths=("./css", thirdparty_path))

uglify_args = ["--comments", "/^!/", "-m", "-c"]
uglify = get_filter("uglifyjs",
                    binary=os.path.join(thirdparty_path, ".bin", "uglifyjs"),
                    extra_args=uglify_args)

css = Bundle(
    "css/inboxen.scss",
    filters=(sass, ),
    output="compiled/css/website.%(version)s.css",
)
register("inboxen_css", css)

js = Bundle(
    "thirdparty/jquery/dist/jquery.js",
    "js/utils.js",
    "js/copy.js",
    "js/alert.js",
    "js/home.js",
    "js/search.js",
    "js/inbox.js",
    filters=(uglify, ),
    output="compiled/js/website.%(version)s.js",
)
Esempio n. 24
0
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

from django_assets import Bundle, register

js_common = Bundle('js/jquery/jquery.js',
                   'js/jquery/jquery.tipsy.js',
                   'js/jquery/jquery.cookie.js',
                   'js/jquery/jquery.bidi.js',
                   'js/jquery/jquery.fancybox.js',
                   'js/common.js',
                   'js/sorttable.js',
                   'js/shortcut.js',
                   filters='rjsmin',
                   output='js/common.min.js')
register('js_common', js_common)

js_admin = Bundle('js/jquery/jquery.form.js',
                  'js/admin.js',
                  filters='rjsmin',
                  output='js/admin.min.js')
register('js_admin', js_admin)

js_editor = Bundle('js/jquery/jquery.easing.js',
                   'js/jquery/jquery.history.js',
                   'js/jquery/jquery.tmpl.js',
Esempio n. 25
0
from django_assets import Bundle, register

JS_ASSETS = (
    'js/jquery-1.7.1.min.js',
    'js/jquery-ui-1.10.3.custom.min.js',
    'js/jquery.uniform.js',
    'js/chosen.jquery.js',
    'bootstrap/js/bootstrap.js',
)

CSS_ASSETS = (
    'bootstrap/css/bootstrap.css',
    'bootstrap/css/bootstrap-responsive.css',
    'css/uniform.default.css',
    'css/chosen.css',
    'css/style.css',
)

js = Bundle(*JS_ASSETS, filters='jsmin', output='gen/packed.js')
css = Bundle(*CSS_ASSETS, filters='cssmin', output='gen/packed.css')

register('js', js)
register('css', css)
Esempio n. 26
0
from django_assets import Bundle, register

js_common = Bundle(
    'js/vendor/jquery/jquery.js',
    'js/vendor/jquery/jquery.tipsy.js',
    'js/vendor/jquery/jquery.cookie.js',
    'js/vendor/jquery/jquery.bidi.js',
    'js/vendor/jquery/jquery.magnific-popup.js',
    'js/vendor/jquery/jquery.utils.js',
    'js/vendor/jquery/jquery.easing.js',
    'js/vendor/jquery/jquery.serializeObject.js',
    'js/vendor/jquery/jquery.select2.js',
    'js/vendor/bootstrap/bootstrap-alert.js',
    'js/vendor/bootstrap/bootstrap-transition.js',
    'js/captcha.js',
    'js/common.js',
    'js/languages.js',
    'js/contact.js',
    'js/search.js',
    'js/stats.js',
    'js/utils.js',
    'js/zoom.js',
    'js/vendor/sorttable.js',
    'js/vendor/spin.js',
    'js/vendor/shortcut.js',  # Leave shortcut.js as the last one.
    filters='rjsmin',
    output='js/common.min.%(version)s.js')
register('js_common', js_common)

js_admin = Bundle('js/admin.js',
Esempio n. 27
0
__author__ = 'm'

from django_assets import Bundle, register

base_js = Bundle(
    'js/select.min.js',
    'js/autosize.min.js',
    "js/icheck.js",
    # 'js/scroll.min.js',
    # 'js/calendar.min.js',
    'js/feeds.min.js',
    # 'js/toggler.min.js',
    # 'js/functions.js',
    filters="jsmin",
    output="dist/base.js")

core_js = Bundle('js/jquery.min.js',
                 "js/bootstrap.min.js",
                 filters="jsmin",
                 output="dist/core.js")

base_css = Bundle('css/bootstrap.min.css',
                  'css/animate.min.css',
                  'css/font-awesome.min.css',
                  'css/form.css',
                  'css/calendar.css',
                  'css/style.css',
                  'css/icons.css',
                  'css/generics.css',
                  'scss/restaurant.css',
                  filters="cssmin",
Esempio n. 28
0
from django_assets import Bundle, register

tableCss = Bundle('css/wordwalls/wordwallsTableSS.css',
                  filters='cssmin',
                  output='css/wordwalls/packedWWT.css')

register('css_table', tableCss)
Esempio n. 29
0
# Copyright (c) 2018, DjaoDjin inc.
# see LICENSE

import os

from django_assets import Bundle, register
from django.conf import settings

#pylint: disable=invalid-name

# All the CSS we need for the entire site. This tradeoff between
# bandwidth and latency is good as long as we have a high and consistent
# utilization of all the CSS tags for all pages on the site.
css_base = Bundle(os.path.join(settings.BASE_DIR,
                               'assets/less/base/base.less'),
                  filters=['less', 'cssmin'],
                  output='cache/base.css',
                  debug=False)
register('css_base', css_base)

css_email = Bundle(os.path.join(settings.BASE_DIR,
                                'assets/less/email/email.less'),
                   filters=['less', 'cssmin'],
                   output='cache/email.css',
                   debug=False)
register('css_email', css_email)

# Minimal: jquery and bootstrap always active on the site
js_base = Bundle('vendor/jquery.js',
                 'vendor/jquery.cookie.js',
                 'vendor/bootstrap.js',
Esempio n. 30
0
from django_assets import Bundle, register

js = Bundle('js/jquery-1.8.2.js',
            'js/bootstrap.js',
            filters='yui_js',
            output='../globalstatic/bundles/app.js')

css = Bundle('css/bootstrap.css',
             'css/bootstrap-responsive.css',
             output='../globalstatic/bundles/app.css')

register('js_app', js)
register('css_app', css)