Module: Jekyll::Convertible

### Home Classes Methods

### In Files

- lib/jekyll/convertible.rb

### Methods

- #converter
- #do_layout
- #output_ext
- #read_yaml
- #render_all_layouts
- #render_liquid
- #to_liquid
- #to_s
- #transform
- #write

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Jekyll
- Jekyll::Command
- Jekyll::Commands
- Jekyll::Commands::Build
- Jekyll::Commands::Doctor
- Jekyll::Commands::New
- Jekyll::Commands::Serve
- Jekyll::Configuration
- Jekyll::Converter
- Jekyll::Converters
- Jekyll::Converters::Identity
- Jekyll::Converters::Markdown
- Jekyll::Converters::Markdown::KramdownParser
- Jekyll::Converters::Markdown::MarukuParser
- Jekyll::Converters::Markdown::RDiscountParser
- Jekyll::Converters::Markdown::RedcarpetParser
- Jekyll::Converters::Markdown::RedcarpetParser::CommonMethods
- Jekyll::Converters::Markdown::RedcarpetParser::WithPygments
- Jekyll::Converters::Markdown::RedcarpetParser::WithoutPygments
- Jekyll::Converters::Textile
- Jekyll::Convertible
- Jekyll::Deprecator
- Jekyll::Draft
- Jekyll::Excerpt
- Jekyll::FatalException
- Jekyll::Filters
- Jekyll::Generator
- Jekyll::Generators
- Jekyll::Generators::Pagination
- Jekyll::GistTag
- Jekyll::Layout
- Jekyll::Page
- Jekyll::Pager
- Jekyll::Plugin
- Jekyll::Post
- Jekyll::RelatedPosts
- Jekyll::Site
- Jekyll::Site::Cleaner
- Jekyll::StaticFile
- Jekyll::Stevenson
- Jekyll::Tags
- Jekyll::Tags::HighlightBlock
- Jekyll::Tags::IncludeTag
- Jekyll::Tags::PostComparer
- Jekyll::Tags::PostUrl
- Jekyll::URL
- Date
- Enumerable
- Hash
- Object

No matching classes.

# Jekyll::Convertible

### Public Instance Methods

converter() click to toggle source

Determine which converter to use based on this convertible's extension.

Returns the Converter instance.

    # File lib/jekyll/convertible.rb, line 68
    def converter
      @converter ||= self.site.converters.find { |c| c.matches(self.ext) }
    end

do_layout(payload, layouts) click to toggle source

Add any necessary layouts to this convertible document.

payload - The site payload Hash. layouts - A Hash of {"name" => "layout"}.

Returns nothing.

    # File lib/jekyll/convertible.rb, line 131
    def do_layout(payload, layouts)
      info = { :filters => [Jekyll::Filters], :registers => { :site => self.site, :page => payload['page'] } }

      # render and transform content (this becomes the final content of the object)
      payload["pygments_prefix"] = converter.pygments_prefix
      payload["pygments_suffix"] = converter.pygments_suffix

      self.content = self.render_liquid(self.content,
                                        payload,
                                        info)
      self.transform

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

      self.render_all_layouts(layouts, payload, info)
    end

output_ext() click to toggle source

Determine the extension depending on content_type.

Returns the String extension for the output file.

    e.g. ".html" for an HTML output file.

    # File lib/jekyll/convertible.rb, line 60
    def output_ext
      converter.output_ext(self.ext)
    end

read_yaml(base, name) click to toggle source

Read the YAML frontmatter.

base - The String path to the dir containing the file. name - The String filename of the file.

Returns nothing.

    # File lib/jekyll/convertible.rb, line 28
    def read_yaml(base, name)
      begin
        self.content = File.read(File.join(base, name))

        if self.content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/
          self.content = $POSTMATCH
          self.data = YAML.safe_load($1)
        end
      rescue SyntaxError => e
        puts "YAML Exception reading #{File.join(base, name)}: #{e.message}"
      rescue Exception => e
        puts "Error reading file #{File.join(base, name)}: #{e.message}"
      end

      self.data ||= {}
    end

render_all_layouts(layouts, payload, info) click to toggle source

Recursively render layouts

layouts - a list of the layouts payload - the payload for Liquid info - the info for Liquid

Returns nothing

    # File lib/jekyll/convertible.rb, line 103
    def render_all_layouts(layouts, payload, info)
      # recursively render layouts
      layout = layouts[self.data["layout"]]
      used = Set.new([layout])

      while layout
        payload = payload.deep_merge({"content" => self.output, "page" => layout.data})

        self.output = self.render_liquid(layout.content,
                                         payload,
                                         info)

        if layout = layouts[layout.data["layout"]]
          if used.include?(layout)
            layout = nil # avoid recursive chain
          else
            used << layout
          end
        end
      end
    end

render_liquid(content, payload, info) click to toggle source

Render Liquid in the content

content - the raw Liquid content to render payload - the payload for Liquid info - the info for Liquid

Returns the converted content

    # File lib/jekyll/convertible.rb, line 79
    def render_liquid(content, payload, info)
      Liquid::Template.parse(content).render!(payload, info)
    rescue Exception => e
      Jekyll.logger.error "Liquid Exception:", "#{e.message} in #{self.path}"
      raise e
    end

to_liquid(attrs = nil) click to toggle source

Convert this Convertible's data to a Hash suitable for use by Liquid.

Returns the Hash representation of this Convertible.

    # File lib/jekyll/convertible.rb, line 89
    def to_liquid(attrs = nil)
      further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map { |attribute|
        [attribute, send(attribute)]
      }]
      data.deep_merge(further_data)
    end

to_s() click to toggle source

Returns the contents as a String.

    # File lib/jekyll/convertible.rb, line 18
    def to_s
      self.content || ''
    end

transform() click to toggle source

Transform the contents based on the content type.

Returns nothing.

    # File lib/jekyll/convertible.rb, line 48
    def transform
      self.content = converter.convert(self.content)
    rescue => e
      Jekyll.logger.error "Conversion error:", "There was an error converting" +
        " '#{self.path}'."
      raise e
    end

write(dest) click to toggle source

Write the generated page file to the destination directory.

dest - The String path to the destination dir.

Returns nothing.

    # File lib/jekyll/convertible.rb, line 154
    def write(dest)
      path = destination(dest)
      FileUtils.mkdir_p(File.dirname(path))
      File.open(path, 'wb') do |f|
        f.write(self.output)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.