Sha256: 6110e8993e247212f432a7457236f44cb42e8dcc7c8bad406b4e78f0e3be1a65

Contents?: true

Size: 851 Bytes

Versions: 6

Compression:

Stored size: 851 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

6 entries across 6 versions & 1 rubygems

Version Path
machined-1.0.0 lib/machined/processors/front_matter_processor.rb
machined-0.9.3 lib/machined/processors/front_matter_processor.rb
machined-0.9.2 lib/machined/processors/front_matter_processor.rb
machined-0.9.1 lib/machined/processors/front_matter_processor.rb
machined-0.9.0 lib/machined/processors/front_matter_processor.rb
machined-0.8.0 lib/machined/processors/front_matter_processor.rb