Class: EJX::Template::Base
Instance Attribute Summary collapse
-
#imports ⇒ Object
Returns the value of attribute imports.
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(**options) ⇒ Base
constructor
A new instance of Base.
- #to_module ⇒ Object
Methods inherited from Node
Constructor Details
#initialize(**options) ⇒ Base
Returns a new instance of Base.
5 6 7 8 |
# File 'lib/ejx/template/base.rb', line 5 def initialize(**) super @imports = [] end |
Instance Attribute Details
#imports ⇒ Object
Returns the value of attribute imports.
3 4 5 |
# File 'lib/ejx/template/base.rb', line 3 def imports @imports end |
Instance Method Details
#to_module ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ejx/template/base.rb', line 10 def to_module var_generator = EJX::Template::VarGenerator.new output = if @escape "import {" + @escape.split('.').reverse.join(" as __ejx_append} from '") + "';\n" else "import {append as __ejx_append} from 'ejx';\n" end @imports.each do |import| output << import << "\n" end output << "\nexport default async function (locals) {\n" output << " var __output = [], __promises = [];\n \n" @children.each do |child| output << case child when EJX::Template::String " __output.push(#{child.to_js});\n" else child.to_js(var_generator: var_generator) end end output << "\n await Promise.all(__promises);" output << "\n return __output;" output << "\n}" output end |