Class: WhoNeedsWP::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/who-needs-wp/Content.rb

Overview

Class for storing content which is rendered on the site

Direct Known Subclasses

Page, Post

Instance Attribute Summary collapse

Instance Method Summary collapse

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::options[:url] + '/' + @filename[:generated]
  # Set the default author of the content to be the site author
  @author = WhoNeedsWP::options[:author]
  
  read_file
end

Instance Attribute Details

#authorObject

Author of the content



13
14
15
# File 'lib/who-needs-wp/Content.rb', line 13

def author
  @author
end

#filenameObject

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

#htmlObject

HTML content of the content



7
8
9
# File 'lib/who-needs-wp/Content.rb', line 7

def html
  @html
end

#idObject

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

#markdownObject

Original Markdown content



9
10
11
# File 'lib/who-needs-wp/Content.rb', line 9

def markdown
  @markdown
end

#summaryObject

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

#tagsObject

An array of tags which are associated with this content



23
24
25
# File 'lib/who-needs-wp/Content.rb', line 23

def tags
  @tags
end

#tiny_urlObject

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

#titleObject

Title of the content derived from the filename



11
12
13
# File 'lib/who-needs-wp/Content.rb', line 11

def title
  @title
end

#urlObject

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

#renderObject

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::options[:url] + '/')
  # Render the content HTML within a page
  WhoNeedsWP::render_html(@filename[:generated], "page", @html, @title, @tags, @summary)
end