class Rugular::HamlRenderer

Attributes

file[RW]

Public Class Methods

new(file) click to toggle source
# File lib/rugular/tasks/helpers/haml_renderer.rb, line 12
def initialize(file)
  @file = file
end
render(file) click to toggle source
# File lib/rugular/tasks/helpers/haml_renderer.rb, line 8
def self.render(file)
  new(file).render
end

Public Instance Methods

render() click to toggle source
# File lib/rugular/tasks/helpers/haml_renderer.rb, line 16
def render
  Haml::Engine.new(file.read).render(get_binding)
end

Private Instance Methods

copy_bower_files(bower_components) click to toggle source
# File lib/rugular/tasks/helpers/haml_renderer.rb, line 63
def copy_bower_files(bower_components)
  bower_components.each do |bower_component|
    FileUtils.mkdir_p(
      File.dirname(bower_component.gsub('bow', '.tmp/bow'))
    )
    FileUtils.cp_r(
      bower_component, bower_component.gsub('bow', '.tmp/bow')
    ) if File.file?(bower_component)
  end
end
get_binding() click to toggle source
# File lib/rugular/tasks/helpers/haml_renderer.rb, line 24
def get_binding
  @_binding ||= binding
end
javascript_include_tag(*sources) click to toggle source

Override Action View to exclude the ‘javascripts’ folder.

# File lib/rugular/tasks/helpers/haml_renderer.rb, line 48
def javascript_include_tag(*sources)
  options = sources.extract_options!.stringify_keys
  path_options = options.extract!('protocol', 'extname').symbolize_keys
  copy_bower_files(
    sources.select { |source| source.match('bower_component') }
  )

  sources.uniq.map { |source|
    tag_options = {
      "src" => source.gsub('.tmp/', '')
    }.merge!(options)
    content_tag(:script, "", tag_options)
  }.join("\n").html_safe
end