Module: Jekyll::Convertible
Instance Method Summary collapse
-
#content_type ⇒ Object
Determine which formatting engine to use based on this convertible’s extension.
-
#do_layout(payload, layouts) ⇒ Object
Add any necessary layouts to this convertible document
layoutsis a Hash of => “layout”site_payloadis the site payload hash. -
#read_yaml(base, name) ⇒ Object
Read the YAML frontmatter
baseis the String path to the dir containing the filenameis the String filename of the file. -
#to_s ⇒ Object
Return the contents as a string.
-
#transform ⇒ Object
Transform the contents based on the file extension.
Instance Method Details
#content_type ⇒ Object
Determine which formatting engine to use based on this convertible’s extension
Returns one of :textile, :markdown or :unknown
52 53 54 55 56 57 58 59 60 |
# File 'lib/jekyll/convertible.rb', line 52 def content_type case self.ext[1..-1] when /textile/i return 'textile' when /markdown/i, /mkdn/i, /md/i, /mkd/i return 'markdown' end return 'unknown' 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
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jekyll/convertible.rb', line 67 def do_layout(payload, layouts) payload['site']['source'] = self.site.source payload['page']['uid'] = self.uid if self.is_a?(Jekyll::Post) # render and transform content (this becomes the final content of the object) erb = Engine.new(payload) erb.content = self.content self.content = erb.render 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 }) erb = Engine.new(payload) erb.content = self.content erb.layout = layout.content self.output = erb.render layout = layouts[layout.data["layout"]] end 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
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jekyll/convertible.rb', line 22 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] self.data = YAML.load($1) end self.data ||= {} end |
#to_s ⇒ Object
Return the contents as a string
13 14 15 |
# File 'lib/jekyll/convertible.rb', line 13 def to_s self.content || '' end |
#transform ⇒ Object
Transform the contents based on the file extension.
Returns nothing
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/jekyll/convertible.rb', line 37 def transform case self.content_type when 'textile' self.ext = ".html" self.content = self.site.textile(self.content) when 'markdown' self.ext = ".html" self.content = self.site.markdown(self.content) end end |