Class: Usmu::Template::Helpers
- Inherits:
-
Object
- Object
- Usmu::Template::Helpers
- Defined in:
- lib/usmu/template/helpers.rb
Overview
Helper functions that get imported into the local scope of templates
Instance Method Summary collapse
- #collection(name) ⇒ void
-
#include(name, args = {}) ⇒ String
Finds and renders a named include.
-
#initialize(configuration, layout) ⇒ Helpers
constructor
Create a new Helpers instance.
- #next_page ⇒ void
- #previous_page ⇒ void
- #url(path) ⇒ void
Constructor Details
#initialize(configuration, layout) ⇒ Helpers
Create a new Helpers instance. These are created on demand as needed by templates, there is not a singleton instance.
10 11 12 13 |
# File 'lib/usmu/template/helpers.rb', line 10 def initialize(configuration, layout) @configuration = configuration @layout = layout end |
Instance Method Details
#collection(name) ⇒ void
52 53 54 |
# File 'lib/usmu/template/helpers.rb', line 52 def collection(name) @configuration.generator.collections[name] end |
#include(name, args = {}) ⇒ String
Finds and renders a named include.
25 26 27 28 29 |
# File 'lib/usmu/template/helpers.rb', line 25 def include(name, args = {}) inc = Usmu::Template::Include.find_include(@configuration, name) inc.arguments = args inc.render end |
#next_page ⇒ void
47 48 49 50 |
# File 'lib/usmu/template/helpers.rb', line 47 def next_page collection = @layout['page', 'collection', default: @layout['collection', default: '']] @configuration.generator.collections[collection].next_from(@layout['page', default: @layout]) end |
#previous_page ⇒ void
42 43 44 45 |
# File 'lib/usmu/template/helpers.rb', line 42 def previous_page collection = @layout['page', 'collection', default: @layout['collection', default: '']] @configuration.generator.collections[collection].previous_from(@layout) end |
#url(path) ⇒ void
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/usmu/template/helpers.rb', line 31 def url(path) path = if path.is_a? String path elsif path.respond_to? :output_filename path.output_filename else path.to_s end @configuration['base path', default: '/'] + path end |