Sha256: 3e0c4fb1990f6cb5977dc9696cf73fd0a54031ad2e32d1f76dacd6efcfbd134e

Contents?: true

Size: 1.16 KB

Versions: 9

Compression:

Stored size: 1.16 KB

Contents

require 'tilt'

module Temple
  module Templates
    class Tilt < ::Tilt::Template
      extend Mixins::Template

      define_options :mime_type => 'text/html'

      def self.default_mime_type
        default_options[:mime_type]
      end

      def self.default_mime_type=(mime_type)
        default_options[:mime_type] = mime_type
      end

      # Prepare Temple template
      #
      # Called immediately after template data is loaded.
      #
      # @return [void]
      def prepare
        # Overwrite option: No streaming support in Tilt
        opts = {}.update(self.class.default_options).update(options).update(:file => eval_file, :streaming => false)
        opts.delete(:mime_type)
        opts.delete(:outvar) # Sinatra gives us this invalid variable
        @src = self.class.compile(data, opts)
      end

      # A string containing the (Ruby) source code for the template.
      #
      # @param [Hash]   locals Local variables
      # @return [String] Compiled template ruby code
      def precompiled_template(locals = {})
        @src
      end

      def self.register_as(*names)
        ::Tilt.register(self, *names.map(&:to_s))
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
temple-0.6.8 lib/temple/templates/tilt.rb
temple-0.6.7 lib/temple/templates/tilt.rb
temple-0.6.6 lib/temple/templates/tilt.rb
temple-0.6.5 lib/temple/templates/tilt.rb
temple-0.6.4 lib/temple/templates/tilt.rb
temple-0.6.3 lib/temple/templates/tilt.rb
temple-0.6.0 lib/temple/templates/tilt.rb
temple-0.5.5 lib/temple/templates/tilt.rb
temple-0.5.4 lib/temple/templates/tilt.rb