gem-create 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.markdown +102 -0
- data/Rakefile +9 -0
- data/gem-create.gemspec +19 -0
- data/lib/rubygems/commands/create_command.rb +224 -0
- data/lib/rubygems_plugin.rb +3 -0
- data/spec/create_command_spec.rb +91 -0
- data/spec/fixtures/skel.yml +3 -0
- data/spec/fixtures/skel/%gem_name%.gemspec +28 -0
- data/spec/fixtures/skel/Gemfile +3 -0
- data/spec/fixtures/skel/LICENSE +21 -0
- data/spec/fixtures/skel/README.markdown +20 -0
- data/spec/fixtures/skel/Rakefile +11 -0
- data/spec/fixtures/skel/lib/%gem_name%.rb +1 -0
- data/spec/fixtures/skel/lib/%gem_name%/version.rb +3 -0
- data/spec/fixtures/skel/spec/%gem_name%_spec.rb +5 -0
- data/spec/fixtures/skel/spec/spec_helper.rb +8 -0
- data/spec/minitest/gem_command_test_case.rb +82 -0
- data/spec/spec_helper.rb +4 -0
- metadata +100 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2012 Joshua Priddle <jpriddle@me.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person ob-
|
4
|
+
taining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without restric-
|
6
|
+
tion, including without limitation the rights to use, copy, modi-
|
7
|
+
fy, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
the Software, and to permit persons to whom the Software is fur-
|
9
|
+
nished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
16
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONIN-
|
17
|
+
FRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
19
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# gem-create [![`gem-create` Build Status][Build Icon]][Build Status]
|
2
|
+
|
3
|
+
> This is my gem template. There are many like it, but this one is mine.
|
4
|
+
|
5
|
+
`gem-create` is a RubyGems plugin. It provides a `gem create` command which
|
6
|
+
can be used to generate a skeleton for working on a new RubyGem.
|
7
|
+
|
8
|
+
[Build Icon]: https://secure.travis-ci.org/itspriddle/gem-create.png?branch=master
|
9
|
+
[Build Status]: http://travis-ci.org/itspriddle/gem-create
|
10
|
+
|
11
|
+
## Setup
|
12
|
+
|
13
|
+
First, install the gem:
|
14
|
+
|
15
|
+
gem install gem-create
|
16
|
+
|
17
|
+
Next, create a data file. By default this is in `~/.gem/skel.yml`. This file
|
18
|
+
contains variables that will be available in your template files. It **must**
|
19
|
+
be a valid YAML file.
|
20
|
+
|
21
|
+
The following default variables are available in addition to any supplied in
|
22
|
+
your data file:
|
23
|
+
|
24
|
+
name # the name of the gem (eg: my_gem)
|
25
|
+
gem_class # the class name of the gem (eg: MyGem)
|
26
|
+
|
27
|
+
See `spec/fixtures/skel.yml` in this repo for an example data file.
|
28
|
+
|
29
|
+
Next, create your gem skeleton. By default this is in `~/.gem/skel`. This
|
30
|
+
directory contains files/directories that will be copied when creating a new
|
31
|
+
gem. Files are rendered via ERB and may utilize the variables set in your data
|
32
|
+
file (eg: `<%= github_name %>`).
|
33
|
+
|
34
|
+
Any file/directory with `%gem_name%` in it's path will be renamed when the new
|
35
|
+
gem is created. Eg (assume `gem create my_new_gem`):
|
36
|
+
|
37
|
+
some/%gem_name% => some/my_new_gem
|
38
|
+
some/gem_name => some/gem_name
|
39
|
+
|
40
|
+
See `spec/fixtures/skel` in this repo for an example gem skeleton.
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
Usage: gem create GEM_NAME [options]
|
45
|
+
|
46
|
+
Options:
|
47
|
+
-f, --force Overwrite existing files
|
48
|
+
-d, --destination-directory DIR Destination directory,
|
49
|
+
$PWD/GEM_NAME by default
|
50
|
+
|
51
|
+
|
52
|
+
Skeleton Options:
|
53
|
+
--template-directory DIR A custom template directory to use
|
54
|
+
--data-file PATH Path to a YAML file containing
|
55
|
+
variables that will be available
|
56
|
+
in all template files
|
57
|
+
|
58
|
+
|
59
|
+
Common Options:
|
60
|
+
-h, --help Get help on this command
|
61
|
+
-V, --[no-]verbose Set the verbose level of output
|
62
|
+
-q, --quiet Silence commands
|
63
|
+
--config-file FILE Use this config file instead of default
|
64
|
+
--backtrace Show stack backtrace on errors
|
65
|
+
--debug Turn on Ruby debugging
|
66
|
+
|
67
|
+
|
68
|
+
Summary:
|
69
|
+
Creates a new RubyGem skeleton
|
70
|
+
|
71
|
+
Defaults:
|
72
|
+
--template-directory ~/.gem/skel --data-file ~/.gem/skel.yml
|
73
|
+
|
74
|
+
## Customization
|
75
|
+
|
76
|
+
If `~/.gem/skel` and `~/.gem/skel.yml` don't work for you, you can customize
|
77
|
+
them in `~/.gemrc`:
|
78
|
+
|
79
|
+
create: --template-directory ~/code/gem-template --data-file ~/code/gem-template-data.yml
|
80
|
+
|
81
|
+
## Development
|
82
|
+
|
83
|
+
`gem-create` depends on rake and minitest for testing.
|
84
|
+
|
85
|
+
git clone git://github.com/itspriddle/gem-create
|
86
|
+
cd gem-create
|
87
|
+
bundle install
|
88
|
+
bundle exec rake spec
|
89
|
+
|
90
|
+
## Note on Patches/Pull Requests
|
91
|
+
|
92
|
+
* Fork the project.
|
93
|
+
* Make your feature addition or bug fix.
|
94
|
+
* Add tests for it. This is important so I don't break it in a future version
|
95
|
+
unintentionally.
|
96
|
+
* Commit, do not bump version. (If you want to have your own version, that is
|
97
|
+
fine but bump version in a commit by itself I can ignore when I pull).
|
98
|
+
* Send me a pull request. Bonus points for topic branches.
|
99
|
+
|
100
|
+
## Copyright
|
101
|
+
|
102
|
+
Copyright (c) 2012 Joshua Priddle. See LICENSE for details.
|
data/Rakefile
ADDED
data/gem-create.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.unshift 'lib'
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.name = "gem-create"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.homepage = "https://github.com/itspriddle/gem-create"
|
8
|
+
s.authors = ["Joshua Priddle"]
|
9
|
+
s.email = "jpriddle@me.com"
|
10
|
+
s.summary = "gem create: create a new gem"
|
11
|
+
s.description = "gem create: create a new gem"
|
12
|
+
|
13
|
+
s.files = %w[ Gemfile Rakefile README.markdown gem-create.gemspec LICENSE ]
|
14
|
+
s.files += Dir['lib/**/*']
|
15
|
+
s.test_files = Dir['spec/**/*']
|
16
|
+
|
17
|
+
s.add_development_dependency 'rake'
|
18
|
+
s.add_development_dependency 'minitest'
|
19
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
# This class facilitates the `gem create` command.
|
6
|
+
class Gem::Commands::CreateCommand < Gem::Command
|
7
|
+
IDENTIFIER = '%gem_name%'.freeze
|
8
|
+
|
9
|
+
class Builder
|
10
|
+
attr_reader :name
|
11
|
+
|
12
|
+
def initialize(name, params = {})
|
13
|
+
@name = name.to_s
|
14
|
+
|
15
|
+
params.each do |(key, value)|
|
16
|
+
self.class.send(:define_method, key) do
|
17
|
+
value.respond_to?(:gsub) ? value.gsub(IDENTIFIER, @name) : value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# The path of the gem.
|
23
|
+
def path
|
24
|
+
name.gsub('-', '/')
|
25
|
+
end
|
26
|
+
|
27
|
+
# The class name of the gem in CamelCase.
|
28
|
+
def gem_class
|
29
|
+
name.split('-').map { |seg| seg.gsub(/(?:^|_| )(.)/) { $1.upcase } }.join('::')
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_binding
|
33
|
+
binding
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Initializes the plugin.
|
38
|
+
def initialize
|
39
|
+
super "create", "Creates a new RubyGem skeleton"
|
40
|
+
add_options!
|
41
|
+
end
|
42
|
+
|
43
|
+
# Creates the gem.
|
44
|
+
def execute
|
45
|
+
@gem_name = get_one_gem_name
|
46
|
+
|
47
|
+
create_gem!
|
48
|
+
end
|
49
|
+
|
50
|
+
# The usage banner displayed for `gem create --help`.
|
51
|
+
def usage
|
52
|
+
"gem create GEM_NAME"
|
53
|
+
end
|
54
|
+
|
55
|
+
def defaults_str
|
56
|
+
'--template-directory ~/.gem/skel --data-file ~/.gem/skel.yml'
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# Private: Adds command line switches used by this plugin.
|
62
|
+
def add_options!
|
63
|
+
add_option "-f", "--force", "Overwrite existing files" do |v, options|
|
64
|
+
options[:force] = true
|
65
|
+
end
|
66
|
+
|
67
|
+
add_option "-d", "--destination-directory PATH", "Destination directory,",
|
68
|
+
"$PWD/GEM_NAME by default" do |directory, options|
|
69
|
+
options[:destination_directory] = directory
|
70
|
+
end
|
71
|
+
#
|
72
|
+
# add_option "-n", "--dry-run", "Don't actually create any files, ",
|
73
|
+
# "just show what would be created" do |v, options|
|
74
|
+
# options[:dry_run] = true
|
75
|
+
# end
|
76
|
+
|
77
|
+
add_option :Skeleton, "--template-directory PATH", "A custom template directory to use" do |directory, options|
|
78
|
+
if File.directory?(directory)
|
79
|
+
options[:template_directory] = directory
|
80
|
+
else
|
81
|
+
raise "Directory #{directory.inspect} doesn't exist!"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
add_option :Skeleton, "--data-file PATH", "Path to a YAML file containing",
|
86
|
+
"variables that will be available",
|
87
|
+
"in all template files" do |file, options|
|
88
|
+
file = File.expand_path(file)
|
89
|
+
|
90
|
+
if File.exists?(file)
|
91
|
+
options[:data_file] = file
|
92
|
+
else
|
93
|
+
raise "File #{file.inspect} doesn't exist!"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Private: Creates the gem skeleton within the destination directory.
|
99
|
+
#
|
100
|
+
# Creates any required directories, renders templates via ERB, and finally,
|
101
|
+
# writes new files.
|
102
|
+
#
|
103
|
+
# When creating directories and files, any occurrence of 'gem_name' is
|
104
|
+
# replaced with the name of the gem to be created.
|
105
|
+
def create_gem!
|
106
|
+
unless File.directory?(destination_directory)
|
107
|
+
FileUtils.mkdir_p(destination_directory)
|
108
|
+
end
|
109
|
+
|
110
|
+
Dir.chdir(destination_directory) do
|
111
|
+
manifest.each do |file|
|
112
|
+
dest = file.gsub(IDENTIFIER, @gem_name)
|
113
|
+
base = File.dirname(dest)
|
114
|
+
|
115
|
+
FileUtils.mkdir_p(base) unless File.directory?(base)
|
116
|
+
|
117
|
+
write_template_file(file, dest)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Private: Returns true if files should be overwritten when creating the new
|
123
|
+
# gem.
|
124
|
+
#
|
125
|
+
# Returns true or false.
|
126
|
+
def force?
|
127
|
+
!! options[:force]
|
128
|
+
end
|
129
|
+
|
130
|
+
# Private: The directory to create the new gem in.
|
131
|
+
#
|
132
|
+
# Defaults to `Dir.pwd`.
|
133
|
+
def destination_directory
|
134
|
+
File.expand_path(options[:destination_directory] || File.join(Dir.pwd, @gem_name))
|
135
|
+
end
|
136
|
+
|
137
|
+
# Private: The directory containing template files for the new gem.
|
138
|
+
#
|
139
|
+
# Defaults to `~/.gem/skel/`.
|
140
|
+
#
|
141
|
+
# Returns a String.
|
142
|
+
def template_directory
|
143
|
+
File.expand_path(options[:template_directory] || "~/.gem/skel")
|
144
|
+
end
|
145
|
+
|
146
|
+
# Private: The file containing variables which will be made available in
|
147
|
+
# template files.
|
148
|
+
#
|
149
|
+
# Defaults to `~/.gem/skel.yml`.
|
150
|
+
#
|
151
|
+
# Returns a String.
|
152
|
+
def data_file
|
153
|
+
File.expand_path(options[:data_file] || "~/.gem/skel.yml")
|
154
|
+
end
|
155
|
+
|
156
|
+
# Private: The directory that contains template files to use when creating
|
157
|
+
# the new gem. By default, this is TEMPLATES. A user can specify their own
|
158
|
+
# directory with the `--template-directory` command line option.
|
159
|
+
#
|
160
|
+
# If a block is supplied, it is called within the template directory (i.e.
|
161
|
+
# Dir.pwd in the block will be set to the template directory), and the value
|
162
|
+
# of this block is returned.
|
163
|
+
#
|
164
|
+
# If no block is supplied, the String template directory is returned.
|
165
|
+
def in_template_directory
|
166
|
+
Dir.chdir(template_directory) { return yield }
|
167
|
+
end
|
168
|
+
|
169
|
+
# Private: An Array containing files to create.
|
170
|
+
#
|
171
|
+
# Returns an Array.
|
172
|
+
def manifest
|
173
|
+
@manifest ||= in_template_directory do
|
174
|
+
Dir.glob("**/*", File::FNM_DOTMATCH).reject { |t| File.directory?(t) }
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# Private: Writes a new file from a template.
|
179
|
+
#
|
180
|
+
# source - Path to the source template.
|
181
|
+
# dest - Path to the destination file.
|
182
|
+
def write_template_file(source, dest)
|
183
|
+
if can_write_file?(dest)
|
184
|
+
s = render_file(source)
|
185
|
+
File.open(dest, "w") { |file| file.puts s }
|
186
|
+
else
|
187
|
+
raise "Can't create #{dest.inspect} as it already exists!"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# Private: Returns true if the given file can be written.
|
192
|
+
#
|
193
|
+
# A file can be written if the user specified `--force` via the command
|
194
|
+
# line, or the file does not yet exist.
|
195
|
+
#
|
196
|
+
# file - Path to the file to check.
|
197
|
+
#
|
198
|
+
# Returns true or false.
|
199
|
+
def can_write_file?(file)
|
200
|
+
force? || ! File.exists?(file)
|
201
|
+
end
|
202
|
+
|
203
|
+
# Private: Renders a file via ERB within the context of a
|
204
|
+
# Gem::Create::Builder instance. This makes methods in that class available
|
205
|
+
# in the template.
|
206
|
+
#
|
207
|
+
# file - Path to the template file.
|
208
|
+
#
|
209
|
+
# Returns the rendered template as a String.
|
210
|
+
def render_file(file)
|
211
|
+
data = in_template_directory { File.read(file) }
|
212
|
+
ERB.new(data).result(builder.get_binding)
|
213
|
+
end
|
214
|
+
|
215
|
+
# Private: Creates/returns a Gem::Create::Builder instance. This will be
|
216
|
+
# used to provide variables in template files.
|
217
|
+
#
|
218
|
+
# Returns a Gem::Create::Builder instance.
|
219
|
+
def builder
|
220
|
+
return @builder if @builder
|
221
|
+
attributes = YAML.load_file(data_file).merge(:gem_name => @gem_name)
|
222
|
+
@builder = Builder.new(@gem_name, attributes)
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gem::Commands::CreateCommand do
|
4
|
+
it "prints help" do
|
5
|
+
out, err = run_command('--help')
|
6
|
+
err.must_equal "", "should not write to STDERR"
|
7
|
+
|
8
|
+
out.must_match "Usage: gem create GEM_NAME [options]"
|
9
|
+
out.must_match "--force"
|
10
|
+
out.must_match "--template-directory PATH"
|
11
|
+
out.must_match "--data-file PATH"
|
12
|
+
out.must_match "--destination-directory PATH"
|
13
|
+
out.must_match "--template-directory ~/.gem/skel --data-file ~/.gem/skel.yml"
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "generated files" do
|
17
|
+
before do
|
18
|
+
run_command *%W(
|
19
|
+
some_gem
|
20
|
+
--data-file #{fixtures_path}/skel.yml
|
21
|
+
--template-directory #{fixtures_path}/skel
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
it_renders "README.markdown" do |data|
|
26
|
+
data.must_match "# SomeGem [![SomeGem Build Status"
|
27
|
+
data.must_match "https://secure.travis-ci.org/bender/some_gem.png?branch=master"
|
28
|
+
data.must_match "http://travis-ci.org/bender/some_gem"
|
29
|
+
data.must_match "Copyright (c) #{Time.now.year} Bender Rodriguez"
|
30
|
+
end
|
31
|
+
|
32
|
+
it_renders "LICENSE" do |data|
|
33
|
+
data.must_match "Copyright (c) #{Time.now.year} Bender Rodriguez <bender@planex.com>"
|
34
|
+
end
|
35
|
+
|
36
|
+
it_renders "some_gem.gemspec" do |data|
|
37
|
+
data.must_match %r{require "some_gem/version}
|
38
|
+
data.must_match %r{s\.version\s*= SomeGem::Version}
|
39
|
+
data.must_match %r{s\.name\s*= "some_gem"}
|
40
|
+
data.must_match %r{s\.summary\s*= "SomeGem: Description here"}
|
41
|
+
data.must_match %r{s\.homepage\s*= "https://github\.com/bender/some_gem"}
|
42
|
+
data.must_match %r{s\.authors\s*= \["Bender Rodriguez"\]}
|
43
|
+
data.must_match %r{s\.email\s*= "bender@planex\.com"}
|
44
|
+
end
|
45
|
+
|
46
|
+
it_renders "lib/some_gem.rb" do |data|
|
47
|
+
data.must_match 'require "some_gem/version"'
|
48
|
+
end
|
49
|
+
|
50
|
+
it_renders "lib/some_gem/version.rb" do |data|
|
51
|
+
data.must_match "module SomeGem"
|
52
|
+
data.must_match " VERSION = Version = '0.0.0'"
|
53
|
+
end
|
54
|
+
|
55
|
+
it_renders "spec/spec_helper.rb"
|
56
|
+
|
57
|
+
it_renders "spec/some_gem_spec.rb"
|
58
|
+
|
59
|
+
it_renders "Rakefile"
|
60
|
+
|
61
|
+
it_renders "Gemfile"
|
62
|
+
|
63
|
+
it_renders ".travis.yml" do |data|
|
64
|
+
data.must_match "recipients:\n - bender@planex.com"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "custom template directory" do
|
69
|
+
it "raises with a non-existing directory" do
|
70
|
+
proc { run_command *%W(some_gem --template-directory /dev/null/asdf) }.
|
71
|
+
must_raise RuntimeError, 'Directory "/dev/null/asdf" doesn\'t exist!'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "custom destination directory" do
|
76
|
+
before do
|
77
|
+
run_command *%W(
|
78
|
+
some_gem
|
79
|
+
--data-file #{fixtures_path}/skel.yml
|
80
|
+
--template-directory #{fixtures_path}/skel
|
81
|
+
--destination-directory blah
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
%W(README.markdown LICENSE some_gem.gemspec lib/some_gem.rb
|
86
|
+
lib/some_gem/version.rb spec/spec_helper.rb spec/some_gem_spec.rb
|
87
|
+
Rakefile Gemfile .travis.yml).each do |template|
|
88
|
+
it_renders template, :in => "blah"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$:.unshift "lib"
|
2
|
+
|
3
|
+
require "<%= name %>/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.name = "<%= path %>"
|
8
|
+
s.version = <%= gem_class %>::Version
|
9
|
+
s.date = Time.now.strftime("%Y-%m-%d")
|
10
|
+
s.summary = "<%= gem_class %>: Description here"
|
11
|
+
s.homepage = "https://github.com/<%= github_name %>/<%= name %>"
|
12
|
+
s.authors = ["<%= author %>"]
|
13
|
+
s.email = "<%= email %>"
|
14
|
+
|
15
|
+
s.files = %w[ Rakefile README.markdown ]
|
16
|
+
s.files += Dir["bin/**/*"] if File.exists? "bin"
|
17
|
+
s.files += Dir["lib/**/*", "spec/**/*"]
|
18
|
+
|
19
|
+
# s.executables = ["templates"]
|
20
|
+
|
21
|
+
# s.add_dependency("gem", "= 0.0.0")
|
22
|
+
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
s.add_development_dependency "rake"
|
25
|
+
|
26
|
+
s.extra_rdoc_files = ["README.markdown"]
|
27
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) <%= Time.now.year %> <%= author %> <<%= email %>>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person ob-
|
4
|
+
taining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without restric-
|
6
|
+
tion, including without limitation the rights to use, copy, modi-
|
7
|
+
fy, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
the Software, and to permit persons to whom the Software is fur-
|
9
|
+
nished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
16
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONIN-
|
17
|
+
FRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
19
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# <%= gem_class %> [![<%= gem_class %> Build Status][Build Icon]][Build Status]
|
2
|
+
|
3
|
+
Description Here
|
4
|
+
|
5
|
+
[Build Icon]: https://secure.travis-ci.org/<%= github_name %>/<%= name %>.png?branch=master
|
6
|
+
[Build Status]: http://travis-ci.org/<%= github_name %>/<%= name %>
|
7
|
+
|
8
|
+
## Note on Patches/Pull Requests
|
9
|
+
|
10
|
+
* Fork the project.
|
11
|
+
* Make your feature addition or bug fix.
|
12
|
+
* Add tests for it. This is important so I don't break it in a future version
|
13
|
+
unintentionally.
|
14
|
+
* Commit, do not bump version. (If you want to have your own version, that is
|
15
|
+
fine but bump version in a commit by itself I can ignore when I pull).
|
16
|
+
* Send me a pull request. Bonus points for topic branches.
|
17
|
+
|
18
|
+
## Copyright
|
19
|
+
|
20
|
+
Copyright (c) <%= Time.now.year %> <%= author %>. See LICENSE for details.
|
@@ -0,0 +1 @@
|
|
1
|
+
require "<%= path %>/version"
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rubygems/mock_gem_ui"
|
3
|
+
require "minitest/spec"
|
4
|
+
require "tmpdir"
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
class Gem::Commands::CreateCommand::TestCase < MiniTest::Spec
|
8
|
+
# Apply this TestCase to any specs with
|
9
|
+
# `describe Gem::Commands::CreateCommand`
|
10
|
+
register_spec_type /Gem::Commands::CreateCommand/, self
|
11
|
+
|
12
|
+
# Clear the tmpdir if needed.
|
13
|
+
before { self.class.rm_tmpdir }
|
14
|
+
|
15
|
+
# Create a temporary directory.
|
16
|
+
def self.tmpdir
|
17
|
+
@tmpdir ||= Dir.mktmpdir
|
18
|
+
end
|
19
|
+
|
20
|
+
# Remove the temporary directory.
|
21
|
+
def self.rm_tmpdir
|
22
|
+
FileUtils.rm_r(tmpdir) if File.exists?(tmpdir)
|
23
|
+
ensure
|
24
|
+
@tmpdir = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
# Shortcut for specs dealing with generated files.
|
28
|
+
#
|
29
|
+
# Asserts that the file exists within the temporary directory.
|
30
|
+
#
|
31
|
+
# path - Path to the subject file
|
32
|
+
#
|
33
|
+
# If a block is given, it yields the contents of the file.
|
34
|
+
#
|
35
|
+
# Examples:
|
36
|
+
#
|
37
|
+
# it_renders "README" do |data|
|
38
|
+
# data.must_match /Hello World!/
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# it_renders "Gemspec"
|
42
|
+
def self.it_renders(path, options = {})
|
43
|
+
it "renders #{path}" do
|
44
|
+
Dir.chdir(self.class.tmpdir) do
|
45
|
+
dest = options.fetch(:in, @cmd.send(:destination_directory))
|
46
|
+
file = File.join(dest, path)
|
47
|
+
|
48
|
+
File.exists?(file).must_equal true,
|
49
|
+
"Expected #{File.expand_path(path).inspect} to exist"
|
50
|
+
|
51
|
+
yield File.read(file) if block_given?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns a Gem::MockGemUI. This allows us to work with IO in tests.
|
57
|
+
def ui
|
58
|
+
@ui ||= Gem::MockGemUi.new
|
59
|
+
end
|
60
|
+
|
61
|
+
# Run the CreateCommand with the specified arguments.
|
62
|
+
#
|
63
|
+
# Returns an Array, [0] is the standard output of the command, [1] is the
|
64
|
+
# error output.
|
65
|
+
def run_command(*args)
|
66
|
+
@cmd = Gem::Commands::CreateCommand.new
|
67
|
+
|
68
|
+
Dir.chdir(self.class.tmpdir) do
|
69
|
+
Gem::DefaultUserInteraction.use_ui(ui) do
|
70
|
+
capture_io { @cmd.invoke *args }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
return ui.output, ui.error
|
75
|
+
end
|
76
|
+
|
77
|
+
def fixtures_path
|
78
|
+
File.expand_path('../../fixtures', __FILE__)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
MiniTest::Unit.after_tests { Gem::Commands::CreateCommand::TestCase.rm_tmpdir }
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-create
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joshua Priddle
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70220464406760 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70220464406760
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: minitest
|
27
|
+
requirement: &70220464406320 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70220464406320
|
36
|
+
description: ! 'gem create: create a new gem'
|
37
|
+
email: jpriddle@me.com
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- Gemfile
|
43
|
+
- Rakefile
|
44
|
+
- README.markdown
|
45
|
+
- gem-create.gemspec
|
46
|
+
- LICENSE
|
47
|
+
- lib/rubygems/commands/create_command.rb
|
48
|
+
- lib/rubygems_plugin.rb
|
49
|
+
- spec/create_command_spec.rb
|
50
|
+
- spec/fixtures/skel/%gem_name%.gemspec
|
51
|
+
- spec/fixtures/skel/Gemfile
|
52
|
+
- spec/fixtures/skel/lib/%gem_name%/version.rb
|
53
|
+
- spec/fixtures/skel/lib/%gem_name%.rb
|
54
|
+
- spec/fixtures/skel/LICENSE
|
55
|
+
- spec/fixtures/skel/Rakefile
|
56
|
+
- spec/fixtures/skel/README.markdown
|
57
|
+
- spec/fixtures/skel/spec/%gem_name%_spec.rb
|
58
|
+
- spec/fixtures/skel/spec/spec_helper.rb
|
59
|
+
- spec/fixtures/skel.yml
|
60
|
+
- spec/minitest/gem_command_test_case.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
homepage: https://github.com/itspriddle/gem-create
|
63
|
+
licenses: []
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.8.11
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: ! 'gem create: create a new gem'
|
86
|
+
test_files:
|
87
|
+
- spec/create_command_spec.rb
|
88
|
+
- spec/fixtures/skel/%gem_name%.gemspec
|
89
|
+
- spec/fixtures/skel/Gemfile
|
90
|
+
- spec/fixtures/skel/lib/%gem_name%/version.rb
|
91
|
+
- spec/fixtures/skel/lib/%gem_name%.rb
|
92
|
+
- spec/fixtures/skel/LICENSE
|
93
|
+
- spec/fixtures/skel/Rakefile
|
94
|
+
- spec/fixtures/skel/README.markdown
|
95
|
+
- spec/fixtures/skel/spec/%gem_name%_spec.rb
|
96
|
+
- spec/fixtures/skel/spec/spec_helper.rb
|
97
|
+
- spec/fixtures/skel.yml
|
98
|
+
- spec/minitest/gem_command_test_case.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
has_rdoc:
|