Sha256: 2aa95e56a0096005d254fb7eba285f6ebec12c03c50ae4fa7e7e813735033f50

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

module Jekyll
  module Slim
    class Converter < ::Jekyll::Converter
      safe false
      priority :low

      def matches(ext)
        ext =~ /slim/i
      end

      def output_ext(ext)
        '.html'
      end

      def convert(content)
        self.class.convert(@config, content)
      end

      class << self
        def convert(config, content)
          config = symbolize_hash(config['slim'] || {}).merge(file: Convertible.slim_current_convertible.path)
          context = hash2ostruct(Utils.deep_merge_hashes(Convertible.slim_current_convertible.site.site_payload,
                                                         page: Convertible.slim_current_convertible.to_liquid))
          # Allow also direct access to the site and page object from Slim
          context.site_object = Convertible.slim_current_convertible.site
          context.page_object = Convertible.slim_current_convertible
          ::Sliq::Converter.new(config) { content }.render(context)
        end

        def hash2ostruct(hash)
          h = {}
          hash.keys.each do |k|
            v = hash[k]
            h[k] = Hash === v ? hash2ostruct(v) : v
          end
          OpenStruct.new(h)
        end

        def symbolize_hash(hash)
          h = {}
          hash.keys.each do |k|
            v = hash[k]
            h[(k.to_sym rescue k) || k] = Hash === v ? symbolize_hash(v) : v
          end
          h
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-slim-0.10.0 lib/jekyll/slim/converter.rb