Skip to content

Allow introspecting a presenter #105

@dasch

Description

@dasch
Contributor

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

Activity

added this to the v2.1 milestone on Oct 27, 2014
modified the milestones: v2.1, v2.2 on Nov 5, 2014
yurifrl

yurifrl commented on Nov 7, 2014

@yurifrl

+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

dasch commented on Nov 7, 2014

@dasch
ContributorAuthor

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

teliosdev

teliosdev commented on Nov 8, 2014

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

thelinuxlich commented on Nov 8, 2014

@thelinuxlich

+1 for @medcat suggestion

yurifrl

yurifrl commented on Nov 10, 2014

@yurifrl

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

teliosdev commented on Nov 10, 2014

@teliosdev
Contributor

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

yurifrl

yurifrl commented on Nov 10, 2014

@yurifrl

my custom_error:

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

dasch commented on Nov 10, 2014

@dasch
ContributorAuthor

Can you guys open a separate issue for that?

yurifrl

yurifrl commented on Nov 10, 2014

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @thelinuxlich@dasch@teliosdev@yurifrl

      Issue actions

        Allow introspecting a presenter · Issue #105 · zendesk/curly