[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

having problems fiddling with rake

Rich Morin

3/8/2007 1:10:00 PM

I'm trying to get "rake doc:app" pull its input from a different
Rails app's source tree. In trying to prototype a solution, I've
fiddled with documentation.rake. However, my hack isn't working:

> rake aborted!
> stack level too deep
> /usr/local/lib/ruby/gems/1.8/gems/
> rake-0.7.1/lib/rake.rb:1038:in `orig_include'
> rake-0.7.1/lib/rake.rb:1036:in `orig_include'
> rails-1.2.2/lib/tasks/documentation.rake:41:in `include'

My trace of the value being mapped contains only a series of:

new_name='.//'


Any idea what I'm doing wrong? Here's the relevant code:

# /usr/.local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb defines
# the include method, as follows:
#
# # Add file names defined by glob patterns to the file list.
# # If an array is given, add each element of the array.
# #
# # Example:
# # file_list.include("*.java", "*.cfg")
# # file_list.include %w( math.c lib.h *.o )
# #
# def include(*filenames)
# # TODO: check for pending
# filenames.each do |fn|
# if fn.respond_to? :to_ary
# include(*fn.to_ary)
# else
# @pending_add << fn
# end
# end
# @pending = true
# self
# end
# alias :add :include
#
#####
#
# We can redefine this to add an arbitrary prefix to each path, based
# on the RDOC_SRC_DIR environment variable:

class FileList

@@rdoc_src_dir = ENV['RDOC_SRC_DIR']

if (@@rdoc_src_dir)
alias :orig_include :include

def include(*filenames)
list = filenames.map do |name|
new_name = "#{@@rdoc_src_dir}/#{name}"
puts "new_name='#{new_name}'" #T
end
orig_include(list)
end
alias :add :include
end
end
...


More generally, if someone has a better way to solve the original
problem, I'd be happy to hear about it!

-r
--
http://www.cf... Rich Morin
http://www.cf.../resume rdm@cfcl.com
http://www.cf.../weblog +1 650-873-7841

Technical editing and writing, programming, and web development

5 Answers

Jim Weirich

3/8/2007 7:28:00 PM

0

Rich Morin wrote:
> Any idea what I'm doing wrong? Here's the relevant code:
> class FileList
>
> @@rdoc_src_dir = ENV['RDOC_SRC_DIR']
>
> if (@@rdoc_src_dir)
> alias :orig_include :include
>
> def include(*filenames)
> list = filenames.map do |name|
> new_name = "#{@@rdoc_src_dir}/#{name}"
> puts "new_name='#{new_name}'" #T
^^^^
> end
> orig_include(list)
> end
> alias :add :include
> end
> end
> ...

Puts doesn't return a useful value for +map+ to use.

That being said, I don't see why you don't just duplicate the rails
doc:app task and replace the filelists with what you need. It is
probably less code than what you've invested in hacking FileList#include
and it will be much less error prone.


-- Jim Weirich

--
Posted via http://www.ruby-....

Rich Morin

3/8/2007 7:39:00 PM

0

At 4:27 AM +0900 3/9/07, Jim Weirich wrote:
> Puts doesn't return a useful value for +map+ to use.

Point taken, but it didn't work even without the puts. So,
my Ruby question remains...

> That being said, I don't see why you don't just duplicate
> the rails doc:app task and replace the filelists with
> what you need. It is probably less code than what you've
> invested in hacking FileList#include and it will be much
> less error prone.

I have considered that and may end up doing so, but it would
mean tracking the changes to the original task, which is the
kind of maintenance sinkhole I try to avoid.

-r
--
http://www.cf... Rich Morin
http://www.cf.../resume rdm@cfcl.com
http://www.cf.../weblog +1 650-873-7841

Technical editing and writing, programming, and web development

Jim Weirich

3/8/2007 7:48:00 PM

0

Rich Morin wrote:
> I have considered that and may end up doing so, but it would
> mean tracking the changes to the original task, which is the
> kind of maintenance sinkhole I try to avoid.

The original task uses a rake standard RDocTask. Of the six lines that
configure it, three consist of selecting the right files (which is the
part you want to change) and the other three set the document directory,
the title and a few options.

Doesn't seem to be too onerous.

Now, duplicating the "doc:rails" task would be another issue.

-- Jim Weirich



--
Posted via http://www.ruby-....

Rich Morin

3/8/2007 8:16:00 PM

0

At 4:48 AM +0900 3/9/07, Jim Weirich wrote:
> The original task uses a rake standard RDocTask. Of
> the six lines that configure it, three consist of
> selecting the right files (which is the part you want
> to change) and the other three set the document
> directory, the title and a few options.
>
> Doesn't seem to be too onerous.

The onerous part is keeping track of the library, in
order to look at the file and see if I NEED to make the
changes. I'm also I'm a bit mystified as to how I'd
(cleanly) change the standard task to get the effect I
want. I'll try explaining again; perhaps you can help.

I want to be able to have one Rails app generate doc/...
files, based on the file tree of another app. That is,
the results should appear locally, but the sources should
stay (unmodified) over in the other app.

I don't see six lines (in documentation.rake). Rather, I
see a long laundry list of "rdoc.rdoc_files.include" calls,
relative to the current directory. The output files (and
actions such as rm_rf) are also defined in terms of the
current directory.

So, doing a chdir won't help. I could edit the file to
change the laundry lists, but that seemed onerous to me.
So, I started looking at redefining "include". How would
you approach this problem, specifically?

-r

P.S. Still having problems with my include aliasing...
--
http://www.cf... Rich Morin
http://www.cf.../resume rdm@cfcl.com
http://www.cf.../weblog +1 650-873-7841

Technical editing and writing, programming, and web development

Rich Morin

3/8/2007 9:23:00 PM

0

FYI, my current (working) solution looks like this:

namespace :doc do

# On occasion, we want to grovel over another app's file tree, but
# put the results in our own DOC directory. In order to make this
# happen, we do the following:
#
# % setenv README_FOR_APP ...
# Make sure that $RDOC_SRC_DIR/doc/README_FOR_APP exists.
# In the following code, do some chdir magic.

rdoc_src_dir = ENV['RDOC_SRC_DIR']
if (rdoc_src_dir)
save_wd = getwd
chdir(rdoc_src_dir)
else
save_wd = '.'
end
...
rdoc.rdoc_dir = "#{save_wd}/doc/api"
...
--
http://www.cf... Rich Morin
http://www.cf.../resume rdm@cfcl.com
http://www.cf.../weblog +1 650-873-7841

Technical editing and writing, programming, and web development