Module: ActionView::Helpers::AssetTagHelper

Defined in:
lib/theme_support/helpers/erb_theme_tags.rb

Overview

These are theme helper tags

Instance Method Summary collapse

Instance Method Details

#theme_image_path(source, theme = nil) ⇒ Object

returns the path to a theme image



12
13
14
15
# File 'lib/theme_support/helpers/erb_theme_tags.rb', line 12

def theme_image_path( source, theme=nil )
   theme = theme || controller.current_theme
   compute_public_path(source, "themes/#{theme}/images", 'png').html_safe
end

#theme_image_tag(source, options = {}) ⇒ Object

This tag will return a theme-specific IMG



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/theme_support/helpers/erb_theme_tags.rb', line 40

def theme_image_tag(source, options = {})
  options.symbolize_keys

  options[:src] = theme_image_path(source)
  options[:alt] ||= File.basename(options[:src], '.*').split('.').first.capitalize

  if options[:size]
    options[:width], options[:height] = options[:size].split("x")
    options.delete :size
  end

  tag("img", options).html_safe
end

#theme_javascript_include_tag(*sources) ⇒ Object

This tag can be used to return theme-specific javscripts



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/theme_support/helpers/erb_theme_tags.rb', line 55

def theme_javascript_include_tag(*sources)
  options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
  if sources.include?(:defaults)        
    sources = sources[0..(sources.index(:defaults))] + 
      @@javascript_default_sources.dup + 
      sources[(sources.index(:defaults) + 1)..sources.length]
    sources.delete(:defaults) 
    sources << "application" if defined?(Rails.root) && File.exists?("#{Rails.root}/public/javascripts/application.js")
  end
  sources.collect { |source|
    source = theme_javascript_pathts(source)
    ("script", "", { "type" => "text/javascript", "src" => source }.merge(options))
  }.join("\n").html_safe
end

#theme_javascript_path(source, theme = nil) ⇒ Object

To keep compatibility with old themesupport plugin



25
26
27
# File 'lib/theme_support/helpers/erb_theme_tags.rb', line 25

def theme_javascript_path( source, theme=nil )
   theme_javascript_pathts( source, theme)
end

#theme_javascript_pathts(source, theme = nil) ⇒ Object

returns the path to a theme javascript Add ts to the name function, because rails think it’s a route (_path)



19
20
21
22
# File 'lib/theme_support/helpers/erb_theme_tags.rb', line 19

def theme_javascript_pathts( source, theme=nil )
   theme = theme || controller.current_theme
   compute_public_path(source, "themes/#{theme}/javascripts", 'js').html_safe
end

This tag it will automatially include theme specific css files



30
31
32
33
34
35
36
37
# File 'lib/theme_support/helpers/erb_theme_tags.rb', line 30

def theme_stylesheet_link_tag(*sources)
   sources.uniq!
   options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
   sources.collect { |source|
      source = theme_stylesheet_path(source)
      tag("link", { "rel" => "Stylesheet", "type" => "text/css", "media" => "screen", "href" => source }.merge(options))
   }.join("\n").html_safe
end

#theme_stylesheet_path(source = nil, theme = nil) ⇒ Object

returns the public path to a theme stylesheet



6
7
8
9
# File 'lib/theme_support/helpers/erb_theme_tags.rb', line 6

def theme_stylesheet_path( source=nil, theme=nil )
   theme = theme || controller.current_theme
   compute_public_path(source || "theme", "themes/#{theme}/stylesheets", 'css').html_safe
end