public
Description: Extends Radiant CMS with tagging capabilities. Tagging as in "2.0" and tagclouds.
Homepage: http://gorilla-webdesign.be
Clone URL: git://github.com/jomz/radiant-tags-extension.git
jomz (author)
Tue Sep 22 13:13:34 -0700 2009
commit  6e1bfa7c4d1df2346937e0d7176b65c32deaf2a0
tree    060a1bbc7f8ee72a07c8e01a61c656e5ce670ff9
parent  82cb81fa23f6c589e69ff84e8b7a9af170286949
radiant-tags-extension / tags_extension.rb
100644 55 lines (48 sloc) 2.101 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require_dependency 'application_controller'
require File.dirname(__FILE__)+'/lib/tagging_methods'
 
class TagsExtension < Radiant::Extension
  version "1.5"
  description "This extension enhances the page model with tagging capabilities, tagging as in \"2.0\" and tagclouds."
  url "http://gorilla-webdesign.be"
  
  DEFAULT_RESULTS_URL = '/search/by-tag'
 
  define_routes do |map|
    if Radiant::Config['tags.results_page_url'].blank?
      Radiant::Config['tags.results_page_url'] = TagsExtension::DEFAULT_RESULTS_URL if Radiant::Config['tags.results_page_url'].blank?
    end
    begin
      if defined?(SiteLanguage) && SiteLanguage.count > 0
        include Globalize
        SiteLanguage.codes.each do |code|
          langname = Locale.new(code).language.code
          map.connect "#{langname}#{Radiant::Config['tags.results_page_url']}/:tag", :controller => 'site', :action => 'show_page', :url => Radiant::Config['tags.results_page_url'], :language => code
        end
      else
        map.connect "#{Radiant::Config['tags.results_page_url']}/:tag", :controller => 'site', :action => 'show_page', :url => Radiant::Config['tags.results_page_url']
      end
    rescue
      # dirty hack; need to get trough here to allow migrations to run..
    end
  end
  
  def activate
    raise "The Shards extension is required and must be loaded first!" unless defined?(admin.page)
    if Radiant::Config.table_exists?
      Radiant::Config['tags.results_page_url'] = TagsExtension::DEFAULT_RESULTS_URL unless Radiant::Config['tags.results_page_url']
      Radiant::Config['tags.complex_strings'] = 'false' unless Radiant::Config['tags.complex_strings']
    end
    TagSearchPage
    Page.send :include, RadiusTags
    begin
      MetaTag
    rescue
      # dirty hack; need to get trough here to allow migrations to run..
    end
    Page.module_eval &TaggingMethods
    admin.page.edit.add :extended_metadata, 'tag_field'
    
    # HELP
    if admin.respond_to?(:help)
      admin.help.index.add :page_details, 'using_tags', :after => 'breadcrumbs'
    end
  end
  
  def deactivate
  end
end