Sha256: d2992727e0c994da49a3283a59ede790e69db711c2c30ea9ba23204a76a193d7

Contents?: true

Size: 839 Bytes

Versions: 4

Compression:

Stored size: 839 Bytes

Contents

require 'yaml'
require 'tilt'

module Machined
  module Processors
    class FrontMatterProcessor < Tilt::Template
      # The Regexp that separates the YAML
      # front matter from the content.
      FRONT_MATTER_PARSER = /
        (
          \A\s*       # Beginning of file
          ^---\s*$\n* # Start YAML Block
          (.*?)\n*    # YAML data
          ^---\s*$\n* # End YAML Block
        )
        (.*)\Z        # Rest of File
      /mx

      # See `Tilt::Template#prepare`.
      def prepare
      end

      # See `Tilt::Template#evaluate`.
      def evaluate(context, locals = {}, &block)
        output = data
        if FRONT_MATTER_PARSER.match data
          locals         = YAML.load $2
          context.locals = locals if locals
          output         = $3
        end
        output
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
machined-1.1.0 lib/machined/processors/front_matter_processor.rb
machined-1.0.3 lib/machined/processors/front_matter_processor.rb
machined-1.0.2 lib/machined/processors/front_matter_processor.rb
machined-1.0.1 lib/machined/processors/front_matter_processor.rb