Sha256: 2fb699183aaf3b2910b5912f7eac8e6e467cfd89ebeb248305e48a9165e4ae25

Contents?: true

Size: 1.81 KB

Versions: 5

Compression:

Stored size: 1.81 KB

Contents

# encoding: utf-8
require 'coffee-script'
require 'uglifier'

# this module exposes additional features for haml files
module AssetHelper
  include ActionView::Context

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

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

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

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

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

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

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

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

  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

  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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
easy_html_generator-1.0.4 lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb
easy_html_generator-1.0.3 lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb
easy_html_generator-1.0.2 lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb
easy_html_generator-1.0.1 lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb
easy_html_generator-1.0.0 lib/easy_html_generator/generator/compile/haml/helper/asset_helper.rb