leitmotif 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +201 -0
- data/README.rdoc +20 -0
- data/Rakefile +51 -0
- data/TODO.md +2 -0
- data/VERSION +1 -0
- data/bin/leitmotif +44 -0
- data/extra/gen-standalone.sh +28 -0
- data/extra/standalone/leitmotif +308 -0
- data/leitmotif.gemspec +71 -0
- data/lib/instantiator.rb +73 -0
- data/lib/leitmotif.rb +205 -0
- data/test/helper.rb +34 -0
- data/test/test_leitmotif.rb +7 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 76dc265b295f6992a5ae6ad03e73c4353c575997
|
4
|
+
data.tar.gz: 8eca58e6c899b389ef969c2da5ff3d4f22cd4d33
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 612823d2c9c4ae9aa8b406eb3e80828a25c04e6f702f41fef3279937779d0fdf0a54bc5aefa89cd18d74a0b6a7a2949bbd5905477e1158109d1609f149d0b2d4
|
7
|
+
data.tar.gz: a6138434773482b06ff24ddb20258b9c8f70885fd9d8caff68d24b73e5094c8e9a4aa289f181df2d3a00c142ab0a7dc6ddc25a6b030a2d68a9275f70a78d4dd5
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0"
|
12
|
+
gem "jeweler", "~> 2.0.1"
|
13
|
+
gem "simplecov", ">= 0"
|
14
|
+
gem "thor", "~> 0.17.0"
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.rdoc
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
= leitmotif
|
2
|
+
|
3
|
+
Leitmotif is yet another tool for generating directory trees from prototypes. It is designed to be
|
4
|
+
extremely simple and have minimal dependencies.
|
5
|
+
|
6
|
+
== Contributing to leitmotif
|
7
|
+
|
8
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
9
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
10
|
+
* Fork the project.
|
11
|
+
* Start a feature/bugfix branch.
|
12
|
+
* Commit and push until you are happy with your contribution.
|
13
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
14
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2014 William Benton. See LICENSE.txt for
|
19
|
+
further details.
|
20
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "leitmotif"
|
18
|
+
gem.homepage = "http://github.com/willb/leitmotif"
|
19
|
+
gem.license = "Apache-2.0"
|
20
|
+
gem.summary = %Q{yet another project template tool}
|
21
|
+
gem.description = %Q{there are many like it, but this one is mine}
|
22
|
+
gem.email = "self@willbenton.com"
|
23
|
+
gem.authors = ["William Benton"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Code coverage detail"
|
36
|
+
task :simplecov do
|
37
|
+
ENV['COVERAGE'] = "true"
|
38
|
+
Rake::Task['test'].execute
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rdoc/task'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "leitmotif #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/TODO.md
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/leitmotif
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "thor"
|
5
|
+
require "leitmotif" # SKIP_FOR_STANDALONE
|
6
|
+
|
7
|
+
class LeitmotifCLI < Thor
|
8
|
+
desc "generate PROTOTYPE OUTPUT_DIR", "instantiate PROTOTYPE into OUTPUT_DIR"
|
9
|
+
method_option :clobber, :type => :boolean, :desc => "overwrite OUTPUT_DIR if it exists"
|
10
|
+
method_option :verbose, :type => :boolean, :desc => "provide additional debugging output"
|
11
|
+
method_option :local, :type => :boolean, :desc => "use a prototype from the user's local prototype store"
|
12
|
+
method_option :debug, :type => :boolean, :desc => "provide way too much additional debugging output"
|
13
|
+
method_option :ref, :type => :string, :desc => "git tree-ish to use for PROTOTYPE instantiation"
|
14
|
+
method_option :bindings, :type => :hash, :desc => "variable bindings for PROTOTYPE instantiation, in the form KEY:VALUE"
|
15
|
+
def generate(prototype, output_dir)
|
16
|
+
$LEITMOTIF_DEBUG = options["debug"]
|
17
|
+
|
18
|
+
puts "prototype is #{prototype}" if $LEITMOTIF_DEBUG
|
19
|
+
puts "output_dir is #{output_dir}" if $LEITMOTIF_DEBUG
|
20
|
+
puts "options are #{options.inspect}" if @LEITMOTIF_DEBUG
|
21
|
+
symbolized_options = options.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
|
22
|
+
exit(Leitmotif.new(symbolized_options[:bindings], symbolized_options).run(prototype, output_dir))
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "clone URL", "clone a remote prototype from URL to the local prototype store"
|
26
|
+
method_option :verbose, :type => :boolean, :desc => "provide additional debugging output"
|
27
|
+
method_option :debug, :type => :boolean, :desc => "provide way too much additional debugging output"
|
28
|
+
def clone(url)
|
29
|
+
symbolized_options = options.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
|
30
|
+
|
31
|
+
exit(LocalPrototypeStore.new(symbolized_options).cloneProto(url))
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "list", "show locally-installed prototypes"
|
35
|
+
method_option :verbose, :type => :boolean, :desc => "provide additional debugging output"
|
36
|
+
method_option :debug, :type => :boolean, :desc => "provide way too much additional debugging output"
|
37
|
+
def list()
|
38
|
+
symbolized_options = options.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
|
39
|
+
|
40
|
+
exit(LocalPrototypeStore.new(symbolized_options).list())
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
LeitmotifCLI.start
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
(
|
4
|
+
cat <<END
|
5
|
+
#!/usr/bin/env ruby
|
6
|
+
#
|
7
|
+
# Copyright (c) 2014 William C. Benton and Red Hat, Inc.
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
|
21
|
+
$(for file in ../lib/*.rb ../bin/leitmotif ; do
|
22
|
+
grep -v SKIP_FOR_STANDALONE $file | grep -v \^\#;
|
23
|
+
done)
|
24
|
+
|
25
|
+
END
|
26
|
+
) > standalone/leitmotif
|
27
|
+
|
28
|
+
chmod 755 standalone/leitmotif
|
@@ -0,0 +1,308 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (c) 2014 William C. Benton and Red Hat, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
|
18
|
+
USE_ERUBIS = false
|
19
|
+
|
20
|
+
if USE_ERUBIS
|
21
|
+
|
22
|
+
require 'erubis'
|
23
|
+
|
24
|
+
class Instantiator
|
25
|
+
DEFAULT_OPTIONS = {:safe_level => 3}
|
26
|
+
|
27
|
+
def initialize(hash, options = nil)
|
28
|
+
@vars = hash.dup
|
29
|
+
@options = DEFAULT_OPTIONS.merge((options || {}))
|
30
|
+
end
|
31
|
+
|
32
|
+
def process(input)
|
33
|
+
Erubis::Eruby.new(template).result(@vars)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
else # USE_ERUBIS
|
38
|
+
|
39
|
+
require 'erb'
|
40
|
+
|
41
|
+
class Instantiator
|
42
|
+
DEFAULT_OPTIONS = {:safe_level => 3}
|
43
|
+
|
44
|
+
# this is the least terrible way to instantiate ERb with a hash
|
45
|
+
# source: http://stackoverflow.com/a/5462069/192616
|
46
|
+
class Namespace
|
47
|
+
def initialize(hash)
|
48
|
+
hash.each do |key, value|
|
49
|
+
puts "adding a binding for #{key} => #{value}" if $LEITMOTIF_DEBUG
|
50
|
+
singleton_class.send(:define_method, key) { value }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_binding
|
55
|
+
binding
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize(vars, options = nil)
|
60
|
+
@options = DEFAULT_OPTIONS.merge((options || {}))
|
61
|
+
@ns = Namespace.new(vars)
|
62
|
+
end
|
63
|
+
|
64
|
+
def process(template)
|
65
|
+
vars = @ns.get_binding
|
66
|
+
|
67
|
+
vars.untaint
|
68
|
+
template.untaint
|
69
|
+
|
70
|
+
# XXX: $SAFE level should be irrelevant here; only the supplied bindings should be available
|
71
|
+
ERB.new(template, @options[:safe_level]).result(vars)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end # USE_ERUBIS
|
76
|
+
|
77
|
+
|
78
|
+
require 'fileutils'
|
79
|
+
require 'find'
|
80
|
+
require 'open3'
|
81
|
+
require 'yaml'
|
82
|
+
|
83
|
+
|
84
|
+
module LMProcessHelpers
|
85
|
+
|
86
|
+
def spawn_and_capture(*cmd)
|
87
|
+
Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thr|
|
88
|
+
exit_status = wait_thr.value
|
89
|
+
raise "command '#{cmd.inspect}' failed; more details follow: #{stderr.read}" unless exit_status == 0
|
90
|
+
stdout.read
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def spawn_with_input(str, *cmd)
|
95
|
+
out, err, s = Open3.capture3(*cmd, :stdin_data=>str)
|
96
|
+
raise "command '#{cmd.inspect}' failed; more details follow: #{err}" unless s.exitstatus == 0
|
97
|
+
[out, err]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
module LMPath
|
102
|
+
def self.localPrototypeStore
|
103
|
+
File.join(Dir.home, ".leitmotif-prototypes")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class LocalPrototypeStore
|
108
|
+
DEFAULT_OPTIONS = {:git => "/usr/bin/git",
|
109
|
+
:verbose => false,
|
110
|
+
:clobber => false}
|
111
|
+
|
112
|
+
def initialize(options = nil)
|
113
|
+
@options = DEFAULT_OPTIONS.merge(options || {})
|
114
|
+
@localps = LMPath::localPrototypeStore
|
115
|
+
unless File.exists?(@localps)
|
116
|
+
FileUtils.mkdir_p(@localps)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
include LMProcessHelpers
|
121
|
+
|
122
|
+
def cloneProto(remoteURL)
|
123
|
+
begin
|
124
|
+
prototypeName = prototype_name(remoteURL)
|
125
|
+
spawn_and_capture(%Q{#{@options[:git]} clone #{remoteURL} "#{File.join(LMPath::localPrototypeStore, prototypeName)}"})
|
126
|
+
0
|
127
|
+
rescue Exception=>ex
|
128
|
+
puts "error: #{ex}"
|
129
|
+
puts ex.backtrace.join("\n") if (@options[:verbose] || $LEITMOTIF_DEBUG)
|
130
|
+
1
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def list()
|
135
|
+
begin
|
136
|
+
Dir[File.join(LMPath::localPrototypeStore, "*")].each do |proto|
|
137
|
+
puts prototype_name(proto)
|
138
|
+
end
|
139
|
+
0
|
140
|
+
rescue Exception=>ex
|
141
|
+
puts "error: #{ex}"
|
142
|
+
puts ex.backtrace.join("\n") if (@options[:verbose] || $LEITMOTIF_DEBUG)
|
143
|
+
1
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
private
|
148
|
+
def prototype_name(url)
|
149
|
+
url.split("/").pop.gsub(".git", "")
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
class Leitmotif
|
155
|
+
DEFAULT_OPTIONS = {:git => "/usr/bin/git",
|
156
|
+
:tar => "/usr/bin/tar",
|
157
|
+
:default_treeish => "master",
|
158
|
+
:verbose => false,
|
159
|
+
:clobber => false,
|
160
|
+
:local => false}
|
161
|
+
|
162
|
+
def initialize(hash = nil, options = nil)
|
163
|
+
@bindings = (hash || {}).dup
|
164
|
+
@options = DEFAULT_OPTIONS.merge(options || {})
|
165
|
+
end
|
166
|
+
|
167
|
+
def run(prototype, outputDir)
|
168
|
+
begin
|
169
|
+
if @options[:local]
|
170
|
+
prototype = File.join(LMPath::localPrototypeStore, prototype)
|
171
|
+
end
|
172
|
+
|
173
|
+
_run(prototype, outputDir)
|
174
|
+
rescue Exception=>ex
|
175
|
+
puts "error: #{ex}"
|
176
|
+
puts ex.backtrace.join("\n") if (@options[:verbose] || $LEITMOTIF_DEBUG)
|
177
|
+
1
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
private
|
182
|
+
def _run(prototype, outputDir)
|
183
|
+
check_output_dir(outputDir)
|
184
|
+
|
185
|
+
meta, archive = get_meta_and_proto(prototype, (@options[:ref] || @options[:default_treeish]))
|
186
|
+
ymeta = YAML.load(meta)
|
187
|
+
|
188
|
+
raise "#{prototype} doesn't look like a leitmotif prototype" unless (ymeta && list_proto(archive).size > 0)
|
189
|
+
|
190
|
+
hash = (ymeta[:defaults] || {}).merge(@bindings).inject({}){|acc,(k,v)| acc[k.to_s] = v; acc}
|
191
|
+
missing_required = (ymeta[:required] || []).select {|k| !hash.has_key?(k)}
|
192
|
+
|
193
|
+
raise "prototype #{prototype} requires values for the following variables: #{missing_required.join(", ")}" unless missing_required == []
|
194
|
+
|
195
|
+
ignore = (ymeta[:ignore] || [])
|
196
|
+
|
197
|
+
FileUtils.mkdir_p(outputDir)
|
198
|
+
oldcwd = Dir.getwd()
|
199
|
+
Dir.chdir(outputDir)
|
200
|
+
|
201
|
+
begin
|
202
|
+
unpack_proto!(archive)
|
203
|
+
instantiator = Instantiator.new(hash)
|
204
|
+
|
205
|
+
Find.find(".") do |templateFile|
|
206
|
+
if File.ftype(templateFile) == "file" && !ignore.member?(templateFile)
|
207
|
+
oldFile = File.open(templateFile, "r") {|f| f.read}
|
208
|
+
result = instantiator.process(oldFile)
|
209
|
+
File.open(templateFile, "w") {|f| f.write(result)}
|
210
|
+
end
|
211
|
+
end
|
212
|
+
ensure
|
213
|
+
Dir.chdir(oldcwd)
|
214
|
+
end
|
215
|
+
0
|
216
|
+
end
|
217
|
+
|
218
|
+
def check_output_dir(outputDir)
|
219
|
+
if File.exists?(outputDir)
|
220
|
+
if @options[:clobber]
|
221
|
+
FileUtils.rm_rf(outputDir)
|
222
|
+
else
|
223
|
+
raise "#{outputDir} already exists; move it first"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def get_meta_and_proto(remote, treeish = nil)
|
229
|
+
meta = nil
|
230
|
+
proto = nil
|
231
|
+
|
232
|
+
begin
|
233
|
+
treeish ||= @options[:default_treeish]
|
234
|
+
meta = get_meta(remote, treeish)
|
235
|
+
proto = get_proto(remote, treeish)
|
236
|
+
rescue Exception=>ex
|
237
|
+
raise "can't load leitmotif prototype and metadata: #{ex}"
|
238
|
+
end
|
239
|
+
|
240
|
+
[meta, proto]
|
241
|
+
end
|
242
|
+
|
243
|
+
def get_meta(remote, treeish = nil)
|
244
|
+
treeish ||= @options[:default_treeish]
|
245
|
+
metaArchive = spawn_and_capture(%Q{#{@options[:git]} archive --remote #{remote} #{treeish} .leitmotif})
|
246
|
+
meta, = spawn_with_input(metaArchive, %Q{#{@options[:tar]} xO .leitmotif})
|
247
|
+
meta
|
248
|
+
end
|
249
|
+
|
250
|
+
def get_proto(remote, treeish = nil)
|
251
|
+
treeish ||= @options[:default_treeish]
|
252
|
+
spawn_and_capture(%Q{#{@options[:git]} archive --remote #{remote} #{treeish} proto})
|
253
|
+
end
|
254
|
+
|
255
|
+
def unpack_proto!(archive)
|
256
|
+
spawn_with_input(archive, %Q{#{@options[:tar]} x --strip 1})
|
257
|
+
end
|
258
|
+
|
259
|
+
def list_proto(archive)
|
260
|
+
out, err = spawn_with_input(archive, %Q{#{@options[:tar]} t})
|
261
|
+
out.split("\n")
|
262
|
+
end
|
263
|
+
|
264
|
+
include LMProcessHelpers
|
265
|
+
end
|
266
|
+
|
267
|
+
require "rubygems"
|
268
|
+
require "thor"
|
269
|
+
|
270
|
+
class LeitmotifCLI < Thor
|
271
|
+
desc "generate PROTOTYPE OUTPUT_DIR", "instantiate PROTOTYPE into OUTPUT_DIR"
|
272
|
+
method_option :clobber, :type => :boolean, :desc => "overwrite OUTPUT_DIR if it exists"
|
273
|
+
method_option :verbose, :type => :boolean, :desc => "provide additional debugging output"
|
274
|
+
method_option :local, :type => :boolean, :desc => "use a prototype from the user's local prototype store"
|
275
|
+
method_option :debug, :type => :boolean, :desc => "provide way too much additional debugging output"
|
276
|
+
method_option :ref, :type => :string, :desc => "git tree-ish to use for PROTOTYPE instantiation"
|
277
|
+
method_option :bindings, :type => :hash, :desc => "variable bindings for PROTOTYPE instantiation, in the form KEY:VALUE"
|
278
|
+
def generate(prototype, output_dir)
|
279
|
+
$LEITMOTIF_DEBUG = options["debug"]
|
280
|
+
|
281
|
+
puts "prototype is #{prototype}" if $LEITMOTIF_DEBUG
|
282
|
+
puts "output_dir is #{output_dir}" if $LEITMOTIF_DEBUG
|
283
|
+
puts "options are #{options.inspect}" if @LEITMOTIF_DEBUG
|
284
|
+
symbolized_options = options.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
|
285
|
+
exit(Leitmotif.new(symbolized_options[:bindings], symbolized_options).run(prototype, output_dir))
|
286
|
+
end
|
287
|
+
|
288
|
+
desc "clone URL", "clone a remote prototype from URL to the local prototype store"
|
289
|
+
method_option :verbose, :type => :boolean, :desc => "provide additional debugging output"
|
290
|
+
method_option :debug, :type => :boolean, :desc => "provide way too much additional debugging output"
|
291
|
+
def clone(url)
|
292
|
+
symbolized_options = options.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
|
293
|
+
|
294
|
+
exit(LocalPrototypeStore.new(symbolized_options).cloneProto(url))
|
295
|
+
end
|
296
|
+
|
297
|
+
desc "list", "show locally-installed prototypes"
|
298
|
+
method_option :verbose, :type => :boolean, :desc => "provide additional debugging output"
|
299
|
+
method_option :debug, :type => :boolean, :desc => "provide way too much additional debugging output"
|
300
|
+
def list()
|
301
|
+
symbolized_options = options.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
|
302
|
+
|
303
|
+
exit(LocalPrototypeStore.new(symbolized_options).list())
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
LeitmotifCLI.start
|
308
|
+
|
data/leitmotif.gemspec
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: leitmotif 0.0.1 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "leitmotif"
|
9
|
+
s.version = "0.0.1"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["William Benton"]
|
14
|
+
s.date = "2014-10-08"
|
15
|
+
s.description = "there are many like it, but this one is mine"
|
16
|
+
s.email = "self@willbenton.com"
|
17
|
+
s.executables = ["leitmotif"]
|
18
|
+
s.extra_rdoc_files = [
|
19
|
+
"LICENSE.txt",
|
20
|
+
"README.rdoc"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
".document",
|
24
|
+
"Gemfile",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"TODO.md",
|
29
|
+
"VERSION",
|
30
|
+
"bin/leitmotif",
|
31
|
+
"extra/gen-standalone.sh",
|
32
|
+
"extra/standalone/leitmotif",
|
33
|
+
"leitmotif.gemspec",
|
34
|
+
"lib/instantiator.rb",
|
35
|
+
"lib/leitmotif.rb",
|
36
|
+
"test/helper.rb",
|
37
|
+
"test/test_leitmotif.rb"
|
38
|
+
]
|
39
|
+
s.homepage = "http://github.com/willb/leitmotif"
|
40
|
+
s.licenses = ["Apache-2.0"]
|
41
|
+
s.rubygems_version = "2.2.2"
|
42
|
+
s.summary = "yet another project template tool"
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 4
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
50
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
51
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
52
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<thor>, ["~> 0.17.0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
59
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
60
|
+
s.add_dependency(%q<thor>, ["~> 0.17.0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
65
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
67
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
68
|
+
s.add_dependency(%q<thor>, ["~> 0.17.0"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
data/lib/instantiator.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Copyright (c) 2014 William C. Benton and Red Hat, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
USE_ERUBIS = false
|
16
|
+
|
17
|
+
# XXX: refactor this ugliness
|
18
|
+
if USE_ERUBIS
|
19
|
+
|
20
|
+
require 'erubis'
|
21
|
+
|
22
|
+
class Instantiator
|
23
|
+
DEFAULT_OPTIONS = {:safe_level => 3}
|
24
|
+
|
25
|
+
def initialize(hash, options = nil)
|
26
|
+
@vars = hash.dup
|
27
|
+
@options = DEFAULT_OPTIONS.merge((options || {}))
|
28
|
+
end
|
29
|
+
|
30
|
+
def process(input)
|
31
|
+
Erubis::Eruby.new(template).result(@vars)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
else # USE_ERUBIS
|
36
|
+
|
37
|
+
require 'erb'
|
38
|
+
|
39
|
+
class Instantiator
|
40
|
+
DEFAULT_OPTIONS = {:safe_level => 3}
|
41
|
+
|
42
|
+
# this is the least terrible way to instantiate ERb with a hash
|
43
|
+
# source: http://stackoverflow.com/a/5462069/192616
|
44
|
+
class Namespace
|
45
|
+
def initialize(hash)
|
46
|
+
hash.each do |key, value|
|
47
|
+
puts "adding a binding for #{key} => #{value}" if $LEITMOTIF_DEBUG
|
48
|
+
singleton_class.send(:define_method, key) { value }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_binding
|
53
|
+
binding
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def initialize(vars, options = nil)
|
58
|
+
@options = DEFAULT_OPTIONS.merge((options || {}))
|
59
|
+
@ns = Namespace.new(vars)
|
60
|
+
end
|
61
|
+
|
62
|
+
def process(template)
|
63
|
+
vars = @ns.get_binding
|
64
|
+
|
65
|
+
vars.untaint
|
66
|
+
template.untaint
|
67
|
+
|
68
|
+
# XXX: $SAFE level should be irrelevant here; only the supplied bindings should be available
|
69
|
+
ERB.new(template, @options[:safe_level]).result(vars)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end # USE_ERUBIS
|
data/lib/leitmotif.rb
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
# Copyright (c) 2014 William C. Benton and Red Hat, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
$:.unshift File.dirname(__FILE__) # SKIP_FOR_STANDALONE
|
16
|
+
|
17
|
+
require 'fileutils'
|
18
|
+
require 'find'
|
19
|
+
require 'open3'
|
20
|
+
require 'yaml'
|
21
|
+
|
22
|
+
require 'instantiator' # SKIP_FOR_STANDALONE
|
23
|
+
|
24
|
+
module LMProcessHelpers
|
25
|
+
|
26
|
+
def spawn_and_capture(*cmd)
|
27
|
+
Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thr|
|
28
|
+
exit_status = wait_thr.value
|
29
|
+
raise "command '#{cmd.inspect}' failed; more details follow: #{stderr.read}" unless exit_status == 0
|
30
|
+
stdout.read
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def spawn_with_input(str, *cmd)
|
35
|
+
out, err, s = Open3.capture3(*cmd, :stdin_data=>str)
|
36
|
+
raise "command '#{cmd.inspect}' failed; more details follow: #{err}" unless s.exitstatus == 0
|
37
|
+
[out, err]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module LMPath
|
42
|
+
def self.localPrototypeStore
|
43
|
+
File.join(Dir.home, ".leitmotif-prototypes")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class LocalPrototypeStore
|
48
|
+
DEFAULT_OPTIONS = {:git => "/usr/bin/git",
|
49
|
+
:verbose => false,
|
50
|
+
:clobber => false}
|
51
|
+
|
52
|
+
def initialize(options = nil)
|
53
|
+
@options = DEFAULT_OPTIONS.merge(options || {})
|
54
|
+
@localps = LMPath::localPrototypeStore
|
55
|
+
unless File.exists?(@localps)
|
56
|
+
FileUtils.mkdir_p(@localps)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
include LMProcessHelpers
|
61
|
+
|
62
|
+
def cloneProto(remoteURL)
|
63
|
+
begin
|
64
|
+
prototypeName = prototype_name(remoteURL)
|
65
|
+
spawn_and_capture(%Q{#{@options[:git]} clone #{remoteURL} "#{File.join(LMPath::localPrototypeStore, prototypeName)}"})
|
66
|
+
0
|
67
|
+
rescue Exception=>ex
|
68
|
+
puts "error: #{ex}"
|
69
|
+
puts ex.backtrace.join("\n") if (@options[:verbose] || $LEITMOTIF_DEBUG)
|
70
|
+
1
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def list()
|
75
|
+
begin
|
76
|
+
Dir[File.join(LMPath::localPrototypeStore, "*")].each do |proto|
|
77
|
+
puts prototype_name(proto)
|
78
|
+
end
|
79
|
+
0
|
80
|
+
rescue Exception=>ex
|
81
|
+
puts "error: #{ex}"
|
82
|
+
puts ex.backtrace.join("\n") if (@options[:verbose] || $LEITMOTIF_DEBUG)
|
83
|
+
1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def prototype_name(url)
|
89
|
+
url.split("/").pop.gsub(".git", "")
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
class Leitmotif
|
95
|
+
DEFAULT_OPTIONS = {:git => "/usr/bin/git",
|
96
|
+
:tar => "/usr/bin/tar",
|
97
|
+
:default_treeish => "master",
|
98
|
+
:verbose => false,
|
99
|
+
:clobber => false,
|
100
|
+
:local => false}
|
101
|
+
|
102
|
+
def initialize(hash = nil, options = nil)
|
103
|
+
@bindings = (hash || {}).dup
|
104
|
+
@options = DEFAULT_OPTIONS.merge(options || {})
|
105
|
+
end
|
106
|
+
|
107
|
+
def run(prototype, outputDir)
|
108
|
+
begin
|
109
|
+
if @options[:local]
|
110
|
+
prototype = File.join(LMPath::localPrototypeStore, prototype)
|
111
|
+
end
|
112
|
+
|
113
|
+
_run(prototype, outputDir)
|
114
|
+
rescue Exception=>ex
|
115
|
+
puts "error: #{ex}"
|
116
|
+
puts ex.backtrace.join("\n") if (@options[:verbose] || $LEITMOTIF_DEBUG)
|
117
|
+
1
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
def _run(prototype, outputDir)
|
123
|
+
check_output_dir(outputDir)
|
124
|
+
|
125
|
+
meta, archive = get_meta_and_proto(prototype, (@options[:ref] || @options[:default_treeish]))
|
126
|
+
ymeta = YAML.load(meta)
|
127
|
+
|
128
|
+
raise "#{prototype} doesn't look like a leitmotif prototype" unless (ymeta && list_proto(archive).size > 0)
|
129
|
+
|
130
|
+
hash = (ymeta[:defaults] || {}).merge(@bindings).inject({}){|acc,(k,v)| acc[k.to_s] = v; acc}
|
131
|
+
missing_required = (ymeta[:required] || []).select {|k| !hash.has_key?(k)}
|
132
|
+
|
133
|
+
raise "prototype #{prototype} requires values for the following variables: #{missing_required.join(", ")}" unless missing_required == []
|
134
|
+
|
135
|
+
ignore = (ymeta[:ignore] || [])
|
136
|
+
|
137
|
+
FileUtils.mkdir_p(outputDir)
|
138
|
+
oldcwd = Dir.getwd()
|
139
|
+
Dir.chdir(outputDir)
|
140
|
+
|
141
|
+
begin
|
142
|
+
unpack_proto!(archive)
|
143
|
+
instantiator = Instantiator.new(hash)
|
144
|
+
|
145
|
+
Find.find(".") do |templateFile|
|
146
|
+
if File.ftype(templateFile) == "file" && !ignore.member?(templateFile)
|
147
|
+
oldFile = File.open(templateFile, "r") {|f| f.read}
|
148
|
+
result = instantiator.process(oldFile)
|
149
|
+
File.open(templateFile, "w") {|f| f.write(result)}
|
150
|
+
end
|
151
|
+
end
|
152
|
+
ensure
|
153
|
+
Dir.chdir(oldcwd)
|
154
|
+
end
|
155
|
+
0
|
156
|
+
end
|
157
|
+
|
158
|
+
def check_output_dir(outputDir)
|
159
|
+
if File.exists?(outputDir)
|
160
|
+
if @options[:clobber]
|
161
|
+
FileUtils.rm_rf(outputDir)
|
162
|
+
else
|
163
|
+
raise "#{outputDir} already exists; move it first"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def get_meta_and_proto(remote, treeish = nil)
|
169
|
+
meta = nil
|
170
|
+
proto = nil
|
171
|
+
|
172
|
+
begin
|
173
|
+
treeish ||= @options[:default_treeish]
|
174
|
+
meta = get_meta(remote, treeish)
|
175
|
+
proto = get_proto(remote, treeish)
|
176
|
+
rescue Exception=>ex
|
177
|
+
raise "can't load leitmotif prototype and metadata: #{ex}"
|
178
|
+
end
|
179
|
+
|
180
|
+
[meta, proto]
|
181
|
+
end
|
182
|
+
|
183
|
+
def get_meta(remote, treeish = nil)
|
184
|
+
treeish ||= @options[:default_treeish]
|
185
|
+
metaArchive = spawn_and_capture(%Q{#{@options[:git]} archive --remote #{remote} #{treeish} .leitmotif})
|
186
|
+
meta, = spawn_with_input(metaArchive, %Q{#{@options[:tar]} xO .leitmotif})
|
187
|
+
meta
|
188
|
+
end
|
189
|
+
|
190
|
+
def get_proto(remote, treeish = nil)
|
191
|
+
treeish ||= @options[:default_treeish]
|
192
|
+
spawn_and_capture(%Q{#{@options[:git]} archive --remote #{remote} #{treeish} proto})
|
193
|
+
end
|
194
|
+
|
195
|
+
def unpack_proto!(archive)
|
196
|
+
spawn_with_input(archive, %Q{#{@options[:tar]} x --strip 1})
|
197
|
+
end
|
198
|
+
|
199
|
+
def list_proto(archive)
|
200
|
+
out, err = spawn_with_input(archive, %Q{#{@options[:tar]} t})
|
201
|
+
out.split("\n")
|
202
|
+
end
|
203
|
+
|
204
|
+
include LMProcessHelpers
|
205
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
require 'rubygems'
|
18
|
+
require 'bundler'
|
19
|
+
begin
|
20
|
+
Bundler.setup(:default, :development)
|
21
|
+
rescue Bundler::BundlerError => e
|
22
|
+
$stderr.puts e.message
|
23
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
24
|
+
exit e.status_code
|
25
|
+
end
|
26
|
+
require 'test/unit'
|
27
|
+
require 'shoulda'
|
28
|
+
|
29
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
30
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
31
|
+
require 'leitmotif'
|
32
|
+
|
33
|
+
class Test::Unit::TestCase
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: leitmotif
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- William Benton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: shoulda
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jeweler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.17.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.17.0
|
97
|
+
description: there are many like it, but this one is mine
|
98
|
+
email: self@willbenton.com
|
99
|
+
executables:
|
100
|
+
- leitmotif
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files:
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.rdoc
|
105
|
+
files:
|
106
|
+
- ".document"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.rdoc
|
110
|
+
- Rakefile
|
111
|
+
- TODO.md
|
112
|
+
- VERSION
|
113
|
+
- bin/leitmotif
|
114
|
+
- extra/gen-standalone.sh
|
115
|
+
- extra/standalone/leitmotif
|
116
|
+
- leitmotif.gemspec
|
117
|
+
- lib/instantiator.rb
|
118
|
+
- lib/leitmotif.rb
|
119
|
+
- test/helper.rb
|
120
|
+
- test/test_leitmotif.rb
|
121
|
+
homepage: http://github.com/willb/leitmotif
|
122
|
+
licenses:
|
123
|
+
- Apache-2.0
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.2.2
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: yet another project template tool
|
145
|
+
test_files: []
|