Ruby to JSON - how to store javascript functions


#1

Hey guys,

I am working on a small plug-in which stores settings in a yaml file,
e.g.:


:before: var lastsel2;
:params:
:url: http://www.google.com
:datatype: xml
:mtype: GET

etc., then later turning them into js with something like

params.each do |key,value|
emit "#{key}: #{value.to_json}
end

so far so good. My question is, what should I put in the place of ???

:params:
:some_func: ???

so that the Ruby code above spits out this:

some_func: function(id) {
do_some_stuff
do_something_else
}

I hope it’s clear :slight_smile: Obviously I’d like to store the function params
and body as well.
Is there a (semi-)standard way of doing this? I thought of
representing the js function with some custom class, storing the param
list and body as strings. Am I completely off?

Cheers,
Peter


http://www.rubyrailways.com
http://scrubyt.org