Sha256: 227f29ddd9fd48fa48a8f6cec50049db00248766500f02abdb976873f8c997a8

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

require 'yard'

module Kangaroo
  module Doc
    class Base
      attr_accessor :logger
      
      def initialize object, logger
        @logger = logger
        ivar_name = self.class.name.demodulize.underscore
        @object = object
        instance_variable_set "@#{ivar_name}", object
      end
      
      def register ; end
      
      protected
      def name
        @object.name
      end
      
      def register_with_yard type, name, root = YARD::Registry.root, &block
        obj = object_for_type(type).new root, name, &block
        YARD::Registry.register obj
        
        obj
      end
      
      def object_for_type type
        YARD::CodeObjects.const_get("#{type}_object".camelize)
      end
      
      class << self
        def generate root_namespace, logger = Logger.new(STDOUT)
          RootNamespace.new(root_namespace, logger).register
          logger.info "Generating documentation ... (this may take a while)"
          YARD::Templates::Engine.generate YARD::Registry.all(:root, :module, :class), yard_options(root_namespace)
          logger.info "Great success!"
        end
        
        protected
        def verifier
          YARD::Verifier.new("!object.tag(:private) && (object.namespace.is_a?(CodeObjects::Proxy) || !object.namespace.tag(:private))",
             "object.type != :method || [:public].include?(object.visibility)")
        end
        
        def yard_options root_namespace
          {
            :files            => [],
            :verifier         =>  verifier,
            :serializer       =>  YARD::Serializers::FileSystemSerializer.new,
            :default_return   => "Object",
            :format           => :html,
            :hide_void_return => false,
            :template         => :default,
            :no_highlight     => false,
            :markup           => :rdoc,
            :title            => "OpenERP Database: #{root_namespace.reflection_model.database.db_name}"
          }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kangaroo-0.1.0.alpha1 lib/kangaroo/doc/base.rb