Sha256: 2ce475c49f06b5668465c848d8469120c77c0a37f4f09e77b6a4abfbb15e5af4
Contents?: true
Size: 1.98 KB
Versions: 5
Compression:
Stored size: 1.98 KB
Contents
# encoding: utf-8 require 'fileutils' require 'haml' require 'easy_html_generator/generator/base' # this generator compiles haml files from src folder and copies them # to the dist folder class EasyHtmlGenerator::Generator::Compile::Haml < EasyHtmlGenerator::Generator::Base require 'easy_html_generator/generator/compile/haml/context' require 'easy_html_generator/generator/compile/haml/layout' def initialize(project, config) super(project, config) @config.src = project.config.paths.src.views @config.dest = project.config.paths.dist.views end def do_input(input, layout, context, scope, _input_file) # 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, @config.renderer) body.render(context) end return result unless @config.minimize EasyHtmlGenerator::Generator::Minimize::Html.compress result end def should_do_file?(i) # dont check if file changed, because partials could have changed !File.basename(i).start_with? '_' end def input_to_output_file(i) super(i).gsub('.html.haml', '.html') end def generate return unless @config.enabled log_running FileUtils.mkdir_p dest_path walk_files(File.join(src_path, @config.selector)) do |i, o| next unless should_do_file? i compile_file i, o end end def compile_file(src, target) file_name = File.basename src scope = file_name.split('.').first context = Context.new(@project, @config, scope) layout = Layout.layout_from_file(@project.src_path_to(:views), src, @config.renderer) begin do_file(src, target, layout, context, scope) rescue StandardError => e raise e, "#{e.message} in #{src} ", e.backtrace end end end
Version data entries
5 entries across 5 versions & 1 rubygems