Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow introspecting a presenter #105

Open
dasch opened this issue Oct 27, 2014 · 9 comments · May be fixed by #118
Open

Allow introspecting a presenter #105

dasch opened this issue Oct 27, 2014 · 9 comments · May be fixed by #118

Comments

@dasch
Copy link
Contributor

dasch commented Oct 27, 2014

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 dasch added this to the v2.1 milestone Oct 27, 2014
@dasch dasch modified the milestones: v2.1, v2.2 Nov 5, 2014
@yurifrl
Copy link

yurifrl commented Nov 7, 2014

+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

@dasch
Copy link
Contributor Author

dasch commented Nov 7, 2014

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

@teliosdev
Copy link
Contributor

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

@thelinuxlich
Copy link

+1 for @medcat suggestion

@yurifrl
Copy link

yurifrl commented Nov 10, 2014

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

@teliosdev
Copy link
Contributor

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

@yurifrl
Copy link

yurifrl commented Nov 10, 2014

my custom_error:

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

@dasch
Copy link
Contributor Author

dasch commented Nov 10, 2014

Can you guys open a separate issue for that?

@yurifrl
Copy link

yurifrl commented Nov 10, 2014

#115

@teliosdev teliosdev linked a pull request Nov 15, 2014 that will close this issue
@dasch dasch modified the milestones: v2.2, v2.4 Jan 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants