class Ansei::Render
Rendering class for Ansei
Attributes
info[R]
original[RW]
Public Class Methods
new(info)
click to toggle source
Initialize a new Render
object
info - FileInformation object
# File lib/ansei/render.rb, line 10 def initialize(info) @info = info @original = File.read(info.file) end
Public Instance Methods
compile()
click to toggle source
Compile the objects content and write that to its destination
# File lib/ansei/render.rb, line 18 def compile Utils.cli_log(" create #{info.name}") type = info.type == :markdown ? info.type : :asset body = method(type).call Utils.file_write(info.destination, body) end
Protected Instance Methods
asset()
click to toggle source
Compile as an asset
Returns the compiled string
# File lib/ansei/render.rb, line 32 def asset return original if info.ext == info.exts.first tilt(info.ext) end
markdown()
click to toggle source
Compile as Markdown
Returns the compiled string
# File lib/ansei/render.rb, line 41 def markdown parts = original.match Ansei.config[:regex][:markdown] @original = parts[:body] markdown = tilt('md') metadata = Utils.string_to_yaml(parts[:yaml]) template(metadata, markdown) end
template(metadata, markdown)
click to toggle source
Compile as a template
metadata - frontmatter YAML markdown - compiled Markdown
Returns the compiled string
# File lib/ansei/render.rb, line 58 def template(metadata, markdown) template = metadata.layout filename = "#{Ansei.config[:directories][:templates].first}/#{template}" return markdown if template.nil? || File.exist?(filename) == false @original = File.read(filename) tilt('erb', metadata, markdown) end
tilt(type, metadata = nil, yieldable = nil)
click to toggle source
“Wrapper” for Tilt
type - type of rendering metadata - optional (local) variables yieldable - object to use with 'yield'
Returns the compiled string
# File lib/ansei/render.rb, line 76 def tilt(type, metadata = nil, yieldable = nil) compiled = Tilt[type].new { original } return compiled.render if metadata.nil? && yieldable.nil? compiled.render(metadata) { yieldable } end