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

Methods included from Mixin

#with_embedded_assets

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?

  options = sources.extract_options!.stringify_keys
  tag_attributes = {:type => "text/javascript"}.merge(options)
  (: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

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?

  options = sources.extract_options!.stringify_keys
  tag_attributes = {"media" => "screen", "type" => "text/css"}.merge(options)
  (: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