Sha256: 4cb6087ce41fa27055f0fda04ecb2d041a383ad7722d15c2c100639eb9c8cf22

Contents?: true

Size: 1.84 KB

Versions: 20

Compression:

Stored size: 1.84 KB

Contents

require 'fortitude/rendering_context'
require 'fortitude/erector'

::ActiveSupport::SafeBuffer.class_eval do
  alias_method :fortitude_concat, :original_concat
  public :fortitude_concat
end

module Fortitude
  module Rails
    class Renderer
      class << self
        # TODO: Refactor this and render :widget => ... support into one method somewhere.
        def render(widget_class, template_handler, local_assigns, is_partial, &block)
          if ::Fortitude::Erector.is_erector_widget_class?(widget_class)
            return ::Erector::Rails.render(widget_class, template_handler, local_assigns, is_partial, &block)
          end

          total_assigns = template_handler.assigns.symbolize_keys.merge(local_assigns.symbolize_keys)

          needed_assigns = if widget_class.extra_assigns == :use
            total_assigns
          else
            widget_class.extract_needed_assigns_from(total_assigns)
          end

          widget = widget_class.new(needed_assigns)
          template_handler.with_output_buffer do
            rendering_context = template_handler.controller.fortitude_rendering_context_for(template_handler, block)

            # TODO: Refactor this -- both passing it into the constructor and setting yield_block here is gross.
            #
            # We need to call #with_yield_block here, because we can actually be invoked with different yield blocks
            # in the case of "partial layouts" (which most people probably don't even realize exist); we use the same
            # RC for both the initial view rendering and for the partial layout, but they need different yield blocks.
            # Yuck, but this does the job.
            rendering_context.with_yield_block(block) do
              widget.render_to(rendering_context)
            end
            rendering_context.flush!
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
fortitude-0.9.4-java lib/fortitude/rails/renderer.rb
fortitude-0.9.4 lib/fortitude/rails/renderer.rb
fortitude-0.9.3-java lib/fortitude/rails/renderer.rb
fortitude-0.9.3 lib/fortitude/rails/renderer.rb
fortitude-0.9.2-java lib/fortitude/rails/renderer.rb
fortitude-0.9.2 lib/fortitude/rails/renderer.rb
fortitude-0.9.1-java lib/fortitude/rails/renderer.rb
fortitude-0.9.1 lib/fortitude/rails/renderer.rb
fortitude-0.9.0-java lib/fortitude/rails/renderer.rb
fortitude-0.9.0 lib/fortitude/rails/renderer.rb
fortitude-0.0.10-java lib/fortitude/rails/renderer.rb
fortitude-0.0.10 lib/fortitude/rails/renderer.rb
fortitude-0.0.9-java lib/fortitude/rails/renderer.rb
fortitude-0.0.9 lib/fortitude/rails/renderer.rb
fortitude-0.0.7-java lib/fortitude/rails/renderer.rb
fortitude-0.0.7 lib/fortitude/rails/renderer.rb
fortitude-0.0.6-java lib/fortitude/rails/renderer.rb
fortitude-0.0.6 lib/fortitude/rails/renderer.rb
fortitude-0.0.5-java lib/fortitude/rails/renderer.rb
fortitude-0.0.5 lib/fortitude/rails/renderer.rb