How do I put empty directories into a gem package?

L

Luke

I feel like an idiot for being unable to get this working...

I'm trying to put together a general purpose "project templating
engine" and I'd like to just package a directory full of project
templates that get copied and rendered in ERB on demand. These
templates often include empty directories that I can't seem to get
packaged into my gem - no matter what I do.

I'm pretty sure I'm doing something really dumb, but I can't seem to
figure out what it is!

It occurred to me that I might pack these templates up in a zip or tar
file and just unpack them on request, but I couldn't get the empty
directories into the zip file either. At this point, that makes me
think I'm just doing something wrong, so rather than going to the pack/
unpack scheme - it seems like I ought to just ask you folks how to do
it correctly.

So -

Does anyone know how to get empty directories into a gem package?

Here's what I have in my rake file:

PKG_LIST = FileList['[a-zA-Z]*',
'bin/**/*',
'lib/**/*',
'templates',
'templates/**/*',
'templates/**/.[a-z]*'
]

PKG_LIST.exclude('.svn')
PKG_LIST.each do |file|
puts 'file: ' + file
task :package => file
end

When I run "rake package", I see all of the desired files *and* all of
the desired directories on screen, but when I install the gem, they're
not there!

I'm guessing there is some simple exclude directive that I'm not able
to find? I dug around in the rake package task code, but can't see
anything obvious (to me at least)


Thanks,


lb.
 
A

Austin Ziegler

I'm trying to put together a general purpose "project templating
engine" and I'd like to just package a directory full of project
templates that get copied and rendered in ERB on demand. These
templates often include empty directories that I can't seem to get
packaged into my gem - no matter what I do.

Um. I'm not sure that's what you want to do. Why not consider
approaching this from a slightly different perspective? Make a .tar.gz
file that gets deployed with your other files and then use
Archive::Tar::Minitar to unpack it on the fly (Ruwiki does this) and
render with ERB as usual. Archive::Tar::Minitar can easily handle this
on both ends and you don't need to try to trick RubyGems.

-austin
 
L

Luke

I definitely considered that direction, and even got it mostly-
working, but then I started having problems with my test cases.

I was writing tests that unpack the actual tarball and found that my
tests now had a dependency on a successful build, but I couldn't get a
successful build unless my tests passed! :-(

I recognize that this is a simple problem and could be fixed by
packing up the tarball in the test_helper or setup methods, but then
it felt like I was violating dry principles by putting my packing
logic (more importantly - the file selection) into the rake file *and*
into my test cases. I wanted to verify that the actual templates being
shipped in the gem are in fact what we're testing against, and I'd
like the test cases stay up to date if our inclusion globs change over
time...

This also puts another dependency into my gem and I was hoping to
minimize those external dependencies.

It just feels like I'm missing some simple setting in the gem package
task...

Something like:
prune_empty_directories = false

Another reason I don't want to tar them up, is because I'm optionally
duplicating them into user_home and/or project_home, and I would
prefer not to have different copy logic when they come out of
gem_home, and it's essential that users can easily modify these
templates when they're placed into those other two locations - so they
can't be tarred up in there.

The final reason it felt strange to tar the templates was simply
because my understanding is that gem is already tarring everything up,
so shouldn't I just be able to get that one working?
Um. I'm not sure that's what you want to do. Why not consider
approaching this from a slightly different perspective? Make a .tar.gz
file that gets deployed with your other files and then use
Archive::Tar::Minitar to unpack it on the fly (Ruwiki does this) and
render with ERB as usual. Archive::Tar::Minitar can easily handle this
on both ends and you don't need to try to trick RubyGems.

Thanks for the response.


Luke
www.asunit.org
 
L

Luke

Does anyone else have any ideas about how to solve this problem?

For what it's worth, I wound up writing a rake task that injects a
bunch of junk files into the entire template directory and then added
these file names to my "ignore list" when copying out of the installed
gem.

Definitely *not* elegant but it works.


Luke Bayes
 
E

Eric Hodel

Does anyone else have any ideas about how to solve this problem?

For what it's worth, I wound up writing a rake task that injects a
bunch of junk files into the entire template directory and then added
these file names to my "ignore list" when copying out of the installed
gem.

Definitely *not* elegant but it works.

Please give some code that shows how this is broken.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,085
Latest member
cryptooseoagencies

Latest Threads

Top