Module: AssetHelper
- Includes:
- ActionView::Context
- 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
- #with_coffee(&block) ⇒ Object
- #with_sass(&block) ⇒ Object
Instance Method Details
#external_path?(path) ⇒ Boolean
9 10 11 |
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 9 def external_path?(path) path.start_with?('//') || path.start_with?('http') end |
#file_exists?(path) ⇒ Boolean
13 14 15 |
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 13 def file_exists?(path) File.exist? File.join(EasyHtmlGenerator::DIST_PATH, path) end |
#glyph_icon(icon, content = '') ⇒ Object
35 36 37 |
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 35 def glyph_icon(icon, content = '') content_tag(:span, content, class: glyph_icon_classes(icon)) end |
#glyph_icon_classes(icon) ⇒ Object
31 32 33 |
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 31 def glyph_icon_classes(icon) "glyphicon glyphicon-#{icon}" end |
#headjs_javascript_include_tag(tag, path) ⇒ Object
39 40 41 42 43 |
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 39 def headjs_javascript_include_tag(tag, path) content_tag :script do raw "head.load({'#{tag}': '#{path_to_js(path)}'});" end end |
#headjs_stylesheet_link_tag(tag, path) ⇒ Object
45 46 47 |
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 45 def headjs_stylesheet_link_tag(tag, path) headjs_javascript_include_tag(tag, path_to_css(path)) end |
#inline_javascript_include_tag(path) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 64 def inline_javascript_include_tag(path) return path if external_path?(path) scripts_path = @project.dist_path_to(:scripts, path) if File.exists? 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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 49 def inline_stylesheet_link_tag(path) return path if external_path?(path) styles_path = @project.dist_path_to(:styles, path) if File.exists? 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 |
#with_coffee(&block) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 17 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
24 25 26 27 28 29 |
# File 'lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb', line 24 def with_sass(&block) input = capture_haml(&block) content_tag :style do raw @project.generators.compile_sass.do_input input end end |