Module: Blogish
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Method Summary collapse
-
#fetch(slug) ⇒ Object
Fetch and parse a single blog entry based on its slug.
-
#fetch_all ⇒ Object
Fetch and parse all blog entries in the ‘views/blog` directory, sorted by date with the most recent entry first.
Instance Method Details
#fetch(slug) ⇒ Object
Fetch and parse a single blog entry based on its slug.
-
@params slug [String]
-
@return [nil] if no matching slug is found
-
@return [Hash] representing the blog entry if a matching slug is found.
Example:
If we have a file named
views/blog/2013-02-07_hello-world.mkd
then running
Blogish.fetch('hello-world')
will find the file and return a hash containing the following keys:
-
:title [String]
-
:date [Date]
-
:slug [String]
-
:intro [String]
-
:body [String]
28 29 30 31 |
# File 'lib/blogish.rb', line 28 def fetch(slug) path = entries.detect { |file| file =~ /_#{Regexp.quote(slug)}.mkd$/ } path ? open(path) : nil end |
#fetch_all ⇒ Object
Fetch and parse all blog entries in the ‘views/blog` directory, sorted by date with the most recent entry first.
-
@params none
-
@return [Array] of hashes representing each blog entry.
Example:
If we have files named
views/blog/2013-02-07_hello-world.mkd
and
views/blog/2013-02-05_foo-post.mkd
then running
Blogish.fetch
will return an Array containing both entries:
[{:title => 'Foo Post', ...}, {:title => 'Hello World', ...}]
50 51 52 |
# File 'lib/blogish.rb', line 50 def fetch_all entries.sort.reverse.map { |entry| open(entry) } end |