Sha256: f01956cd6df8096095efacd7cca9ab6e78b0d5e402b85c00c6c9e6a6b0b0b39f
Contents?: true
Size: 1.69 KB
Versions: 4
Compression:
Stored size: 1.69 KB
Contents
# encoding: utf-8 require 'action_view' helper_path = 'easy_html_generator/generator/compile/haml/helper' require "#{helper_path}/activesupport_override.rb" require "#{helper_path}/asset_helper.rb" # this class represents the render context for a haml file class EasyHtmlGenerator::Generator::Compile::Haml::Context # Any properties of this object are available in the Haml templates. attr_reader :project include ActionView::Helpers include ActivesupportOverride include AssetHelper def initialize(project, config, scope) @config = config @project = project @scope = scope @input_folder = @project.src_path_to :views load_helper EasyHtmlGenerator::SHARED_HELPER_PATH load_helper @project.src_path_to :helper end def load_helper(folder) Dir.glob("#{folder}/**/*.rb").each do |path| load path file_without_ext = path.split('/')[-1].split('.').first module_name = file_without_ext.classify STDERR.puts " | -> loading haml helper: #{module_name.green}" self.class.send(:include, module_name.constantize) end end def render_partial(file_name) file_to_render = "#{@input_folder}/#{file_name}.haml" if @scope # Look for a partial prefixed with the current "scope" # (which is just the name of the primary template being rendered). scope_file = "#{@input_folder}/#{@scope}_#{file_name}.haml" # Use it if it's there. file_to_render = scope_file if File.exist? scope_file end if File.exist? file_to_render Haml::Engine.new(File.read(file_to_render), @config).render self end rescue StandardError => e raise e, "#{e.message} in #{file_name} ", e.backtrace end end
Version data entries
4 entries across 4 versions & 1 rubygems