class Card::Reference::NestParser

Extracts all information needed to generate the nest editor form from a nest syntax string

Constants

NEST_OPTIONS

Attributes

item_options[R]
name[R]
options[R]
raw[R]

Public Class Methods

new(nest_string, default_view, default_item_view) click to toggle source
Calls superclass method
# File 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(nest_string, _default_view, default_item_view) click to toggle source
# File 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
new_image(name) click to toggle source
# File 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

Public Instance Methods

field?() click to toggle source
# File lib/card/reference/nest_parser.rb, line 25
def field?
  @field
end

Private Instance Methods

applicable_options(options) click to toggle source
# File lib/card/reference/nest_parser.rb, line 59
def applicable_options options
  Card::Reference::NestParser::NEST_OPTIONS.select { |key| options[key] }
end
default_item_options() click to toggle source
# File lib/card/reference/nest_parser.rb, line 74
def default_item_options
  [:view, @default_item_view]
end
extract_item_options(options) click to toggle source
# File lib/card/reference/nest_parser.rb, line 63
def extract_item_options options
  @item_options = []
  item_options = options[:items]
  while item_options
    next_item_options = item_options[:items]
    @item_options << extract_options(item_options)
    item_options = next_item_options
  end
  # @item_options << default_item_options
end
extract_options(options) click to toggle source
# File lib/card/reference/nest_parser.rb, line 45
def extract_options options
  applicable_options(options).each_with_object([]) do |key, res|
    if key.in? %i[show hide]
      res.concat viz_values(key, options)
    else
      res << [key, options[key]]
    end
  end
end
init_name(name) click to toggle source
# File lib/card/reference/nest_parser.rb, line 40
def init_name name
  @field = name.to_name.simple_relative?
  @name = @field ? name.to_s[1..-1] : name
end
viz_values(key, options) click to toggle source
# File lib/card/reference/nest_parser.rb, line 55
def viz_values key, options
  Card::View.normalize_list(options[key]).map { |val| [key, val] }
end