sow 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +622 -0
- data/HISTORY +14 -0
- data/MANIFEST +138 -0
- data/NOTES +86 -0
- data/README +157 -0
- data/bin/sow +4 -0
- data/lib/sow.rb +12 -0
- data/lib/sow/command.rb +201 -0
- data/lib/sow/context.rb +29 -0
- data/lib/sow/core_ext.rb +47 -0
- data/lib/sow/generators/base.rb +321 -0
- data/lib/sow/generators/create.rb +111 -0
- data/lib/sow/generators/delete.rb +50 -0
- data/lib/sow/generators/update.rb +47 -0
- data/lib/sow/logger.rb +73 -0
- data/lib/sow/manager.rb +101 -0
- data/lib/sow/metadata.rb +115 -0
- data/lib/sow/plugin.rb +484 -0
- data/lib/sow/script.rb +186 -0
- data/lib/sow/session.rb +150 -0
- data/meta/authors +1 -0
- data/meta/contact +1 -0
- data/meta/description +1 -0
- data/meta/homepage +1 -0
- data/meta/loadpath +2 -0
- data/meta/package +1 -0
- data/meta/project +1 -0
- data/meta/repository +1 -0
- data/meta/requires +2 -0
- data/meta/ruby +2 -0
- data/meta/version +1 -0
- data/plug/sow/seeds/bin/.meta/created +1 -0
- data/plug/sow/seeds/bin/.meta/description +1 -0
- data/plug/sow/seeds/bin/.meta/license +1 -0
- data/plug/sow/seeds/bin/.meta/package +1 -0
- data/plug/sow/seeds/bin/.meta/requires +1 -0
- data/plug/sow/seeds/bin/.meta/title +1 -0
- data/plug/sow/seeds/bin/.meta/version +1 -0
- data/plug/sow/seeds/bin/SCRIPT.rb +22 -0
- data/plug/sow/seeds/bin/template/bin/command.rb +12 -0
- data/plug/sow/seeds/hoe/SCRIPT.rb +28 -0
- data/plug/sow/seeds/hoe/template/History.txt +7 -0
- data/plug/sow/seeds/hoe/template/Manifest.txt +8 -0
- data/plug/sow/seeds/hoe/template/README.txt +49 -0
- data/plug/sow/seeds/hoe/template/Rakefile +13 -0
- data/plug/sow/seeds/hoe/template/bin/__name__ +0 -0
- data/plug/sow/seeds/hoe/template/lib/__name__.rb +4 -0
- data/plug/sow/seeds/hoe/template/test/test___name__.rb +1 -0
- data/plug/sow/seeds/license/SCRIPT.rb +27 -0
- data/plug/sow/seeds/license/template/META/license +1 -0
- data/plug/sow/seeds/license/template/gpl/LICENSE +622 -0
- data/plug/sow/seeds/license/template/lgpl/LICENSE +789 -0
- data/plug/sow/seeds/license/template/mit/LICENSE +22 -0
- data/plug/sow/seeds/ruby/COPY.yml +14 -0
- data/plug/sow/seeds/ruby/DATA.yml +8 -0
- data/plug/sow/seeds/ruby/USAGE.txt +8 -0
- data/plug/sow/seeds/ruby/script.sow.rb +17 -0
- data/plug/sow/seeds/ruby/template/COPYING +622 -0
- data/plug/sow/seeds/ruby/template/History.rdoc +18 -0
- data/plug/sow/seeds/ruby/template/README.rdoc +43 -0
- data/plug/sow/seeds/ruby/template/README.rdoc.till +43 -0
- data/plug/sow/seeds/ruby/template/Rakefile +1 -0
- data/plug/sow/seeds/ruby/template/bin/__package__ +2 -0
- data/plug/sow/seeds/ruby/template/lib/__package__.rb +3 -0
- data/plug/sow/seeds/ruby/template/meta/created +1 -0
- data/plug/sow/seeds/ruby/template/meta/description +1 -0
- data/plug/sow/seeds/ruby/template/meta/license +1 -0
- data/plug/sow/seeds/ruby/template/meta/package +1 -0
- data/plug/sow/seeds/ruby/template/meta/requires +1 -0
- data/plug/sow/seeds/ruby/template/meta/title +1 -0
- data/plug/sow/seeds/ruby/template/meta/version +1 -0
- data/plug/sow/seeds/ruby/template/setup.rb +1467 -0
- data/plug/sow/seeds/ruby/template/test/template.rb +17 -0
- data/plug/sow/seeds/testunit/COPY.yml +12 -0
- data/plug/sow/seeds/testunit/DATA.yml +23 -0
- data/plug/sow/seeds/testunit/USAGE.txt +11 -0
- data/plug/sow/seeds/testunit/_SCRIPT.rb +42 -0
- data/plug/sow/seeds/testunit/template/form/testunit +24 -0
- data/plug/sow/seeds/testunit/template/test/test_template.rb +15 -0
- data/plug/sow/seeds/website/template/assets/styles/color.css +0 -0
- data/plug/sow/seeds/website/template/assets/styles/font.css +0 -0
- data/plug/sow/seeds/website/template/assets/styles/index.css +4 -0
- data/plug/sow/seeds/website/template/assets/styles/reset.css +0 -0
- data/plug/sow/seeds/website/template/assets/styles/struct.css +0 -0
- data/plug/sow/seeds/website/template/index.html +15 -0
- data/test/features/scaffold.feature +13 -0
- data/test/features/step_definitions/cli_steps.rb +0 -0
- data/test/features/step_definitions/fixture_steps.rb +72 -0
- data/test/features/support/env.rb +41 -0
- data/test/unit/fixtures/README +5 -0
- data/test/unit/helper.rb +23 -0
- data/test/unit/test_metadata.rb +17 -0
- data/test/unit/test_scaffold.rb +37 -0
- metadata +178 -0
data/lib/sow/script.rb
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
module Sow
|
2
|
+
|
3
|
+
# A Sow Script provides a simple DSL for specifying
|
4
|
+
# arguments, a copylist and the various specificities
|
5
|
+
# needed to define a scaffold generator proccess.
|
6
|
+
#
|
7
|
+
# Note: This is the old way of building a plugin.
|
8
|
+
|
9
|
+
class Script
|
10
|
+
|
11
|
+
# Script registery/
|
12
|
+
|
13
|
+
def self.registry
|
14
|
+
@registry ||= {}
|
15
|
+
end
|
16
|
+
|
17
|
+
# If inherited, register the script by it's class basename downcased.
|
18
|
+
|
19
|
+
def self.inherited(base)
|
20
|
+
registry[base.basename.downcase] = base
|
21
|
+
end
|
22
|
+
|
23
|
+
# Setup procedure, used to setup metadata.
|
24
|
+
|
25
|
+
def self.setup(&block)
|
26
|
+
define_method(:setup,&block)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Manifest procedure, used to invoke #copy.
|
30
|
+
|
31
|
+
def self.manifest(&block)
|
32
|
+
define_method(:manifest,&block)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Specify a valid option.
|
36
|
+
|
37
|
+
def self.option(name)
|
38
|
+
attr_accessor(name)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Give the main argument a name.
|
42
|
+
|
43
|
+
def self.argument(name)
|
44
|
+
define_method(name){ argument }
|
45
|
+
end
|
46
|
+
|
47
|
+
# Override and setup metadata and validate.
|
48
|
+
# If something does jive, then use #abort to
|
49
|
+
# terminate execution.
|
50
|
+
def setup
|
51
|
+
end
|
52
|
+
|
53
|
+
# Override and place copy statment in this method.
|
54
|
+
#
|
55
|
+
def manifest
|
56
|
+
copy '**/*', '.'
|
57
|
+
end
|
58
|
+
|
59
|
+
# Instance of Session.
|
60
|
+
|
61
|
+
attr :session
|
62
|
+
|
63
|
+
#
|
64
|
+
|
65
|
+
attr :options
|
66
|
+
|
67
|
+
# Copylist contains the a list of transfer operations as
|
68
|
+
# compiled from the plugin.
|
69
|
+
|
70
|
+
attr :copylist
|
71
|
+
|
72
|
+
#
|
73
|
+
def initialize(session, options)
|
74
|
+
@session = session
|
75
|
+
@options = options
|
76
|
+
|
77
|
+
@copylist = []
|
78
|
+
end
|
79
|
+
|
80
|
+
# Main argument.
|
81
|
+
|
82
|
+
def argument
|
83
|
+
options.argument
|
84
|
+
end
|
85
|
+
|
86
|
+
# Access to Metadata. When the script is initially executed,
|
87
|
+
# ie. toplevel and argument blocks, this is an OpenStruct.
|
88
|
+
# Use it to assign values to the metadata, which is used to
|
89
|
+
# render the file templates. When the scaffold block is
|
90
|
+
# finally executed, this is reassigned to the destinations
|
91
|
+
# metadata, so that it can be used in the copy calls, if
|
92
|
+
# needed.
|
93
|
+
|
94
|
+
def metadata
|
95
|
+
session.metadata
|
96
|
+
end
|
97
|
+
|
98
|
+
# Destiation pathname. This is used by some plugins,
|
99
|
+
# particularly full-project scaffolds, as a default
|
100
|
+
# package name. It is the basename of the output directory.
|
101
|
+
|
102
|
+
def destination
|
103
|
+
session.destination
|
104
|
+
end
|
105
|
+
|
106
|
+
#def values
|
107
|
+
# @values
|
108
|
+
#end
|
109
|
+
|
110
|
+
#def location=(path)
|
111
|
+
# @location = Pathname.new(path)
|
112
|
+
#end
|
113
|
+
|
114
|
+
# Describe the purpose of this generator.
|
115
|
+
def about(text)
|
116
|
+
@about = text
|
117
|
+
end
|
118
|
+
|
119
|
+
# Give a one line usage template.
|
120
|
+
# Eg. '--reap=<name>'
|
121
|
+
# "Usage: sow" is automatically prefixed to this.
|
122
|
+
#def usage(usage)
|
123
|
+
# @usage = usage
|
124
|
+
#end
|
125
|
+
|
126
|
+
# Define the commandline argument.
|
127
|
+
#def argument(name, desc=nil, &valid)
|
128
|
+
# @arguments << [name, desc, valid]
|
129
|
+
# #argv[name] = @arguments[@argc+=1]
|
130
|
+
# #valid.call(argv[name]) if valid
|
131
|
+
# #define_method(name) do
|
132
|
+
# # @arguments[i]
|
133
|
+
# #end
|
134
|
+
#end
|
135
|
+
|
136
|
+
#def option(name, desc=nil, &valid)
|
137
|
+
# @options << [name, desc, valid]
|
138
|
+
#end
|
139
|
+
|
140
|
+
# Designate a copying action.
|
141
|
+
#
|
142
|
+
# call-seq:
|
143
|
+
# copy(from, opts)
|
144
|
+
# copy(from, to, opts)
|
145
|
+
#
|
146
|
+
def copy(*from_to_opts)
|
147
|
+
opts = Hash===from_to_opts.last ? from_to_opts.pop : {}
|
148
|
+
from, to = *from_to_opts
|
149
|
+
to = to || '.'
|
150
|
+
@copylist << [from, to, opts.rekey(&:to_s)]
|
151
|
+
end
|
152
|
+
|
153
|
+
# This is to allow Plugin access to the internal state.
|
154
|
+
def [](var)
|
155
|
+
instance_variable_get("@#{var}")
|
156
|
+
end
|
157
|
+
|
158
|
+
# Set ... using a singleton method.
|
159
|
+
def []=(var, val)
|
160
|
+
quaclass = (class << self; self; end)
|
161
|
+
raise "invalid argument name -- #{var}" if quaclass.method_defined?(var)
|
162
|
+
quaclass.class_eval do
|
163
|
+
define_method(var){ val }
|
164
|
+
end
|
165
|
+
#@session[var.to_sym] = val
|
166
|
+
end
|
167
|
+
|
168
|
+
# If method missing, routes the call to +session+.
|
169
|
+
def method_missing(var,*a)
|
170
|
+
if val = @session.__send__(var)
|
171
|
+
return val
|
172
|
+
else
|
173
|
+
super
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
end#class Script
|
178
|
+
|
179
|
+
#
|
180
|
+
module Plugins
|
181
|
+
# see Sow::Script
|
182
|
+
Script = Sow::Script
|
183
|
+
end
|
184
|
+
|
185
|
+
end#module Sow
|
186
|
+
|
data/lib/sow/session.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'sow/metadata'
|
2
|
+
|
3
|
+
module Sow
|
4
|
+
|
5
|
+
# Session provides a central store of commandline
|
6
|
+
# options and system state related to invocation
|
7
|
+
# the +sow+ command. This includes the destination
|
8
|
+
# directory, it's metadata and any special sow
|
9
|
+
# configurations.
|
10
|
+
#
|
11
|
+
class Session
|
12
|
+
|
13
|
+
# Create a new session instance.
|
14
|
+
|
15
|
+
def initialize(arguments, options)
|
16
|
+
@arguments = arguments
|
17
|
+
@options = options
|
18
|
+
|
19
|
+
@trial = options.trial?
|
20
|
+
@debug = options.debug?
|
21
|
+
@quiet = options.quiet?
|
22
|
+
@force = options.force?
|
23
|
+
@prompt = options.prompt?
|
24
|
+
@skip = options.skip?
|
25
|
+
|
26
|
+
@create = options.create?
|
27
|
+
@update = options.update?
|
28
|
+
@delete = options.delete?
|
29
|
+
|
30
|
+
@destination = Pathname.new(options.destination || Dir.pwd)
|
31
|
+
|
32
|
+
if file = Dir.glob(File.join(destination, '{,.}config/sow.{yml,yaml}')).first
|
33
|
+
@config = YAML.load(File.new(file))
|
34
|
+
@sowed = true
|
35
|
+
else
|
36
|
+
@config = {}
|
37
|
+
@sowed = false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
public
|
42
|
+
|
43
|
+
# Destination for generated scaffolding.
|
44
|
+
|
45
|
+
attr :destination
|
46
|
+
|
47
|
+
# DEPREICATE: Is "output" too generic a name for a tool like Sow?
|
48
|
+
|
49
|
+
alias_method :output, :destination
|
50
|
+
|
51
|
+
# Tiral run? (Also know as a +noop+.)
|
52
|
+
|
53
|
+
def trial? ; @trial ; end
|
54
|
+
|
55
|
+
# Provide debugging information?
|
56
|
+
|
57
|
+
def debug? ; @debug ; end
|
58
|
+
|
59
|
+
# Run silently?
|
60
|
+
|
61
|
+
def quiet? ; @quiet ; end
|
62
|
+
|
63
|
+
# Override protected operations.
|
64
|
+
|
65
|
+
def force? ; @force ; end
|
66
|
+
|
67
|
+
# Prompot the user for options?
|
68
|
+
|
69
|
+
def prompt? ; @prompt ; end
|
70
|
+
|
71
|
+
# Skip overwrites?
|
72
|
+
|
73
|
+
def skip? ; @skip ; end
|
74
|
+
|
75
|
+
# Return command mode based on command options.
|
76
|
+
# Defaults to +:create+.
|
77
|
+
#--
|
78
|
+
# TODO: Are their circumstances where mode should defualt to update?
|
79
|
+
#++
|
80
|
+
|
81
|
+
def mode
|
82
|
+
return 'create' if @create
|
83
|
+
return 'update' if @update
|
84
|
+
return 'delete' if @delete
|
85
|
+
return 'create' #sowed? ? :update : :create
|
86
|
+
end
|
87
|
+
|
88
|
+
# Creation mode?
|
89
|
+
|
90
|
+
def create? ; @create ; end
|
91
|
+
|
92
|
+
# Update mode?
|
93
|
+
|
94
|
+
def update? ; @update ; end
|
95
|
+
|
96
|
+
# Delete mode?
|
97
|
+
|
98
|
+
def delete? ; @delete ; end
|
99
|
+
|
100
|
+
#
|
101
|
+
#def scaffold?
|
102
|
+
# mode == :create && !sowed? #|| force? instad of delete and update?
|
103
|
+
#end
|
104
|
+
|
105
|
+
# Sow configuration.
|
106
|
+
|
107
|
+
def config ; @config ; end
|
108
|
+
|
109
|
+
# Previously sowed?
|
110
|
+
|
111
|
+
def sowed? ; @sowed ; end
|
112
|
+
|
113
|
+
# Does the destination contain any files?
|
114
|
+
|
115
|
+
def empty?
|
116
|
+
@empty ||= Dir[destination + '*'].empty?
|
117
|
+
end
|
118
|
+
|
119
|
+
# Alias for #empty?
|
120
|
+
|
121
|
+
alias_method :new?, :empty?
|
122
|
+
|
123
|
+
# Metadata for destination, if any.
|
124
|
+
#--
|
125
|
+
# TODO: Use POM::Metadata in future?
|
126
|
+
#++
|
127
|
+
|
128
|
+
def metadata
|
129
|
+
@metadata ||= Metadata.new(destination)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Destination has metadata?
|
133
|
+
|
134
|
+
def metadata?
|
135
|
+
metadata.exist?
|
136
|
+
end
|
137
|
+
|
138
|
+
# What is the destinations meta directory (+meta+ or +.meta+)?
|
139
|
+
# If none then defaults to +.meta+.
|
140
|
+
|
141
|
+
def metadir
|
142
|
+
@meta_directory ||= (Dir[File.join(destination, '{.meta,meta}/')].first || '.meta/').chomp('/')
|
143
|
+
end
|
144
|
+
|
145
|
+
# Alias for meta_directory
|
146
|
+
#alias_method :metadir, :meta_directory
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
data/meta/authors
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
trans <transfire@gmail.com>
|
data/meta/contact
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
tigerops-community@rubyforge.org
|
data/meta/description
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Sow is a flexible and straightforward project file generation system.
|
data/meta/homepage
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
http://sow.rubyforge.org
|
data/meta/loadpath
ADDED
data/meta/package
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
sow
|
data/meta/project
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
proutils
|
data/meta/repository
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
git://github.com/proutils/sow.git
|
data/meta/requires
ADDED
data/meta/ruby
ADDED
data/meta/version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.4.0
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= Time.now.strftime("%Y-%M-%D") %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= package %> is a __FIX__.
|
@@ -0,0 +1 @@
|
|
1
|
+
GPL
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= package %>
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= package.capitalize %>
|
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Sow::Plugins
|
2
|
+
|
3
|
+
# Scaffold a ruby bin/ file.
|
4
|
+
#
|
5
|
+
class Bin < Script
|
6
|
+
|
7
|
+
option :name
|
8
|
+
|
9
|
+
setup do
|
10
|
+
@name = argument || destination
|
11
|
+
abort "Exectuable name is required." unless name
|
12
|
+
abort "Executable name must be a single word." if /\w/ !~ name
|
13
|
+
end
|
14
|
+
|
15
|
+
manifest do
|
16
|
+
copy 'bin/command.rb', "bin/#{@name}", :chmod => 0754
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created <%= "by #{author} " if author %>on <%= (now = Time.now).year %>-<%= now.month %>-<%= now.day %>.
|
4
|
+
# Copyright (c) <%= now.year %>. All rights reserved.
|
5
|
+
#
|
6
|
+
# TODO: write executable
|
7
|
+
#
|
8
|
+
# It might be something like the following.
|
9
|
+
|
10
|
+
require '<%= package %>/command.rb'
|
11
|
+
<%= title %>::Command.execute
|
12
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# How plugin, to make up for the fact the Sow clobber's
|
2
|
+
# Hoe's +sow+ command.
|
3
|
+
#
|
4
|
+
# It's silly for Hoe to have a command called +sow+ when
|
5
|
+
# it could just as well used +hoe+ andyway.
|
6
|
+
|
7
|
+
module Sow::Plugins
|
8
|
+
|
9
|
+
# Scaffold a new Hoe-ready project
|
10
|
+
#
|
11
|
+
class Hoe < Script
|
12
|
+
|
13
|
+
option :name
|
14
|
+
|
15
|
+
setup do
|
16
|
+
name = name() || argument
|
17
|
+
abort "Project name argument required." unless name
|
18
|
+
metadata.name = name
|
19
|
+
end
|
20
|
+
|
21
|
+
manifest do
|
22
|
+
copy "**/*", '.'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|