Class: Card::Content::Chunk::Nest
Overview
Handler for nest chunks: {example}
Constant Summary
collapse
- DEFAULT_OPTION =
a value without a key is interpreted as view
:view
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
#options ⇒ Object
Returns the value of attribute options.
10
11
12
|
# File 'mod/core/chunk/nest.rb', line 10
def options
@options
end
|
Instance Method Details
#explicit_view=(view) ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'mod/core/chunk/nest.rb', line 85
def explicit_view= view
return if @options[:view]
if @text =~ /\|/
@text.sub! "|", "|#{view};"
else
@text.sub! "}}", "|#{view}}}"
end
end
|
#inspect ⇒ Object
67
68
69
|
# File 'mod/core/chunk/nest.rb', line 67
def inspect
"<##{self.class}:n[#{@name}] p[#{@process_chunk}] txt:#{@text}>"
end
|
#interpret(match, _content) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'mod/core/chunk/nest.rb', line 17
def interpret match, _content
in_brackets = strip_tags match[1]
name, @opt_lists = in_brackets.split "|", 2
name = name.to_s.strip
if name =~ /^\#/
@process_chunk = name =~ /^\#\#/ ? "" : (in_brackets)
else
@options = interpret_options.merge nest_name: name,
nest_syntax: in_brackets
@name = name
end
end
|
#interpret_options ⇒ Object
40
41
42
43
44
45
|
# File 'mod/core/chunk/nest.rb', line 40
def interpret_options
raw_options = @opt_lists.to_s.split("|").reverse
raw_options.inject(nil) do |prev_level, level_options|
interpret_piped_options level_options, prev_level
end || {}
end
|
#interpret_piped_options(list_string, items) ⇒ Object
47
48
49
50
51
|
# File 'mod/core/chunk/nest.rb', line 47
def interpret_piped_options list_string, items
options_hash = items.nil? ? {} : { items: items }
option_string_to_hash list_string, options_hash
options_hash
end
|
#option_string_to_hash(list_string, options_hash) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'mod/core/chunk/nest.rb', line 53
def option_string_to_hash list_string, options_hash
each_option(list_string) do |key, value|
key = key.to_sym
if key == :item
options_hash[:items] ||= {}
options_hash[:items][:view] = value
elsif Card::View::Options.nest_keys.include? key
options_hash[key] = value
end
end
end
|
#process_chunk ⇒ Object
71
72
73
74
75
76
77
|
# File 'mod/core/chunk/nest.rb', line 71
def process_chunk
return @process_chunk if @process_chunk
referee_name
@processed = yield @options
end
|
#replace_reference(old_name, new_name) ⇒ Object
79
80
81
82
83
|
# File 'mod/core/chunk/nest.rb', line 79
def replace_reference old_name, new_name
replace_name_reference old_name, new_name
nest_body = [@name.to_s, @opt_lists].compact * "|"
@text = "{{#{nest_body}}}"
end
|
30
31
32
33
34
|
# File 'mod/core/chunk/nest.rb', line 30
def strip_tags string
string.gsub(/\<[^\>]*\>/, "")
end
|
36
37
38
|
# File 'mod/core/chunk/nest.rb', line 36
def message
"<!-- #{CGI.escapeHTML message} -->"
end
|