Module: Rails2AssetPipeline::ViewHelpers

Defined in:
lib/rails2_asset_pipeline/view_helpers.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.ignored_foldersObject

e.g. ‘images’



4
5
6
# File 'lib/rails2_asset_pipeline/view_helpers.rb', line 4

def ignored_folders
  @ignored_folders
end

Class Method Details

.asset_path(asset) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rails2_asset_pipeline/view_helpers.rb', line 38

def asset_path(asset)
  Rails2AssetPipeline.warn_user_about_misconfiguration!

  asset_with_id = if Rails2AssetPipeline.static?
    @sprockets_manifest ||= Sprockets::Manifest.new(Rails2AssetPipeline.env, Rails2AssetPipeline.manifest)
    @sprockets_manifest.assets[asset] || "DID_NOT_FIND_#{asset}_IN_MANIFEST"
  else
    data = Rails2AssetPipeline.env[asset]
    data ? "#{asset}?#{data.mtime.to_i}" : "DID_NOT_FIND_#{asset}_IN_ASSETS"
  end

  "/#{assets_prefix}/#{asset_with_id}"
end

.assets_prefixObject



26
27
28
# File 'lib/rails2_asset_pipeline/view_helpers.rb', line 26

def assets_prefix
  Rails2AssetPipeline.prefix
end

Instance Method Details

#compute_public_path(*args) ⇒ Object

Overwrite rails helper to use pipeline path for all relative assets args: source, ‘javascripts’, ‘js’



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rails2_asset_pipeline/view_helpers.rb', line 9

def compute_public_path(*args)
  source = args[0]
  ignored_folders = Rails2AssetPipeline::ViewHelpers.ignored_folders
  source_is_relative = (
    source.is_a?(String) and
    source =~ /^[\w\-]+(\/|\.|$)/ and # xxx or xxx.js or xxx/yyy, not /xxx or http://
    not (ignored_folders and ignored_folders.include?(args[1]))
  )

  if source_is_relative
    source = "#{source}.#{args[2]}" if args[2] and File.extname(source) != ".#{args[2]}"
    super(asset_path(source), *args[1..-1])
  else
    super
  end
end

#rails_asset_id(file) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/rails2_asset_pipeline/view_helpers.rb', line 30

def rails_asset_id(file)
  if file.start_with?("/#{assets_prefix}/")
    nil
  else
    super
  end
end