class Everything::Piece::Content
Attributes
piece_path[R]
Public Class Methods
new(piece_path)
click to toggle source
# File lib/everything/piece/content.rb, line 6 def initialize(piece_path) @piece_path = piece_path end
Public Instance Methods
absolute_dir()
click to toggle source
# File lib/everything/piece/content.rb, line 10 def absolute_dir @absolute_dir ||= Everything.path.join(dir) end
absolute_path()
click to toggle source
# File lib/everything/piece/content.rb, line 14 def absolute_path @absolute_path ||= absolute_dir.join(file_name) end
body()
click to toggle source
# File lib/everything/piece/content.rb, line 37 def body partitioned_text.last end
dir()
click to toggle source
# File lib/everything/piece/content.rb, line 18 def dir @dir ||= calculated_dir end
file_name()
click to toggle source
# File lib/everything/piece/content.rb, line 22 def file_name 'index.md' end
file_path()
click to toggle source
# 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/ deprecation_message = "Piece Content's #file_path is deprecated and will be removed soon. Use #absolute_path instead." warn deprecation_message @file_path ||= File.join(piece_path, file_name) end
path()
click to toggle source
# File lib/everything/piece/content.rb, line 41 def path @path ||= dir.join(file_name) end
raw_markdown()
click to toggle source
# File lib/everything/piece/content.rb, line 45 def raw_markdown @raw_markdown ||= absolute_path.read end
raw_markdown=(value)
click to toggle source
# File lib/everything/piece/content.rb, line 49 def raw_markdown=(value) @raw_markdown = value end
save()
click to toggle source
# File lib/everything/piece/content.rb, line 53 def save FileUtils.mkdir_p(piece_path) absolute_path.write(@raw_markdown) end
title()
click to toggle source
# File lib/everything/piece/content.rb, line 33 def title partitioned_text.first.sub('# ', '') end
Private Instance Methods
calculated_dir()
click to toggle source
# File lib/everything/piece/content.rb, line 66 def calculated_dir full_pathname = Pathname.new(piece_path) _relative_pathname = full_pathname.relative_path_from(Everything.path) end
partitioned_text()
click to toggle source
# File lib/everything/piece/content.rb, line 62 def partitioned_text @partitioned_text ||= raw_markdown.partition("\n\n") end