Class: Pakyow::Presenter::Templates
- Inherits:
-
Object
- Object
- Pakyow::Presenter::Templates
- Defined in:
- lib/pakyow/presenter/templates.rb
Constant Summary collapse
- DEFAULT_LAYOUTS_PATH =
"layouts"
- DEFAULT_PARTIALS_PATH =
"includes"
- DEFAULT_PAGES_PATH =
"pages"
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#includes ⇒ Object
readonly
Returns the value of attribute includes.
-
#layouts ⇒ Object
readonly
Returns the value of attribute layouts.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#processor ⇒ Object
readonly
Returns the value of attribute processor.
Instance Method Summary collapse
-
#each ⇒ Object
Yields each template.
- #info(path) ⇒ Object
-
#initialize(name, path, processor: nil, config: {}) ⇒ Templates
constructor
A new instance of Templates.
- #layout(name_or_path) ⇒ Object
- #layouts_path ⇒ Object
- #page(path) ⇒ Object
- #pages_path ⇒ Object
- #partial(path, name) ⇒ Object
- #partials(path) ⇒ Object
- #partials_path ⇒ Object
- #paths ⇒ Object
- #template?(path) ⇒ Boolean
- #view?(path) ⇒ Boolean
Constructor Details
#initialize(name, path, processor: nil, config: {}) ⇒ Templates
Returns a new instance of Templates.
18 19 20 21 22 23 |
# File 'lib/pakyow/presenter/templates.rb', line 18 def initialize(name, path, processor: nil, config: {}) @name, @path, @processor = name, Pathname(path), processor @layouts, @includes, @info = {}, {}, {} build_config(config) load_templates end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/pakyow/presenter/templates.rb', line 12 def config @config end |
#includes ⇒ Object (readonly)
Returns the value of attribute includes.
12 13 14 |
# File 'lib/pakyow/presenter/templates.rb', line 12 def includes @includes end |
#layouts ⇒ Object (readonly)
Returns the value of attribute layouts.
12 13 14 |
# File 'lib/pakyow/presenter/templates.rb', line 12 def layouts @layouts end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/pakyow/presenter/templates.rb', line 12 def name @name end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
12 13 14 |
# File 'lib/pakyow/presenter/templates.rb', line 12 def pages @pages end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/pakyow/presenter/templates.rb', line 12 def path @path end |
#processor ⇒ Object (readonly)
Returns the value of attribute processor.
12 13 14 |
# File 'lib/pakyow/presenter/templates.rb', line 12 def processor @processor end |
Instance Method Details
#each ⇒ Object
Yields each template.
80 81 82 83 84 85 86 87 88 |
# File 'lib/pakyow/presenter/templates.rb', line 80 def each @info.each do |_path, info| yield info[:layout] yield info[:page] info[:partials].each do |_name, partial| yield partial end end end |
#info(path) ⇒ Object
33 34 35 36 37 |
# File 'lib/pakyow/presenter/templates.rb', line 33 def info(path) if view?(path) @info[path] end end |
#layout(name_or_path) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/pakyow/presenter/templates.rb', line 39 def layout(name_or_path) if name_or_path.is_a?(Symbol) layout_with_name(name_or_path) else info(name_or_path) & [:layout] end end |
#layouts_path ⇒ Object
59 60 61 |
# File 'lib/pakyow/presenter/templates.rb', line 59 def layouts_path path.join(@config[:paths][:layouts]) end |
#page(path) ⇒ Object
47 48 49 |
# File 'lib/pakyow/presenter/templates.rb', line 47 def page(path) info(path) & [:page] end |
#pages_path ⇒ Object
67 68 69 |
# File 'lib/pakyow/presenter/templates.rb', line 67 def pages_path path.join(@config[:paths][:pages]) end |
#partial(path, name) ⇒ Object
55 56 57 |
# File 'lib/pakyow/presenter/templates.rb', line 55 def partial(path, name) partials(path)[name.to_sym] end |
#partials(path) ⇒ Object
51 52 53 |
# File 'lib/pakyow/presenter/templates.rb', line 51 def partials(path) info(path) & [:partials] || {} end |
#partials_path ⇒ Object
63 64 65 |
# File 'lib/pakyow/presenter/templates.rb', line 63 def partials_path path.join(@config[:paths][:partials]) end |
#paths ⇒ Object
29 30 31 |
# File 'lib/pakyow/presenter/templates.rb', line 29 def paths @info.keys end |
#template?(path) ⇒ Boolean
71 72 73 74 75 76 |
# File 'lib/pakyow/presenter/templates.rb', line 71 def template?(path) return false if path.basename.to_s.start_with?(".") return false unless path.extname == ".html" || @processor&.process?(path.extname) true end |
#view?(path) ⇒ Boolean
25 26 27 |
# File 'lib/pakyow/presenter/templates.rb', line 25 def view?(path) @info.key?(path) end |