Sha256: 32a4d52f4c33f34b0b6d9c85fbcc2506b3a1afc55730599c433c42432c8a606b

Contents?: true

Size: 954 Bytes

Versions: 1

Compression:

Stored size: 954 Bytes

Contents

module Rakyll
  module Compiler
    class Match
      include Apply
      include SetFilename
      attr_reader :body, :url

      def initialize(source_filename)
        @source_filename = source_filename
        metadata_string, markdown_string = File.read(@source_filename).split("---\n")
        set_metadata_from_yaml(metadata_string)
        set_body_from_markdown(markdown_string)
        set_filename(source_filename, '.html')
      end

      def save
        File.write(@filename, @body)
      end

      private
      def set_metadata_from_yaml(metadata_string)
        YAML.load(metadata_string).each do |key, value|
          instance_variable_set(:"@#{key}", value)
          singleton_class.class_eval { attr_reader key }
        end
      end

      def set_body_from_markdown(markdown_string)
        markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
        @body = markdown.render(markdown_string)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rakyll-0.1.0 lib/rakyll/compiler/match.rb