Class: WhoNeedsWP::Content
- Inherits:
-
Object
- Object
- WhoNeedsWP::Content
- Defined in:
- lib/who-needs-wp/Content.rb
Overview
Class for storing content which is rendered on the site
Instance Attribute Summary collapse
-
#author ⇒ Object
Author of the content.
-
#filename ⇒ Object
A Hash which contains the original and generated filename.
-
#html ⇒ Object
HTML content of the content.
-
#id ⇒ Object
Unique identifier of the content, can be used in RSS & Atom feeds.
-
#markdown ⇒ Object
Original Markdown content.
-
#summary ⇒ Object
A short summary of this content, normally first paragraph.
-
#tags ⇒ Object
An array of tags which are associated with this content.
-
#tiny_url ⇒ Object
A tiny URL which can be used when referring to this content.
-
#title ⇒ Object
Title of the content derived from the filename.
-
#url ⇒ Object
The full URL of this peice of content.
Instance Method Summary collapse
-
#initialize(filename) ⇒ Content
constructor
A new instance of Content.
-
#render ⇒ Object
Render this peice of content.
Constructor Details
#initialize(filename) ⇒ Content
Returns a new instance of Content.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/who-needs-wp/Content.rb', line 25 def initialize(filename) @filename = { :original => filename, :generated => generate_filename(filename) } @title = generate_title(filename) @url = WhoNeedsWP::[:url] + '/' + @filename[:generated] # Set the default author of the content to be the site author @author = WhoNeedsWP::[:author] read_file end |
Instance Attribute Details
#author ⇒ Object
Author of the content
13 14 15 |
# File 'lib/who-needs-wp/Content.rb', line 13 def @author end |
#filename ⇒ Object
A Hash which contains the original and generated filename
21 22 23 |
# File 'lib/who-needs-wp/Content.rb', line 21 def filename @filename end |
#html ⇒ Object
HTML content of the content
7 8 9 |
# File 'lib/who-needs-wp/Content.rb', line 7 def html @html end |
#id ⇒ Object
Unique identifier of the content, can be used in RSS & Atom feeds
5 6 7 |
# File 'lib/who-needs-wp/Content.rb', line 5 def id @id end |
#markdown ⇒ Object
Original Markdown content
9 10 11 |
# File 'lib/who-needs-wp/Content.rb', line 9 def markdown @markdown end |
#summary ⇒ Object
A short summary of this content, normally first paragraph
19 20 21 |
# File 'lib/who-needs-wp/Content.rb', line 19 def summary @summary end |
#tags ⇒ Object
An array of tags which are associated with this content
23 24 25 |
# File 'lib/who-needs-wp/Content.rb', line 23 def @tags end |
#tiny_url ⇒ Object
A tiny URL which can be used when referring to this content
17 18 19 |
# File 'lib/who-needs-wp/Content.rb', line 17 def tiny_url @tiny_url end |
#title ⇒ Object
Title of the content derived from the filename
11 12 13 |
# File 'lib/who-needs-wp/Content.rb', line 11 def title @title end |
#url ⇒ Object
The full URL of this peice of content
15 16 17 |
# File 'lib/who-needs-wp/Content.rb', line 15 def url @url end |
Instance Method Details
#render ⇒ Object
Render this peice of content
39 40 41 42 43 44 45 46 |
# File 'lib/who-needs-wp/Content.rb', line 39 def render # Set the summary to be the first paragraph @summary = $1 if @html =~ (/(?:<p>)(.*?)(?:<\/p>)/) # Append the full site URL to any links referring to the root folder @html.gsub!(/(href|src)=\"\//, '\1="' + WhoNeedsWP::[:url] + '/') # Render the content HTML within a page WhoNeedsWP::render_html(@filename[:generated], "page", @html, @title, @tags, @summary) end |