jimmycuadra / jquery-tmpl-rails Goto Github PK
View Code? Open in Web Editor NEWjQuery Templates for the Rails asset pipeline.
Home Page: http://rubygems.org/gems/jquery-tmpl-rails
License: MIT License
jQuery Templates for the Rails asset pipeline.
Home Page: http://rubygems.org/gems/jquery-tmpl-rails
License: MIT License
Hi,
Since you removed inheritance from Rails::Engine, Rails doesn't known you're providing the asset "jquery-tmpl", and your gem doesn't appear in Rails.application.config.assets.paths anymore.
Could you fix this, please ?
I'm running
Rails 4.2.1
rake, version 10.4.2
Bundler version 1.10.5
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin14.0]
and I've added
//= require jquery-tmpl
//= require_tree ./templates
to my Gem (and the jquery-tmpl-rails gem to my Gemfile of cause) - but when I use the gem the page load stops with the above mentioned "couldn't find file" error - and a stack trace looking like this:
/Users/walther/Projects/gems/oxen_media/app/assets/javascripts/oxen_media.js:2
sprockets (3.2.0) lib/sprockets/resolve.rb:64:in `resolve!'
sprockets (3.2.0) lib/sprockets/directive_processor.rb:399:in `resolve'
sprockets (3.2.0) lib/sprockets/directive_processor.rb:207:in `process_require_directive'
sprockets (3.2.0) lib/sprockets/directive_processor.rb:180:in `block in process_directives'
sprockets (3.2.0) lib/sprockets/directive_processor.rb:178:in `each'
sprockets (3.2.0) lib/sprockets/directive_processor.rb:178:in `process_directives'
sprockets (3.2.0) lib/sprockets/directive_processor.rb:83:in `_call'
sprockets (3.2.0) lib/sprockets/directive_processor.rb:68:in `call'
sprockets (3.2.0) lib/sprockets/processor_utils.rb:75:in `call_processor'
sprockets (3.2.0) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
sprockets (3.2.0) lib/sprockets/processor_utils.rb:56:in `reverse_each'
sprockets (3.2.0) lib/sprockets/processor_utils.rb:56:in `call_processors'
sprockets (3.2.0) lib/sprockets/loader.rb:86:in `load_asset_by_uri'
sprockets (3.2.0) lib/sprockets/loader.rb:45:in `block in load'
sprockets (3.2.0) lib/sprockets/loader.rb:155:in `fetch_asset_from_dependency_cache'
sprockets (3.2.0) lib/sprockets/loader.rb:38:in `load'
sprockets (3.2.0) lib/sprockets/cached_environment.rb:20:in `block in initialize'
sprockets (3.2.0) lib/sprockets/cached_environment.rb:47:in `yield'
sprockets (3.2.0) lib/sprockets/cached_environment.rb:47:in `load'
sprockets (3.2.0) lib/sprockets/bundle.rb:23:in `block in call'
sprockets (3.2.0) lib/sprockets/utils.rb:183:in `dfs'
sprockets (3.2.0) lib/sprockets/bundle.rb:24:in `call'
sprockets (3.2.0) lib/sprockets/processor_utils.rb:75:in `call_processor'
sprockets (3.2.0) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
sprockets (3.2.0) lib/sprockets/processor_utils.rb:56:in `reverse_each'
sprockets (3.2.0) lib/sprockets/processor_utils.rb:56:in `call_processors'
sprockets (3.2.0) lib/sprockets/loader.rb:86:in `load_asset_by_uri'
sprockets (3.2.0) lib/sprockets/loader.rb:45:in `block in load'
sprockets (3.2.0) lib/sprockets/loader.rb:155:in `fetch_asset_from_dependency_cache'
sprockets (3.2.0) lib/sprockets/loader.rb:38:in `load'
sprockets (3.2.0) lib/sprockets/cached_environment.rb:20:in `block in initialize'
sprockets (3.2.0) lib/sprockets/cached_environment.rb:47:in `yield'
sprockets (3.2.0) lib/sprockets/cached_environment.rb:47:in `load'
sprockets (3.2.0) lib/sprockets/base.rb:63:in `find_asset'
sprockets (3.2.0) lib/sprockets/environment.rb:30:in `find_asset'
sprockets (3.2.0) lib/sprockets/base.rb:89:in `[]'
sprockets-rails (2.3.2) lib/sprockets/rails/helper.rb:230:in `lookup_asset_for_path'
sprockets-rails (2.3.2) lib/sprockets/rails/helper.rb:190:in `check_errors_for'
sprockets-rails (2.3.2) lib/sprockets/rails/helper.rb:137:in `block in javascript_include_tag'
sprockets-rails (2.3.2) lib/sprockets/rails/helper.rb:136:in `map'
sprockets-rails (2.3.2) lib/sprockets/rails/helper.rb:136:in `javascript_include_tag'
app/views/layouts/_head.html.haml:26:in `_app_views_layouts__head_html_haml___3569935750097020933_70308056945640'
might you have a clou on this?
cheers,
Walther
Hi,
First, thanks a lot for your amazing job on that gem. I'm using it and it works (almost) like a charm. I just changed the naming of templates not to include folder name in the final name (to allow multiple styles switching) but for all other things its perfect.
I have a suggestion, though, that you may want to look at: I suggest you include helpers in the compilation process. Since templates are quite like views, I often need my helpers and I have to do things like
<% environment.context_class.instance_eval { include ApplicationHelper } %>
on top of every single template I create, which is ok for me but could be done in your gem, I suppose (and maybe with a way not to do it, like an option for instance).
Don't hesitate to challenge me on this.
Yann
This is also filed under Sprockets core for guidance here.
The latest version of jquery-tmpl-rails
triggers a sprockets deprecation warning of:
DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.
Please register a mime type using `register_mime_type` then
use `register_compressor` or `register_transformer`.
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block (2 levels) in <class:Railtie> at /my/path/to/gems/jquery-tmpl-rails-ef6f58001d41/lib/jquery-tmpl-rails/engine.rb:10)
Following the deprecation warning, the problem within the gem simply resides here: https://github.com/jimmycuadra/jquery-tmpl-rails/blob/master/lib/jquery-tmpl-rails/engine.rb#L10
Which is currently:
app.assets.register_engine(".tmpl", JqueryTemplate)
I then visited the sprockets guide for handling deprecations, extensibility and compliance with sprockets 2,3,4. https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
I made my best attempt at rectifying the problem with a commit on this fork here: oceanshq@de7a598
Which was:
asset.register_mime_type 'application/javascript', extensions: ['.tmpl'], charset: :unicode
asset.register_preprocessor 'application/javascript', JqueryTemplate
However, this attempt simply deals out breakages when trying to run the web application at all or test it on the CI. So obviously I've missed something. I am not the gem maintainer but am trying to put this PR together myself as we rely on this gem.
register_engine
is deprecated in Sprockets 3, is it actually possible to migrate from register_engine
while staying in Sprockets 3?Sprockets raises an error trying to require the file
application.js:1Uncaught Error: Sprockets::FileNotFound: couldn't find file 'tmpl/message'
(in /Users/recipher/code/mentor/app/assets/javascripts/application.js:30)
It raises the same error if the file is in the tmpl directory or in the root of javascripts.
If I put a leading / into the require:
/tmpl/message
The error does not get raised but when calling $.tmpl("tmpl/message", ...) the template is not used and the template filename is written out.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.