Class: Staticpress::ViewHelpers
- Inherits:
-
Object
- Object
- Staticpress::ViewHelpers
- Includes:
- Helpers
- Defined in:
- lib/staticpress/view_helpers.rb
Instance Attribute Summary collapse
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Instance Method Summary collapse
-
#initialize(page) ⇒ ViewHelpers
constructor
A new instance of ViewHelpers.
- #partial(name, locals = {}) ⇒ Object
-
#site_meta ⇒ Object
TODO site_meta should be an aggregate all metadata.
- #tag(name, attributes = {}, &block) ⇒ Object
Methods included from Helpers
#config, #extensionless_basename, #extensionless_path, #hash_from_array, #hash_from_match_data, #paginate, #settings, #spider_map, #titleize
Constructor Details
#initialize(page) ⇒ ViewHelpers
Returns a new instance of ViewHelpers.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/staticpress/view_helpers.rb', line 7 def initialize(page) @page = page @meta, @theme = page., page.theme Staticpress::Plugin.activate_enabled class << self Staticpress::Plugins.constants.each do |plugin| include Staticpress::Plugins.const_get(plugin) end end end |
Instance Attribute Details
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
5 6 7 |
# File 'lib/staticpress/view_helpers.rb', line 5 def @meta end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
5 6 7 |
# File 'lib/staticpress/view_helpers.rb', line 5 def page @page end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
5 6 7 |
# File 'lib/staticpress/view_helpers.rb', line 5 def theme @theme end |
Instance Method Details
#partial(name, locals = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/staticpress/view_helpers.rb', line 18 def partial(name, locals = {}) template_name = theme.include_for name if template_name.file? template = Tilt[template_name].new { template_name.read } template.render self.class.new(page), locals end end |
#site_meta ⇒ Object
TODO site_meta should be an aggregate all metadata
27 28 |
# File 'lib/staticpress/view_helpers.rb', line 27 def end |
#tag(name, attributes = {}, &block) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/staticpress/view_helpers.rb', line 30 def tag(name, attributes = {}, &block) attribute_string = attributes.map do |key, value| " #{key}=\"#{value}\"" end.join('') content = block_given? ? block.call : '' "<#{name}#{attribute_string}>#{content}</#{name}>" end |