Sha256: 94dffb16dae30aaed7554117cbf446567dde328d9239c8c8b657e1932befebbc

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

require 'tilt'

# We need to ensure that Tilt's ERB template uses
# the same output variable that Padrino's helpers expect.
Tilt::ERBTemplate.default_output_variable = '@_out_buf'

module Machined
  module Helpers
    module OutputHelpers
      # A hash of Tilt templates that support
      # capture blocks where the key is the name
      # of the template.
      CAPTURE_ENGINES = {
        'Tilt::HamlTemplate'   => :haml,
        'Tilt::ERBTemplate'    => :erb,
        'Tilt::ErubisTemplate' => :erubis,
        'Slim::Template'       => :slim
      }
      
      protected
      
      # Attempts to return the current engine based on
      # the processors for this file. This is used by
      # Padrino's helpers to determine which type of template
      # engine to use when capturing blocks.
      def current_engine
        unless defined?(@current_engine)
          processors = environment.attributes_for(self.pathname).processors
          processors.each do |processor|
            if engine = CAPTURE_ENGINES[processor.to_s]
              @current_engine = engine
              break
            end
          end
        end
        
        @current_engine
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
machined-1.0.0 lib/machined/helpers/output_helpers.rb
machined-0.9.3 lib/machined/helpers/output_helpers.rb
machined-0.9.2 lib/machined/helpers/output_helpers.rb
machined-0.9.1 lib/machined/helpers/output_helpers.rb
machined-0.9.0 lib/machined/helpers/output_helpers.rb
machined-0.8.0 lib/machined/helpers/output_helpers.rb