Module: AssetHelper

Includes:
ActionView::Context
Included in:
Generator::Context
Defined in:
lib/generator/helper/asset_helper.rb

Instance Method Summary collapse

Instance Method Details

#file_exists?(relative_path) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/generator/helper/asset_helper.rb', line 7

def file_exists?(relative_path)
  File.exists?("#{@output_folder}/#{relative_path}")
end

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



29
30
31
# File 'lib/generator/helper/asset_helper.rb', line 29

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

#glyph_icon_classes(icon) ⇒ Object



25
26
27
# File 'lib/generator/helper/asset_helper.rb', line 25

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

#headjs_javascript_include_bower_tag(tag, path) ⇒ Object



56
57
58
# File 'lib/generator/helper/asset_helper.rb', line 56

def headjs_javascript_include_bower_tag(tag, path)
  headjs_javascript_include_tag(tag, path_to_bower(path))
end

#headjs_javascript_include_tag(tag, path) ⇒ Object



50
51
52
53
54
# File 'lib/generator/helper/asset_helper.rb', line 50

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


60
61
62
# File 'lib/generator/helper/asset_helper.rb', line 60

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

#javascript_include_bower_tag(path) ⇒ Object



41
42
43
# File 'lib/generator/helper/asset_helper.rb', line 41

def javascript_include_bower_tag(path)
  '<script src="'+path_to_bower(path)+'"></script>'
end

#path_to_bower(path) ⇒ Object



45
46
47
48
# File 'lib/generator/helper/asset_helper.rb', line 45

def path_to_bower(path)
  return "bower_components/#{path}"
  path
end

#select_partials(dir = '*', &block) ⇒ Object



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

def select_partials(dir='*', &block)
  folder = "#{@input_folder}/partials/#{dir}"
  Dir.glob("#{folder}").each do |partial|
    partial = partial.sub("#{@input_folder}/partials/", '').sub('.haml', '')
    block.call(partial) if block_given?
  end
end

#with_coffee(&block) ⇒ Object



11
12
13
14
15
16
# File 'lib/generator/helper/asset_helper.rb', line 11

def with_coffee(&block)
  input = capture_haml(&block)
   :script do
    raw Uglifier.compile(Generator::CoffeeGenerator.new.compile(input))
  end
end

#with_sass(&block) ⇒ Object



18
19
20
21
22
23
# File 'lib/generator/helper/asset_helper.rb', line 18

def with_sass(&block)
  input = capture_haml(&block)
   :style do
    raw Generator::SassGenerator.new.compile(input)
  end
end