Class: Entry

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/lokka/entry.rb

Direct Known Subclasses

Page, Post

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_by_fuzzy_slug(str) ⇒ Object



34
35
36
37
# File 'lib/lokka/entry.rb', line 34

def self.get_by_fuzzy_slug(str)
  ret = first(:slug => str)
  ret.blank? ? get(str) : ret
end

.recent(count = 5) ⇒ Object



44
45
46
# File 'lib/lokka/entry.rb', line 44

def self.recent(count = 5)
  all(:limit => count, :order => [:created_at.desc])
end

.search(str) ⇒ Object



39
40
41
42
# File 'lib/lokka/entry.rb', line 39

def self.search(str)
  all(:title.like => "%#{str}%") |
  all(:body.like => "%#{str}%")
end

Instance Method Details



56
57
58
# File 'lib/lokka/entry.rb', line 56

def edit_link
  "/admin/#{self.class.to_s.tableize}/#{id}/edit"
end

#fuzzy_slugObject



48
49
50
# File 'lib/lokka/entry.rb', line 48

def fuzzy_slug
  slug.blank? ? id : slug
end


52
53
54
# File 'lib/lokka/entry.rb', line 52

def link
  "/#{fuzzy_slug}"
end

#tag_collection=(string) ⇒ Object



27
28
29
30
31
32
# File 'lib/lokka/entry.rb', line 27

def tag_collection=(string)
  reg = RUBY_VERSION >= "1.9.0" ? /[^\p{Word}_]/i : /[^\w\s_-]/i
  @tag_list = string.to_s.split(',').map { |name|
    name.force_encoding(Encoding.default_external).gsub(reg, '').strip
  }.reject{|x|x.blank?}.uniq.sort
end

#tags_to_htmlObject



60
61
62
63
64
65
66
# File 'lib/lokka/entry.rb', line 60

def tags_to_html
  html = '<ul>'
  tags.each do |tag|
    html += %Q(<li><a href="#{tag.link}">#{tag.name}</a></li>)
  end
  html + '</ul>'
end