Class: Everything::Piece::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/everything/piece/content.rb

Instance Method Summary collapse

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_dirObject



10
11
12
# File 'lib/everything/piece/content.rb', line 10

def absolute_dir
  @absolute_dir ||= Everything.path.join(dir)
end

#absolute_pathObject



14
15
16
# File 'lib/everything/piece/content.rb', line 14

def absolute_path
  @absolute_path ||= absolute_dir.join(file_name)
end

#bodyObject



37
38
39
# File 'lib/everything/piece/content.rb', line 37

def body
  partitioned_text.last
end

#dirObject



18
19
20
# File 'lib/everything/piece/content.rb', line 18

def dir
  @dir ||= calculated_dir
end

#file_nameObject



22
23
24
# File 'lib/everything/piece/content.rb', line 22

def file_name
  'index.md'
end

#file_pathObject



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/
  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

#pathObject



41
42
43
# File 'lib/everything/piece/content.rb', line 41

def path
  @path ||= dir.join(file_name)
end

#raw_markdownObject



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

#saveObject



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

#titleObject



33
34
35
# File 'lib/everything/piece/content.rb', line 33

def title
  partitioned_text.first.sub('# ', '')
end