pakyow-presenter/lib/presenter/template.rb in pakyow-presenter-0.8.0 vs pakyow-presenter/lib/presenter/template.rb in pakyow-presenter-0.9.0
- old
+ new
@@ -1,75 +1,51 @@
module Pakyow
module Presenter
class Template < View
- include DocHelpers
- include TitleHelpers
-
attr_accessor :name, :doc
class << self
def load(path)
- format = Utils::String.split_at_last_dot(path)[-1]
+ format = String.split_at_last_dot(path)[-1]
contents = File.read(path)
name = File.basename(path, '.*').to_sym
- return self.new(name, contents, format)
+ self.new(name, contents, format: format)
end
end
- def initialize(name, contents = '', format = :html)
+ def initialize(name, contents = '', format: :html)
@name = name
- super(contents, format)
+ super(contents, format: format)
end
def initialize_copy(original_template)
super
# copy doc
@doc = original_template.doc.dup
- @context = original_template.context
- @composer = original_template.composer
end
def container(name = :default)
- container = @containers[name.to_sym]
- return view_from_path(container[:path])
+ View.from_doc(@doc.container(name.to_sym))
end
- def containers(refind = false)
- @containers = (!@containers || refind) ? find_containers : @containers
- end
-
def build(page)
- # add content to each container
- containers.each do |container|
+ @doc.containers.each do |container|
name = container[0]
begin
- container(name).replace(page.content(name))
+ container[1][:doc].replace(page.content(name))
rescue MissingContainer
- Pakyow.logger.debug "No content for '#{name}' in page '#{page.path}'"
+ # 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
- return View.from_doc(doc)
- end
-
- private
-
- # returns an array of hashes, each with the container name and doc
- def find_containers
- containers = {}
-
- @doc.traverse {|e|
- next unless e.is_a?(Nokogiri::XML::Comment)
- next unless match = e.text.strip.match(/@container( ([a-zA-Z0-9\-_]*))*/)
- name = match[2] || :default
-
- containers[name.to_sym] = { doc: e, path: path_to(e) }
- }
-
- return containers
+ View.from_doc(doc)
end
end
end
end