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
- #external_path?(path) ⇒ Boolean
- #file_exists?(path) ⇒ Boolean
- #glyph_icon(icon, content = '') ⇒ Object
- #glyph_icon_classes(icon) ⇒ Object
- #headjs_javascript_include_tag(tag, path) ⇒ Object
- #headjs_stylesheet_link_tag(tag, path) ⇒ Object
- #inline_javascript_include_tag(path) ⇒ Object
- #inline_stylesheet_link_tag(path) ⇒ Object
- #link_tag(source, relation, type = '') ⇒ Object
- #meta_tag(type, content) ⇒ Object
- #meta_tag_http(type, content) ⇒ Object
- #with_coffee(&block) ⇒ Object
- #with_sass(&block) ⇒ Object
Instance Method Details
#external_path?(path) ⇒ 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
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 = '') content_tag(: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) content_tag :script do raw "head.load({'#{tag}': '#{path_to_javascript(path)}'});" end end |
#headjs_stylesheet_link_tag(tag, path) ⇒ Object
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 content_tag :script do raw @project.generators.minimize_js.do_input! File.read(path) end end |
#inline_stylesheet_link_tag(path) ⇒ Object
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 content_tag :style do raw @project.generators.minimize_css.do_input! File.read(path) end end |
#link_tag(source, relation, type = '') ⇒ Object
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 (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 (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) content_tag :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) content_tag :style do raw @project.generators.compile_sass.do_input! input end end |