Module: ActionView::Helpers::AssetTagHelper

Defined in:
lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb

Instance Method Summary collapse

Instance Method Details

#theme_font_include(theme_id, font_file_name, options = {}) ⇒ Object

theme_font_include(theme_id, font_file_name, options={}) @param1: theme_id(string) @param2: font_file_name(string) @param3: options =

  sources: [
              {url: 'font1', format: 'format1',
              'font2', format: 'format2'
           ],
           font_family: 'FontFamilyName',
           font_style: normal,
           font_weight: normal,
           font_stretch: '',
           unicode_range: '',
           apply_to: ''
}


114
115
116
117
118
119
# File 'lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb', line 114

def theme_font_include(theme_id, font_file_name, options={})
  theme = controller.website.themes.find_by_theme_id(theme_id)
  return("could not find theme with the id #{theme_id}") unless theme

  theme_font_src_tag(theme, font_file_name, options)
end

#theme_image_path(theme, source) ⇒ Object Also known as: theme_path_to_image



67
68
69
70
71
72
73
74
75
# File 'lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb', line 67

def theme_image_path(theme, source)
  theme = controller.website.themes.find_by_theme_id(theme) unless theme.is_a?(Theme)

  name, directory = name_and_path_from_source(source, "#{theme.url}/images")

  file = theme.files.where('name = ? and directory = ?', name, directory).first

  file.nil? ? '' : file.data.url
end

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



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb', line 79

def theme_image_tag(theme_id, source, options = {})
  theme = controller.website.themes.find_by_theme_id(theme_id)
  return("could not find theme with the id #{theme_id}") unless theme

  options.symbolize_keys!
  options[:src] = theme_path_to_image(theme, source)
  options[:alt] ||= File.basename(options[:src], '.*').split('.').first.to_s.capitalize

  if size = options.delete(:size)
    options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
  end

  if mouseover = options.delete(:mouseover)
    options[:onmouseover] = "this.src='#{theme_image_path(theme, mouseover)}'"
    options[:onmouseout] = "this.src='#{theme_image_path(theme, options[:src])}'"
  end

  tag("img", options)
end

#theme_javascript_include_tag(theme_id, *sources) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb', line 25

def theme_javascript_include_tag(theme_id, *sources)
  theme = controller.website.themes.find_by_theme_id(theme_id)
  return("could not find theme with the id #{theme_id}") unless theme

  options = sources.extract_options!.stringify_keys
  cache = options.delete("cache")
  recursive = options.delete("recursive")

  sources = theme_expand_javascript_sources(theme, sources, recursive).collect do |source|
    theme_javascript_src_tag(theme, source, options)
  end.join("\n")
  raw sources
  #end
end

#theme_javascript_path(theme, source) ⇒ Object Also known as: theme_path_to_javascript



13
14
15
16
17
18
19
20
21
# File 'lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb', line 13

def theme_javascript_path(theme, source)
  theme = controller.website.themes.find_by_theme_id(theme) unless theme.is_a?(Theme)

  name, directory = name_and_path_from_source(source, "#{theme.url}/javascripts")

  file = theme.files.where('name = ? and directory = ?', name, directory).first

  file.nil? ? '' : file.data.url
end


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb', line 52

def theme_stylesheet_link_tag(theme_id, *sources)
  theme = controller.website.themes.find_by_theme_id(theme_id)
  return("could not find theme with the id #{theme_id}") unless theme

  options = sources.extract_options!.stringify_keys
  cache = options.delete("cache")
  recursive = options.delete("recursive")

  sources = theme_expand_stylesheet_sources(theme, sources, recursive).collect do |source|
    theme_stylesheet_tag(theme, source, options)
  end.join("\n")
  raw sources
  #end
end

#theme_stylesheet_path(theme, source) ⇒ Object Also known as: theme_path_to_stylesheet



40
41
42
43
44
45
46
47
48
# File 'lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb', line 40

def theme_stylesheet_path(theme, source)
  theme = controller.website.themes.find_by_theme_id(theme) unless theme.is_a?(Theme)

  name, directory = name_and_path_from_source(source, "#{theme.url}/stylesheets")

  file = theme.files.where('name = ? and directory = ?', name, directory).first

  file.nil? ? '' : file.data.url
end