Class: WsItem

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/ws_item.rb

Direct Known Subclasses

Page, Post

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_all_tagged_with(tag_or_tags, conditions = []) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'app/models/ws_item.rb', line 23

def self.find_all_tagged_with(tag_or_tags, conditions=[])
  return [] if tag_or_tags.nil? || tag_or_tags.empty?
  case tag_or_tags
  when Array, IsTaggable::TagList
    all(:include => ['tags', 'taggings'], :conditions => conditions ).select { |record| tag_or_tags.all? { |tag| record.tags.map(&:name).include?(tag) } } || []
  else
    all(:include => ['tags', 'taggings'], :conditions => conditions).select { |record| record.tags.map(&:name).include?(tag_or_tags)  } || []
  end
end

Instance Method Details

#format_markupObject



33
34
35
36
37
38
39
40
41
42
# File 'app/models/ws_item.rb', line 33

def format_markup
  self.body = RedCloth.new(self.body_raw,[:sanitize_html, :filter_html]).to_html
  
  #~ if self.excerpt.blank?
    #~ self.excerpt = self.body.gsub(/\<[^\>]+\>/, '')[0...50] + "..."
  #~ else
    #~ self.excerpt = self.excerpt.gsub(/\<[^\>]+\>/, '')
  #~ end
  
end


44
45
46
47
# File 'app/models/ws_item.rb', line 44

def generate_permalink
  self.permalink = self.title.dup if self.permalink.blank?
  self.permalink.linkify!
end


49
50
51
# File 'app/models/ws_item.rb', line 49

def link
  ensure_slash_prefix permalink
end

#monthObject



66
67
68
# File 'app/models/ws_item.rb', line 66

def month
  published_at.strftime('%B %Y')
end

#publishedObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/ws_item.rb', line 53

def published
  #self.published_at ||= Time.now unless self.is_active == 0
  if self.is_active == 0
    if !self.published_at.blank?
        self.published_at = nil
    end
  else
    if self.published_at.blank?
        self.published_at = Time.now
    end
  end
end

#to_paramObject



70
71
72
# File 'app/models/ws_item.rb', line 70

def to_param
  "#{id}-#{permalink}"
end