Coder Social home page Coder Social logo

Comments (5)

imlucas avatar imlucas commented on August 19, 2024

I've implemented this as a bundle filter exfm@90bfd2e

We then use it in our environment like so.

js_templates = Bundle('js/templates/*', filters='jst', output='js/templates.js')
environment.register('js_templates', js_templates)

libs = ['jquery-1.6.2', 'underscore', 'backbone']
libs_js_bundle = Bundle(*['js/libs/%s.js' % f for f in libs])
app_base_js_bundle = Bundle('js/app/models.js', 'js/app/views.js')
app_js = Bundle('js/config.js', libs_js_bundle, js_templates, app_base_js_bundle, output='js/app.js')
environment.register('app_js', app_js)

I has cleaned up our code substantially and has made testing significantly easier (templates used to be scattered in Jinja templates, making them hard to include without dupes). Did you have something else in mind for this?

from webassets.

miracle2k avatar miracle2k commented on August 19, 2024

I'm not sure what I had in mind exactly. Something about using a filter seems to irk me the wrong way, but I'm not sure. Maybe the way you need to combine both input and output filters via a shared state.

At the same time, it is without a doubt a very elegant solution. Let's merge it.

A couple notes though:

  • Is there a reason why you are opening and reading the file in input() yourself? If you were to just read from the "_in" stream instead then other filters could be applied to preprocess the templates.
  • When determine the template name, you seem to assume they are located in a "templates/" directory. That seems wrong. I think the proper way to do this is storing the full source_path in "self.templates", and then making the output() function smart enough to determine the common prefix of all templates, ignoring it, and using the rest as the accessor (this is how Jammit does it). So a template may be accessed as Templates.license, or, if the templates are organised subdirectories, then it might be Templates['public/license'].

Finally, if you find the time to add a test for the filter, that would mean I don't have to ;)

from webassets.

imlucas avatar imlucas commented on August 19, 2024

Sweet. Really just wanted to see what you thought about this. I'll add more 1:1 jammit stuff along with your notes.

from webassets.

miracle2k avatar miracle2k commented on August 19, 2024

This is now implemented in master as a filter. Thanks Lucas.

from webassets.

imlucas avatar imlucas commented on August 19, 2024

Sweettt

from webassets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.