Sha256: d6ac78b7d29f5dada5fa1b7ab35e2fe2423f25b6bb7b2cb0d310eb3cf20559a3

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

module Jekyll
  module Convertible
    # Return the contents as a string
    def to_s
      self.content || ''
    end

    # Read the YAML frontmatter
    #   +base+ is the String path to the dir containing the file
    #   +name+ is the String filename of the file
    #
    # Returns nothing
    def read_yaml(base, name)
      self.content = File.read(File.join(base, name))

      if self.content =~ /^(---\s*\n.*?)\n---\s*\n/m
        self.content = self.content[($1.size + 5)..-1]

        self.data = YAML.load($1)
      end
    end

    # Transform the contents based on the file extension.
    #
    # Returns nothing
    def transform
      case self.ext[1..-1]
      when /textile/i
        self.ext = ".html"
        self.content = RedCloth.new(self.content).to_html
      when /markdown/i, /mkdn/i, /md/i
        self.ext = ".html"
        self.content = Jekyll.markdown_proc.call(self.content)
      end
    end

    # Add any necessary layouts to this convertible document
    #   +layouts+ is a Hash of {"name" => "layout"}
    #   +site_payload+ is the site payload hash
    #
    # Returns nothing
    def do_layout(payload, layouts)
      # render and transform content (this becomes the final content of the object)
      self.content = Liquid::Template.parse(self.content).render(payload, [Jekyll::Filters])
      self.transform

      # output keeps track of what will finally be written
      self.output = self.content

      # recursively render layouts
      layout = layouts[self.data["layout"]]
      while layout
        payload = payload.deep_merge({"content" => self.output, "page" => layout.data})
        self.output = Liquid::Template.parse(layout.content).render(payload, [Jekyll::Filters])

        layout = layouts[layout.data["layout"]]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tristandunn-jekyll-0.3.0 lib/jekyll/convertible.rb