Module: Broadway::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
layouts
is a Hash of => “layout”site_payload
is the site payload hash. - #read(attribute = nil) ⇒ Object
-
#read_yaml(path) ⇒ Object
Read the YAML frontmatter
base
is the String path to the dir containing the filename
is the String filename of the file You can also get the content from xml, so this might not need to run Returns nothing. -
#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
69 70 71 72 73 74 75 76 77 |
# File 'lib/broadway/convertible.rb', line 69 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
84 85 86 87 88 89 |
# File 'lib/broadway/convertible.rb', line 84 def do_layout(payload, layouts) info = { :filters => [], :registers => { :site => self.site } } # render and transform content (this becomes the final content of the object) payload["content_type"] = self.content_type self.output = Liquid::Template.parse(self.content).render(payload, info) end |
#read(attribute = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/broadway/convertible.rb', line 18 def read(attribute = nil) self.content = IO.read(self.path) if self.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m if attribute output = YAML.load($1)[attribute] || "" return output end self.content = self.content[($1.size + $2.size)..-1] end result = self.render(site.layouts, site.site_payload) self.content = self.output = nil result end |
#read_yaml(path) ⇒ Object
Read the YAML frontmatter
+base+ is the String path to the dir containing the file
+name+ is the String filename of the file
You can also get the content from xml, so this might not need to run Returns nothing
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/broadway/convertible.rb', line 37 def read_yaml(path) return if !File.exists?(path) || File.directory?(path) self.content = IO.read(path) if self.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m self.content = self.content[($1.size + $2.size)..-1] self.data.merge!(YAML.load($1)) end self.data ||= {} end |
#to_s ⇒ Object
Return the contents as a string
14 15 16 |
# File 'lib/broadway/convertible.rb', line 14 def to_s self.content || '' end |
#transform ⇒ Object
Transform the contents based on the file extension.
Returns nothing
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/broadway/convertible.rb', line 54 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 |