class Generator::HamlGenerator

Public Class Methods

changed?(path) click to toggle source
# File lib/generator/haml_generator.rb, line 50
def self.changed?(path)
  true #allways recompile haml because of partials etc.
end
new() click to toggle source
# File lib/generator/haml_generator.rb, line 12
def initialize()
  @example_boolean = false
  @haml_options = { attr_wrapper: '"', format: :html5 }
  @compressor = HtmlCompressor::Compressor.new
end

Public Instance Methods

compile(input, output_file, layout, context, scope) click to toggle source
# File lib/generator/haml_generator.rb, line 36
def compile(input, output_file, layout, context, scope)
  # If the file being processed by Haml contains a yield statement, the block passed to
  # "render" will be called when it's hit.
  result = layout.render(context, body_class: scope) do
    # Render the actual page contents in place of the call to "yield".
    body = Haml::Engine.new(input, @haml_options)
    body.render(context)
  end

  @compressor.compress result
rescue Exception => e
  raise $!, "#{$!} TEMPLATE::#{output_file} ", $!.backtrace
end
generate(input_folder, output_folder) click to toggle source
# File lib/generator/haml_generator.rb, line 18
def generate(input_folder, output_folder)
  layout_path = "#{input_folder}/layout.haml"
  return unless File.file? layout_path
  layout      = Haml::Engine.new(File.read(layout_path), @haml_options)

  Dir.glob("#{input_folder}/*.haml").select do |input_file|
    next unless File.file? input_file and !input_file.include? 'layout.haml'

    output_file_name = input_file.split('/')[-1].gsub('.haml', '.html')
    output_file      = File.join(output_folder, output_file_name)
    scope            = output_file_name.split('.').first
    context          = Context.new(@example_boolean, scope, @haml_options,
                                  input_folder, output_folder)

    compile_file(input_file, output_file, layout, context, scope)
  end
end