Sha256: 6db4422ad4067d3126aa919b8bd33a22b33da5bfd36254c7fa9501877e2d90b7

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

require 'ruhl'
require 'ruhl/rails/ruhl_presenter'

module Ruhl
  class Plugin < ActionView::TemplateHandler

    def initialize(action_view)
      @action_view = action_view
    end
    
    def render(template, options = {})
      layout = options[:layout]
      if layout
        layout_template = @action_view.controller.send(:find_layout, layout, 
                                                       @action_view.controller.send(:default_template_format) )
      else
        unless layout == false
          layout_template = @action_view.controller.active_layout
        end
      end

      if layout_template
        options[:layout]        = layout_template.filename 
        options[:layout_source] = layout_template.source
      end

      Ruhl::Engine.new(template.source, options).render(@action_view)
    end
  end
end

ActionView::Template.register_template_handler(:ruhl, Ruhl::Plugin)

ActionView::Template.exempt_from_layout(:ruhl)


module Ruhl
  class Engine
    private

    def render_partial
      template = scope.view_paths.find_template(call_result)

      raise PartialNotFoundError.new(call_result) unless template

      render_nodes Nokogiri::HTML.fragment( template.source )
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruhl-1.3.6 lib/ruhl/rails.rb
ruhl-1.3.5 lib/ruhl/rails.rb
ruhl-1.3.4 lib/ruhl/rails.rb