Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use babel transpiler in ruby #291

Open
bharathsn0812 opened this issue May 19, 2016 · 2 comments
Open

how to use babel transpiler in ruby #291

bharathsn0812 opened this issue May 19, 2016 · 2 comments

Comments

@bharathsn0812
Copy link

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
Copy link

anshul commented Jun 3, 2016

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

@jwoertink
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants