curly icon indicating copy to clipboard operation
curly copied to clipboard

Allow introspecting a presenter

Open dasch opened this issue 11 years ago • 9 comments

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: []
         },
       ]
     },
   ]
 }

dasch avatar Oct 27 '14 13:10 dasch

+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 avatar Nov 07 '14 18:11 yurifrl

@yurifrl that can be tricky, as Curly is statically typed :-/

dasch avatar Nov 07 '14 23:11 dasch

@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.

teliosdev avatar Nov 08 '14 06:11 teliosdev

+1 for @medcat suggestion

thelinuxlich avatar Nov 08 '14 07:11 thelinuxlich

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

yurifrl avatar Nov 10 '14 11:11 yurifrl

If it doesn't exist however, it should still error with the original tag.

teliosdev avatar Nov 10 '14 11:11 teliosdev

my custom_error:

def custom_error(tag: nil)
    "####{tag}###"
end

yurifrl avatar Nov 10 '14 11:11 yurifrl

Can you guys open a separate issue for that?

dasch avatar Nov 10 '14 12:11 dasch

https://github.com/zendesk/curly/issues/115

yurifrl avatar Nov 10 '14 12:11 yurifrl