Class: Plate::Dsl
- Inherits:
-
Object
- Object
- Plate::Dsl
- Defined in:
- lib/plate/dsl.rb
Overview
The Dsl class provides the methods available in plugin files in order to extend the functionality a generated site.
Defined Under Namespace
Classes: PageProxy
Class Method Summary collapse
-
.evaluate_plugin(file_path) ⇒ Object
Evaluate the given file path into the dsl instance.
-
.instance_eval_plugin(content) ⇒ Object
Performs evaluation of the file’s content.
-
.read_plugin_file(file_path) ⇒ String
Read the given plugin file path into a string.
Instance Method Summary collapse
-
#archives(item_type, options = {}, &block) ⇒ Object
Loop through the given item name to generate archive pages.
-
#callback(object, event, method_name = nil, &block) ⇒ Object
(also: #register_callback)
Register a new callback for the given object and event.
-
#register_asset_engine(extension, klass) ⇒ Object
Set up a new engine designed for rendering dynamic assets.
-
#register_template_engine(extension, klass) ⇒ Object
Set up a new engine designed for rendering dynamic assets.
-
#write_page(path, site = nil, &block) ⇒ Object
(also: #write)
Create and write a dynamic page.
Class Method Details
.evaluate_plugin(file_path) ⇒ Object
Evaluate the given file path into the dsl instance.
10 11 12 |
# File 'lib/plate/dsl.rb', line 10 def evaluate_plugin(file_path) instance_eval_plugin(read_plugin_file(file_path)) end |
.instance_eval_plugin(content) ⇒ Object
Performs evaluation of the file’s content
15 16 17 |
# File 'lib/plate/dsl.rb', line 15 def instance_eval_plugin(content) new.instance_eval(content) end |
.read_plugin_file(file_path) ⇒ String
Read the given plugin file path into a string
22 23 24 25 26 |
# File 'lib/plate/dsl.rb', line 22 def read_plugin_file(file_path) File.read(file_path) rescue raise PluginNotReadable end |
Instance Method Details
#archives(item_type, options = {}, &block) ⇒ Object
Loop through the given item name to generate archive pages.
Available item types are:
-
:category
-
:tag
-
:year
-
:month
-
:day
84 85 86 87 88 89 |
# File 'lib/plate/dsl.rb', line 84 def archives(item_type, = {}, &block) # If there is a method to return the list of items if self.respond_to?("archive_#{item_type}_items") self.send("archive_#{item_type}_items", , &block) end end |
#callback(object, event, method_name = nil, &block) ⇒ Object Also known as: register_callback
Register a new callback for the given object and event.
112 113 114 115 116 117 118 |
# File 'lib/plate/dsl.rb', line 112 def callback(object, event, method_name = nil, &block) if Symbol === object object = "Plate::#{object.to_s.classify}".constantize end object.register_callback(event, method_name, &block) end |
#register_asset_engine(extension, klass) ⇒ Object
Set up a new engine designed for rendering dynamic assets. Engines should be compatible with the Tilt::Template syntax.
123 124 125 |
# File 'lib/plate/dsl.rb', line 123 def register_asset_engine(extension, klass) Plate.register_asset_engine(extension, klass) end |
#register_template_engine(extension, klass) ⇒ Object
Set up a new engine designed for rendering dynamic assets. Engines should be compatible with the Tilt::Template syntax.
129 130 131 |
# File 'lib/plate/dsl.rb', line 129 def register_template_engine(extension, klass) Plate.register_template_engine(extension, klass) end |
#write_page(path, site = nil, &block) ⇒ Object Also known as: write
Create and write a dynamic page. Pages are written during the Site.after_render callback.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/plate/dsl.rb', line 135 def write_page(path, site = nil, &block) delayed_write = lambda { |site| page = DynamicPage.new(site, path) proxy = PageProxy.new(page, site) proxy.instance_eval(&block) page.write! proxy = nil page = nil } # If a site was passed to the write method, use it. if site delayed_write.call(site) # If no site was sent to the write method, run it after site render else callback :site, :after_render do |rendered_site| delayed_write.call(rendered_site) end end end |