Module: Jekyll::Convertible

Included in:
Layout, Page, Post
Defined in:
lib/jekyll/convertible.rb

Instance Method Summary collapse

Instance Method Details

#converterObject

Determine which converter to use based on this convertible’s extension



55
56
57
# File 'lib/jekyll/convertible.rb', line 55

def converter
  @converter ||= self.site.converters.find { |c| c.matches(self.ext) }
end

#do_layout(payload, layouts) ⇒ Object

Add any necessary layouts to this convertible document

+layouts+ is a Hash of {"name" => "layout"}
+site_payload+ is the site payload hash

Returns nothing



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/jekyll/convertible.rb', line 64

def do_layout(payload, layouts)
  info = { :filters => [Jekyll::Filters], :registers => { :site => self.site } }

  # render and transform content (this becomes the final content of the object)
  payload["pygments_prefix"] = converter.pygments_prefix
  payload["pygments_suffix"] = converter.pygments_suffix
  
  begin
    self.content = Liquid::Template.parse(self.content).render(payload, info)
  rescue => e
    puts "Liquid Exception: #{e.message} in #{self.data["layout"]}"
  end
  
  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})

    begin
      content = converter.convert(layout.content)
      self.output = Liquid::Template.parse(content).render(payload, info)
    rescue => e
      puts "Liquid Exception: #{e.message} in #{self.data["layout"]}"
    end

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

#output_extObject

Determine the extension depending on content_type

Returns the extensions for the output file



49
50
51
# File 'lib/jekyll/convertible.rb', line 49

def output_ext
  converter.output_ext(self.ext)
end

#read_yaml(base, name) ⇒ Object

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jekyll/convertible.rb', line 23

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 + $2.size)..-1]

    begin
      self.data = YAML.load($1)
    rescue => e
      puts "YAML Exception: #{e.message}"
    end
  end

  self.data ||= {}
end

#to_sObject

Return the contents as a string



14
15
16
# File 'lib/jekyll/convertible.rb', line 14

def to_s
  self.content || ''
end

#transformObject

Transform the contents based on the content type.

Returns nothing



42
43
44
# File 'lib/jekyll/convertible.rb', line 42

def transform
  self.content = converter.convert(self.content)
end