Generating output files for CodeObjects

23 views
Skip to first unread message

Stephen Gregory

unread,
Sep 3, 2014, 5:09:47 PM9/3/14
to yar...@googlegroups.com

I'm trying to build out an extensions for documenting padrino controllers.  The main problem with yard & padrino is that padrino controllers are blocks, but for documentation it would be handy to be grouped the way classes are.  There is an existing project gem here https://github.com/dayflower/yard-padrino. Their approach is to convert the controllers into CodeObject::ClassObjects.


 I'm trying to do something similar, but add some static analysis for our internal documentation.  For my purposes it would be handy to be able to use a subclass of ClassObject (or NamespaceObject) and generate the documentation from that.  So I built out a ControllerClass whose type method returns :controller, and added a /template/default/controller/html/setup.rb and controller.rb.  I can generate a menu_list for the controllers so it looks like they're getting parsed correctly.  I'm just not sure how to generate the pages for the controller objects.


Does the custom CodeObject approach sound valid, or should I just convert them to ClassObjects instead to work around this? 

Loren Segal

unread,
Sep 3, 2014, 5:28:17 PM9/3/14
to yar...@googlegroups.com
You can do either. Generating classes would certainly be the easier route, as there are already class templates and code to generate them, but it's possible to make a new object (like ControllerObject), and this might provide you with more control in the end. If that's what you want to do, go for it!

If you go the controller route, you do have to extend the YARD::CLI::Yardoc#all_objects method to include the :controller object when generating HTML files. See https://github.com/lsegal/yard/blob/master/lib/yard/cli/yardoc.rb#L308-L310

You probably want to alias chain it so as not to step on the toes of other plugins. It might look something like:

    class YARD::CLI::Yardoc
      def all_objects_with_controller
        all_objects_without_controller + Registry.all(:controller)
      end

      alias all_objects_without_controller all_objects
      alias all_objects all_objects_with_controller
    end

Hope that helps!

Loren
--

---
You received this message because you are subscribed to the Google Groups "YARD" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yardoc+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen Gregory

unread,
Sep 3, 2014, 9:21:41 PM9/3/14
to yar...@googlegroups.com
Ah perfect!  Thanks.

Yeah I'm really wanting to build up custom templates and I think I'm going to need this level of control anyway.
Reply all
Reply to author
Forward
0 new messages