gemsmith 0.2.0 → 0.3.0

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.
@@ -1,3 +1,16 @@
1
+ = v0.3.0
2
+
3
+ * Added Best Practices section to the README.
4
+ * Added the -e (edit) option for editing gem settings in default editor.
5
+ * Added Thor utilities for info and error messaging.
6
+ * Removed the classify and underscore methods since their equivalents are found in the Thor::Util class.
7
+ * Removed the print_version method.
8
+ * Added Rails generator USAGE documentation for the install and update generator templates.
9
+ * Removed excess shell calls from the CLI template.
10
+ * Added Thor::Actions to CLI class template.
11
+ * Added "Built with Gemsmith" to README template.
12
+ * Updated README template so that Gemfile mention is only provided when Rails is enabled.
13
+
1
14
  = v0.2.0
2
15
 
3
16
  * Fixed typo in upgrade generator doc.
@@ -54,6 +54,7 @@ choose what options to define. Up to you. If no options are configured, then the
54
54
  From the command line, type: gemsmith help
55
55
 
56
56
  gemsmith -c, [create=GEM_NAME] # Create new gem.
57
+ gemsmith -e, [edit] # Edit gem settings in default editor (assumes $EDITOR environment variable).
57
58
  gemsmith -h, [help] # Show this message.
58
59
  gemsmith -v, [version] # Show version.
59
60
 
@@ -71,6 +72,10 @@ available to you via Bundler (i.e. rake -T):
71
72
  rake install # Build and install <gem>-<version>.gem into system gems
72
73
  rake release # Create tag v0.1.1 and build and push <gem>-<version>.gem to Rubygems
73
74
 
75
+ = Best Practices
76
+
77
+ 1. Ensure your RUBYOPT env variable includes the -w option. {Read the reasons why here}[http://avdi.org/devblog/2011/06/23/how-ruby-helps-you-fix-your-broken-code/].
78
+
74
79
  = Author
75
80
 
76
81
  {Red Alchemist}[http://www.redalchemist.com]
@@ -1,4 +1,5 @@
1
1
  require File.join File.dirname(__FILE__), "gemsmith", "version.rb"
2
+ require File.join File.dirname(__FILE__), "gemsmith", "utilities.rb"
2
3
 
3
4
  module Gemsmith
4
5
  # Placeholder.
@@ -5,8 +5,9 @@ require "thor/actions"
5
5
  module Gemsmith
6
6
  class CLI < Thor
7
7
  include Thor::Actions
8
+ include Gemsmith::Utilities
8
9
 
9
- # Overwritten Thor template source root.
10
+ # Overwrites the Thor template source root.
10
11
  def self.source_root
11
12
  File.expand_path File.join(File.dirname(__FILE__), "templates")
12
13
  end
@@ -14,26 +15,22 @@ module Gemsmith
14
15
  # Initialize.
15
16
  def initialize args = [], options = {}, config = {}
16
17
  super
17
-
18
- # Defaults.
19
- @shell = shell
20
18
  @settings_file = File.join ENV["HOME"], ".gemsmith", "settings.yml"
21
-
22
- # Load and apply custom settings (if any).
23
19
  load_settings
24
20
  end
25
21
 
26
22
  desc "-c, [create=GEM_NAME]", "Create new gem."
27
23
  map "-c" => :create
28
- method_option :bin, :aliases => "-b", :desc => "Adds binary support.", :type => :boolean, :default => false
29
- method_option :rails, :aliases => "-R", :desc => "Adds Rails support.", :type => :boolean, :default => false
24
+ method_option :bin, :aliases => "-b", :desc => "Add binary support.", :type => :boolean, :default => false
25
+ method_option :rails, :aliases => "-R", :desc => "Add Rails support.", :type => :boolean, :default => false
30
26
  method_option :rspec, :aliases => "-r", :desc => "Add RSpec support.", :type => :boolean, :default => true
31
27
  def create name
32
- shell.say "\nCreating gem..."
28
+ say
29
+ say_info "Creating gem..."
33
30
 
34
31
  # Initialize options.
35
- gem_name = underscore name
36
- gem_class = classify gem_name
32
+ gem_name = Thor::Util.snake_case name
33
+ gem_class = Thor::Util.camel_case name
37
34
  author_name = @settings[:author_name] || `git config user.name`.chomp || "TODO: Write full name here."
38
35
  author_url = @settings[:author_url] || "TODO: Write home page URL here."
39
36
  template_options = {
@@ -84,7 +81,9 @@ module Gemsmith
84
81
  # Generators
85
82
  empty_directory File.join(target_path, "lib", "generators", gem_name, "templates")
86
83
  template File.join("lib", "generators", "gem", "install", "install_generator.rb.tmp"), File.join(target_path, "lib", "generators", gem_name, "install", "install_generator.rb"), template_options
84
+ template File.join("lib", "generators", "gem", "install", "USAGE.tmp"), File.join(target_path, "lib", "generators", gem_name, "install", "USAGE"), template_options
87
85
  template File.join("lib", "generators", "gem", "upgrade", "upgrade_generator.rb.tmp"), File.join(target_path, "lib", "generators", gem_name, "upgrade", "upgrade_generator.rb"), template_options
86
+ template File.join("lib", "generators", "gem", "upgrade", "USAGE.tmp"), File.join(target_path, "lib", "generators", gem_name, "upgrade", "USAGE"), template_options
88
87
  end
89
88
 
90
89
  # RSpec (optional).
@@ -101,48 +100,29 @@ module Gemsmith
101
100
  `git commit -a -n -m "Gemsmith skeleton created."`
102
101
  end
103
102
 
104
- shell.say "Gem created: #{gem_name}\n\n"
103
+ say_info "Gem created."
104
+ say
105
+ end
106
+
107
+ desc "-e, [edit]", "Edit gem settings in default editor (assumes $EDITOR environment variable)."
108
+ map "-e" => :edit
109
+ def edit
110
+ `$EDITOR #{@settings_file}`
105
111
  end
106
112
 
107
113
  desc "-v, [version]", "Show version."
108
114
  map "-v" => :version
109
115
  def version
110
- print_version
116
+ say "Gemsmith " + VERSION
111
117
  end
112
118
 
113
119
  desc "-h, [help]", "Show this message."
114
120
  def help task = nil
115
- shell.say and super
121
+ say and super
116
122
  end
117
123
 
118
124
  private
119
125
 
120
- # Transforms a camelcased string to an underscored equivalent (code stolen from the Ruby on Rails ActiveSupport underscore method).
121
- # ==== Examples
122
- # * "ExampleGem" -> "example_gem"
123
- # * "SSLGem" -> "ssl_gem"
124
- # ==== Parameters
125
- # * +string+ - The string to underscore.
126
- def underscore string
127
- string = string.to_s.dup
128
- string.gsub! /([A-Z]+)([A-Z][a-z])/, '\1_\2'
129
- string.gsub! /([a-z\d])([A-Z])/, '\1_\2'
130
- string.tr! "-", "_"
131
- string.downcase
132
- end
133
-
134
- # Transforms a lowercased/camelcased to a proper class name (code inspired by the Ruby on Rails ActiveSupport classify method).
135
- # ==== Examples
136
- # * "example" -> "example"
137
- # * "my_cool_gem" -> "MyCoolGem"
138
- # ==== Parameters
139
- # * +string+ - The string to classify.
140
- def classify string
141
- string = string.to_s.dup
142
- string.gsub!(/(^.{1}|_.)/) {$1.upcase}
143
- string.tr '_', ''
144
- end
145
-
146
126
  # Load settings.
147
127
  def load_settings
148
128
  if File.exists? @settings_file
@@ -150,14 +130,9 @@ module Gemsmith
150
130
  settings = YAML::load_file @settings_file
151
131
  @settings = settings.reject {|key, value| value.nil?}
152
132
  rescue
153
- shell.say "ERROR: Invalid settings: #{@settings_file}."
133
+ say_error "Invalid settings: #{@settings_file}."
154
134
  end
155
135
  end
156
136
  end
157
-
158
- # Print version information.
159
- def print_version
160
- shell.say "Gemsmith " + VERSION
161
- end
162
137
  end
163
138
  end
@@ -11,11 +11,11 @@
11
11
  Type the following from the command line to install:
12
12
 
13
13
  gem install <%= config[:gem_name] %>
14
-
14
+ <% if config[:rails] %>
15
15
  Add the following to your Gemfile:
16
16
 
17
17
  gem "<%= config[:gem_name] %>"
18
-
18
+ <% end %>
19
19
  = Usage
20
20
 
21
21
  = Author
@@ -30,3 +30,4 @@ Read the LICENSE for details.
30
30
  = History
31
31
 
32
32
  Read the CHANGELOG for details.
33
+ Built with Gemsmith[https://github.com/bkuhlmann/gemsmith].
@@ -1,8 +1,9 @@
1
- require "yaml"
2
1
  require "thor"
2
+ require "thor/actions"
3
3
 
4
4
  module <%= config[:gem_class] %>
5
5
  class CLI < Thor
6
+ include Thor::Actions
6
7
 
7
8
  # Initialize.
8
9
  def initialize args = [], options = {}, config = {}
@@ -12,19 +13,12 @@ module <%= config[:gem_class] %>
12
13
  desc "-v, [version]", "Show version."
13
14
  map "-v" => :version
14
15
  def version
15
- print_version
16
+ say "<%= config[:gem_class] %> " + VERSION
16
17
  end
17
18
 
18
19
  desc "-h, [help]", "Show this message."
19
20
  def help task = nil
20
- shell.say and super
21
- end
22
-
23
- private
24
-
25
- # Print version information.
26
- def print_version
27
- shell.say "<%= config[:gem_class] %> " + VERSION
21
+ say and super
28
22
  end
29
23
  end
30
24
  end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Installs additional <%= config[:gem_class] %> resources.
3
+
4
+ Example:
5
+ rails generate <%= config[:gem_name] %>:install
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Upgrades previously installed <%= config[:gem_class] %> resources.
3
+
4
+ Example:
5
+ rails generate <%= config[:gem_name] %>:upgrade
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,14 @@
1
+ module Gemsmith
2
+ # Additional utilities for the command line.
3
+ module Utilities
4
+ # Prints info to the console.
5
+ def say_info message
6
+ say_status :info, message, :white
7
+ end
8
+
9
+ # Prints an error to the console.
10
+ def say_error message
11
+ say_status :error, message, :red
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Gemsmith
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemsmith
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brooke Kuhlmann
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-12 00:00:00 Z
18
+ date: 2011-07-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: thor
@@ -97,11 +97,14 @@ files:
97
97
  - lib/gemsmith/templates/lib/gem/active_record/instance_methods.rb.tmp
98
98
  - lib/gemsmith/templates/lib/gem/cli.rb.tmp
99
99
  - lib/gemsmith/templates/lib/gem/version.rb.tmp
100
+ - lib/gemsmith/templates/lib/generators/gem/install/USAGE.tmp
100
101
  - lib/gemsmith/templates/lib/generators/gem/install/install_generator.rb.tmp
102
+ - lib/gemsmith/templates/lib/generators/gem/upgrade/USAGE.tmp
101
103
  - lib/gemsmith/templates/lib/generators/gem/upgrade/upgrade_generator.rb.tmp
102
104
  - lib/gemsmith/templates/rspec.tmp
103
105
  - lib/gemsmith/templates/spec/gem_spec.rb.tmp
104
106
  - lib/gemsmith/templates/spec/spec_helper.rb.tmp
107
+ - lib/gemsmith/utilities.rb
105
108
  - lib/gemsmith/version.rb
106
109
  homepage: http://www.redalchemist.com
107
110
  licenses: []