Allow introspecting a presenter
It would be great to get a description of a presenter, including all nested presenters.
class OrganizationPresenter < Curly::Presenter
def name; end
def members(max: nil); end
def open?; end
class MemberPresenter < Curly::Presenter
def name; end
def admin?; end
end
end
OrganizationPresenter.description #=>
{
components: [
{
name: "name",
type: "value",
parameters: []
},
{
name: "open?",
type: "conditional",
parameters: []
},
{
name: "members",
type: "collection",
parameters: [ { name: "max", required: false } ],
components: [
{
name: "name",
type: "value",
parameters: []
},
{
name: "admin?",
type: "conditional",
parameters: []
},
]
},
]
}
+1 one on this, it would be also nice to have a option to not throw an exception when curly can't parse a tag, only display a html error, the same way i18n does
@yurifrl that can be tricky, as Curly is statically typed :-/
@dasch doing so could lead to an alternative feature: if a tag couldn't be found, pass it on to a method that acts kind of like method_missing. I'm not sure if this would be a part of the "curly way," but it could allow for some user extensibility.
+1 for @medcat suggestion
maybe something like that, when curly can't find a tag it renders a custom_error method
module Curly
ComponentCompiler.class_eval do
def initialize(presenter_class, component, type: nil)
unless presenter_class.component_available?(component.name)
component = Curly::Parser::Component.new('custom_error', nil, {'tag' => 'custom_error'})
end
@presenter_class, @component, @type = presenter_class, component, type
end
end
end
If it doesn't exist however, it should still error with the original tag.
my custom_error:
def custom_error(tag: nil)
"####{tag}###"
end
Can you guys open a separate issue for that?
https://github.com/zendesk/curly/issues/115