Class: Card::Reference::NestParser
- Defined in:
- mod/tinymce_editor/lib/card/reference/nest_parser.rb
Overview
Extracts all information needed to generate the nest editor form from a nest syntax string
Constant Summary collapse
- NEST_OPTIONS =
%i[view title show hide wrap help variant size params].freeze
Instance Attribute Summary collapse
-
#item_options ⇒ Object
readonly
Returns the value of attribute item_options.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Class Method Summary collapse
Instance Method Summary collapse
-
#empty? ⇒ Boolean
-
#field! ⇒ Object
-
#field? ⇒ Boolean
-
#initialize(nest_string) ⇒ NestParser
constructor
A new instance of NestParser.
-
#option_value(name) ⇒ Object
Constructor Details
#initialize(nest_string) ⇒ NestParser
Returns a new instance of NestParser.
43 44 45 46 47 48 49 50 |
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 43 def initialize nest_string @raw = nest_string # @default_item_view = default_item_view nest = Card::Content::Chunk::Nest.new nest_string, nil init_name nest.name nest. @options = nest. end |
Instance Attribute Details
#item_options ⇒ Object (readonly)
Returns the value of attribute item_options.
8 9 10 |
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 8 def @item_options end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 8 def @options end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
8 9 10 |
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 8 def raw @raw end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
8 9 10 |
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 8 def view @view end |
Class Method Details
.new(nest_string) ⇒ Object
10 11 12 13 14 15 16 |
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 10 def self.new nest_string return super if nest_string.is_a? String OpenStruct.new(name: "", field?: true, options: [], item_options: [], raw: "{{+ }}") end |
.new_image(name) ⇒ Object
18 19 20 21 22 23 24 |
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 18 def self.new_image name OpenStruct.new(name: name, field?: false, view: "content", options: [%i[size medium]], item_options: [], raw: "{{#{name}|view: content; size: medium}}") end |
Instance Method Details
#empty? ⇒ Boolean
26 27 28 |
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 26 def empty? @raw.empty? || @raw =~ /\{\{+?\s*\|?\s*\}\}/ end |
#field! ⇒ Object
34 35 36 37 |
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 34 def field! @raw.sub!(/\{\{\s*\+?/, "{{+") @field = true end |
#field? ⇒ Boolean
30 31 32 |
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 30 def field? @field end |
#option_value(name) ⇒ Object
39 40 41 |
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 39 def option_value name .find { |(key, _value)| key == name }&.second end |