Class: Parchemin::Static
- Inherits:
-
Object
- Object
- Parchemin::Static
- Defined in:
- lib/parchemin/models/static.rb
Overview
This class represents a static content such as an about page
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#body(interpret_markdown = true) ⇒ Object
return the body of the static content.
-
#initialize(id) ⇒ Static
constructor
initializes the static content with its name.
Constructor Details
#initialize(id) ⇒ Static
initializes the static content with its name
10 11 12 13 |
# File 'lib/parchemin/models/static.rb', line 10 def initialize(id) @id = id @filename = "#{Parchemin::Config.statics_path}/#{@id}.markdown" end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/parchemin/models/static.rb', line 7 def filename @filename end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/parchemin/models/static.rb', line 7 def id @id end |
Instance Method Details
#body(interpret_markdown = true) ⇒ Object
return the body of the static content. It is possible to prevent the markup’s interpretation by passing false to the method. It is useful when you only have a paragraph and don’t want to see <p></p> around it.
16 17 18 19 20 21 22 23 24 |
# File 'lib/parchemin/models/static.rb', line 16 def body(interpret_markdown=true) raise "#{@filename} doesn't exist." if not File.exist?(@filename) if interpret_markdown @body ||= RDiscount.new(File.read(@filename)).to_html else @body ||= File.read(@filename) end @body end |