summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorRyan Davis <ryand@zenspider.com>2012-11-12 16:35:30 -0800
committerRyan Davis <ryand@zenspider.com>2012-11-12 16:35:30 -0800
commitb2937f7df735710a0a1ffc6d2ec448a2d38d8645 (patch)
tree867498333e4034a12207c40c03a9a32231c3da58 /bin
parent74afa78b07b272e3187a7905505f5e7608ed020a (diff)
downloadhoe-b2937f7df735710a0a1ffc6d2ec448a2d38d8645.tar.gz
+ Added Sow#make_sub_modules. (bhenderson)
+ Hoe.normalize_names now returns test class name separately. (bhenderson) + Sow now generates test and impl files with proper namespacing. (bhenderson) [git-p4: depot-paths = "//src/hoe/dev/": change = 7966]
Diffstat (limited to 'bin')
-rwxr-xr-xbin/sow25
1 files changed, 20 insertions, 5 deletions
diff --git a/bin/sow b/bin/sow
index 1a66544..7e2939c 100755
--- a/bin/sow
+++ b/bin/sow
@@ -20,6 +20,16 @@ def check_subdir option
end
end
+def make_sub_modules klass
+ last = nil
+ result = ''
+ klass.split('::')[0..-2].each do |part|
+ last = [last, part].compact.join('::')
+ result << "module #{last}; end\n"
+ end
+ result << "\n" unless result.empty?
+end
+
op = OptionParser.new do |opts|
opts.banner = "Usage: sow [options] project_name"
@@ -79,7 +89,7 @@ project = ARGV.shift
abort op.to_s unless project
abort "Project #{project} seems to exist" if test ?d, project
-_, file_name, klass = Hoe.normalize_names project
+_, file_name, klass, test_klass = Hoe.normalize_names project
FileUtils.cp_r template_path, project
@@ -96,7 +106,7 @@ Dir.chdir project do
warn "erb: #{path}"
File.open path, "w" do |io|
- erb = ERB.new file
+ erb = ERB.new file, nil, '<>'
erb.filename = path
io.puts erb.result(binding)
end
@@ -105,12 +115,17 @@ Dir.chdir project do
paths.grep(/file_name|\.erb$/).each do |file|
new_file = file.sub(/file_name/, file_name).sub(/\.erb$/, '')
- # TODO change template to separate a flat filename from a directory
- # filename
- if file =~ /^(bin|test)/ then
+ case file
+ when /^bin/ then
dir, *rest = new_file.split File::SEPARATOR
new_file = File.join dir, rest.join('_')
+ when /^test/ then
+ dir, *rest = new_file.split File::SEPARATOR
+
+ rest.last.sub! /^/, 'test_'
+
+ new_file = File.join dir, *rest
end
FileUtils.mkdir_p File.dirname new_file