Class: Card::Reference::NestParser

Inherits:
Object
  • Object
show all
Defined in:
card-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, _default_view, default_item_view) ⇒ NestParser

Returns a new instance of NestParser.



29
30
31
32
33
34
35
36
# File 'card-mod-tinymce_editor/lib/card/reference/nest_parser.rb', line 29

def initialize nest_string, _default_view, default_item_view
  @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 'card-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 'card-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 'card-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 'card-mod-tinymce_editor/lib/card/reference/nest_parser.rb', line 8

def raw
  @raw
end

Class Method Details

.new(nest_string, default_view, default_item_view) ⇒ Object



10
11
12
13
14
15
16
# File 'card-mod-tinymce_editor/lib/card/reference/nest_parser.rb', line 10

def self.new nest_string, default_view, default_item_view
  return super if nest_string.is_a? String

  OpenStruct.new(name: "", field?: true,
                 options: [[:view, default_view]], item_options: [],
                 raw: "{{+|view: #{default_view}}}")
end

.new_image(name) ⇒ Object



18
19
20
21
22
23
# File 'card-mod-tinymce_editor/lib/card/reference/nest_parser.rb', line 18

def self.new_image name
  OpenStruct.new(name: name, field?: true,
                 options: [%i[view content], %i[size medium]],
                 item_options: [],
                 raw: "{{+#{name}|view: content; size: medium}}")
end

Instance Method Details

#field?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'card-mod-tinymce_editor/lib/card/reference/nest_parser.rb', line 25

def field?
  @field
end