Module: Sprockets::Helpers::RailsHelper

Extended by:
ActiveSupport::Concern
Includes:
ActionView::Helpers::AssetTagHelper
Defined in:
lib/sprockets/helpers/rails_helper.rb

Defined Under Namespace

Classes: AssetPaths

Constant Summary

Constants included from ActionView::Helpers::TagHelper

ActionView::Helpers::TagHelper::BOOLEAN_ATTRIBUTES

Instance Method Summary collapse

Methods included from ActionView::Helpers::AssetTagHelper

#audio_path, #audio_tag, #auto_discovery_link_tag, #favicon_link_tag, #image_alt, #image_path, #image_tag, #video_path, #video_tag

Methods included from ActionView::Helpers::AssetTagHelper::StylesheetTagHelpers

#stylesheet_path

Methods included from ActionView::Helpers::AssetTagHelper::JavascriptTagHelpers

#javascript_path

Methods included from ActionView::Helpers::TagHelper

#cdata_section, #content_tag, #escape_once, #tag

Methods included from ActionView::Helpers::CaptureHelper

#capture, #content_for, #content_for?, #flush_output_buffer, #provide, #with_output_buffer

Instance Method Details

#asset_path(source, default_ext = nil, body = false, protocol = nil) ⇒ Object



67
68
69
70
71
# File 'lib/sprockets/helpers/rails_helper.rb', line 67

def asset_path(source, default_ext = nil, body = false, protocol = nil)
  source = source.logical_path if source.respond_to?(:logical_path)
  path = asset_paths.compute_public_path(source, 'assets', default_ext, true, protocol)
  body ? "#{path}?body=1" : path
end

#asset_pathsObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sprockets/helpers/rails_helper.rb', line 9

def asset_paths
  @asset_paths ||= begin
    config     = self.config if respond_to?(:config)
    config   ||= Rails.application.config
    controller = self.controller if respond_to?(:controller)
    paths = RailsHelper::AssetPaths.new(config, controller)
    paths.asset_environment = asset_environment
    paths.asset_prefix      = asset_prefix
    paths.asset_digests     = asset_digests
    paths
  end
end

#javascript_include_tag(*sources) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sprockets/helpers/rails_helper.rb', line 22

def javascript_include_tag(*sources)
  options = sources.extract_options!
  debug = options.key?(:debug) ? options.delete(:debug) : debug_assets?
  body  = options.key?(:body)  ? options.delete(:body)  : false

  sources.collect do |source|
    if debug && asset = asset_paths.asset_for(source, 'js')
      asset.to_a.map { |dep|
        javascript_include_tag(dep, :debug => false, :body => true)
      }.join("\n").html_safe
    else
      tag_options = {
        'type' => "text/javascript",
        'src'  => asset_path(source, 'js', body)
      }.merge(options.stringify_keys)

       'script', "", tag_options
    end
  end.join("\n").html_safe
end


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/sprockets/helpers/rails_helper.rb', line 43

def stylesheet_link_tag(*sources)
  options = sources.extract_options!
  debug = options.key?(:debug) ? options.delete(:debug) : debug_assets?
  body  = options.key?(:body)  ? options.delete(:body)  : false
  media = options.key?(:media) ? options.delete(:media) : "screen"

  sources.collect do |source|
    if debug && asset = asset_paths.asset_for(source, 'css')
      asset.to_a.map { |dep|
        stylesheet_link_tag(dep, :media => media, :debug => false, :body => true)
      }.join("\n").html_safe
    else
      tag_options = {
        'rel'   => "stylesheet",
        'type'  => "text/css",
        'media' => media,
        'href'  => asset_path(source, 'css', body, :request)
      }.merge(options.stringify_keys)

      tag 'link', tag_options
    end
  end.join("\n").html_safe
end