zendesk/curly

Question: How would you use curly without Rails?

philippfrank opened this issue · 1 comments

Is it safe to do something like this:

def compile(source, presented_object)
    context = {}
    presenter = PresentedObjectPresenter.new(context, presented_object: presented_object)
    compiled = Curly::Compiler.new(source, PresentedObjectPresenter).compile
    options = {}
    eval(compiled)
end

And also, how would you handle rendering of partials then? I'd like to make something like {{include name="foo"}} available. That should render something from another template called foo.

Thanks, I appreciate your answers.

Hi @philippfrank, sorry for the late reply. Curly was designed to integrate closely with Rails, and as such doesn't offer support for rendering outside of a Rails context. That being said, you seem to be pretty close.

As for partial rendering: that is done entirely by Rails, so Curly itself offers no support there. If you want to implement your own renderer on top of Curly, you'll have to figure out partials for yourself. The "Curly Way" would be to hide the fact that a partial is being used from the template, instead handling that stuff in the presenter.