Class: Marko::Model::Topic
- Inherits:
-
Object
- Object
- Marko::Model::Topic
show all
- Extended by:
- Forwardable
- Includes:
- TreeNode
- Defined in:
- lib/marko/model/topic.rb
Overview
Instance Attribute Summary collapse
Attributes included from TreeNode
#parent
Instance Method Summary
collapse
Methods included from TreeNode
#nesting_level, #root, #root?
Constructor Details
#initialize(title, content, **metadata) ⇒ Topic
Returns a new instance of Topic.
30
31
32
33
34
35
36
37
|
# File 'lib/marko/model/topic.rb', line 30
def initialize(title, content, **metadata)
@parent = nil
@items = []
@title = title
@content = content
@metadata = metadata
@markup = metadata.delete(:markup)
end
|
Instance Attribute Details
21
22
23
|
# File 'lib/marko/model/topic.rb', line 21
def content
@content
end
|
25
26
27
|
# File 'lib/marko/model/topic.rb', line 25
def markup
@markup
end
|
23
24
25
|
# File 'lib/marko/model/topic.rb', line 23
def metadata
@metadata
end
|
19
20
21
|
# File 'lib/marko/model/topic.rb', line 19
def title
@title
end
|
Instance Method Details
#add(item) ⇒ Object
52
53
54
55
56
|
# File 'lib/marko/model/topic.rb', line 52
def add(item)
item.parent = self
@items << item
self
end
|
#delete(item) ⇒ Object
58
59
60
|
# File 'lib/marko/model/topic.rb', line 58
def delete(item)
@items.delete(item)
end
|
#each(&block) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/marko/model/topic.rb', line 45
def each(&block)
super(&block)
items.each do |e|
e.each(&block)
end
end
|
#find_by_id(ref) ⇒ Object
68
69
70
|
# File 'lib/marko/model/topic.rb', line 68
def find_by_id(ref)
find{ it.id == ref } || root.find{ it.id == ref }
end
|
#id ⇒ Object
82
83
84
85
86
87
|
# File 'lib/marko/model/topic.rb', line 82
def id
@metadata.fetch(:id, '').then do |e|
e = parent.id + e if e.start_with?(?.) && parent
e
end
end
|
#id=(id) ⇒ Object
89
90
91
|
# File 'lib/marko/model/topic.rb', line 89
def id=(id)
@metadata[:id] = id
end
|
#links ⇒ Array<String>
Returns macro links in content.
63
64
65
66
|
# File 'lib/marko/model/topic.rb', line 63
def links
return [] if @content.empty?
@content.scan(/\[\[([\w\.]*)\]\]/).flatten.uniq
end
|
#lost_order_index ⇒ Array<String>
Returns ids in order_index but out of @items.
73
74
75
|
# File 'lib/marko/model/topic.rb', line 73
def lost_order_index
order_index.reject{ item(it) }
end
|
#to_s ⇒ Object
39
40
41
42
43
|
# File 'lib/marko/model/topic.rb', line 39
def to_s
to_a
.map{ "<#Topic id: #{it.id}, title: #{it.title}, level: #{it.nesting_level}>"}
.join(?\n)
end
|