Sha256: 2776809c7c7b13c7dfcd36225d79e53a64b6cf2259a5ad3a3a3c1208c0dd815c

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module Rail
  module Processor
    class Haml < Base
      def self.input_extension
        'haml'
      end

      def self.output_extension
        'html'
      end

      def self.mime_type
        'text/html'
      end

      def compile(filename, options = {}, &block)
        options = {
          filename: filename,
          line: 1,
          ugly: compress?
        }.merge(options)

        engine = ::Haml::Engine.new(File.read(filename), options)

        layout_filename = find_layout(filename)

        if layout_filename
          compile(layout_filename, options) do
            engine.render(options[:context], {}, &block)
          end
        else
          engine.render(options[:context], {}, &block)
        end
      end

      private

      def find_layout(filename)
        asset = "layouts/#{ filename.split('/')[-2] }"

        [ "#{ asset }.haml", "#{ asset }.html.haml" ].each do |asset|
          filename = pipeline.find(asset)
          return filename if filename
        end

        nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rail-0.0.7 lib/rail/processor/haml.rb
rail-0.0.6 lib/rail/processor/haml.rb