gem-new 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ GEM NEW HISTORY
2
+ ===============
3
+
4
+
5
+
6
+ 2011- - Released Version 0.2.0
7
+ ------------------------------
8
+
9
+ * New: Added basic rake tasks to build the gem.
10
+ * Changed: .literal Suffix no longer exists, use .stop instead.
11
+ * Changed: Files are now processed by suffix, until .stop or an unknown suffix is hit.
12
+ E.g. foo.html.markdown.erb will first be processed by the ERB processor, then by the
13
+ Markdown processor and then it'll stop (because .html is not being processed any
14
+ further)
15
+ * Fixed: Fixed broken template file default/skeleton/lib/REQUIRE_NAME.rb.
16
+ * Improved: Added executables detection and setting of spec.executables to
17
+ GEM\_NAME.gemspec.erb
18
+ * Improved: Removed spec.date from GEM\_NAME.gemspec.erb
19
+
20
+
21
+
22
+ 2011-06-15 - Released Version 0.1.2
23
+ -----------------------------------
24
+
25
+ * Fixed: Fixed a bug in the text of "gem help new"
26
+
27
+
28
+
29
+ 2011-06-13 - Released Version 0.1.1
30
+ -----------------------------------
31
+
32
+ * Fixed: Fixed a small bug in the initial release
33
+
34
+
35
+
36
+ 2011-06-13 - Released Version 0.1.0
37
+ -----------------------------------
38
+
39
+ * Initial Release
@@ -0,0 +1,41 @@
1
+ GEM NEW
2
+ =======
3
+
4
+
5
+
6
+ Summary
7
+ -------
8
+ Create new gems easily
9
+
10
+
11
+
12
+ Quick Install & Usage
13
+ ---------------------
14
+ 1. `gem install gem-new`
15
+ 2. `gem new my_new_gems_name`
16
+ 3. Profit!
17
+
18
+ See `gem help new` for more information (only available after you installed the `gem-new`
19
+ gem).
20
+
21
+
22
+
23
+ Description
24
+ -----------
25
+ Gem-new is a gem command plugin that allows you to easily create a new gem.
26
+ To facilitate gem creation, it relies on directory templates. You can create your own templates and
27
+ let a template use other templates. For example you could have a 'rails-plugin' template, which
28
+ includes a 'git-repository', 'rspec', 'ruby-lib' and 'yard' template. This way you can modularly
29
+ build up your templates and quickly create matching directory structures.
30
+
31
+
32
+
33
+ Executable
34
+ ----------
35
+ Use `gem help new` for information on how to use the gem-new executable.
36
+
37
+
38
+
39
+ Known Bugs and Issues
40
+ ---------------------
41
+ Go to https://github.com/apeiros/gem-new/issues
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../rake/lib', __FILE__))
2
+ Dir.glob(File.expand_path('../rake/tasks/**/*.{rake,task,rb}', __FILE__)) do |task_file|
3
+ begin
4
+ import task_file
5
+ rescue LoadError => e
6
+ warn "Failed to load task file #{task_file}"
7
+ warn " #{e.class} #{e.message}"
8
+ warn " #{e.backtrace.first}"
9
+ end
10
+ end
@@ -0,0 +1,2 @@
1
+ The default template for gem new. It is very minimalistic and will only generate the basic
2
+ structure of a rubygem, without anything in it.
@@ -1,3 +1,3 @@
1
1
  ---
2
- version: 1
2
+ version: 2
3
3
  includes: []
@@ -4,8 +4,9 @@ Gem::Specification.new do |s|
4
4
  s.name = <%= gem_name.inspect %>
5
5
  s.version = <%= version.to_s.inspect %>
6
6
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1")
7
+ # According to Eric Hodel (Rubygems maintainer), you should generally not set this value
8
+ # s.date = <%= date.inspect %>
7
9
  s.authors = <%= author.inspect %>
8
- s.date = <%= date.inspect %>
9
10
  s.description = <<-DESCRIPTION.gsub(/^ /, '').chomp
10
11
  <%= description && description.gsub(/^/,' ') %>
11
12
  DESCRIPTION
@@ -24,6 +25,10 @@ Gem::Specification.new do |s|
24
25
  README.markdown
25
26
  ]
26
27
  s.require_paths = %w[lib]
28
+ if File.directory?('bin') then
29
+ executables = Dir.chdir('bin') { Dir.glob('**/*').select { |f| File.executable?(f) } }
30
+ s.executables = executables unless executables.empty?
31
+ end
27
32
  s.rubygems_version = "1.3.1"
28
33
  s.specification_version = 3
29
34
  end
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.expand_path('../rake/lib', __FILE__))
2
2
  Dir.glob(File.expand_path('../rake/tasks/**/*.{rake,task,rb}', __FILE__)) do |task_file|
3
3
  begin
4
- require task_file
4
+ import task_file
5
5
  rescue LoadError => e
6
6
  warn "Failed to load task file #{task_file}"
7
7
  warn " #{e.class} #{e.message}"
@@ -1,24 +1,12 @@
1
1
  # encoding: utf-8
2
2
 
3
- Gem::Specification.new do |s|
4
- s.name = "gem-new"
5
- s.version = "0.1.0"
6
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1")
7
- s.authors = ["Stefan Rusterholz"]
8
- s.date = "2011-06-10"
9
- s.default_executable = "baretest"
10
- s.description = <<-DESCRIPTION.chomp
11
- Gem-new is a gem command plugin that allows you to easily create a new gem.
12
- DESCRIPTION
13
- s.summary = <<-SUMMARY.chomp
14
- Create new gems easily
15
- SUMMARY
16
- s.email = "stefan.rusterholz@gmail.com"
17
- s.files = %w[
18
- lib/rubygems_plugin.rb
19
- ]
20
- s.homepage = "http://github.com/apeiros/gem-new"
21
- s.require_paths = %w[lib]
22
- s.rubygems_version = "1.3.1"
23
- s.specification_version = 3
3
+
4
+
5
+ require '<%= require_name %>/version'
6
+
7
+
8
+
9
+ # <%= namespace.chomp %>
10
+ <%= description.gsub(/\n*\z/, '').gsub(/^/, '# ')+"\n" %>
11
+ module <%= namespace %>
24
12
  end
@@ -1,6 +1,10 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'gem/version'
3
+ begin
4
+ require 'rubygems/version' # newer rubygems use this
5
+ rescue LoadError
6
+ require 'gem/version' # older rubygems use this
7
+ end
4
8
 
5
9
  module <%= namespace %>
6
10
  Version = Gem::Version.new(<%= version.to_s.inspect %>)
@@ -0,0 +1 @@
1
+ This template provides a couple of rake tasks related to building your gem.
@@ -0,0 +1,3 @@
1
+ ---
2
+ version: 1
3
+ includes: []
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'rubygems/package_task'
3
+ rescue
4
+ require 'gem/package_task'
5
+ end
6
+
7
+ namespace :gem do
8
+ spec_files = Dir.glob('*.gemspec')
9
+ abort("No gemspec found in project-root") if spec_files.empty?
10
+ abort("More than one gemspec found in project-root: #{spec.join(', ')}") if spec_files.size > 1
11
+ gem_spec = Gem::Specification.load(spec_files.first)
12
+
13
+ Gem::PackageTask.new(gem_spec) do |pkg|
14
+ pkg.package_dir = 'pkg'
15
+ pkg.need_zip = false
16
+ pkg.need_tar = false
17
+ end
18
+ end
19
+
20
+ desc "Clobbers previous products and builds the gem"
21
+ task :gem => ['gem:clobber_package', 'gem:gem']
@@ -37,9 +37,17 @@ class Gem::Commands::NewCommand < Gem::Command
37
37
  add_option('--variables', 'Show all available variables') do |value, opts|
38
38
  opts[:variables] = value
39
39
  end
40
+ add_option('--version', 'Show gem-new version and exit') do |value, opts|
41
+ opts[:version] = true
42
+ end
40
43
  end
41
44
 
42
45
  def execute
46
+ if options[:version] then
47
+ puts "gem-new version #{VERSION}"
48
+ return
49
+ end
50
+
43
51
  if File.exist?(ConfigPath) then
44
52
  if Configuration.new(ConfigPath).config_version < ConfigVersion then
45
53
  FileUtils.mv(ConfigPath, "#{ConfigPath}.bak")
@@ -267,6 +275,7 @@ private
267
275
  path_variables: {}
268
276
  YAML
269
277
  FileUtils.mkdir_p(File.dirname(ConfigPath))
278
+ FileUtils.mkdir_p(UserTemplatesDir.last)
270
279
  File.open(ConfigPath, 'wb') { |fh| fh.write(yaml) }
271
280
  end
272
281
 
@@ -286,6 +295,6 @@ private
286
295
  end
287
296
 
288
297
  def camelcase(string)
289
- string.gsub(/(?:^|_)([a-z])/) { |m| $1.upcase }
298
+ string.gsub(/(?:^|_)([a-z])/) { $1.upcase }
290
299
  end
291
300
  end
@@ -6,22 +6,42 @@ require 'gem/commands/new_command/erb_template'
6
6
 
7
7
 
8
8
  class Gem::Commands::NewCommand < Gem::Command
9
+ # Preregistered processors
10
+ # * .erb: Interprets the file as ERB template, see rubys stdlib docs on ERB.
11
+ # * .stop: Stops the preprocessing chain, it's advised to add that to all files.
12
+ # * .rb: Same as .stop
13
+ # * .yaml: Same as .stop
14
+ # * .html: Same as .stop
15
+ # * .js: Same as .stop
16
+ # * .png: Same as .stop
17
+ # * .jpg: Same as .stop
18
+ # * .gif: Same as .stop
19
+ #
9
20
  class Skeleton
10
21
  DefaultOptions = {
11
22
  :verbose => false,
12
23
  :silent => false,
13
24
  :out => $stdout,
14
25
  }
15
- Processors = {}
26
+ Processors = {
27
+ '.stop' => nil,
28
+ '.rb' => nil,
29
+ '.yaml' => nil,
30
+ '.html' => nil,
31
+ '.js' => nil,
32
+ '.png' => nil,
33
+ '.jpg' => nil,
34
+ '.gif' => nil,
35
+ }
16
36
  Processor = Struct.new(:suffix, :name, :execute)
17
-
37
+
18
38
  def self.register_processor(suffix, name, &execute)
39
+ raise ArgumentError, "A processor named #{suffix.inspect} is already registered" if Processors[suffix]
40
+ raise TypeError, "Processor name must be a String, but is #{suffix.class}:#{suffix.inspect}" unless suffix.is_a?(String)
41
+
19
42
  Processors[suffix] = Processor.new(suffix, name, execute)
20
43
  end
21
44
 
22
- register_processor '.literal', 'Literal' do |template, variables|
23
- template
24
- end
25
45
  register_processor '.erb', 'ERB' do |template, variables|
26
46
  ErbTemplate.replace(template, variables)
27
47
  end
@@ -100,25 +120,33 @@ class Gem::Commands::NewCommand < Gem::Command
100
120
 
101
121
  def source_to_target_path_and_processors(source_path, target_dir, replacer)
102
122
  replaced_source = replacer.replace(source_path[@source_slice])
103
- extname = File.extname(replaced_source)
123
+ processed_source = replaced_source.dup
104
124
  processors = []
105
- processed_source = replaced_source
106
125
 
107
- if processor = Processors[extname] then
108
- processors << processor
109
- processed_source = processed_source.chomp(extname)
126
+ while processor = extract_processor_from_path(processed_source)
127
+ processors << processor
110
128
  end
111
129
  target_path = File.join(target_dir, processed_source)
112
- # while processor = Processors[extname]
113
- # processors << processor
114
- # processed_source = File.basename(processed_source, extname)
115
- # extname = File.extname(processed_source)
116
- # end
117
130
 
118
131
  [target_path, processors]
119
132
  end
120
133
 
121
134
  private
135
+ # @param [String] path
136
+ # The path to extract the processor from.
137
+ # BEWARE! The string referenced by path will be mutated. The extension is being
138
+ # removed.
139
+ #
140
+ # @return [Processor, nil]
141
+ # Returns the processor or nil
142
+ def extract_processor_from_path(path)
143
+ extname = File.extname(path)
144
+ processor = Processors[extname]
145
+ path.chomp!(extname) if processor
146
+
147
+ processor
148
+ end
149
+
122
150
  def info(msg)
123
151
  @out.puts msg unless @silent
124
152
  end
@@ -1,3 +1,3 @@
1
1
  class Gem::Commands::NewCommand < Gem::Command
2
- VERSION = Gem::Version.new("0.1.0")
2
+ VERSION = Gem::Version.new("0.2.0")
3
3
  end
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'rubygems/package_task'
3
+ rescue
4
+ require 'gem/package_task'
5
+ end
6
+
7
+ namespace :gem do
8
+ spec_files = Dir.glob('*.gemspec')
9
+ abort("No gemspec found in project-root") if spec_files.empty?
10
+ abort("More than one gemspec found in project-root: #{spec.join(', ')}") if spec_files.size > 1
11
+ gem_spec = Gem::Specification.load(spec_files.first)
12
+
13
+ Gem::PackageTask.new(gem_spec) do |pkg|
14
+ pkg.package_dir = 'pkg'
15
+ pkg.need_zip = false
16
+ pkg.need_tar = false
17
+ end
18
+ end
19
+
20
+ desc "Clobbers previous products and builds the gem"
21
+ task :gem => ['gem:clobber_package', 'gem:gem']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-new
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-10 00:00:00.000000000 Z
12
+ date: 2011-06-10 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: ! ' Gem-new is a gem command plugin that allows you to easily create
15
15
  a new gem.'
@@ -18,15 +18,19 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - data/gem-new/default/description.txt
21
22
  - data/gem-new/default/meta.yaml
22
23
  - data/gem-new/default/skeleton/GEM_NAME.gemspec.erb
23
24
  - data/gem-new/default/skeleton/lib/REQUIRE_NAME/version.rb.erb
24
25
  - data/gem-new/default/skeleton/lib/REQUIRE_NAME.rb.erb
25
26
  - data/gem-new/default/skeleton/Rakefile
26
- - data/gem-new/default/skeleton/README.markdown.literal
27
+ - data/gem-new/default/skeleton/README.markdown.stop.erb
27
28
  - data/gem-new/default/skeleton/README_DIRECTORIES
28
29
  - data/gem-new/gem-new-template/meta.yaml
29
30
  - data/gem-new/gem-new-template/skeleton/data/GEM_NAME/your_template_name/meta.yaml
31
+ - data/gem-new/gem-raketasks/description.txt
32
+ - data/gem-new/gem-raketasks/meta.yaml
33
+ - data/gem-new/gem-raketasks/skeleton/rake/tasks/gem.rake
30
34
  - data/gem-new/default/skeleton/bin/.gitkeep
31
35
  - data/gem-new/default/skeleton/development/.gitkeep
32
36
  - data/gem-new/default/skeleton/documentation/.gitkeep
@@ -35,6 +39,8 @@ files:
35
39
  - data/gem-new/default/skeleton/rake/tasks/.gitkeep
36
40
  - data/gem-new/default/skeleton/test/.gitkeep
37
41
  - data/gem-new/gem-new-template/skeleton/data/GEM_NAME/your_template_name/skeleton/.gitkeep
42
+ - data/gem-new/gem-raketasks/skeleton/rake/lib/.gitkeep
43
+ - data/gem-new/gem-raketasks/skeleton/rake/tasks/.gitkeep
38
44
  - lib/gem/commands/new_command/blank_slate.rb
39
45
  - lib/gem/commands/new_command/configuration.rb
40
46
  - lib/gem/commands/new_command/erb_template.rb
@@ -43,6 +49,10 @@ files:
43
49
  - lib/gem/commands/new_command/version.rb
44
50
  - lib/gem/commands/new_command.rb
45
51
  - lib/rubygems_plugin.rb
52
+ - rake/tasks/gem.rake
53
+ - HISTORY.markdown
54
+ - Rakefile
55
+ - README.markdown
46
56
  homepage: https://github.com/apeiros/gem-new
47
57
  licenses: []
48
58
  post_install_message:
@@ -63,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
73
  version: 1.3.1
64
74
  requirements: []
65
75
  rubyforge_project:
66
- rubygems_version: 1.8.5
76
+ rubygems_version: 1.8.6
67
77
  signing_key:
68
78
  specification_version: 3
69
79
  summary: Create new gems easily