Class: Card::Reference::NestParser

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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
  extract_item_options nest.options
  @options = extract_options nest.options
end

Instance Attribute Details

#item_optionsObject (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
  @item_options
end

#nameObject (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

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'mod/tinymce_editor/lib/card/reference/nest_parser.rb', line 8

def options
  @options
end

#rawObject (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

#viewObject (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

Returns:

  • (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

Returns:

  • (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
  options.find  { |(key, _value)| key == name }&.second
end