codeplant/simple-navigation

json render

Closed this issue · 11 comments

I'm writing a json render for simple_navigation for my project and thought it could be useful for people in general, so i was thinking of sending a push request including that feature.

Are you interested on me adding that feature or do you think there in no place for that render on your codebase?

Cheers, and thank you for your great work :)

andi commented

Can you quickly describe your use case for a json renderer? I'm curious :-)

I did a custom js based menu, i think that having a renderer that generates a js object tree would be helpful for those kinds of scenarios, you can do it using the list rendering and then parsing the DOM tree but it can get cumbersome.

andi commented

true. so please send a pull request, specs included. Thanks!

What do you think should be the correct behaviour? Should the renderer return a json string or should it return a simple hash requiring the user to call to_json on the results?.

I was thinking on doing the former, but that would mean that for the specs we would need to test against a prerender string, is that acceptable?

Thank you for your time

andi commented

Since it is a Json renderer, I would expect it to return json... If there is the need to customize the resulting json, we could either allow options for to_json (hmm, probably there are no options for to_json), or we could even have an option :as_hash, which just skips the to_json call in the renderer... For testing it's ok to test against the string. If that is too cumbersome, we can add the json_spec gem and then you can call

parse_json(resulting_json_string)['x']['y'].should == 'value'

What do you think?

I like the idea about as_hash, and also i think it would be better to use json_spec gem as you suggest, i'll send you the pull request later today.

andi commented

merged

andi commented

I will leave it open until you added this to the wiki, ok?

Sure, I'll let you know

I've already added the documentation as requested.

andi commented

Great! thanks for your work.