Class: WhoNeedsWP::Post
- Defined in:
- lib/who-needs-wp/content/Post.rb
Constant Summary collapse
- @@posts =
A list of all the pages on the site
[]
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Date at which content was created, or specified in filing structure.
Attributes inherited from Content
#author, #filename, #html, #id, #markdown, #summary, #tags, #tiny_url, #title, #url
Class Method Summary collapse
-
.all ⇒ Object
Return all the posts created.
-
.atom(filename = "posts.atom") ⇒ Object
Generate an ATOM feed of all the posts.
- .index(filename = "posts/index.html") ⇒ Object
-
.load ⇒ Object
Load all pages.
-
.render_all ⇒ Object
Render all the posts loaded.
-
.rss(filename = "posts.rss") ⇒ Object
Generate an RSS feed of all the posts.
Instance Method Summary collapse
-
#initialize(filename, created_at) ⇒ Post
constructor
Create a new Post object.
-
#render(previous_post, next_post) ⇒ Object
See Content.render_content.
Constructor Details
#initialize(filename, created_at) ⇒ Post
Create a new Post object
6 7 8 9 10 |
# File 'lib/who-needs-wp/content/Post.rb', line 6 def initialize(filename, created_at) super(filename) @created_at = created_at generate_id end |
Instance Attribute Details
#created_at ⇒ Object
Date at which content was created, or specified in filing structure
4 5 6 |
# File 'lib/who-needs-wp/content/Post.rb', line 4 def created_at @created_at end |
Class Method Details
.all ⇒ Object
Return all the posts created
49 50 51 |
# File 'lib/who-needs-wp/content/Post.rb', line 49 def self.all return @@posts end |
.atom(filename = "posts.atom") ⇒ Object
Generate an ATOM feed of all the posts
71 72 73 74 75 76 77 |
# File 'lib/who-needs-wp/content/Post.rb', line 71 def self.atom(filename = "posts.atom") File.open(filename, "w") do |file| file.write WhoNeedsWP::render_template("atom", { :posts => @@posts }) end end |
.index(filename = "posts/index.html") ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/who-needs-wp/content/Post.rb', line 53 def self.index(filename = "posts/index.html") if File.exists?(File.dirname(filename)) WhoNeedsWP::render_html(filename, "post_index", WhoNeedsWP::render_template("all_posts", { :posts => @@posts }), "All Posts") end end |
.load ⇒ Object
Load all pages
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/who-needs-wp/content/Post.rb', line 16 def self.load Dir.glob('posts/**/*.markdown').each do |filename| match = filename.match(/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/([^\.]*)/) date = DateTime.new(match[1].to_i, match[2].to_i, match[3].to_i) @@posts << Post.new(filename, date) end # Sort the posts @@posts.sort! { |a, b| a.created_at <=> b.created_at } @@posts.reverse! end |
.render_all ⇒ Object
Render all the posts loaded
39 40 41 42 43 44 45 46 |
# File 'lib/who-needs-wp/content/Post.rb', line 39 def self.render_all @@posts.each_index do |index| post = @@posts[index] previous_post = @@posts[index + 1] if index + 1 < @@posts.length next_post = @@posts[index - 1] if index > 1 post.render(previous_post, next_post) end end |
.rss(filename = "posts.rss") ⇒ Object
Generate an RSS feed of all the posts
62 63 64 65 66 67 68 |
# File 'lib/who-needs-wp/content/Post.rb', line 62 def self.rss(filename = "posts.rss") File.open(filename, "w") do |file| file.write WhoNeedsWP::render_template("rss", { :posts => @@posts }) end end |
Instance Method Details
#render(previous_post, next_post) ⇒ Object
See Content.render_content
28 29 30 31 32 33 34 35 36 |
# File 'lib/who-needs-wp/content/Post.rb', line 28 def render(previous_post, next_post) @html = WhoNeedsWP::render_template("post", { :post => self, :title => @title, :previous_post => previous_post, :next_post => next_post }) super() end |