Class: Formalist::RichText::EmbeddedFormCompiler
- Inherits:
-
Object
- Object
- Formalist::RichText::EmbeddedFormCompiler
- Defined in:
- lib/formalist/rich_text/embedded_form_compiler.rb
Overview
Our input data looks like this example, which consists of 3 elements:
- A text line
- embedded form data
- Another text line
[ ["block",["unstyled","b14hd",[["inline",[[],"Before!"]]]]], ["block",["atomic","48b4f",[["entity",["formalist","1","IMMUTABLE",with caption","data":{"image_id":"5678","caption":"Large panda"},[["inline",[[],"ΒΆ"]]]]]]]], ["block",["unstyled","aivqi",[["inline",[[],"After!"]]]]] ]
We want to intercept the embededed form data and transform them into full form ASTs, complete with validation messages.
Instance Attribute Summary collapse
-
#embedded_forms ⇒ Object
readonly
Returns the value of attribute embedded_forms.
Instance Method Summary collapse
- #call(ast) ⇒ Object (also: #[])
-
#initialize(embedded_form_collection) ⇒ EmbeddedFormCompiler
constructor
A new instance of EmbeddedFormCompiler.
Constructor Details
#initialize(embedded_form_collection) ⇒ EmbeddedFormCompiler
Returns a new instance of EmbeddedFormCompiler.
24 25 26 |
# File 'lib/formalist/rich_text/embedded_form_compiler.rb', line 24 def initialize() @embedded_forms = end |
Instance Attribute Details
#embedded_forms ⇒ Object (readonly)
Returns the value of attribute embedded_forms.
22 23 24 |
# File 'lib/formalist/rich_text/embedded_form_compiler.rb', line 22 def @embedded_forms end |
Instance Method Details
#call(ast) ⇒ Object Also known as: []
28 29 30 31 32 33 34 |
# File 'lib/formalist/rich_text/embedded_form_compiler.rb', line 28 def call(ast) return ast if ast.nil? ast = ast.is_a?(String) ? JSON.parse(ast) : ast ast.map { |node| visit(node) } end |