Sha256: 00858216f5aa3b838d48f42f25324579cec8d672fe96d8862fbcf8366bc1b786
Contents?: true
Size: 1.47 KB
Versions: 3
Compression:
Stored size: 1.47 KB
Contents
require 'wunderbar/render' require 'ruby2js/filter/react' require 'execjs' react = File.expand_path('../vendor/react-with-addons.min.js', __FILE__) Wunderbar::Asset.script name: 'react-min.js', file: react, render: true reactdom = File.expand_path('../vendor/react-dom.min.js', __FILE__) Wunderbar::Asset.script name: 'react-dom.min.js', file: reactdom, render: true, server: File.expand_path('../vendor/react-dom-server.min.js', __FILE__) class Wunderbar::Render RUBY2JS_OPTIONS = {react: true} def self.server(common) "ReactDOMServer.renderToString(#{common})" end # return all nodes on server rendering, as there is no wrapper element # like there is for vue def self.extract(nodes) nodes end def self.client(common, element, target) "ReactDOM.render(#{common}, #{element})" end def self.eval(scripts, server) context = ExecJS.compile(scripts.compact.join(";\n")) context.eval(server) rescue ExecJS::ProgramError => e Wunderbar.error e "<pre>" + e.message.gsub('&', '&').gsub('<', '<').gsub('>', '>') + "</pre>" end end # Monkeypatch to address https://github.com/sstephenson/execjs/pull/180 require 'execjs' class ExecJS::ExternalRuntime::Context alias_method :w_write_to_tempfile, :write_to_tempfile def write_to_tempfile(*args) tmpfile = w_write_to_tempfile(*args).path.untaint tmpfile = Struct.new(:path, :to_str).new(tmpfile, tmpfile) def tmpfile.unlink File.unlink path end tmpfile end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
wunderbar-1.3.4 | lib/wunderbar/react.rb |
wunderbar-1.3.3 | lib/wunderbar/react.rb |
wunderbar-1.3.2 | lib/wunderbar/react.rb |