Module: AssetHelper

Included in:
EasyHtmlGenerator::Generator::Compile::Haml::Context
Defined in:
lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb

Overview

this module exposes additional features for haml files

Instance Method Summary collapse

Instance Method Details

#external_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 18

def external_path?(path)
  path.start_with?('//') || path.start_with?('http')
end

#file_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 22

def file_exists?(path)
  File.exist? File.join(EasyHtmlGenerator::DIST_PATH, path)
end

#glyph_icon(icon, content = '') ⇒ Object



44
45
46
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 44

def glyph_icon(icon, content = '')
  (:span, content, class: glyph_icon_classes(icon))
end

#glyph_icon_classes(icon) ⇒ Object



40
41
42
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 40

def glyph_icon_classes(icon)
  "glyphicon glyphicon-#{icon}"
end

#headjs_javascript_include_tag(tag, path) ⇒ Object



48
49
50
51
52
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 48

def headjs_javascript_include_tag(tag, path)
   :script do
    raw "head.load({'#{tag}': '#{path_to_javascript(path)}'});"
  end
end


54
55
56
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 54

def headjs_stylesheet_link_tag(tag, path)
  headjs_javascript_include_tag(tag, path_to_stylesheet(path))
end

#inline_javascript_include_tag(path) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 73

def inline_javascript_include_tag(path)
  return path if external_path?(path)

  scripts_path = @project.dist_path_to(:scripts, path)
  if File.exist? scripts_path
    path = scripts_path
  else
    path = File.join(@project.dist_path, path)
  end

   :script do
    raw @project.generators.minimize_js.do_input! File.read(path)
  end
end


58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 58

def inline_stylesheet_link_tag(path)
  return path if external_path?(path)

  styles_path = @project.dist_path_to(:styles, path)
  if File.exist? styles_path
    path = styles_path
  else
    path = File.join(@project.dist_path, path)
  end

   :style do
    raw @project.generators.minimize_css.do_input! File.read(path)
  end
end


13
14
15
16
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 13

def link_tag(source, relation, type = '')
  type = " type='#{type}'" if type
  '<link rel="' + relation + '" href="' + source + '"' + type + '/>'
end

#meta_tag(type, content) ⇒ Object



5
6
7
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 5

def meta_tag(type, content)
  '<meta name="' + type + '" content="' + content + '" />'
end

#meta_tag_http(type, content) ⇒ Object



9
10
11
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 9

def meta_tag_http(type, content)
  '<meta http-equiv="' + type + '" content="' + content + '" />'
end

#with_coffee(&block) ⇒ Object



26
27
28
29
30
31
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 26

def with_coffee(&block)
  input = capture_haml(&block)
   :script do
    raw @project.generators.compile_coffee.do_input! input
  end
end

#with_sass(&block) ⇒ Object



33
34
35
36
37
38
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 33

def with_sass(&block)
  input = capture_haml(&block)
   :style do
    raw @project.generators.compile_sass.do_input! input
  end
end