Class: Quiver::Note
- Inherits:
-
Object
- Object
- Quiver::Note
- Defined in:
- lib/quiver/note.rb
Instance Attribute Summary collapse
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#notebook ⇒ Object
Returns the value of attribute notebook.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #cells ⇒ Object
- #content ⇒ Object
- #created_at ⇒ Object
- #image_url(path) ⇒ Object
-
#initialize(content:, meta:, path: nil, notebook: nil) ⇒ Note
constructor
A new instance of Note.
- #save ⇒ Object
- #title ⇒ Object
- #to_html ⇒ Object
- #updated_at ⇒ Object
- #uuid ⇒ Object
Constructor Details
#initialize(content:, meta:, path: nil, notebook: nil) ⇒ Note
Returns a new instance of Note.
4 5 6 7 8 9 10 |
# File 'lib/quiver/note.rb', line 4 def initialize(content: , meta: , path: nil, notebook: nil) @content = content @meta = @path = Pathname.new(path) if path @notebook = notebook @adapter = notebook.root.adapter if notebook end |
Instance Attribute Details
#meta ⇒ Object
Returns the value of attribute meta.
3 4 5 |
# File 'lib/quiver/note.rb', line 3 def @meta end |
#notebook ⇒ Object
Returns the value of attribute notebook.
3 4 5 |
# File 'lib/quiver/note.rb', line 3 def notebook @notebook end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/quiver/note.rb', line 3 def path @path end |
Instance Method Details
#as_json(options = nil) ⇒ Object
50 51 52 53 |
# File 'lib/quiver/note.rb', line 50 def as_json( = nil) return super if {content: @content, meta: @meta, path: @path.to_s} end |
#cells ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/quiver/note.rb', line 28 def cells content['cells'].map do |cell| case cell['type'] when 'text'; Quiver::Cell::Text.new(cell, self) when 'markdown'; Quiver::Cell::Markdown.new(cell, self) else Quiver::Cell.new(cell, self) end end end |
#content ⇒ Object
23 24 25 26 27 |
# File 'lib/quiver/note.rb', line 23 def content @content ||= begin JSON.parse(@adapter.load(@path + 'content.json')) end end |
#created_at ⇒ Object
11 12 13 |
# File 'lib/quiver/note.rb', line 11 def created_at Time.at(['created_at']) end |
#image_url(path) ⇒ Object
40 41 42 43 |
# File 'lib/quiver/note.rb', line 40 def image_url(path) rel_path = path.gsub('quiver-image-url/', '') @adapter.image_url(@path + 'resources' + rel_path) end |
#save ⇒ Object
44 45 46 47 48 49 |
# File 'lib/quiver/note.rb', line 44 def save raise 'add to notebook first!' unless @path && @adapter adapter.mkpath(@path) adapter.save(@path + 'content.json', @content.to_json) if @content adapter.save(@path + 'meta.json', @meta.to_json) end |
#title ⇒ Object
17 18 19 |
# File 'lib/quiver/note.rb', line 17 def title @meta['title'] end |
#to_html ⇒ Object
37 38 39 |
# File 'lib/quiver/note.rb', line 37 def to_html cells.map(&:to_html).join end |
#updated_at ⇒ Object
14 15 16 |
# File 'lib/quiver/note.rb', line 14 def updated_at Time.at(['updated_at']) end |
#uuid ⇒ Object
20 21 22 |
# File 'lib/quiver/note.rb', line 20 def uuid @meta['uuid'] end |