Sha256: 41ae4ca0991ab3f36c51efd10c8f10d70db1417daf4b40e4e43501daf8ac8da8

Contents?: true

Size: 1.92 KB

Versions: 7

Compression:

Stored size: 1.92 KB

Contents

require 'awestruct/handler_chain'
require 'awestruct/handlers/base_tilt_handler'
require 'awestruct/handlers/file_handler'
require 'awestruct/handlers/front_matter_handler'
require 'awestruct/handlers/interpolation_handler'
require 'awestruct/handlers/layout_handler'

require 'tilt'

module Awestruct
  module Handlers

    class TiltMatcher
      def match(path)
        !Tilt[path].nil?
      end
    end

    class NonInterpolatingTiltMatcher
      EXT_REGEX = /\.(haml|slim|erb|mustache)$/

      def match(path)
        if match = EXT_REGEX.match(path)
          if match[0] == '.slim' && Tilt[path].nil?
            require 'slim'
          end
          true
        else
          false
        end
      end
    end

    class TiltHandler < BaseTiltHandler

      INTERPOLATION_CHAIN = Awestruct::HandlerChain.new( Awestruct::Handlers::TiltMatcher.new(),
        Awestruct::Handlers::FileHandler,
        Awestruct::Handlers::FrontMatterHandler,
        Awestruct::Handlers::InterpolationHandler,
        Awestruct::Handlers::TiltHandler,
        Awestruct::Handlers::LayoutHandler
      )

      NON_INTERPOLATION_CHAIN = Awestruct::HandlerChain.new( Awestruct::Handlers::NonInterpolatingTiltMatcher.new(),
        Awestruct::Handlers::FileHandler,
        Awestruct::Handlers::FrontMatterHandler,
        Awestruct::Handlers::TiltHandler,
        Awestruct::Handlers::LayoutHandler
      )

      def initialize(site, delegate)
        super( site, delegate )
      end

    end

  end
end

require 'awestruct/handlers/template/mustache'
Tilt::register Tilt::MustacheTemplate, '.mustache'

# As of Haml 4.0.0, Textile is no longer registered by default
# Monkeypatch the Tilt templates to force Textile to be registered
class Tilt::HamlTemplate
  def initialize_engine
    require_template_library 'haml'
    if Haml::VERSION >= '4.0.0' && !Haml::Filters.constants.include?('Textile')
      Haml::Filters.register_tilt_filter 'Textile'
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
awestruct-0.5.3 lib/awestruct/handlers/tilt_handler.rb
awestruct-0.5.2.1 lib/awestruct/handlers/tilt_handler.rb
awestruct-0.5.2 lib/awestruct/handlers/tilt_handler.rb
awestruct-0.5.1 lib/awestruct/handlers/tilt_handler.rb
awestruct-0.5.1a lib/awestruct/handlers/tilt_handler.rb
awestruct-0.5.0 lib/awestruct/handlers/tilt_handler.rb
awestruct-0.5.0.cr lib/awestruct/handlers/tilt_handler.rb