Sha256: dbd98d9e03676bb983a7d839e61cfd10000e1848e41fa6007117f46016f46d40

Contents?: true

Size: 859 Bytes

Versions: 3

Compression:

Stored size: 859 Bytes

Contents

module ActionView #:nodoc:
  module TemplateHandlers #:nodoc:
    class Erector
      def self.line_offset
        2
      end

      attr_reader :view
      def initialize(view)
        @view = view
      end

      def compilable?
        true
      end

      ActionView::Base.register_template_handler :rb, ActionView::TemplateHandlers::Erector

      def render(template, local_assigns)
        relative_path_parts = view.first_render.split('/')
        require_dependency view.template_file_path

        dot_rb = /\.rb$/
        widget_class = relative_path_parts.inject(Views) do |mod, node|
          mod.const_get(node.gsub(dot_rb, '').gsub(".html", "").camelize)
        end
        render_method = view.is_partial_template? ? 'render_partial' : 'render'
        widget_class.new(view, view.assigns).to_s(render_method)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
pivotal-erector-0.5.1 lib/erector/rails/template_handlers/1.2.5/action_view_template_handler.rb
erector-0.5.1 lib/erector/rails/template_handlers/1.2.5/action_view_template_handler.rb
erector-0.5.0 lib/erector/rails/template_handlers/1.2.5/action_view_template_handler.rb