mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 03:51:07 +08:00
The ability to attach attrs
when embedding widgets
This commit is contained in:
28
script/test_hbs_compiler.rb
Normal file
28
script/test_hbs_compiler.rb
Normal file
@ -0,0 +1,28 @@
|
||||
template = <<~HBS
|
||||
{{attach widget="widget-name" attrs=attrs}}
|
||||
{{#if state.category}}
|
||||
{{attach widget="category-display" attrs=(hash category=state.category)}}
|
||||
{{/if}}
|
||||
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.es6")
|
||||
ctx.eval(source)
|
||||
|
||||
js_source = ::JSON.generate(template, quirks_mode: true)
|
||||
|
||||
puts ctx.eval("exports.compile(#{js_source})");
|
||||
|
Reference in New Issue
Block a user