Class: Everything::Piece::Content
- Inherits:
-
Object
- Object
- Everything::Piece::Content
- Defined in:
- lib/everything/piece/content.rb
Instance Method Summary collapse
- #absolute_dir ⇒ Object
- #absolute_path ⇒ Object
- #body ⇒ Object
- #dir ⇒ Object
- #file_name ⇒ Object
- #file_path ⇒ Object
-
#initialize(piece_path) ⇒ Content
constructor
A new instance of Content.
- #path ⇒ Object
- #raw_markdown ⇒ Object
- #raw_markdown=(value) ⇒ Object
- #save ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(piece_path) ⇒ Content
Returns a new instance of Content.
6 7 8 |
# File 'lib/everything/piece/content.rb', line 6 def initialize(piece_path) @piece_path = piece_path end |
Instance Method Details
#absolute_dir ⇒ Object
10 11 12 |
# File 'lib/everything/piece/content.rb', line 10 def absolute_dir @absolute_dir ||= Everything.path.join(dir) end |
#absolute_path ⇒ Object
14 15 16 |
# File 'lib/everything/piece/content.rb', line 14 def absolute_path @absolute_path ||= absolute_dir.join(file_name) end |
#body ⇒ Object
37 38 39 |
# File 'lib/everything/piece/content.rb', line 37 def body partitioned_text.last end |
#dir ⇒ Object
18 19 20 |
# File 'lib/everything/piece/content.rb', line 18 def dir @dir ||= calculated_dir end |
#file_name ⇒ Object
22 23 24 |
# File 'lib/everything/piece/content.rb', line 22 def file_name 'index.md' end |
#file_path ⇒ Object
26 27 28 29 30 31 |
# File 'lib/everything/piece/content.rb', line 26 def file_path # TODO: Could try a deprecation approach like http://seejohncode.com/2012/01/09/deprecating-methods-in-ruby/ = "Piece Content's #file_path is deprecated and will be removed soon. Use #absolute_path instead." warn @file_path ||= File.join(piece_path, file_name) end |
#path ⇒ Object
41 42 43 |
# File 'lib/everything/piece/content.rb', line 41 def path @path ||= dir.join(file_name) end |
#raw_markdown ⇒ Object
45 46 47 |
# File 'lib/everything/piece/content.rb', line 45 def raw_markdown @raw_markdown ||= absolute_path.read end |
#raw_markdown=(value) ⇒ Object
49 50 51 |
# File 'lib/everything/piece/content.rb', line 49 def raw_markdown=(value) @raw_markdown = value end |
#save ⇒ Object
53 54 55 56 57 |
# File 'lib/everything/piece/content.rb', line 53 def save FileUtils.mkdir_p(piece_path) absolute_path.write(@raw_markdown) end |
#title ⇒ Object
33 34 35 |
# File 'lib/everything/piece/content.rb', line 33 def title partitioned_text.first.sub('# ', '') end |