2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-28 15:08:14 -05:00
|
|
|
template = <<~HBS
|
2019-05-01 17:31:01 -05:00
|
|
|
{{attach widget="wat" attrs=(hash test="abc" text=(i18n "hello" count=attrs.wat))}}
|
|
|
|
{{action-link action="undo" className="undo" text=(i18n (concat "post.actions.undo." attrs.action))}}
|
|
|
|
{{actions-summary-item attrs=as}}
|
|
|
|
{{attach widget="actions-summary-item" attrs=as}}
|
|
|
|
{{testing value="hello"}}
|
2020-08-06 13:35:46 -05:00
|
|
|
{{date "today"}}
|
2017-09-28 15:08:14 -05:00
|
|
|
HBS
|
|
|
|
|
|
|
|
ctx = MiniRacer::Context.new(timeout: 15000)
|
|
|
|
ctx.eval("var self = this; #{File.read("#{Rails.root}/vendor/assets/javascripts/babel.js")}")
|
|
|
|
ctx.eval(File.read(Ember::Source.bundled_path_for('ember-template-compiler.js')))
|
2018-12-03 21:48:13 -06:00
|
|
|
ctx.eval("module = {}; exports = {};")
|
2017-09-28 15:08:14 -05:00
|
|
|
ctx.attach("rails.logger.info", proc { |err| puts(err.to_s) })
|
|
|
|
ctx.attach("rails.logger.error", proc { |err| puts(err.to_s) })
|
|
|
|
ctx.eval <<JS
|
|
|
|
console = {
|
|
|
|
prefix: "",
|
|
|
|
log: function(msg){ rails.logger.info(console.prefix + msg); },
|
|
|
|
error: function(msg){ rails.logger.error(console.prefix + msg); }
|
|
|
|
}
|
|
|
|
|
|
|
|
JS
|
2020-03-27 11:06:14 -05:00
|
|
|
source = File.read("#{Rails.root}/lib/javascripts/widget-hbs-compiler.js")
|
2017-09-28 15:08:14 -05:00
|
|
|
ctx.eval(source)
|
|
|
|
|
|
|
|
js_source = ::JSON.generate(template, quirks_mode: true)
|
|
|
|
|
2018-12-03 21:48:13 -06:00
|
|
|
puts ctx.eval("exports.compile(#{js_source})")
|