Sha256: 28a6d54f7f315137d5ae6ed9c48e5bae78ba8ea6283c58ee15324491935889f4
Contents?: true
Size: 1.3 KB
Versions: 9
Compression:
Stored size: 1.3 KB
Contents
module Pakyow module Presenter class Template < View attr_accessor :name, :doc class << self def load(path) format = String.split_at_last_dot(path)[-1] contents = File.read(path) name = File.basename(path, '.*').to_sym self.new(name, contents, format: format) end end def initialize(name, contents = '', format: :html) @name = name super(contents, format: format) end def initialize_copy(original_template) super # copy doc @doc = original_template.doc.dup end def container(name = :default) View.from_doc(@doc.container(name.to_sym)) end def build(page) @doc.containers.each do |container| name = container[0] begin container[1][:doc].replace(page.content(name)) rescue MissingContainer # This hasn't proven to be useful in dev (or prd for that matter) # so decided to remove it. It'll save us from filling console / log # with information that will most likely just be ignored. # # Pakyow.logger.info "No content for '#{name}' in page '#{page.path}'" end end View.from_doc(doc) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems