Class: Awestruct::Extensions::TagCloud

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/extensions/tag_cloud.rb

Instance Method Summary collapse

Constructor Details

#initialize(tagged_items_property, output_path = 'tags', opts = {}) ⇒ TagCloud

Returns a new instance of TagCloud.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/awestruct/extensions/tag_cloud.rb', line 5

def initialize(tagged_items_property, output_path='tags', opts={})
  @tagged_items_property = tagged_items_property
  @output_path = output_path
  @layout = opts[:layout].to_s
  @title  = opts[:title] || 'Tags'
  if opts[:template] && Pathname.new(opts[:template]).relative?
    @template = Pathname.new(::Awestruct::Engine.instance.site.config.dir).join(opts[:template])
  else
    @template = File.join( File.dirname(__FILE__), 'tag_cloud.html.haml' )
  end
end

Instance Method Details

#execute(site) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/awestruct/extensions/tag_cloud.rb', line 17

def execute(site)
  page = site.engine.load_page( @template )
  page.output_path = File.join( @output_path )
  page.layout = @layout
  page.title  = @title
  page.tags = site.send( "#{@tagged_items_property}_tags" ) || []
  site.pages << page
  site.send( "#{@tagged_items_property}_tag_cloud=", LazyPage.new( page ) )
end