Class: Card::Content::Chunk::Link
Constant Summary
collapse
- CODE =
"L".freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Reference
delete_if_referer_missing, map_referees, mass_insert, recreate_all, #referee, #referer, repair_all, unmap_if_referee_missing, unmap_referees
Instance Attribute Details
#link_text ⇒ Object
Returns the value of attribute link_text.
8
9
10
|
# File 'mod/core/chunk/link.rb', line 8
def link_text
@link_text
end
|
Instance Method Details
#divider_index(string) ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'mod/core/chunk/link.rb', line 36
def divider_index string
return unless string.index "|"
string_copy = string.dup
string.scan(/\{\{[^\}]*\}\}/) do |incl|
string_copy.gsub! incl, ("x" * incl.length)
end
string_copy.index "|"
end
|
#inspect ⇒ Object
85
86
87
88
|
# File 'mod/core/chunk/link.rb', line 85
def inspect
"<##{self.class}:e[#{@explicit_link}]n[#{@name}]l[#{@link_text}]" \
"p[#{@process_chunk}] txt:#{@text}>"
end
|
#interpret(match, _content) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'mod/core/chunk/link.rb', line 18
def interpret match, _content
target, @link_text =
if (raw_syntax = match[1])
if (i = divider_index(raw_syntax)) [raw_syntax[0..(i - 1)], raw_syntax[(i + 1)..-1]]
else [raw_syntax, nil]
end
end
@link_text = objectify @link_text
if target =~ %r{/|mailto:}
@explicit_link = objectify target
else
@name = target
end
end
|
#link_target ⇒ Object
73
74
75
76
77
78
79
|
# File 'mod/core/chunk/link.rb', line 73
def link_target
if @explicit_link
render_obj @explicit_link
elsif @name
referee_name
end
end
|
#objectify(raw) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'mod/core/chunk/link.rb', line 52
def objectify raw
return unless raw
raw.strip!
if raw =~ /(^|[^\\])\{\{/
Card::Content.new raw, format
else
raw
end
end
|
#options ⇒ Object
48
49
50
|
# File 'mod/core/chunk/link.rb', line 48
def options
link_text ? { title: link_text } : {}
end
|
#process_chunk ⇒ Object
81
82
83
|
# File 'mod/core/chunk/link.rb', line 81
def process_chunk
@process_chunk ||= render_link
end
|
#reference_code ⇒ Object
14
15
16
|
# File 'mod/core/chunk/link.rb', line 14
def reference_code
CODE
end
|
#render_link ⇒ Object
62
63
64
65
66
67
68
69
70
71
|
# File 'mod/core/chunk/link.rb', line 62
def render_link
@link_text = render_obj @link_text
if @explicit_link
@explicit_link = render_obj @explicit_link
format.link_to_resource @explicit_link, @link_text
elsif @name
format.nest referee_name, options.merge(view: :link)
end
end
|
#replace_reference(old_name, new_name) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'mod/core/chunk/link.rb', line 90
def replace_reference old_name, new_name
replace_name_reference old_name, new_name
if @link_text.is_a?(Card::Content)
@link_text.find_chunks(Card::Content::Chunk::Reference).each do |chunk|
chunk.replace_reference old_name, new_name
end
elsif old_name.to_name == @link_text
@link_text = new_name
end
@text = if @link_text.nil?
"[[#{referee_name}]]"
else
"[[#{referee_name}|#{@link_text}]]"
end
end
|