lib/pakyow/presenter/templates.rb in pakyow-presenter-1.0.0.rc2 vs lib/pakyow/presenter/templates.rb in pakyow-presenter-1.0.0.rc3
- old
+ new
@@ -7,11 +7,11 @@
module Presenter
class Templates
using Support::DeepDup
using Support::Refinements::String::Normalization
- attr_reader :name, :path, :layouts, :pages, :includes, :config
+ attr_reader :name, :path, :processor, :layouts, :pages, :includes, :config
DEFAULT_LAYOUTS_PATH = "layouts"
DEFAULT_PARTIALS_PATH = "includes"
DEFAULT_PAGES_PATH = "pages"
@@ -107,24 +107,26 @@
def load_layouts
@layouts = if File.exist?(layouts_path)
layouts_path.children.each_with_object({}) { |file, layouts|
next unless template?(file)
- layout = load_view_of_type_at_path(Layout, file)
- layouts[layout.name] = layout
+ if layout = load_view_of_type_at_path(Views::Layout, file)
+ layouts[layout.name] = layout
+ end
}
else
{}
end
end
def load_partials
@includes = if File.exist?(partials_path)
partials_path.children.each_with_object({}) { |file, partials|
next unless template?(file)
- partial = load_view_of_type_at_path(Partial, file, normalize_path(file))
- partials[partial.name] = partial
+ if partial = load_view_of_type_at_path(Views::Partial, file, normalize_path(file))
+ partials[partial.name] = partial
+ end
}
else
{}
end
end
@@ -138,11 +140,11 @@
next unless template?(path)
begin
if page = page_at_path(path)
- @info[File.join(@config[:prefix], normalize_path(path, pages_path))] = {
+ @info[String.normalize_path(File.join(@config[:prefix], normalize_path(path, pages_path)))] = {
page: page,
layout: layout_with_name(page.info(:layout)),
partials: @includes.merge(partials_at_path(path))
}
end
@@ -166,11 +168,11 @@
if File.directory?(path)
if Dir.glob(File.join(path, "index.*")).empty?
index_page_at_path(path)
end
else
- load_view_of_type_at_path(Page, path, normalize_path(path))
+ load_view_of_type_at_path(Views::Page, path, normalize_path(path))
end
end
def index_page_at_path(path)
# TODO: don't ascend above store path
@@ -206,24 +208,31 @@
# FIXME: don't ascend above store path
path.ascend.select(&:directory?).each_with_object({}) { |parent_path, partials|
parent_path.children.select { |child|
child.basename.to_s.start_with?("_")
}.each_with_object(partials) { |child, child_partials|
- partial = load_view_of_type_at_path(Partial, child, normalize_path(child))
- child_partials[partial.name] ||= partial
+ if partial = load_view_of_type_at_path(Views::Partial, child, normalize_path(child))
+ child_partials[partial.name] ||= partial
+ end
}
}
end
def load_view_of_type_at_path(type, path, logical_path = nil)
- content = File.read(path)
- info, content = FrontMatterParser.parse_and_scrub(content)
+ extension = File.extname(path)
- if @processor
- content = @processor.process(content, File.extname(path).delete(".").to_sym)
- end
+ if extension.end_with?(".html") || @processor&.process?(extension)
+ content = File.read(path)
+ info, content = FrontMatterParser.parse_and_scrub(content)
- type.load(path, info: info, content: content, logical_path: logical_path)
+ if @processor
+ content = @processor.process(content, extension.delete(".").to_sym)
+ end
+
+ type.load(path, info: info, content: content, logical_path: logical_path)
+ else
+ nil
+ end
end
end
end
end