Sha256: fda91f9b922f4377a0bdc8dd3f25c593a7b32f928ab5ebed769ffde0cd32b981

Contents?: true

Size: 1.71 KB

Versions: 12

Compression:

Stored size: 1.71 KB

Contents

require 'tilt'
require 'active_support/inflector'
require 'fortitude/rendering_context'
require 'fortitude/doctypes'

module Fortitude
  module Tilt
    class FortitudeTemplate < ::Tilt::Template
      def prepare
        ::Object.class_eval(data)

        # 2014-06-19 ageweke -- Earlier versions of Tilt try to instantiate the engine with an empty tempate as a way
        # of making sure it can be created, so we have to support this case.
        if data.strip.length > 0
          @fortitude_class = ::Fortitude::Widget.widget_class_from_source(
            data,
            :magic_comment_text => 'fortitude_tilt_class',
            :class_names_to_try => Array(options[:fortitude_class]) + Array(options[:class_names_to_try]))
        end
      end

      def render(scope=Object.new, locals = nil, &block)
        locals ||= { }

        rendering_context = Fortitude::RenderingContext.new({
          :yield_block => block, :render_yield_result => false,
          :helpers_object => scope, :instance_variables_object => scope })

        widget_assigns = { }.with_indifferent_access

        scope.instance_variables.each do |instance_variable_name|
          if instance_variable_name.to_s =~ /^\@(.*)$/
            widget_assigns[$1] = scope.instance_variable_get(instance_variable_name)
          end
        end

        widget_assigns = widget_assigns.merge(locals)
        widget_assigns = fortitude_class.extract_needed_assigns_from(widget_assigns) unless fortitude_class.extra_assigns == :use

        widget = fortitude_class.new(widget_assigns)
        widget.render_to(rendering_context)
        rendering_context.output_buffer_holder.output_buffer
      end

      private
      attr_reader :fortitude_class
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
fortitude-0.9.1-java lib/fortitude/tilt/fortitude_template.rb
fortitude-0.9.1 lib/fortitude/tilt/fortitude_template.rb
fortitude-0.9.0-java lib/fortitude/tilt/fortitude_template.rb
fortitude-0.9.0 lib/fortitude/tilt/fortitude_template.rb
fortitude-0.0.10-java lib/fortitude/tilt/fortitude_template.rb
fortitude-0.0.10 lib/fortitude/tilt/fortitude_template.rb
fortitude-0.0.9-java lib/fortitude/tilt/fortitude_template.rb
fortitude-0.0.9 lib/fortitude/tilt/fortitude_template.rb
fortitude-0.0.7-java lib/fortitude/tilt/fortitude_template.rb
fortitude-0.0.7 lib/fortitude/tilt/fortitude_template.rb
fortitude-0.0.6-java lib/fortitude/tilt/fortitude_template.rb
fortitude-0.0.6 lib/fortitude/tilt/fortitude_template.rb