Module: WithEmbeddedAssets::ViewHelpers
- Includes:
- Mixin
- Defined in:
- lib/with_embedded_assets/view_helpers.rb
Overview
Module that replaces helpers methods used on views to embed assets.
The replaced methods only work if the embedding is enabled. If it is not, the behaviour is exactly the same as the original method.
Instance Method Summary collapse
-
#javascript_include_tag(*sources) ⇒ Object
Inserts a script tag for Javascript assets.
-
#stylesheet_link_tag(*sources) ⇒ Object
Inserts a link tag for stylesheets assets.
Methods included from Mixin
Instance Method Details
#javascript_include_tag(*sources) ⇒ Object
Inserts a script tag for Javascript assets.
This method return a string containing a script tag with Javascript code processed by the asset pipeline directly embed into it.
See the original method documentation here.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/with_embedded_assets/view_helpers.rb', line 16 def javascript_include_tag(*sources) return super unless WithEmbeddedAssets.enabled? = sources..stringify_keys tag_attributes = {:type => "text/javascript"}.merge() content_tag(:script, nil, tag_attributes, false) do assets = Array(sources).collect do |js_asset| Rails.application.assets[js_asset.to_s + ".js"].to_s end raw assets.join("\n") end end |
#stylesheet_link_tag(*sources) ⇒ Object
Inserts a link tag for stylesheets assets.
This method return a string with a link tag with stylesheet declarations processed by the asset pipeline directly embed into it.
See the original method documentation here.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/with_embedded_assets/view_helpers.rb', line 35 def stylesheet_link_tag(*sources) return super unless WithEmbeddedAssets.enabled? = sources..stringify_keys tag_attributes = {"media" => "screen", "type" => "text/css"}.merge() content_tag(:style, nil, tag_attributes, false) do assets = Array(sources).collect do |css_asset| Rails.application.assets[css_asset.to_s + ".css"].to_s end raw assets.join("\n") end end |