Class: Gidget::Page
- Inherits:
-
Object
- Object
- Gidget::Page
- Defined in:
- lib/gidget/page.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#meta_data ⇒ Object
readonly
Returns the value of attribute meta_data.
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(file_path) ⇒ Page
constructor
A new instance of Page.
- #method_missing(m, *args, &block) ⇒ Object
- #request_path ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(file_path) ⇒ Page
Returns a new instance of Page.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gidget/page.rb', line 12 def initialize(file_path) @file_path = file_path begin file = File.open(@file_path, "r") # read the first paragraph and load it into a Hash with symbols as keys @meta_data = YAML.load(file.gets("")).inject({}) { |h, (k,v)| h.merge(k.to_sym => v) } ensure file.close() end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
51 52 53 |
# File 'lib/gidget/page.rb', line 51 def method_missing(m, *args, &block) @meta_data[m] || super end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
8 9 10 |
# File 'lib/gidget/page.rb', line 8 def file_path @file_path end |
#meta_data ⇒ Object (readonly)
Returns the value of attribute meta_data.
9 10 11 |
# File 'lib/gidget/page.rb', line 9 def @meta_data end |
Instance Method Details
#body ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gidget/page.rb', line 36 def body begin file = File.open(@file_path, "r") # ignore the first paragraph file.gets("") # read the rest of the file and process it's markdown RDiscount.new(file.gets(nil)).to_html ensure file.close() end end |
#request_path ⇒ Object
26 27 28 |
# File 'lib/gidget/page.rb', line 26 def request_path @meta_data[:permalink] || "/" + self.title.slugize end |
#title ⇒ Object
31 32 33 |
# File 'lib/gidget/page.rb', line 31 def title @meta_data[:title] end |