pakyow-presenter/lib/presenter/page.rb in pakyow-presenter-0.8.0 vs pakyow-presenter/lib/presenter/page.rb in pakyow-presenter-0.9.0
- old
+ new
@@ -3,20 +3,19 @@
class Page
MATTER_MATCHER = /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
class << self
def load(path)
- format = Utils::String.split_at_last_dot(path)[-1]
+ format = String.split_at_last_dot(path)[-1]
name = File.basename(path, '.*').to_sym
contents = FileTest.file?(path) ? File.read(path) : nil
return Page.new(name, contents, path, format)
end
end
attr_reader :path, :contents
- attr_accessor :composer
def initialize(name, contents, path, format = :html)
@name, @contents, @path, @format = name, contents, path, format
@info = { template: :pakyow }
@@ -43,11 +42,11 @@
container = @containers.fetch(container.to_sym) {
raise MissingContainer, "No container named #{container} in #{@path}"
}
- return container.to_html
+ return container.doc
end
def info(key = nil)
return @info if key.nil?
return @info[key]
@@ -65,25 +64,17 @@
def each_container
@containers.each_pair { |name, container| yield(name, container) }
end
- def composer=(composer)
- @composer = composer
-
- @containers.each do |name, container|
- container.composer = composer
- end
- end
-
private
def parse_info
info = parse_front_matter(@contents)
info = {} if !info || !info.is_a?(Hash)
- @info.merge!(Utils::Hash.symbolize(info))
+ @info.merge!(Hash.symbolize(info))
end
def parse_content
# remove yaml front matter
@contents.gsub!(/---(.|\n)*---/, '')
@@ -94,14 +85,14 @@
# find content in named containers
within_regex = /<!--\s*@within\s*([a-zA-Z0-9\-_]*)\s*-->(.*?)<!--\s*\/within\s*-->/m
@contents.scan(within_regex) do |m|
container_name = m[0].to_sym
- @containers[container_name] = Container.new(m[1], @format)
+ @containers[container_name] = Container.new(m[1])
end
# find default content
- @containers[:default] = Container.new(@contents.gsub(within_regex, ''), @format)
+ @containers[:default] = Container.new(@contents.gsub(within_regex, ''))
end
def parse_front_matter(contents)
# match the matter
matter = contents.match(MATTER_MATCHER).to_s