class Thoth::Tag
Public Class Methods
suggest(query, limit = 1000)
click to toggle source
Gets an array of tag names and post counts for tags with names that begin with the specified query string.
# File lib/thoth/model/tag.rb, line 43 def self.suggest(query, limit = 1000) tags = [] self.dataset.grep(:name, "#{query}%").all do |tag| tags << [tag.name, tag.posts.count] end tags.sort!{|a, b| b[1] <=> a[1]} tags[0, limit] end
Public Instance Methods
atom_url()
click to toggle source
Gets the Atom feed URL for this tag.
# File lib/thoth/model/tag.rb, line 59 def atom_url Config.site['url'].chomp('/') + TagController.r(:atom, name).to_s end
posts()
click to toggle source
Gets published posts with this tag.
# File lib/thoth/model/tag.rb, line 64 def posts @posts ||= posts_dataset.filter(:is_draft => false).reverse_order( :created_at) end
url()
click to toggle source
URL for this tag.
# File lib/thoth/model/tag.rb, line 70 def url Config.site['url'].chomp('/') + TagController.r(:/, name).to_s end
validate()
click to toggle source
# File lib/thoth/model/tag.rb, line 74 def validate validates_presence(:name) validates_max_length(64, :name) end