forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_hbs_compiler.rb
31 lines (26 loc) · 1.12 KB
/
test_hbs_compiler.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true
template = <<~HBS
{{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"}}
{{date "today"}}
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')))
ctx.eval("module = {}; exports = {};")
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
source = File.read("#{Rails.root}/lib/javascripts/widget-hbs-compiler.js")
ctx.eval(source)
js_source = ::JSON.generate(template, quirks_mode: true)
puts ctx.eval("exports.compile(#{js_source})")