sprockets

How do I get escape_javascript and other helpers in my sprockets pre-processed js file (not a view)?

血红的双手。 提交于 2019-12-04 17:30:31
问题 I'm using Rails 3.1 and the sprockets stuff. I want to use ERB to pre-process a js file that will then be included using javascript_include_tag. It is generated from code, and so I'm pre-processing it with ERB, but I can't get to the helpers like escape_javascript from ActionView::Helpers::JavaScriptHelper Say my file is called dynamic.js.erb, and it contains obj = { name: "test", tag: "<%= escape_javascript( image_tag( "logo.png" ) )%>" }; How do I stop it from producing the error: throw

How to override single files from gem assets for assets:precompile?

╄→гoц情女王★ 提交于 2019-12-04 17:26:45
问题 Situation I use a gem that brings its own JavaScript and stylesheet assets. This gem uses a standard application.js and application.css manifest to require all its assets: [gem]/app/assets/javascripts/gem_name/application.js require_tree . [gem]/app/assets/javascripts/gem_name/backoffice/menu.js … some JavaScript code … [gem]/app/assets/javascripts/gem_name/backoffice/forms.js … some JavaScript code … In development mode I can then override single asset files by placing them in [my_app]/app

Conditional require in Sprockets

不打扰是莪最后的温柔 提交于 2019-12-04 13:43:24
How can I conditionally require assets using Sprockets? I've googled for solutions before asking and found this discussion in the Sprockets repository - Conditional require The solution discussed there is to use ERB: <% require_asset "#{ActiveScaffold.js_framework}/my_test" %> I've tried it this way: app.js.erb <% if debug == true %> <% require_asset "lib-debug" %> <% else %> <% require_asset "lib-min" %> <%end%> Rakefile def bundle_app(debug) env = Sprockets::Environment.new env.append_path "app/" env.js_compressor = Uglifier.new assets = env.find_asset("app.js.erb") return assets.to_s end

rails generate rspec:install - no such file to load --sprockets/railtie (LoadError)

僤鯓⒐⒋嵵緔 提交于 2019-12-04 11:35:38
问题 I'm a RoR-Beginner and I started learning it with the RoR-Tutorial. Actually I'm at this chapter (http://ruby.railstutorial.org/chapters/static-pages#top) and try to install rspec. But everytime when I try to use "rails g rspec:install" I get this error message: C:\Sites\rails\rails_projects\sample_appp>rails g rspec:install C:/Sites/rails/rails_projects/sample_appp/config/application.rb:8:in `require': no such file to load -- sprockets/railtie (LoadError) from C:/Sites/rails/rails_projects

Rails 3.1: The public directory no longer serves js assets. How to load an additional js file after page is loaded?

我与影子孤独终老i 提交于 2019-12-04 08:45:11
问题 I use a jQuery plugin that loads another js file from the server after the initial page load. Since all js assets are concatenated in Rails 3.1 and the public directory is not used to serve js assets, how can I reference this file? Where do I put it? 回答1: Every asset in the Sprockets load path is accessible at runtime. You can see your load path in Rails console with Rails.application.config.assets.paths You can add load paths in an initializer: Rails.application.config.assets.paths << your

How can I get the Rails asset pipeline to produce source maps?

…衆ロ難τιáo~ 提交于 2019-12-04 07:57:27
问题 I'd like to have Rails produce source maps alongside the compiled coffeescript/minified JS, for better error logging. There doesn't seem to be comprehensive documentation on the net on how to do this, yet, though. Has anyone done this? I'm on Rails 3.2 and Heroku. 回答1: Rails supports source maps for minified JavaScript! Rails relies on Sprockets for asset compilation, and source maps support was added to Sprockets in this pull request. 回答2: If you don't really want source-maps, but instead

Rails 4 static assets in public/ or app/assets/

你说的曾经没有我的故事 提交于 2019-12-04 07:55:31
问题 Sorry if this is a lengthy buildup to a simple question, but I wanted to get my thoughts clear. I've used Rails 4 on a couple projects now and I've been using image_tag('/assets/image.png') to get around the changes to how asset path helpers work in Rails 4. That is until today when I decided to learn more about the changes and found this first change note in sprockets-rails. I've also noted that the ASSET_PUBLIC_DIRECTORIES in /actionview/lib/action_view/helpers/asset_url_helper.rb#L170 in

Dynamically render a sass file through sprockets

寵の児 提交于 2019-12-04 07:43:46
I want, from a helper, to render some variables in a .scss.erb template that makes use of the image-url() sass function: // template.scss.erb #<%= id %> { background-image: image-url('<%= image_file %>'); } So far, the ERB part has been easy: (leveraging this stack overflow answer ) vars_binding = OpenStruct.new( id: 'foo', image_file: 'foo.jpg' ).instance_eval { binding } template = File.read('path/to/template.scss.erb') rendered_sass = ERB.new(template).result(vars_binding) Running that code, sass is now equal to: #foo { background-image: image-url('foo.jpg'); } However, when I next try to

Compressing assets in Ruby on Rails 3

痞子三分冷 提交于 2019-12-04 06:58:44
I have following configurations in production.rb # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = false # Compress JavaScripts and CSS config.assets.compress = true # Choose the compressors to use config.assets.js_compressor = :uglifier config.assets.css_compressor = :yui # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = true # Generate digests for assets URLs. config.assets.digest = true But when the ruby on rails application on production server I get following error: Error compiling CSS asset

Requiring a sprockets-preprocessed file with Browserify and browserify-rails

徘徊边缘 提交于 2019-12-04 06:53:53
I'm using browserify-rails and I'm trying to get sprockets to preprocess a file that contains a sprockets directive, so that when I require() it using browserify, it will contain the generated JavaScript. The sprockets directive tries to include the output of the gem js-routes , in order to allow me to access the Rails routes from the clientside. This is my setup (within app/assets/javascripts ): system/ rails_routes.js application.js application.js is the main file, and it runs the rest of the application. I would like to be able to do something like var rr = require("./system/rails_routes.js