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

A question about the compiler. #6

Open
gotno opened this issue Jul 17, 2015 · 5 comments
Open

A question about the compiler. #6

gotno opened this issue Jul 17, 2015 · 5 comments

Comments

@gotno
Copy link

gotno commented Jul 17, 2015

Hi @marcioj, you seem to be the most active contributor to this repo, so I thought I'd direct this question to you.

I wanted to upgrade to the latest version of riot, so I forked the repo. Swapping out the riot.js file was easy, but I spent a lot of time yesterday trying to figure out how to update the compiler with no luck. It turns out I may not have needed to expend the effort, as the old compiler seems to work fine with the new version of riot (so far).

My question is: how was the version of the compiler in this project built? The official server compiler is set up to run on node/io.js with require.js. Would you care to share with me how you were able to compile that js into the flat file that appears as riot_compiler.js in this repo?

Thanks!

@gotno
Copy link
Author

gotno commented Jul 24, 2015

@adambutler?

@marcioj
Copy link
Collaborator

marcioj commented Jul 24, 2015

Hi @gotno sorry for the delay.

riot is split in two parts: the runtime and compiler.
It's possible to update the runtime in your own project by adding a file in vendor/assets/javascripts/riot.js. But in order to update the compiler you should replace lib/support/riot_compiler.js with the riot compiler file.
The way this is compiled is by loading the riot compiler file, using execjs to evaluate the javascript, and then returning the compiled tag.

@marcioj
Copy link
Collaborator

marcioj commented Jul 24, 2015

I have plans to add some configuration to point to a different compiler file. So you can easily update the compiler without forking the gem.

@gotno
Copy link
Author

gotno commented Jul 25, 2015

thanks for the reply, @marcioj

the problem i ran into was this, on line 256 of that compiler:

var doc = window.document,

that's the runtime compiler, which compiles .tag files in browser. maybe it was different when this gem was first created, but the server-side compiler now looks like this: https://github.com/riot/riot/tree/master/lib/server, which is meant to be run on a node-based framework like express or koa. i was hoping you might have some insight as to how to build all of that into a flat file to avoid all the require.js stuff that rails doesn't handle, but maybe it just wasn't necessary to do that when this gem was first built.

@gotno
Copy link
Author

gotno commented Jul 25, 2015

made a little more progress with this, but it's still kind of a mess. cloned the riot repo, added this to /lib/server-compiler.js:

// /lib/server-compiler.js
import 'server/parsers'
import 'server/analyzer'
import 'server/sdom'
import 'shared/compiler'
import 'server/compiler'
import 'server/index'

added this line to the Makefile, under the 'raw' section:

@ $(SMASH) lib/server-compiler.js > $(DIST)riot_compiler.js

and run

make riot

getting closer! but rails complains it can't find the simple-dom module. makes sense because that's an npm module. looking closer, i found that /lib/server/sdom.js requires both 'simple-dom' and 'simple-html-tokenizer'. ok, let's build them in too, just to see what happens. i pull out the built js files from node_modules, throw them in the server directory, add them to the server-compiler.js manifest and build again. eslint tests fail so i comment them out of the make file. the build succeeds, but now i get some really strange javascript error from rails because this is probably the worst possible way to do what i'm trying to do. ha.

i'm going to look into using commonjs.rb next, as that could make building the compiler unnecessary, but for right now i have to give it a rest.

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

2 participants