Sha256: 486a31263f090b57feec3538874d68e5f92db4f302d733fa46ce1f246abe6bf2

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

require "active_support"
require "action_view"
require 'set'

require "inline_templates/version"
require "inline_templates/builder"
require "inline_templates/blank_object"
require "inline_templates/buffer_wrapper"
require "inline_templates/rendering_context"
require "inline_templates/helpers"
require "inline_templates/template_handler.rb"

module InlineTemplates
  def self.render(view, details, locals, &block)
    identifier = "(inline:#{block.inspect})"
 
    handler = ->(template) do
      method_name = nil
      template.instance_exec do
        method_name = self.method_name
 
        view.singleton_class.send :define_method, "#{method_name}_block" do
          block 
        end
      end
 
      <<-EOF
        @output_buffer ||= ActionView::OutputBuffer.new
        context = ::InlineTemplates::RenderingContext.new(self, local_assigns, ::InlineTemplates::Builder.new)
        context.instance_exec &self.#{method_name}_block
        @output_buffer.to_s
      EOF
    end
 
    template = ActionView::Template.new("", identifier, handler, details)
    template.render view, locals
  end
end

ActionView::Template.register_template_handler :rit, InlineTemplates::TemplateHandler.new

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
inline_templates-1.0.0 lib/inline_templates.rb
inline_templates-0.0.6 lib/inline_templates.rb
inline_templates-0.0.5 lib/inline_templates.rb