class Stormy::Template

Attributes

content[RW]
details[R]

Public Class Methods

new(app,key,details) click to toggle source
# File lib/stormy/template.rb, line 6
def initialize(app,key,details)
  @app = app
  @details = details
  @key = key
  @body = details["body"]

  @engine = resolve_engine(self.class.extract_extension(@key))
end

Protected Class Methods

extract_extension(key) click to toggle source
# File lib/stormy/template.rb, line 49
def self.extract_extension(key)
  return "txt" unless key.include?(".")
  key.split(".")[-1].to_s.downcase
end
extract_segment(path) click to toggle source
# File lib/stormy/template.rb, line 40
def self.extract_segment(path)
  extension = extract_extension(path)
  if rendered_extension?(extension)
    File.basename(path,"." + extension)
  else 
    File.basename(path)
  end
end
rendered_extension?(extension) click to toggle source
# File lib/stormy/template.rb, line 36
def self.rendered_extension?(extension)
  @@supported_extensions.include?(extension)
end

Public Instance Methods

render(&block) click to toggle source
# File lib/stormy/template.rb, line 15
def render(&block)
  if @engine
    @engine.render(@body,resolve_bindings,&block)
  else
    nil
  end
end

Protected Instance Methods

resolve_bindings() click to toggle source
# File lib/stormy/template.rb, line 61
def resolve_bindings
  { 
    meta: @details
  }.merge(@content || {})
end
resolve_engine(extension) click to toggle source
# File lib/stormy/template.rb, line 54
def resolve_engine(extension)
  engine = @@engines[extension]
  if !engine.nil?
    "Stormy::Engines::#{engine}".constantize.new(@app)
  end
end