Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merging iteh's fork

  • Loading branch information...
commit 08975df2664fe32982e9fefed0f792e9bf936e9b 2 parents d83fa79 + e33927e
@jomz jomz authored
View
26 app/models/meta_tag.rb
@@ -36,18 +36,38 @@ def find_or_create_by_name!(name)
end
def cloud(args = {})
+ args = {:by => 'popularity', :order => 'desc', :limit => 5}.merge(args)
+
find(:all, :select => 'meta_tags.*, count(*) as popularity',
- :limit => args[:limit] || 5,
+ :limit => args[:limit],
:joins => "JOIN taggings ON taggings.meta_tag_id = meta_tags.id",
:conditions => args[:conditions],
:group => "meta_tags.id, meta_tags.name",
- :order => "popularity DESC" )
+ :order => order_string(args) )
+ end
+
+ def order_string(attr)
+ by = (attr[:by]).strip
+ order = (attr[:order]).strip
+ order_string = ''
+ if self.new.attributes.keys.dup.push("popularity").include?(by)
+ order_string << by
+ else
+ raise TagError.new("`by' attribute of `each' tag must be set to a valid field name")
+ end
+ if order =~ /^(asc|desc)$/i
+ order_string << " #{$1.upcase}"
+ else
+ raise TagError.new(%{`order' attribute of `each' tag must be set to either "asc" or "desc"})
+ end
+
end
+
end
def <=>(other)
# To be able to sort an array of tags
name <=> other.name
end
-
+
end
View
54 app/models/radius_tags.rb
@@ -85,7 +85,7 @@ class TagError < StandardError; end
The results_page attribute will default to #{Radiant::Config['tags.results_page_url']}
*Usage:*
- <pre><code><r:tag_cloud_list [limit="number"] [results_page="/some/url"] [scope="/some/url"]/></code></pre>
+ <pre><code><r:tag_cloud [limit="number"] [results_page="/some/url"] [scope="/some/url"]/></code></pre>
}
tag "tag_cloud" do |tag|
tag_cloud = MetaTag.cloud(:limit => tag.attr['limit'] || 5).sort
@@ -98,10 +98,33 @@ class TagError < StandardError; end
output += "<li class=\"#{cloud_class}\"><span>#{pluralize(amount, 'page is', 'pages are')} tagged with </span><a href=\"#{results_page}/#{tag}\" class=\"tag\">#{tag}</a></li>"
end
else
- return "<p>No tags found.</p>"
+ return I18n.t('tags_extension.no_tags_found')
end
output += "</ol>"
end
+
+ desc %{
+ Render a Tag cloud with div-tags
+ The results_page attribute will default to #{Radiant::Config['tags.results_page_url']}
+
+ *Usage:*
+ <pre><code><r:tag_cloud_div [limit="number"] [results_page="/some/url"] [scope="/some/url"]/></code></pre>
+ }
+ tag "tag_cloud_div" do |tag|
+ tag_cloud = MetaTag.cloud(:limit => tag.attr['limit'] || 10).sort
+ tag_cloud = filter_tags_to_url_scope(tag_cloud, tag.attr['scope']) unless tag.attr['scope'].nil?
+
+ results_page = tag.attr['results_page'] || Radiant::Config['tags.results_page_url']
+ output = "<div class=\"tag_cloud\">"
+ if tag_cloud.length > 0
+ build_tag_cloud(tag_cloud, %w(size1 size2 size3 size4 size5 size6 size7 size8 size9)) do |tag, cloud_class, amount|
+ output += "<div class=\"#{cloud_class}\"><a href=\"#{results_page}/#{tag}\" class=\"tag\">#{tag}</a></div>\n"
+ end
+ else
+ return I18n.t('tags_extension.no_tags_found')
+ end
+ output += "</div>"
+ end
desc %{
Render a Tag list, more for 'categories'-ish usage, i.e.: Cats (2) Logs (1) ...
@@ -121,7 +144,7 @@ class TagError < StandardError; end
output += "<li class=\"#{cloud_class}\"><a href=\"#{results_page}/#{tag}\" class=\"tag\">#{tag} (#{amount})</a></li>"
end
else
- return "<p>No tags found.</p>"
+ return I18n.t('tags_extension.no_tags_found')
end
output += "</ul>"
end
@@ -174,18 +197,14 @@ class TagError < StandardError; end
Iterates through each tag and allows you to specify the order: by popularity or by name.
The default is by name. You may also limit the search; the default is 5 results.
- Usage: <pre><code><r:all_tags:each order="popularity" limit="5">...</r:all_tags:each></code></pre>
+ Usage: <pre><code><r:all_tags:each [order="asc|desc"] [by="name|popularity"] limit="5">...</r:all_tags:each></code></pre>
}
tag "all_tags:each" do |tag|
- order = tag.attr['order'] || 'name'
+ by = tag.attr['by'] || 'name'
+ order = tag.attr['order'] || 'asc'
limit = tag.attr['limit'] || '5'
result = []
- case order
- when 'name'
- all_tags = MetaTag.find(:all, :limit => limit)
- else
- all_tags = MetaTag.cloud(:limit => limit)
- end
+ all_tags = MetaTag.cloud(:limit => limit, :order => order, :by => by)
all_tags.each do |t|
next if t.pages.empty? # skip unused tags
tag.locals.meta_tag = t
@@ -202,9 +221,18 @@ class TagError < StandardError; end
tag "all_tags:each:link" do |tag|
results_page = tag.attr['results_page'] || Radiant::Config['tags.results_page_url']
name = tag.locals.meta_tag.name
- return "<a href=\"#{results_page}/#{name}\" class=\"tag\">#{name}</a>"
+ "<a href=\"#{results_page}/#{name}\" class=\"tag\">#{name}</a>"
+ end
+
+ tag "all_tags:each:popularity" do |tag|
+ (tag.locals.meta_tag.respond_to?(:popularity)) ? tag.locals.meta_tag.popularity : ""
+ end
+
+ tag "all_tags:each:url" do |tag|
+ results_page = tag.attr['results_page'] || Radiant::Config['tags.results_page_url']
+ name = tag.locals.meta_tag.name
+ "#{results_page}/#{name}"
end
-
desc "Set the scope for the tag's pages"
tag "all_tags:each:pages" do |tag|
View
25 app/models/tag_search_page.rb
@@ -1,7 +1,28 @@
class TagSearchPage < Page
attr_accessor :requested_tag
+
#### Tags ####
+
+ desc %{ The namespace for all tagsearch tags.}
+ tag 'tagsearch' do |tag|
+ tag.expand
+ end
+
+ desc %{ to show a index page, if the page was not able to find a tag, it is considered to be a index page}
+ tag 'tagsearch:if_index' do |tag|
+ if requested_tag.nil? || (requested_tag && requested_tag.blank?)
+ tag.expand
+ end
+ end
+
+ desc %{ resultpage, if the page got a tag, it is considered to be a result page}
+ tag 'tagsearch:unless_index' do |tag|
+ if requested_tag && ! requested_tag.blank?
+ tag.expand
+ end
+ end
+
desc %{ The namespace for all search tags.}
tag 'search' do |tag|
tag.expand
@@ -68,8 +89,8 @@ def found_tags
end
def render
- self.requested_tag = @request.parameters[:tag] unless requested_tag
- self.title = "Tagged with #{requested_tag}" if requested_tag
+ self.requested_tag = @request.parameters[:tag] if @request.parameters[:tag]
+ self.title = "#{self.title} #{requested_tag}" if requested_tag
super
end
View
6 config/locales/de.yml
@@ -0,0 +1,6 @@
+---
+de:
+ tags:
+ tags: "Schlagworte"
+ no_tags_found: "<p>Es wurden keine Schlagworte gefunden.</p>"
+
View
3  config/locales/en.yml
@@ -1,4 +1,5 @@
en:
tags_extensions:
+ no_tags_found: "<p>No tags found.</p>"
tags: Tags
- type_a_tag: Separate tags with ;
+ type_a_tag: Separate tags with ;
View
20 config/routes.rb
@@ -0,0 +1,20 @@
+ActionController::Routing::Routes.draw 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 if defined?(VhostExtension)
+ map.connect "#{Radiant::Config['tags.results_page_url']}/:tag", :controller => 'site', :action => 'show_page', :url => Radiant::Config['tags.results_page_url']
+ end
+ 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
View
21 tags_extension.rb
@@ -8,27 +8,6 @@ class TagsExtension < Radiant::Extension
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 if defined?(VhostExtension)
- map.connect "#{Radiant::Config['tags.results_page_url']}/:tag", :controller => 'site', :action => 'show_page', :url => Radiant::Config['tags.results_page_url']
- end
- 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?
Please sign in to comment.
Something went wrong with that request. Please try again.