Sha256: 2bdda0e718d54e8a087a5e9b0e1d26255302a51a1ef03b31f6b2180dea92ed91

Contents?: true

Size: 851 Bytes

Versions: 12

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

12 entries across 12 versions & 1 rubygems

Version Path
machined-0.7.1 lib/machined/processors/front_matter_processor.rb
machined-0.7.0 lib/machined/processors/front_matter_processor.rb
machined-0.6.0 lib/machined/processors/front_matter_processor.rb
machined-0.5.0 lib/machined/processors/front_matter_processor.rb
machined-0.4.0 lib/machined/processors/front_matter_processor.rb
machined-0.3.1 lib/machined/processors/front_matter_processor.rb
machined-0.3.0 lib/machined/processors/front_matter_processor.rb
machined-0.2.2 lib/machined/processors/front_matter_processor.rb
machined-0.2.1 lib/machined/processors/front_matter_processor.rb
machined-0.2.0 lib/machined/processors/front_matter_processor.rb
machined-0.1.1 lib/machined/processors/front_matter_processor.rb
machined-0.1.0 lib/machined/processors/front_matter_processor.rb