Sha256: 712c7c3c9b15713baa577aa28c062685a8307de63c75401c8a513c757b871019
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
module ActionView #:nodoc: module TemplateHandlers #:nodoc: class Erector < TemplateHandler include Compilable def self.line_offset 2 end ActionView::Template.instance_eval do register_template_handler :rb, ActionView::TemplateHandlers::Erector end def compile(template) relative_path_parts = template.path.split('/') is_partial = relative_path_parts.last =~ /^_/ require_dependency File.expand_path(template.filename) widget_class_parts = relative_path_parts.inject(['Views']) do |class_parts, node| class_parts << node.gsub(/^_/, "").gsub(/(\.html)?\.rb$/, '').camelize class_parts end widget_class_name = widget_class_parts.join("::") render_method = is_partial ? 'render_partial' : 'render' erb_template = <<-ERB <% assigns = instance_variables.inject({}) do |hash, name| hash[name.sub('@', "")] = instance_variable_get(name) hash end widget = #{widget_class_name}.new(self, assigns, output_buffer) widget.#{render_method} %> ERB ::ERB.new( erb_template, nil, ::ActionView::TemplateHandlers::ERB.erb_trim_mode, "@output_buffer" ).src end end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
pivotal-erector-0.5.1 | lib/erector/rails/template_handlers/2.2.0/action_view_template_handler.rb |
erector-0.5.1 | lib/erector/rails/template_handlers/2.2.0/action_view_template_handler.rb |