Woops! I mean:

This redefines the add_require method originally defined in
RDoc::Context, where it has different behavior.

On Wed, Oct 14, 2009 at 3:33 PM, Rein Henrichs <[email protected]> wrote:
> In the following code:
>
>> +        def add_require(required)
>> +            add_to(@requires, required)
>> +        end
>
> This redefines the add_require method, which has RDoc::Context, where
> it has different behavior. Perhaps a comment indicating that this is
> due to the behavior of require in puppet code would help unsuspecting
> readers?
>
> In the following code:
>
> +    # This module is used to generate a referenced full name list of
> ContextUser
> +    module ReferencedListBuilder
> +        def build_referenced_list(list)
> +            res = []
> +            list.each do |i|
> +                ref = AllReferences[i.name]
> +                ref = @context.find_symbol(i.name)
> +                ref = ref.viewer if ref
> +                name = i.respond_to?(:full_name) ? i.full_name : i.name
> +                h_name = CGI.escapeHTML(name)
> +                if ref and ref.document_self
> +                    path = url(ref.path)
> +                    res << { "name" => h_name, "aref" => path }
> +                else
> +                    res << { "name" => h_name }
> +                end
> +            end
> +            res
> +        end
> +    end
>
> The second ref = line inside the each block appears to reassign to ref
> whether it was found in AllReferences or not. This strikes me as
> probably unintended. Is the following closer to your intent?
>
> ref = AllReferences[i.name] || @context.find_symbol(i.name)
>
> In the following code:
>
> +                case stmt.name
> +                when "include"
> +                    stmt.arguments.each do |included|
> +                        Puppet.debug "found include: %s" % included.value
> +
> container.add_include(Include.new(included.value, stmt.doc))
> +                    end
> +                when "require"
> +                    stmt.arguments.each do |required|
> +                        Puppet.debug "found require: %s" % required.value
> +
> container.add_require(Include.new(required.value, stmt.doc))
> +                    end
> +                end
>
> I don't have a problem with this, but how do you feel about something
> like the following?
>
> stmt.arguments.each do |argument|
>    Puppet.debug "found %s: %s" % [argument.name, argument.value]
>    container.send("add_#{argument.name}", Include.new(argument.value,
> stmt.doc))
> end
>
> On Tue, Oct 13, 2009 at 2:51 PM, Brice Figureau
> <[email protected]> wrote:
>>
>> Puppetdoc wasn't parsing 'require'. This patch adds a 'require' section
>> to list all required class from nodes and classes.
>>
>> Signed-off-by: Brice Figureau <[email protected]>
>> ---
>>  lib/puppet/util/rdoc/code_objects.rb               |    7 +++-
>>  .../util/rdoc/generators/puppet_generator.rb       |   40 
>> +++++++++++++++++++-
>>  .../util/rdoc/generators/template/puppet/puppet.rb |   25 ++++++------
>>  lib/puppet/util/rdoc/parser.rb                     |   26 ++++++++----
>>  4 files changed, 74 insertions(+), 24 deletions(-)
>>
>> diff --git a/lib/puppet/util/rdoc/code_objects.rb 
>> b/lib/puppet/util/rdoc/code_objects.rb
>> index 6e384e1..e59e1a0 100644
>> --- a/lib/puppet/util/rdoc/code_objects.rb
>> +++ b/lib/puppet/util/rdoc/code_objects.rb
>> @@ -88,11 +88,12 @@ module RDoc
>>     # It is mapped to a HTMLPuppetClass for display
>>     # It leverages RDoc (ruby) Class
>>     class PuppetClass < ClassModule
>> -        attr_accessor :resource_list
>> +        attr_accessor :resource_list, :requires
>>
>>         def initialize(name, superclass)
>>             super(name,superclass)
>>             @resource_list = []
>> +           �...@requires = []
>>         end
>>
>>         def add_resource(resource)
>> @@ -106,6 +107,10 @@ module RDoc
>>         def superclass=(superclass)
>>             @superclass = superclass
>>         end
>> +
>> +        def add_require(required)
>> +            add_to(@requires, required)
>> +        end
>>     end
>>
>>     # PuppetNode holds a puppet node
>> diff --git a/lib/puppet/util/rdoc/generators/puppet_generator.rb 
>> b/lib/puppet/util/rdoc/generators/puppet_generator.rb
>> index bf2609f..378c3aa 100644
>> --- a/lib/puppet/util/rdoc/generators/puppet_generator.rb
>> +++ b/lib/puppet/util/rdoc/generators/puppet_generator.rb
>> @@ -320,6 +320,27 @@ module Generators
>>
>>     end
>>
>> +    # This module is used to generate a referenced full name list of 
>> ContextUser
>> +    module ReferencedListBuilder
>> +        def build_referenced_list(list)
>> +            res = []
>> +            list.each do |i|
>> +                ref = AllReferences[i.name]
>> +                ref = @context.find_symbol(i.name)
>> +                ref = ref.viewer if ref
>> +                name = i.respond_to?(:full_name) ? i.full_name : i.name
>> +                h_name = CGI.escapeHTML(name)
>> +                if ref and ref.document_self
>> +                    path = url(ref.path)
>> +                    res << { "name" => h_name, "aref" => path }
>> +                else
>> +                    res << { "name" => h_name }
>> +                end
>> +            end
>> +            res
>> +        end
>> +    end
>> +
>>     # This module is used to hold/generate a list of puppet resources
>>     # this is used in HTMLPuppetClass and HTMLPuppetNode
>>     module ResourceContainer
>> @@ -360,7 +381,7 @@ module Generators
>>     end
>>
>>     class HTMLPuppetClass < HtmlClass
>> -        include ResourceContainer
>> +        include ResourceContainer, ReferencedListBuilder
>>
>>         def value_hash
>>             super
>> @@ -376,12 +397,20 @@ module Generators
>>                     secdata["resource_list"] = rdl unless rdl.empty?
>>                 end
>>             end
>> +
>> +            rl = build_require_list(@context)
>> +           �...@values["requires"] = rl unless rl.empty?
>> +
>>             @values
>>         end
>> +
>> +        def build_require_list(context)
>> +            build_referenced_list(context.requires)
>> +        end
>>     end
>>
>>     class HTMLPuppetNode < ContextUser
>> -        include ResourceContainer
>> +        include ResourceContainer, ReferencedListBuilder
>>
>>         attr_reader :path
>>
>> @@ -452,6 +481,9 @@ module Generators
>>             il = build_include_list(@context)
>>             @values["includes"] = il unless il.empty?
>>
>> +            rl = build_require_list(@context)
>> +           �...@values["requires"] = rl unless rl.empty?
>> +
>>             @values["sections"] = @context.sections.map do |section|
>>
>>                 secdata = {
>> @@ -554,6 +586,10 @@ module Generators
>>             @values['infiles'] = files
>>         end
>>
>> +        def build_require_list(context)
>> +            build_referenced_list(context.requires)
>> +        end
>> +
>>         def <=>(other)
>>             self.name <=> other.name
>>         end
>> diff --git a/lib/puppet/util/rdoc/generators/template/puppet/puppet.rb 
>> b/lib/puppet/util/rdoc/generators/template/puppet/puppet.rb
>> index e12b651..c8f1e7d 100644
>> --- a/lib/puppet/util/rdoc/generators/template/puppet/puppet.rb
>> +++ b/lib/puppet/util/rdoc/generators/template/puppet/puppet.rb
>> @@ -538,18 +538,6 @@ IF:description
>>     </div>
>>  ENDIF:description
>>
>> -IF:requires
>> -    <div id="requires-list">
>> -      <h3 class="section-bar">Required files</h3>
>> -
>> -      <div class="name-list">
>> -START:requires
>> -      HREF:aref:name:&nbsp;&nbsp;
>> -END:requires
>> -      </div>
>> -    </div>
>> -ENDIF:requires
>> -
>>  IF:toc
>>     <div id="contents-list">
>>       <h3 class="section-bar">Contents</h3>
>> @@ -601,6 +589,19 @@ END:includes
>>     </div>
>>  ENDIF:includes
>>
>> +    <!-- if requires -->
>> +IF:requires
>> +    <div id="requires">
>> +      <h3 class="section-bar">Required Classes</h3>
>> +
>> +      <div id="requires-list">
>> +START:requires
>> +        <span class="require-name">HREF:aref:name:</span>
>> +END:requires
>> +      </div>
>> +    </div>
>> +ENDIF:requires
>> +
>>  START:sections
>>     <div id="section">
>>  IF:sectitle
>> diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb
>> index 554f8cb..842b81c 100644
>> --- a/lib/puppet/util/rdoc/parser.rb
>> +++ b/lib/puppet/util/rdoc/parser.rb
>> @@ -147,14 +147,22 @@ class Parser
>>
>>     # create documentation for include statements we can find in +code+
>>     # and associate it with +container+
>> -    def scan_for_include(container, code)
>> +    def scan_for_include_or_require(container, code)
>>         code.each do |stmt|
>> -            scan_for_include(container,stmt.children) if 
>> stmt.is_a?(Puppet::Parser::AST::ASTArray)
>> -
>> -            if stmt.is_a?(Puppet::Parser::AST::Function) and stmt.name == 
>> "include"
>> -                stmt.arguments.each do |included|
>> -                    Puppet.debug "found include: %s" % included.value
>> -                    container.add_include(Include.new(included.value, 
>> stmt.doc))
>> +            scan_for_include_or_require(container,stmt.children) if 
>> stmt.is_a?(Puppet::Parser::AST::ASTArray)
>> +
>> +            if stmt.is_a?(Puppet::Parser::AST::Function)
>> +                case stmt.name
>> +                when "include"
>> +                    stmt.arguments.each do |included|
>> +                        Puppet.debug "found include: %s" % included.value
>> +                        container.add_include(Include.new(included.value, 
>> stmt.doc))
>> +                    end
>> +                when "require"
>> +                    stmt.arguments.each do |required|
>> +                        Puppet.debug "found require: %s" % required.value
>> +                        container.add_require(Include.new(required.value, 
>> stmt.doc))
>> +                    end
>>                 end
>>             end
>>         end
>> @@ -220,7 +228,7 @@ class Parser
>>         code = klass.code.children if 
>> klass.code.is_a?(Puppet::Parser::AST::ASTArray)
>>         code ||= klass.code
>>         unless code.nil?
>> -            scan_for_include(cls, code)
>> +            scan_for_include_or_require(cls, code)
>>             scan_for_resource(cls, code) if Puppet.settings[:document_all]
>>         end
>>
>> @@ -241,7 +249,7 @@ class Parser
>>         code = node.code.children if 
>> node.code.is_a?(Puppet::Parser::AST::ASTArray)
>>         code ||= node.code
>>         unless code.nil?
>> -            scan_for_include(n, code)
>> +            scan_for_include_or_require(n, code)
>>             scan_for_vardef(n, code)
>>             scan_for_resource(n, code) if Puppet.settings[:document_all]
>>         end
>> --
>> 1.6.4
>>
>>
>> >>
>>
>
>
>
> --
> Rein Henrichs
> http://reductivelabs.com
>



-- 
Rein Henrichs
http://reductivelabs.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to