ruby-babel-transpiler icon indicating copy to clipboard operation
ruby-babel-transpiler copied to clipboard

how to use babel transpiler in ruby

Open bharathsn0812 opened this issue 8 years ago • 2 comments

Hi,

I am novice to ruby also es6

have created file foo.es6 which contains below code

class View {
  constructor(options) {
    this.model = options.model;
    this.template = options.template;
  }

  render() {
    return _.template(this.template, this.model.toObject());
  }
}

in ubuntu command line sudo gem install babel-transpiler -which installed babel-gem

then running ruby file esjs.rb

require 'babel/transpiler'
Babel::Transpiler.transform File.read("foo.es6")

will this convert es6 to js??

bharathsn0812 avatar May 19 '16 09:05 bharathsn0812

@bharathsn0812 You can see the usage here - https://github.com/babel/ruby-babel-transpiler/blob/master/test/test_babel_transpiler.rb

anshul avatar Jun 03 '16 15:06 anshul

@bharathsn0812 Just to add to this, here's an example of what I'm doing https://github.com/jwoertink/fez/blob/master/src/templates/Rakefile.ecr#L5-L10

The Babel::Transpiler.transform method will return a hash where the code key is a giant string of the converted code. Just write that to a file, and call it "whatever.js".

jwoertink avatar Aug 02 '16 00:08 jwoertink