Class: Staticpress::ViewHelpers

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/staticpress/view_helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.meta, 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

#metaObject (readonly)

Returns the value of attribute meta.



5
6
7
# File 'lib/staticpress/view_helpers.rb', line 5

def meta
  @meta
end

#pageObject (readonly)

Returns the value of attribute page.



5
6
7
# File 'lib/staticpress/view_helpers.rb', line 5

def page
  @page
end

#themeObject (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_metaObject

TODO site_meta should be an aggregate all metadata



27
28
# File 'lib/staticpress/view_helpers.rb', line 27

def site_meta
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