tmpvar / weld

Template antimatter for Node.js (Browsers too!)
674 stars 39 forks source link

Server side weld with ruby #33

Closed amiel closed 12 years ago

amiel commented 12 years ago

Hello, I figure this might be the best place to start this discussion:

I'm interested in using weld server side within ruby on rails. Has there already been an effort to make this work?

There are a few other javascript based projects running nicely in rails (for example: https://github.com/cowboyd/handlebars.rb). However, this is a little trickier with Weld because it requires a DOM implementation.

Here's what I've tried:

  1. therubyracer + jsdom -- couldn't get jsdom loaded correctly
  2. therubyracer + domcore -- domcore stolen from sproutcore, couldn't load html directly into domcore synchronously
  3. execjs (node) + jsdom -- this one actually works pretty well, the only downside is that you can't run ruby procs within javascript, which would be handy for map and alias. most of the code is here: https://github.com/amiel/weld-rails-prototype/blob/master/config/initializers/weld_handler.rb Look in app/views/test and app/controllers to see how it is used.)
  4. harmony + johnson + jsdom -- jsdom and weld loaded fine, but could not get rendered result from weld. I'm not sure if weld never rendered anything or if I screwed something up. Anyway, johnson doesn't work with ruby 1.9 and looks like a dying project.

Anyway, I will probably continue working on the execjs implementation, but I was wondering if anyone else was working on this. Also, I think ideally the implementation would use therubyracer instead of execjs and node and therefore would not depend on node and would have the added benefit of being able to write rendering logic in ruby.

Thoughts,

-Amiel

tmpvar commented 12 years ago

The closest thing that I've seen is http://blog.envylabs.com/tag/jsdom/ -- I'm not a rubyist, so I'm not sure how helpful that is.

maybe you should ask this on the jsdom mailing list

-- Elijah

heapwolf commented 12 years ago

There is no straight forward answer to this. so im going to close it, however keep this conversation going. You may consider creating a simple nodejs server that plays the roll of a template/content server.

tmpvar commented 12 years ago

@hij1nx, I agree.. this isn't really a weld issue per se.

amiel commented 12 years ago

Uh yeah, sorry. I didn't mean to imply that this was an issue the weld team needed to work on. I just wanted a place to start this discussion.

Thanks for the pointers. I did see the envylabs article and found that ExecJS.compile_async didn't work at all. (I continually got a JavascriptError on code that worked just fine with ExecJS.compile.

I will also check the jsdom mailing list.

If anyone has anymore thoughts, post 'em here. I'm going to start work on this here: http://github.com/amiel/weld-rails

heapwolf commented 12 years ago

If you get this working id love to hear about it :) it would make a great blog post!

amiel commented 12 years ago

I'll let you know.

FWIW rendering does work in my "prototype app": https://github.com/amiel/weld-rails-prototype. I think what I'll do if I don't get any specific help from the jsdom mailing list or from therubyracer folks is expect the config hash to be written in javascript and come up with a clever way to include it.