Class: Plain::Document

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/plain/document.rb

Overview

app/models/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content.



5
6
7
# File 'app/models/plain/document.rb', line 5

def content
  @content
end

#current_pathObject

Returns the value of attribute current_path.



5
6
7
# File 'app/models/plain/document.rb', line 5

def current_path
  @current_path
end

Returns the value of attribute menu_position.



5
6
7
# File 'app/models/plain/document.rb', line 5

def menu_position
  @menu_position
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'app/models/plain/document.rb', line 5

def path
  @path
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'app/models/plain/document.rb', line 5

def title
  @title
end

Instance Method Details

#saveObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/plain/document.rb', line 11

def save
  return false unless valid?

  # Ensure the directory exists
  FileUtils.mkdir_p(File.dirname(file_path))

  # Write to the file
  File.open(file_path, 'w') do |file|
    file.write("---\n")
    file.write("title: #{title}\n")
    file.write("menu_position: #{menu_position}\n")
    file.write("---\n\n")
    file.write(self.content)
  end

  true
rescue
  false
end