Class: Odin::Forms::Parser
- Inherits:
-
Object
- Object
- Odin::Forms::Parser
- Defined in:
- lib/odin/forms/parser.rb
Overview
Parses ODIN forms text into a typed OdinForm structure. Low-level ODIN parsing is delegated to Odin.parse; the flat path space is then mapped onto the Forms model.
Constant Summary collapse
- VALID_UNITS =
%w[inch cm mm pt].freeze
- VALID_INPUT_TYPES =
%w[text email tel password number url].freeze
- VALID_BARCODE_TYPES =
%w[code39 code128 qr datamatrix pdf417].freeze
- REGION_OWN_PROPS =
%w[x y w h bind max overflow].freeze
- REGION_CHILD_TYPES =
%w[text field img barcode].freeze
- TPL_HEADER =
/\A\s*\{\s*@(tpl_[A-Za-z0-9_]+)\s*\}\s*\z/.freeze
- TOP_LEVEL_HEADER =
/\A\s*\{\s*(\$|page\[\d+\]|@tpl_)/.freeze
- ANCHOR_HEADER =
/\A\s*\{\s*(page\[\d+\]|tpl\.[A-Za-z0-9_]+)\s*\}\s*\z/.freeze
- RELATIVE_HEADER =
/\A\s*\{\s*\./.freeze
- RELATIVE_TABULAR =
/\A\s*\{\s*\.[^}]*\[\]\s*:/.freeze
- PAGE_PATH =
/\Apage\[(\d+)\]\./.freeze
Instance Method Summary collapse
Instance Method Details
#parse(text) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/odin/forms/parser.rb', line 24 def parse(text) body, template_blocks = split_templates(text) doc = Odin.parse(body) i18n = extract_i18n(doc) OdinForm.new( metadata: (doc), page_defaults: extract_page_defaults(doc), screen: extract_screen(doc), i18n: i18n, pages: extract_pages(doc, i18n), templates: extract_templates(template_blocks, i18n) ) end |