babel / ruby-babel-transpiler

Ruby Babel is a bridge to the JS Babel transpiler.
https://github.com/babel/ruby-babel-transpiler
MIT License
159 stars 27 forks source link

how to use babel transpiler in ruby #291

Open bharathsn0812 opened 8 years ago

bharathsn0812 commented 8 years ago

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??

anshul commented 8 years ago

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

jwoertink commented 8 years ago

@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".