gem-this 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Rakefile +109 -0
  2. data/Rakefile.erb +130 -0
  3. data/Readme.markdown +91 -0
  4. data/bin/gem-this +71 -0
  5. metadata +56 -0
data/Rakefile ADDED
@@ -0,0 +1,109 @@
1
+ require "rubygems"
2
+ require "rake/gempackagetask"
3
+ require "rake/rdoctask"
4
+
5
+ task :default => :package do
6
+ puts "Don't forget to write some tests!"
7
+ end
8
+
9
+ # This builds the actual gem. For details of what all these options
10
+ # mean, and other ones you can add, check the documentation here:
11
+ #
12
+ # http://rubygems.org/read/chapter/20
13
+ #
14
+ spec = Gem::Specification.new do |s|
15
+
16
+ # Change these as appropriate
17
+ s.name = "gem-this"
18
+ s.version = "0.1.3"
19
+ s.summary = "Make existing code into a gem, without any fuss."
20
+ s.author = "James Adam"
21
+ s.email = "james@lazyatom.com"
22
+ s.homepage = "http://github.com/lazyatom/gem-this"
23
+
24
+ s.has_rdoc = true
25
+ # s.extra_rdoc_files = %w(Readme.markdown)
26
+ # s.rdoc_options = %w(--main Readme.markdown)
27
+
28
+ # Add any extra files to include in the gem
29
+ s.files = %w(Rakefile Readme.markdown Rakefile.erb) + Dir.glob("{bin}/**/*")
30
+ s.executables = FileList["bin/**"].map { |f| File.basename(f) }
31
+ s.require_paths = ["bin"]
32
+
33
+ # If you want to depend on other gems, add them here, along with any
34
+ # relevant versions
35
+ # s.add_dependency("some_other_gem", "~> 0.1.0")
36
+
37
+ # If your tests use any gems, include them here
38
+ # s.add_development_dependency("mocha")
39
+
40
+ # If you want to publish automatically to rubyforge, you'll may need
41
+ # to tweak this, and the publishing task below too.
42
+ s.rubyforge_project = "gem-this"
43
+ end
44
+
45
+ # This task actually builds the gem. We also regenerate a static
46
+ # .gemspec file, which is useful if something (i.e. GitHub) will
47
+ # be automatically building a gem for this project. If you're not
48
+ # using GitHub, edit as appropriate.
49
+ Rake::GemPackageTask.new(spec) do |pkg|
50
+ pkg.gem_spec = spec
51
+
52
+ # Generate the gemspec file for github.
53
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
54
+ File.open(file, "w") {|f| f << spec.to_ruby }
55
+ end
56
+
57
+ # Generate documentation
58
+ Rake::RDocTask.new do |rd|
59
+ rd.main = "Readme.markdown"
60
+ rd.rdoc_files.include("Readme.markdown", "lib/**/*.rb")
61
+ rd.rdoc_dir = "rdoc"
62
+ end
63
+
64
+ desc 'Clear out RDoc and generated packages'
65
+ task :clean => [:clobber_rdoc, :clobber_package] do
66
+ rm "#{spec.name}.gemspec"
67
+ end
68
+
69
+ # If you want to publish to RubyForge automatically, here's a simple
70
+ # task to help do that. If you don't, just get rid of this.
71
+ # Be sure to set up your Rubyforge account details with the Rubyforge
72
+ # gem
73
+ begin
74
+ require "rake/contrib/sshpublisher"
75
+ namespace :rubyforge do
76
+
77
+ desc "Release gem and RDoc documentation to RubyForge"
78
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
79
+
80
+ namespace :release do
81
+ desc "Release a new version of this gem"
82
+ task :gem => [:package] do
83
+ require 'rubyforge'
84
+ rubyforge = RubyForge.new
85
+ rubyforge.configure
86
+ rubyforge.login
87
+ rubyforge.userconfig['release_notes'] = spec.summary
88
+ path_to_gem = File.join(File.dirname(__FILE__), "pkg", "#{spec.name}-#{spec.version}.gem")
89
+ puts "calling rubyforge.add_release(#{spec.rubyforge_project.inspect}, #{spec.name.inspect}, #{spec.version.to_s.inspect}, #{path_to_gem.inspect})"
90
+ rubyforge.add_release(spec.rubyforge_project, spec.name, spec.version.to_s, path_to_gem)
91
+ end
92
+
93
+ desc "Publish RDoc to RubyForge."
94
+ task :docs => [:rdoc] do
95
+ config = YAML.load(
96
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
97
+ )
98
+
99
+ host = "#{config['username']}@rubyforge.org"
100
+ remote_dir = "/var/www/gforge-projects/gem-this/" # Should be the same as the rubyforge project name
101
+ local_dir = 'rdoc'
102
+
103
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
104
+ end
105
+ end
106
+ end
107
+ rescue LoadError
108
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
109
+ end
data/Rakefile.erb ADDED
@@ -0,0 +1,130 @@
1
+ require "rubygems"
2
+ require "rake/gempackagetask"
3
+ require "rake/rdoctask"
4
+
5
+ <% if using_rspec? %>
6
+ task :default => :spec
7
+
8
+ require "spec"
9
+ require "spec/rake/spectask"
10
+ Spec::Rake::SpecTask.new do |t|
11
+ t.spec_opts = %w(--format specdoc --colour)
12
+ t.libs = ["spec"]
13
+ end
14
+ <% elsif using_test_unit? %>
15
+ task :default => :test
16
+
17
+ require "rake/testtask"
18
+ Rake::TestTask.new do |t|
19
+ t.libs << "test"
20
+ t.test_files = FileList["test/**/*_test.rb"]
21
+ t.verbose = true
22
+ end
23
+ <% else %>
24
+ task :default => :package do
25
+ puts "Don't forget to write some tests!"
26
+ end
27
+ <% end %>
28
+
29
+ # This builds the actual gem. For details of what all these options
30
+ # mean, and other ones you can add, check the documentation here:
31
+ #
32
+ # http://rubygems.org/read/chapter/20
33
+ #
34
+ spec = Gem::Specification.new do |s|
35
+
36
+ # Change these as appropriate
37
+ s.name = "<%= gem_name %>"
38
+ s.version = "0.1.0"
39
+ s.summary = "What this thing does"
40
+ s.author = "Your name"
41
+ s.email = "you@example.com"
42
+ s.homepage = "http://example.com"
43
+
44
+ s.has_rdoc = true
45
+ <% if readme %>
46
+ s.extra_rdoc_files = %w(<%= readme %>)
47
+ s.rdoc_options = %w(--main <%= readme %>)
48
+
49
+ # Add any extra files to include in the gem
50
+ <% else %>
51
+ # You should probably have a README of some kind. Change the filename
52
+ # as appropriate
53
+ # s.extra_rdoc_files = %w(README)
54
+ # s.rdoc_options = %w(--main README)
55
+
56
+ # Add any extra files to include in the gem (like your README)
57
+ <% end %>
58
+ s.files = %w(<%= files_in_root %>) + Dir.glob("{<%= dirs_to_include %>}/**/*")
59
+ <% if has_executables? %>
60
+ s.executables = FileList["bin/**"].map { |f| File.basename(f) }
61
+ <% end %>
62
+ s.require_paths = ["lib"]
63
+
64
+ # If you want to depend on other gems, add them here, along with any
65
+ # relevant versions
66
+ # s.add_dependency("some_other_gem", "~> 0.1.0")
67
+
68
+ <% if using_rspec? %>
69
+ s.add_development_dependency("rspec") # add any other gems for testing/development
70
+ <% else %>
71
+ # If your tests use any gems, include them here
72
+ # s.add_development_dependency("mocha")
73
+ <% end %>
74
+
75
+ # If you want to publish automatically to rubyforge, you'll may need
76
+ # to tweak this, and the publishing task below too.
77
+ s.rubyforge_project = "<%= gem_name %>"
78
+ end
79
+
80
+ # This task actually builds the gem. We also regenerate a static
81
+ # .gemspec file, which is useful if something (i.e. GitHub) will
82
+ # be automatically building a gem for this project. If you're not
83
+ # using GitHub, edit as appropriate.
84
+ Rake::GemPackageTask.new(spec) do |pkg|
85
+ pkg.gem_spec = spec
86
+
87
+ # Generate the gemspec file for github.
88
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
89
+ File.open(file, "w") {|f| f << spec.to_ruby }
90
+ end
91
+
92
+ # Generate documentation
93
+ Rake::RDocTask.new do |rd|
94
+ <% if readme %>rd.main = "<%= readme %>"<% end %>
95
+ rd.rdoc_files.include(<%= %{"#{readme}", } if readme %>"lib/**/*.rb")
96
+ rd.rdoc_dir = "rdoc"
97
+ end
98
+
99
+ desc 'Clear out RDoc and generated packages'
100
+ task :clean => [:clobber_rdoc, :clobber_package] do
101
+ rm "#{spec.name}.gemspec"
102
+ end
103
+
104
+ # If you want to publish to RubyForge automatically, here's a simple
105
+ # task to help do that. If you don't, just get rid of this.
106
+ begin
107
+ require "rake/contrib/sshpublisher"
108
+ namespace :rubyforge do
109
+
110
+ desc "Release gem and RDoc documentation to RubyForge"
111
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
112
+
113
+ namespace :release do
114
+ desc "Publish RDoc to RubyForge."
115
+ task :docs => [:rdoc] do
116
+ config = YAML.load(
117
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
118
+ )
119
+
120
+ host = "#{config['username']}@rubyforge.org"
121
+ remote_dir = "/var/www/gforge-projects/<%= gem_name %>/" # Should be the same as the rubyforge project name
122
+ local_dir = 'rdoc'
123
+
124
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
125
+ end
126
+ end
127
+ end
128
+ rescue LoadError
129
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
130
+ end
data/Readme.markdown ADDED
@@ -0,0 +1,91 @@
1
+ Most of the time, I don't set out to write a gem.
2
+ =================================================
3
+
4
+ Perhaps I'm not audacious enough to consider every piece of code I write to be worthy of use by other developers. Perhaps.
5
+
6
+ But, more likely than that, it's just that I don't think that far ahead. I'm more interested in playing with the idea at the start, rather than thinking about how other people are going to remember - nay, worship my name, years in the future.
7
+
8
+ Anyway, sometimes - after a bit of tinkering and pondering - I do end up with a library that I consider gem-worthy and fit for consumption. But every time I look at the existing tools to build gems, I'm paralysed by the comprehensive nature of their function.
9
+
10
+ Often, they'll try to generate a particular directory structure, with test stubs and a website, which is fine in principle, but I've already got my code the way I want it; I'm not generating a new project.
11
+
12
+ Even worse, sometimes they'll add themselves as dependencies for your gem! Yuck.
13
+
14
+ I am not interested in that. I just want the simplest thing that could possibly work, to build my gem and make it available to the world. I will add any bells and whistles that I want later.
15
+
16
+ And so:
17
+
18
+ Gem This
19
+ ========
20
+
21
+ The `gem-this` command expects to be run in the directory of your existing code:
22
+
23
+ $ cd my-project
24
+ $ mate lib/sweet_code.rb
25
+ ... hacking ...
26
+ $ gem-this
27
+
28
+ When you run `gem-this`, it will create a new `Rakefile` in your project directory. If you already had a `Rakefile`, it will append to the end of it, so your existing tasks are safe.
29
+
30
+ $ rake -T
31
+ rake clean # Clear out RDoc and generated packages
32
+ rake clobber_package # Remove package products
33
+ rake clobber_rdoc # Remove rdoc products
34
+ rake gem # Build the gem file gem-this-0.1.0.gem
35
+ rake package # Build all the packages
36
+ rake rdoc # Build the rdoc HTML Files
37
+ rake repackage # Force a rebuild of the package files
38
+ rake rerdoc # Force a rebuild of the RDOC files
39
+ rake rubyforge:release # Release gem and RDoc documentation to RubyForge
40
+ rake rubyforge:release:docs # Publish RDoc to RubyForge.
41
+
42
+
43
+ The simplest thing to do next is simply run `rake package`:
44
+
45
+ mkdir -p pkg
46
+ Successfully built RubyGem
47
+ Name: my-project
48
+ Version: 0.1.0
49
+ File: my-project-0.1.0.gem
50
+ mv my-project-0.1.0.gem pkg/my-project-0.1.0.gem
51
+
52
+ As you can tell, it's used the current directory name as the name of the gem. But, you can change any of that. Just open your `Rakefile` and edit the details.
53
+
54
+ It tries to be a little bit clever, detecting the presence of a few directories (like `bin`, `test` and `spec`) and behave accordingly. If you're already using git, it will ignore the `rdoc` and `pkg` directories for you.
55
+
56
+ What next?
57
+ ----------
58
+
59
+ For the most part, `gem-this` simply sets up a good base for you to customise yourself, with as little fuss or overhead as possible. It's up to you if you want make it more sophisticated, but I trust you.
60
+
61
+ Don't worry; you'll be fine.
62
+
63
+
64
+ Thanks
65
+ ======
66
+
67
+ Inspiration, and sometimes code chunks, were taking from lots of the existing gem tools, but particularly 'gemify' (wish I could've used that name!) and 'simple-gem'.
68
+
69
+
70
+ MIT License
71
+ ===========
72
+
73
+ (c) James Adam 2009, or whatever
74
+
75
+ Permission is hereby granted, free of charge, to any person obtaining a copy
76
+ of this software and associated documentation files (the "Software"), to deal
77
+ in the Software without restriction, including without limitation the rights
78
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
79
+ copies of the Software, and to permit persons to whom the Software is
80
+ furnished to do so, subject to the following conditions:
81
+
82
+ The above copyright notice and this permission notice shall be included in
83
+ all copies or substantial portions of the Software.
84
+
85
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
86
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
87
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
88
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
89
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
90
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
91
+ THE SOFTWARE.
data/bin/gem-this ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ args = ARGV.dup
4
+
5
+ if args.first =~ /-?-h/
6
+ puts "Creates a Rakefile suitable for turning the current project into a gem."
7
+ puts "Usage: #{__FILE__} [-d -h] [gem name]"
8
+ puts "If a gem name is not given, the name of the current directory will be used as the gem"
9
+ puts "-h help, prints out this message."
10
+ puts "-d debug, only prints out the generated Rakefile."
11
+ exit(0)
12
+ end
13
+
14
+ debug = args.delete("-d")
15
+
16
+ gem_name = args.first || File.basename(Dir.pwd)
17
+
18
+ def using_rspec?
19
+ File.directory?('spec')
20
+ end
21
+
22
+ def using_test_unit?
23
+ File.directory?('test')
24
+ end
25
+
26
+ def has_executables?
27
+ File.directory?('bin')
28
+ end
29
+
30
+ def dirs_to_include
31
+ %w(bin test spec lib).select { |d| File.directory?(d) }.join(",")
32
+ end
33
+
34
+ def readme
35
+ Dir['*'].find { |f| f =~ /readme/i }
36
+ end
37
+
38
+ def files_in_root
39
+ Dir['*'].reject { |f| File.directory?(f) }.join(" ")
40
+ end
41
+
42
+ def using_git?
43
+ File.exist?(".git")
44
+ end
45
+
46
+ def add_to_gitignore
47
+ ignores = File.readlines(".gitignore") if File.exist?(".gitignore")
48
+ ignores += ["pkg", "rdoc"]
49
+ File.open(".gitignore", "w") { |f| f.write ignores.map { |l| l.strip }.uniq.join("\n") }
50
+ end
51
+
52
+ require 'erb'
53
+
54
+ template = ERB.new File.read(File.join(File.dirname(__FILE__), '..', 'Rakefile.erb')), nil, '<>'
55
+ rakefile = template.result(binding)
56
+
57
+ if debug
58
+ puts rakefile
59
+ exit(0)
60
+ else
61
+ if File.exist?('Rakefile')
62
+ puts "Appended to existing Rakefile"
63
+ File.open('Rakefile', 'a') { |f| 2.times { f.puts }; f.write rakefile }
64
+ else
65
+ puts "Writing new Rakefile"
66
+ File.open('Rakefile', 'w') { |f| f.write rakefile }
67
+ end
68
+ add_to_gitignore if using_git?
69
+ end
70
+
71
+ exit(0)
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-this
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - James Adam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-08 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: james@lazyatom.com
18
+ executables:
19
+ - gem-this
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - Rakefile
26
+ - Readme.markdown
27
+ - Rakefile.erb
28
+ - bin/gem-this
29
+ has_rdoc: true
30
+ homepage: http://github.com/lazyatom/gem-this
31
+ post_install_message:
32
+ rdoc_options: []
33
+
34
+ require_paths:
35
+ - bin
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0"
41
+ version:
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ requirements: []
49
+
50
+ rubyforge_project: gem-this
51
+ rubygems_version: 1.3.1
52
+ signing_key:
53
+ specification_version: 2
54
+ summary: Make existing code into a gem, without any fuss.
55
+ test_files: []
56
+