These are chat archives for opal/opal

5th
Oct 2017
Andrew Havens
@andrewhavens
Oct 05 2017 03:48
Hello everyone. I'm trying to find an example of how to load/compile a ".erb" file. I'm new to using Opal, but I have this idea that I want to try rendering an ".erb" file on both the server side and client side.
I came across this example (https://github.com/opal/opal/blob/master/lib/opal/erb.rb) but I don't quite understand it. It looks like it's only intended for compiling at runtime, but I want to do the compiling from an actual file at build time.
Elia Schito
@elia
Oct 05 2017 20:31
@andrewhavens here's an usage example:
$ cd /tmp
$ opal -v
Opal v0.11.0.rc1
$ echo "require 'bar'; puts Template['bar'].render(self)" > foo.rb        /p/tmp
$ echo "<h1><%= self.inspect %></h1>" > bar.opalerb
$ opal -I. foo.rb
<h1>main</h1>
$ opal -I. foo.rb -c > foo.js
$ tail -n 20 foo.js
    return output_buffer.$join();}, TMP_1.$$s = self, TMP_1.$$arity = 1, TMP_1));
};

/* Generated by Opal 0.11.0.rc1 */
(function(Opal) {
  var self = Opal.top, $nesting = [], nil = Opal.nil, $breaker = Opal.breaker, $slice = Opal.slice;

  Opal.add_stubs(['$require', '$puts', '$render', '$[]']);

  self.$require("bar");
  return self.$puts(Opal.const_get_relative($nesting, 'Template')['$[]']("bar").$render(self));
})(Opal);

/* Generated by Opal 0.11.0.rc1 */
(function(Opal) {
  var self = Opal.top, $nesting = [], nil = Opal.nil, $breaker = Opal.breaker, $slice = Opal.slice;

  Opal.add_stubs(['$exit']);
  return Opal.const_get_relative($nesting, 'Kernel').$exit()
})(Opal);