Class: Aerial::Article

Inherits:
Content show all
Defined in:
lib/aerial/article.rb

Instance Attribute Summary collapse

Attributes inherited from Content

#author, #body, #title

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Content

#initialize

Constructor Details

This class inherits a constructor from Aerial::Content

Instance Attribute Details

#archive_nameObject (readonly)

Returns the value of attribute archive_name.



5
6
7
# File 'lib/aerial/article.rb', line 5

def archive_name
  @archive_name
end

#body_htmlObject (readonly)

Returns the value of attribute body_html.



5
6
7
# File 'lib/aerial/article.rb', line 5

def body_html
  @body_html
end

#commentsObject (readonly)

Returns the value of attribute comments.



5
6
7
# File 'lib/aerial/article.rb', line 5

def comments
  @comments
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



5
6
7
# File 'lib/aerial/article.rb', line 5

def file_name
  @file_name
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/aerial/article.rb', line 5

def id
  @id
end

#metaObject (readonly)

Returns the value of attribute meta.



5
6
7
# File 'lib/aerial/article.rb', line 5

def meta
  @meta
end

#publish_dateObject (readonly)

Returns the value of attribute publish_date.



5
6
7
# File 'lib/aerial/article.rb', line 5

def publish_date
  @publish_date
end

#tagsObject (readonly)

Returns the value of attribute tags.



5
6
7
# File 'lib/aerial/article.rb', line 5

def tags
  @tags
end

#updated_onObject (readonly)

Returns the value of attribute updated_on.



5
6
7
# File 'lib/aerial/article.rb', line 5

def updated_on
  @updated_on
end

Class Method Details

.all(options = {}) ⇒ Object

Find all articles, including drafts



13
14
15
# File 'lib/aerial/article.rb', line 13

def self.all(options={})
  self.find_all
end

.archivesObject

Calculate the archives



72
73
74
# File 'lib/aerial/article.rb', line 72

def self.archives
  self.find_archives
end

.exists?(id) ⇒ Boolean

Return true if the article file exists id



62
63
64
# File 'lib/aerial/article.rb', line 62

def self.exists?(id)
  self.find_by_name(id) ? true : false
end

.find(id, options = {}) ⇒ Object

Find a single article by id

+id+ of the blob


25
26
27
# File 'lib/aerial/article.rb', line 25

def self.find(id, options={})
  self.find_by_id(id, options)
end

.open(id, options = {}) ⇒ Object

A quick way to load an article by blob id

+id+ of the blob


19
20
21
# File 'lib/aerial/article.rb', line 19

def self.open(id, options = {})
  self.find_by_blob_id(id, options)
end

.recent(options = {}) ⇒ Object

Find the most recent articles



55
56
57
58
# File 'lib/aerial/article.rb', line 55

def self.recent(options={})
  limit = options.delete(:limit) || 4
  self.find_all(options).first(limit)
end

.tagsObject

Return all the tags assigned to the articles



67
68
69
# File 'lib/aerial/article.rb', line 67

def self.tags
  self.find_tags
end

.with_date(year, month, options = {}) ⇒ Object

Find articles by month and year

+year+ of when article was published
+ month+ of when the article was published


44
45
46
# File 'lib/aerial/article.rb', line 44

def self.with_date(year, month, options={})
  self.find_by_date(year, month, options)
end

.with_name(name, options = {}) ⇒ Object

Find a single article by name

+name+ of the article file


31
32
33
# File 'lib/aerial/article.rb', line 31

def self.with_name(name, options={})
  self.find_by_name(name, options)
end

Return an article given its permalink value

+link+ full path of the link


50
51
52
# File 'lib/aerial/article.rb', line 50

def self.with_permalink(link, options={})
  self.find_by_permalink(link, options)
end

.with_tag(tag, options = {}) ⇒ Object

Find articles by tag

+tag+ category


37
38
39
# File 'lib/aerial/article.rb', line 37

def self.with_tag(tag, options={})
  self.find_by_tag(tag, options)
end

Instance Method Details

#add_comment(comment) ⇒ Object

Add a comment to the list of this Article’s comments

+comment new comment


82
83
84
# File 'lib/aerial/article.rb', line 82

def add_comment(comment)
  self.comments << comment.save(self.archive_name) # TODO: should we overload the << method?
end

#archive_expand_pathObject

Returns the full path to the article archive (directory)



98
99
100
101
# File 'lib/aerial/article.rb', line 98

def archive_expand_path
  return unless archive = self.archive_name
  return "#{Aerial.repo.working_dir}/#{Aerial.config.articles.dir}/#{archive}"
end

#expand_pathObject

Returns the absolute path to the article file



93
94
95
# File 'lib/aerial/article.rb', line 93

def expand_path
  return "#{self.archive_expand_path}/#{self.file_name}"
end

Make a permanent link for the article



87
88
89
90
# File 'lib/aerial/article.rb', line 87

def permalink
  link = self.file_name.gsub(/\.article$|\.markdown$|\.md$|\.mdown$|\.mkd$|\.mkdn$/, '')
  "/#{publish_date.year}/#{publish_date.month}/#{publish_date.day}/#{escape(link)}"
end