[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Rdoc with hyperlinks

Dave Howell

7/19/2006 12:20:00 AM


On Jul 18, 2006, at 8:05, listrecv@gmail.com wrote:


Ken Bloom wrote:
In general, you should not rely on knowledge of the source code to
understand how a library works, because the library writer reserves
the right to change the behavior of things that are not specified in
the documentation.

Ken - I certainly agree in theory. However, in practice, that is often
the only way to understand most Ruby libs.

No kidding.

OK, I gritted my teeth and ignored you the first time I saw your
request, but this time I couldn't let it go. Took almost five hours to
solve. Sigh.

There's a very good reason you couldn't figure out how to do it by
looking at the RDoc source. The necessary path simply isn't available;
by the time RDoc is generating output, it no longer knows where the
original source code file was.


Make the following changes to files in ..../lib/rdoc

code_objects.rb:
Insert at line 467
attr_accessor :source_path
Insert at line 483
@source_path = File.join(Dir.getwd,file_name)

This will modify class TopLevel so it looks like this:

class TopLevel < Context
attr_accessor :file_stat
attr_accessor :file_relative_name
attr_accessor :file_absolute_name
attr_accessor :source_path
attr_accessor :diagram

@@all_classes = {}
@@all_modules = {}

def TopLevel::reset
@@all_classes = {}
@@all_modules = {}
end

def initialize(file_name)
super()
@name = "TopLevel"
@file_relative_name = file_name
@file_absolute_name = file_name
@source_path = File.join(Dir.getwd,file_name)
@file_stat = File.stat(file_name)
@diagram = nil
end



Make the following changes to generators/html_generator.rb
Insert at line 877
@values["source_path"] = CGI.escapeHTML(@context.source_path)
Change line 1031 from
'charset' => @options.charset
to
'charset' => @options.charset,
'source_path'=> @context.parent.toplevel.source_path,
'source_file'=> @context.parent.toplevel.file_relative_name


The first addition makes the "%source_path%" variable available for
most of the templates by changing HtmlFile::file_attribute_values to
look like

@values["short_name"] = CGI.escapeHTML(short_name)
@values["full_path"] = CGI.escapeHTML(full_path)
@values["source_path"] = CGI.escapeHTML(@context.source_path)
@values["dtm_modified"] = @context.file_stat.mtime.to_s

The second makes the new source_path available for the pop-up source
code windows, by modifying HtmlMethod::create_source_code_file to look
like this:

def create_source_code_file(code_body)
meth_path = @html_class.path.sub(/\.html$/, '.src')
File.makedirs(meth_path)
file_path = File.join(meth_path, @seq) + ".html"

template = TemplatePage.new(RDoc::Page::SRC_PAGE)
File.open(file_path, "w") do |f|
values = {
'title' => CGI.escapeHTML(index_name),
'code' => code_body,
'style_url' => style_url(file_path, @options.css),
'charset' => @options.charset,
'source_path'=> @context.parent.toplevel.source_path,
'source_file'=> @context.parent.toplevel.file_relative_name
}
template.write_html_on(f, values)
end
HTMLGenerator.gen_url(path, file_path)
end

Finally, you need to edit whatever HTML template you're using. If
you're using the default HTML template
(generators/templates/html/html.rb) you might want to find the
FILE_PAGE and change

<td>%full_path%
to
<td>%full_path% [<a href="%source_path%">Source</a>]

Another possible place to add a link is inside the pop-up source code
pages. Find SRC_PAGE, and change
<body class="standalone-code">
<pre>%code%</pre>
</body>
to
<body class="standalone-code">
<div style="text-align: right;">Open <a
href="%source_path%">%source_file%</a></div>
<pre>%code%</pre>
</body>
or something along those lines.



8 Answers

List Recv

7/19/2006 5:34:00 PM

0


Dave Howell wrote:
> OK, I gritted my teeth and ignored you the first time I saw your
> request, but this time I couldn't let it go. Took almost five hours to
> solve. Sigh.

Thanks, greatly appreciated!

>
> There's a very good reason you couldn't figure out how to do it by
> looking at the RDoc source. The necessary path simply isn't available;
> by the time RDoc is generating output, it no longer knows where the
> original source code file was.

Dave - I'm a little confused here. RDoc templates always have a link
to the files where the class comes from. However, the "file" pages
have no source code - only any file level RDoc, if there is any. But
RDoc must have the path to those files.

How would you modify RDoc to, instead of just including file level Rdoc
on file pages, include the full, formatted, source of the file (just
like it does for methods)?

Eric Hodel

7/20/2006 5:44:00 PM

0

On Jul 18, 2006, at 5:19 PM, Dave Howell wrote:

> Make the following changes to files in ..../lib/rdoc

Can you turn this into a patch?

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



Dave Howell

7/20/2006 9:47:00 PM

0


On Jul 20, 2006, at 10:43, Eric Hodel wrote:

> On Jul 18, 2006, at 5:19 PM, Dave Howell wrote:
>
>> Make the following changes to files in ..../lib/rdoc
>
> Can you turn this into a patch?

Short answer: "no".

Slightly longer answer: "Um, I dunno. What kind of a patch, to be
applied with what tool? I've never made a patch. Is it hard?"



Logan Capaldo

7/21/2006 2:54:00 AM

0


On Jul 20, 2006, at 5:47 PM, Dave Howell wrote:

>
> On Jul 20, 2006, at 10:43, Eric Hodel wrote:
>
>> On Jul 18, 2006, at 5:19 PM, Dave Howell wrote:
>>
>>> Make the following changes to files in ..../lib/rdoc
>>
>> Can you turn this into a patch?
>
> Short answer: "no".
>
> Slightly longer answer: "Um, I dunno. What kind of a patch, to be
> applied with what tool? I've never made a patch. Is it hard?"
>
>
>

One way:

diff -u your_version_with_changes.rb original_version.rb > your.patch

If you changed more than one file I would suggest

diff -u your_version_of_whole_src_tree_directory
original_version_of_source_tree_directory > your.patch

the people who ask for patches will know how to use the patch tool to
apply it.






Logan Capaldo

7/21/2006 2:57:00 AM

0


On Jul 20, 2006, at 10:53 PM, Logan Capaldo wrote:

>
> On Jul 20, 2006, at 5:47 PM, Dave Howell wrote:
>
>>
>> On Jul 20, 2006, at 10:43, Eric Hodel wrote:
>>
>>> On Jul 18, 2006, at 5:19 PM, Dave Howell wrote:
>>>
>>>> Make the following changes to files in ..../lib/rdoc
>>>
>>> Can you turn this into a patch?
>>
>> Short answer: "no".
>>
>> Slightly longer answer: "Um, I dunno. What kind of a patch, to be
>> applied with what tool? I've never made a patch. Is it hard?"
>>
>>
>>
>
> One way:
>
> diff -u your_version_with_changes.rb original_version.rb > your.patch
>
> If you changed more than one file I would suggest
>
> diff -u your_version_of_whole_src_tree_directory
> original_version_of_source_tree_directory > your.patch
>
> the people who ask for patches will know how to use the patch tool
> to apply it.
>

Ack!!! I lied. I always mix that up.

its diff -u original your_version

Sorry :(.




jmg3000

7/21/2006 2:43:00 PM

0

On 7/20/06, Logan Capaldo <logancapaldo@gmail.com> wrote:
>
> On Jul 20, 2006, at 10:53 PM, Logan Capaldo wrote:
>
> >
> > On Jul 20, 2006, at 5:47 PM, Dave Howell wrote:
> >
> >>
> >> On Jul 20, 2006, at 10:43, Eric Hodel wrote:
> >>
> >>> On Jul 18, 2006, at 5:19 PM, Dave Howell wrote:
> >>>
> >>>> Make the following changes to files in ..../lib/rdoc
> >>>
> >>> Can you turn this into a patch?
> >>
> >> Short answer: "no".
> >>
> >> Slightly longer answer: "Um, I dunno. What kind of a patch, to be
> >> applied with what tool? I've never made a patch. Is it hard?"
> >>
> >
> > One way:
> >
> > diff -u your_version_with_changes.rb original_version.rb > your.patch
> >
> > If you changed more than one file I would suggest
> >
> > diff -u your_version_of_whole_src_tree_directory
> > original_version_of_source_tree_directory > your.patch
> >
> > the people who ask for patches will know how to use the patch tool
> > to apply it.
> >
>
> Ack!!! I lied. I always mix that up.
>
> its diff -u original your_version
>
> Sorry :(.
>

If making a patch between two directory trees, you'll also need the -r option:

diff -ur foo_original foo_modified > foo_mychanges.patch

---John

Eric Hodel

7/21/2006 4:54:00 PM

0

On Jul 20, 2006, at 7:53 PM, Logan Capaldo wrote:

> On Jul 20, 2006, at 5:47 PM, Dave Howell wrote:
>> On Jul 20, 2006, at 10:43, Eric Hodel wrote:
>>> On Jul 18, 2006, at 5:19 PM, Dave Howell wrote:
>>>> Make the following changes to files in ..../lib/rdoc
>>>
>>> Can you turn this into a patch?
>>
>> Short answer: "no".
>>
>> Slightly longer answer: "Um, I dunno. What kind of a patch, to be
>> applied with what tool? I've never made a patch. Is it hard?"
>
> One way:
>
> diff -u your_version_with_changes.rb original_version.rb > your.patch
>
> If you changed more than one file I would suggest
>
> diff -u your_version_of_whole_src_tree_directory
> original_version_of_source_tree_directory > your.patch
>
> the people who ask for patches will know how to use the patch tool
> to apply it.

The easiest way is to check out ruby from CVS:

http://www.ruby-lang.org/en/200...

Make your changes, test them, then run cvs diff -u and send the
output to me.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



List Recv

7/21/2006 8:10:00 PM

0

I think we should have options for linking to the actual file (in the
original source), a rdoc highlighted html copy, or both.