visionmedia-mygem 0.0.2

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.
Files changed (42) hide show
  1. data/History.rdoc +4 -0
  2. data/Manifest +40 -0
  3. data/README.rdoc +53 -0
  4. data/Rakefile +12 -0
  5. data/Todo.rdoc +23 -0
  6. data/bin/mygem +12 -0
  7. data/lib/mygem/commands/init.rb +29 -0
  8. data/lib/mygem/commands.rb +2 -0
  9. data/lib/mygem/template.rb +124 -0
  10. data/lib/mygem/templates/exceptions.rb +18 -0
  11. data/lib/mygem/templates/init.rb +2 -0
  12. data/lib/mygem/version.rb +4 -0
  13. data/lib/mygem.rb +30 -0
  14. data/my-test-gem/README.rdoc +29 -0
  15. data/my-test-gem/spec/spec_helper.rb +0 -0
  16. data/mygem.gemspec +39 -0
  17. data/spec/fixtures/_replace_tokens.rb +4 -0
  18. data/spec/fixtures/foo/GEM/GEM_something.rb +1 -0
  19. data/spec/fixtures/foo/bar/cookies.rb +1 -0
  20. data/spec/mygem_spec.rb +96 -0
  21. data/spec/spec_helper.rb +15 -0
  22. data/tasks/docs.rake +13 -0
  23. data/tasks/gemspec.rake +3 -0
  24. data/tasks/mygem.rake +32 -0
  25. data/tasks/spec.rake +25 -0
  26. data/templates/default/History.rdoc +4 -0
  27. data/templates/default/README.rdoc +29 -0
  28. data/templates/default/Rakefile +15 -0
  29. data/templates/default/Todo.rdoc +12 -0
  30. data/templates/default/lib/GEM/version.rb +7 -0
  31. data/templates/default/lib/GEM.rb +26 -0
  32. data/templates/default/spec/GEM_spec.rb +0 -0
  33. data/templates/default/spec/spec_helper.rb +0 -0
  34. data/templates/default/tasks/docs.rake +13 -0
  35. data/templates/default/tasks/gemspec.rake +3 -0
  36. data/templates/default/tasks/spec.rake +25 -0
  37. data/templates/small/History.rdoc +4 -0
  38. data/templates/small/README.rdoc +33 -0
  39. data/templates/small/Rakefile +10 -0
  40. data/templates/small/lib/GEM/version.rb +7 -0
  41. data/templates/small/lib/GEM.rb +26 -0
  42. metadata +129 -0
data/History.rdoc ADDED
@@ -0,0 +1,4 @@
1
+
2
+ === 0.0.1 / 2009-02-25
3
+
4
+ * Initial release
data/Manifest ADDED
@@ -0,0 +1,40 @@
1
+ bin/mygem
2
+ History.rdoc
3
+ lib/mygem/commands/init.rb
4
+ lib/mygem/commands.rb
5
+ lib/mygem/template.rb
6
+ lib/mygem/templates/exceptions.rb
7
+ lib/mygem/templates/init.rb
8
+ lib/mygem/version.rb
9
+ lib/mygem.rb
10
+ Manifest
11
+ my-test-gem/README.rdoc
12
+ my-test-gem/spec/spec_helper.rb
13
+ Rakefile
14
+ README.rdoc
15
+ spec/fixtures/_replace_tokens.rb
16
+ spec/fixtures/foo/bar/cookies.rb
17
+ spec/fixtures/foo/GEM/GEM_something.rb
18
+ spec/mygem_spec.rb
19
+ spec/spec_helper.rb
20
+ tasks/docs.rake
21
+ tasks/gemspec.rake
22
+ tasks/mygem.rake
23
+ tasks/spec.rake
24
+ templates/default/History.rdoc
25
+ templates/default/lib/GEM/version.rb
26
+ templates/default/lib/GEM.rb
27
+ templates/default/Rakefile
28
+ templates/default/README.rdoc
29
+ templates/default/spec/GEM_spec.rb
30
+ templates/default/spec/spec_helper.rb
31
+ templates/default/tasks/docs.rake
32
+ templates/default/tasks/gemspec.rake
33
+ templates/default/tasks/spec.rake
34
+ templates/default/Todo.rdoc
35
+ templates/small/History.rdoc
36
+ templates/small/lib/GEM/version.rb
37
+ templates/small/lib/GEM.rb
38
+ templates/small/Rakefile
39
+ templates/small/README.rdoc
40
+ Todo.rdoc
data/README.rdoc ADDED
@@ -0,0 +1,53 @@
1
+
2
+ = MyGem
3
+
4
+ Rubygem generation, done YOUR way. Utilize and customize
5
+ gem templates for tiny, medium, or large gems.
6
+
7
+ == Features:
8
+
9
+ * Use default templates
10
+ * Create your own templates (or customize the copied defaults to suit your liking)
11
+ * Use placeholders in directory names and file contents (GEM_NAME, GEM_AUTHOR, GEM_DESCRIPTION, etc)
12
+
13
+ == Examples:
14
+
15
+ # Creates a new 'large' gem template for 'gemname'
16
+ $ mygem init gemname --template large
17
+
18
+ # Creates a default template for 'yummy-cookies' specifying some gem options
19
+ $ mygem init yummy-cookies \
20
+ --author 'TJ Holowaychuk' \
21
+ --email 'tj@vision-media.ca' \
22
+ --description 'Does some stuff with yummy cookies'
23
+
24
+ == Templates:
25
+
26
+ Gem templates are located within ~/.mygem/templates. This allows
27
+ you to customize the default templates as you like. Currently ships
28
+ with only the 'default', and 'small' templates.
29
+
30
+ == License:
31
+
32
+ (The MIT License)
33
+
34
+ Copyright (c) 2008 TJ Holowaychuk
35
+
36
+ Permission is hereby granted, free of charge, to any person obtaining
37
+ a copy of this software and associated documentation files (the
38
+ 'Software'), to deal in the Software without restriction, including
39
+ without limitation the rights to use, copy, modify, merge, publish,
40
+ distribute, sublicense, and/or sell copies of the Software, and to
41
+ permit persons to whom the Software is furnished to do so, subject to
42
+ the following conditions:
43
+
44
+ The above copyright notice and this permission notice shall be
45
+ included in all copies or substantial portions of the Software.
46
+
47
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
48
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
50
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
51
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
52
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
53
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+
2
+ %w[ rubygems rake echoe ./lib/mygem.rb ].each { |dep| require dep }
3
+
4
+ Echoe.new("mygem", MyGem::VERSION) do |p|
5
+ p.author = "TJ Holowaychuk"
6
+ p.email = "tj@vision-media.ca"
7
+ p.summary = "Rubygem generation, done YOUR way."
8
+ p.url = "http://github.com/visionmedia/mygem"
9
+ p.runtime_dependencies = ["facets", "visionmedia-commander >=2.1.1"]
10
+ end
11
+
12
+ Dir['tasks/**/*.rake'].sort.each { |f| load f }
data/Todo.rdoc ADDED
@@ -0,0 +1,23 @@
1
+
2
+ == Major:
3
+
4
+ * Fix stupid replacement buGGG-a-saurous
5
+ * Do not build ri and rdoc when installing gem... to slow! option?
6
+ * Support for TextMate's Command + R for running specs in default templates
7
+ * Remove commander and see if dependency works... (how to add github source in Rakefile?)
8
+ * rake docs <---+
9
+ * rake docs:read | Do this? remove description for echoe's tasks so they do not show up
10
+ * rake docs:publish <---+
11
+ * rake notes
12
+ * rake notes:todo <---
13
+ * rake notes:fixme |
14
+ * rake notes:optimize | Add these to all templates
15
+ * rake misc:stats <-- basic stats, somewhat like rails or require San within the rake task
16
+ * gemspec / manifest / version / history / <--- task for this routine
17
+
18
+ == Minor:
19
+
20
+ * Add support for GEM anywhere in the file or dirname
21
+ * Come up with large template ... nested spec like rails with functional, integration, etc.. more rake tasks
22
+ * Add subcommand like mygem merge <file> --template TEMPLATE which will add any recent changes you made
23
+ * Clean up spec...
data/bin/mygem ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander'
5
+ require 'mygem'
6
+
7
+ program :name, 'mygem'
8
+ program :version, MyGem::VERSION::STRING
9
+ program :description, 'Rubygem generation, done your way.'
10
+
11
+ require 'mygem/templates/init'
12
+ require 'mygem/commands'
@@ -0,0 +1,29 @@
1
+
2
+ command :init do |c|
3
+ c.syntax = 'mygem init <gem_name> [options]'
4
+ c.summary = 'Initialize a rubygem template'
5
+ c.description = 'Initialize a rubygem template. Available templates: %s' % MyGem::Templates.list.join(', ')
6
+ c.example "Create the 'coolgem' gem default template", 'mygem init coolgem'
7
+ c.example "Create the 'coolgem' gem using the large template", 'mygem init coolgem --template large'
8
+ c.option '--template NAME', 'Specify the template to use'
9
+ c.option '--author NAME', 'Author of this gem'
10
+ c.option '--email EMAIL', 'Authors email'
11
+ c.option '--description DESCRIPTION', 'Gem description'
12
+ c.option '--url URI', 'This gems url'
13
+
14
+ c.when_called do |args, options|
15
+ abort "provide a gem name." if args.empty?
16
+ begin
17
+ gemname = args.shift
18
+ options.name = gemname
19
+ options.class = gemname.camelcase
20
+ dest = File.expand_path gemname
21
+ source = File.join(MyGem::Templates.path(options.template || :default), ".")
22
+ mkdir dest
23
+ cp_r source, dest
24
+ MyGem::Templates.replace_tokens_with_struct Dir["#{dest}/**/*"], options
25
+ rescue Exception => e
26
+ abort "Error: #{e}"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,2 @@
1
+
2
+ require 'mygem/commands/init'
@@ -0,0 +1,124 @@
1
+
2
+ require 'fileutils'
3
+ require 'mygem/templates/exceptions'
4
+
5
+ module MyGem
6
+ module Templates
7
+
8
+ include FileUtils
9
+
10
+ ##
11
+ # Path to ~/.mygem directory.
12
+
13
+ DEST = File.join ENV['HOME'], ".mygem"
14
+
15
+ ##
16
+ # Path to mygem's templates.
17
+
18
+ SOURCE = File.expand_path File.join(MYGEM_ROOT, "..", "templates")
19
+
20
+ class << self
21
+
22
+ ##
23
+ # Ensure that the templates are available for customization within
24
+ # the developers HOME directory, and within the .mygem directory. This
25
+ # is only attempted the initial time, since the user may have already made
26
+ # customizations.
27
+
28
+ def init
29
+ unless File.directory? DEST
30
+ mkdir DEST
31
+ cp_r SOURCE, DEST
32
+ end
33
+ end
34
+
35
+ ##
36
+ # Check if the .mygem directory has been initialized.
37
+
38
+ def initialized?
39
+ File.directory? DEST
40
+ end
41
+
42
+ ##
43
+ # Build _template_ path conditionally from users .mygem
44
+ # directory or the mygem defaults.
45
+
46
+ def path template
47
+ template = template.to_s
48
+ user_dir = File.join DEST, "templates", template
49
+ lib_dir = File.join SOURCE, template
50
+ return user_dir if File.directory? user_dir
51
+ return lib_dir if File.directory? lib_dir
52
+ raise NoTemplateError, template, caller
53
+ end
54
+
55
+ ##
56
+ # Return array of valid template names.
57
+
58
+ def available_templates
59
+ user_templates = Dir["#{DEST}/templates/*"].collect &File.method(:basename)
60
+ lib_templates = Dir["#{SOURCE}/*"].collect &File.method(:basename)
61
+ user_templates | lib_templates
62
+ end
63
+ alias :list :available_templates
64
+
65
+ ##
66
+ # Replace gem tokens of _input_ with _struct_ attributes.
67
+ # This method performs the following operations:
68
+ #
69
+ # * When _input_ is a string, simply replaces tokens
70
+ # * When _input_ is a file, replaces its contents with tokenized version
71
+ # * When _input_ is array it is considered a list of files and directories to replace
72
+ # * Files and dirs named ^GEM replace GEM with the gem name (struct.name)
73
+ #
74
+
75
+ def replace_tokens_with_struct input, struct
76
+ prefix = "GEM"
77
+ token = /^#{prefix}(.*)/
78
+
79
+ # Build destination path; rename files beginning with GEM
80
+ dest = lambda { File.join(File.dirname(input), "#{struct.name}#{$1}") }
81
+
82
+ # Move input to destination
83
+ move = lambda { mv input, dest.call, :force => true if File.basename(input).match token }
84
+
85
+ # Iterate and replace all files or directories
86
+ replace_list = lambda { |a| a.each { |f| replace_tokens_with_struct f, struct } }
87
+
88
+ # Replace string tokens
89
+ replace_string = lambda {
90
+ i = input.dup
91
+ h = struct.instance_eval { @table }
92
+ h.each_pair { |k, v| i.gsub! "#{prefix}_#{k.to_s.upcase}", v }
93
+ i
94
+ }
95
+
96
+ # Replace a single file's contents
97
+ replace_file_contents = lambda {
98
+ contents = File.read input
99
+ File.open(input, "r+") do |f|
100
+ f.write replace_tokens_with_struct(contents, struct)
101
+ end
102
+ move.call
103
+ }
104
+
105
+ # Replace files before directories so that our queue is not stale
106
+ # and trying to replace files that do not exist
107
+ replace_files_then_dirs = lambda {
108
+ dirs = input.select { |f| File.directory? f }
109
+ files = input - dirs
110
+ replace_list.call files
111
+ replace_list.call dirs
112
+ }
113
+
114
+ case
115
+ when input.is_a?(Array) : replace_files_then_dirs.call
116
+ when File.directory?(input) : move.call
117
+ when File.file?(input) : replace_file_contents.call
118
+ else replace_string.call
119
+ end
120
+ end
121
+
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,18 @@
1
+
2
+ module MyGem
3
+ module Templates
4
+
5
+ #--
6
+ # No template error
7
+ #++
8
+
9
+ class NoTemplateError < StandardError
10
+ attr_accessor :template
11
+ def initialize template
12
+ @template = template
13
+ super "Template '#{template}' not found"
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,2 @@
1
+
2
+ MyGem::Templates.init
@@ -0,0 +1,4 @@
1
+
2
+ module MyGem
3
+ VERSION = '0.0.2'
4
+ end
data/lib/mygem.rb ADDED
@@ -0,0 +1,30 @@
1
+ #--
2
+ # Copyright (c) 2008 TJ Holowaychuk
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ MYGEM_ROOT = File.dirname(__FILE__)
25
+ $:.unshift MYGEM_ROOT
26
+
27
+ require 'rubygems'
28
+ require 'facets/string'
29
+ require 'mygem/version'
30
+ require 'mygem/template'
@@ -0,0 +1,29 @@
1
+
2
+ = my-test-gem
3
+
4
+ just a description of stuff
5
+
6
+ == License:
7
+
8
+ (The MIT License)
9
+
10
+ Copyright (c) 2008 TJ
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining
13
+ a copy of this software and associated documentation files (the
14
+ 'Software'), to deal in the Software without restriction, including
15
+ without limitation the rights to use, copy, modify, merge, publish,
16
+ distribute, sublicense, an d/or sell copies of the Software, and to
17
+ permit persons to whom the Software is furnished to do so, subject to
18
+ the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be
21
+ included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
24
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File without changes
data/mygem.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{mygem}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["TJ Holowaychuk"]
9
+ s.date = %q{2009-03-05}
10
+ s.default_executable = %q{mygem}
11
+ s.description = %q{Rubygem generation, done YOUR way.}
12
+ s.email = %q{tj@vision-media.ca}
13
+ s.executables = ["mygem"]
14
+ s.extra_rdoc_files = ["bin/mygem", "lib/mygem/commands/init.rb", "lib/mygem/commands.rb", "lib/mygem/template.rb", "lib/mygem/templates/exceptions.rb", "lib/mygem/templates/init.rb", "lib/mygem/version.rb", "lib/mygem.rb", "README.rdoc", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/mygem.rake", "tasks/spec.rake"]
15
+ s.files = ["bin/mygem", "History.rdoc", "lib/mygem/commands/init.rb", "lib/mygem/commands.rb", "lib/mygem/template.rb", "lib/mygem/templates/exceptions.rb", "lib/mygem/templates/init.rb", "lib/mygem/version.rb", "lib/mygem.rb", "Manifest", "my-test-gem/README.rdoc", "my-test-gem/spec/spec_helper.rb", "Rakefile", "README.rdoc", "spec/fixtures/_replace_tokens.rb", "spec/fixtures/foo/bar/cookies.rb", "spec/fixtures/foo/GEM/GEM_something.rb", "spec/mygem_spec.rb", "spec/spec_helper.rb", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/mygem.rake", "tasks/spec.rake", "templates/default/History.rdoc", "templates/default/lib/GEM/version.rb", "templates/default/lib/GEM.rb", "templates/default/Rakefile", "templates/default/README.rdoc", "templates/default/spec/GEM_spec.rb", "templates/default/spec/spec_helper.rb", "templates/default/tasks/docs.rake", "templates/default/tasks/gemspec.rake", "templates/default/tasks/spec.rake", "templates/default/Todo.rdoc", "templates/small/History.rdoc", "templates/small/lib/GEM/version.rb", "templates/small/lib/GEM.rb", "templates/small/Rakefile", "templates/small/README.rdoc", "Todo.rdoc", "mygem.gemspec"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://github.com/visionmedia/mygem}
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Mygem", "--main", "README.rdoc"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{mygem}
21
+ s.rubygems_version = %q{1.3.1}
22
+ s.summary = %q{Rubygem generation, done YOUR way.}
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 2
27
+
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ s.add_runtime_dependency(%q<facets>, [">= 0"])
30
+ s.add_runtime_dependency(%q<visionmedia-commander>, [">= 2.1.1"])
31
+ else
32
+ s.add_dependency(%q<facets>, [">= 0"])
33
+ s.add_dependency(%q<visionmedia-commander>, [">= 2.1.1"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<facets>, [">= 0"])
37
+ s.add_dependency(%q<visionmedia-commander>, [">= 2.1.1"])
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ require 'cookies-are-cool'
2
+ require 'cookies-are-cool/version'
3
+ mod CookiesAreCool
4
+ end
@@ -0,0 +1 @@
1
+ require 'GEM_NAME/something'
@@ -0,0 +1 @@
1
+ class GEM_CLASS; end
@@ -0,0 +1,96 @@
1
+
2
+ describe MyGem do
3
+
4
+ it "should copy templates to the users home directory" do
5
+ MyGem::Templates.init
6
+ MyGem::Templates.initialized?.should be_true
7
+ end
8
+
9
+ it "should raise error when fetching path for non-existant template" do
10
+ lambda { MyGem::Templates.path :does_not_exist }.should raise_error(MyGem::Templates::NoTemplateError)
11
+ end
12
+
13
+ it "should generate paths to templates" do
14
+ MyGem::Templates.path(:default).should eql("#{ENV["HOME"]}/.mygem/templates/default")
15
+ end
16
+
17
+ it "should replace GEM_* tokens in strings" do
18
+ struct = OpenStruct.new
19
+ struct.name = "mygem"
20
+ struct.author = "TJ Holowaychuk"
21
+ struct.class = "some-gem-name".camelcase
22
+ string = MyGem::Templates.replace_tokens_with_struct "'GEM_NAME', :GEM_AUTHOR, [GEM_CLASS], 'GEM_NAME/version'", struct
23
+ string.should eql("'mygem', :TJ Holowaychuk, [SomeGemName], 'mygem/version'")
24
+ end
25
+
26
+ it "should replace GEM_* tokens in files" do
27
+ struct = OpenStruct.new
28
+ struct.name = "cookies-are-cool"
29
+ struct.class = struct.name.camelcase
30
+ file = create_file_for_replace_tokens_with_struct
31
+ MyGem::Templates.replace_tokens_with_struct file, struct
32
+ File.read(file).should == <<-"end;"
33
+ require 'cookies-are-cool'
34
+ require 'cookies-are-cool/version'
35
+ mod CookiesAreCool
36
+ end
37
+ end;
38
+ end
39
+
40
+ it "should rename files prefixed with GEM" do
41
+ struct = OpenStruct.new
42
+ struct.name = "cookies"
43
+ oldfile = File.join(File.dirname(__FILE__), "fixtures", "GEM.rb")
44
+ newfile = File.join(File.dirname(__FILE__), "fixtures", "cookies.rb")
45
+ FileUtils.touch oldfile
46
+ MyGem::Templates.replace_tokens_with_struct oldfile, struct
47
+ File.file?(newfile).should be_true
48
+ FileUtils.rm newfile
49
+ end
50
+
51
+ it "should rename directories prefixed with GEM" do
52
+ struct = OpenStruct.new
53
+ struct.name = "cookies"
54
+ olddir = File.join(File.dirname(__FILE__), "fixtures", "GEM_something")
55
+ newdir = File.join(File.dirname(__FILE__), "fixtures", "cookies_something")
56
+ FileUtils.mkdir olddir
57
+ MyGem::Templates.replace_tokens_with_struct olddir, struct
58
+ File.directory?(newdir).should be_true
59
+ FileUtils.rmdir newdir
60
+ end
61
+
62
+ it "should traverse directories in order to perform replacements" do
63
+ begin
64
+ # TODO: clean me!!! rawr
65
+ struct = OpenStruct.new
66
+ struct.name = "cookies"
67
+ struct.class = "cookies".camelcase
68
+ dir = File.join(File.dirname(__FILE__), "fixtures", "foo")
69
+ olddir = File.join(File.dirname(__FILE__), "fixtures", "foo", "GEM")
70
+ newdir = File.join(File.dirname(__FILE__), "fixtures", "foo", "cookies")
71
+ oldfile = File.join(File.dirname(__FILE__), "fixtures", "foo", "GEM", "GEM_something.rb")
72
+ newfile = File.join(File.dirname(__FILE__), "fixtures", "foo", "cookies", "cookies_something.rb")
73
+ regfile = File.join(File.dirname(__FILE__), "fixtures", "foo", "bar", "cookies.rb")
74
+ files = Dir["#{dir}/**/*"]
75
+ MyGem::Templates.replace_tokens_with_struct files, struct
76
+ File.directory?(newdir).should be_true
77
+ File.file?(newfile).should be_true
78
+ File.read(regfile).should eql("class Cookies; end")
79
+ File.read(newfile).should eql("require 'cookies/something'")
80
+ ensure
81
+ if File.directory? dir
82
+ FileUtils.rm_rf dir + "/."
83
+ FileUtils.rmdir dir
84
+ end
85
+ FileUtils.mkdir_p File.join(dir, "bar")
86
+ FileUtils.mkdir File.join(dir, "GEM")
87
+ File.open(File.join(dir, "bar", "cookies.rb"), 'w+') do |f|
88
+ f.write "class GEM_CLASS; end"
89
+ end
90
+ File.open(File.join(dir, "GEM", "GEM_something.rb"), 'w+') do |f|
91
+ f.write "require 'GEM_NAME/something'"
92
+ end
93
+ end
94
+ end
95
+
96
+ end
@@ -0,0 +1,15 @@
1
+
2
+ %w( mygem fileutils ostruct ).each { |dep| require dep }
3
+
4
+ def create_file_for_replace_tokens_with_struct
5
+ file = File.join(File.dirname(__FILE__), "fixtures", "_replace_tokens.rb")
6
+ File.open(file, "w+") do |f|
7
+ f.write <<-"end;"
8
+ require 'GEM_NAME'
9
+ require 'GEM_NAME/version'
10
+ mod GEM_CLASS
11
+ end
12
+ end;
13
+ end
14
+ file
15
+ end
data/tasks/docs.rake ADDED
@@ -0,0 +1,13 @@
1
+
2
+ namespace :docs do
3
+
4
+ desc 'Remove rdoc products'
5
+ task :remove => [:clobber_docs]
6
+
7
+ desc 'Build docs, and open in browser for viewing (specify BROWSER)'
8
+ task :open => [:docs] do
9
+ browser = ENV["BROWSER"] || "safari"
10
+ sh "open -a #{browser} doc/index.html"
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+
2
+ desc 'Build gemspec file'
3
+ task :gemspec => [:build_gemspec]
data/tasks/mygem.rake ADDED
@@ -0,0 +1,32 @@
1
+
2
+ namespace :mygem do
3
+
4
+ desc 'Initialize gem template test as my-gem-name (specify TEMPLATE)'
5
+ task :test => [:install, :remove, :uninstall] do
6
+ sh %(mygem init my-test-gem \
7
+ --template #{ENV["TEMPLATE"]} \
8
+ --author 'TJ' \
9
+ --email 'tj@vision-media.ca' \
10
+ --description 'just a description of stuff' \
11
+ --url 'http://test.com')
12
+ end
13
+
14
+ desc 'Remove installation of templates to ~/.mygem'
15
+ task :uninstall do
16
+ d = File.join ENV["HOME"], ".mygem"
17
+ if File.directory? d
18
+ rm_rf File.join(d, ".")
19
+ rmdir d
20
+ end
21
+ end
22
+
23
+ desc 'Remove product of gem template test'
24
+ task :remove do
25
+ d = "my-test-gem"
26
+ if File.directory? d
27
+ rm_rf File.join(d, ".")
28
+ rmdir d
29
+ end
30
+ end
31
+
32
+ end
data/tasks/spec.rake ADDED
@@ -0,0 +1,25 @@
1
+
2
+ require 'spec/rake/spectask'
3
+
4
+ desc "Run all specifications"
5
+ Spec::Rake::SpecTask.new(:spec) do |t|
6
+ t.libs << "lib"
7
+ t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
8
+ end
9
+
10
+ namespace :spec do
11
+
12
+ desc "Run all specifications verbosely"
13
+ Spec::Rake::SpecTask.new(:verbose) do |t|
14
+ t.libs << "lib"
15
+ t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
16
+ end
17
+
18
+ desc "Run specific specification verbosely (specify SPEC)"
19
+ Spec::Rake::SpecTask.new(:select) do |t|
20
+ t.libs << "lib"
21
+ t.spec_files = [ENV["SPEC"]]
22
+ t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
23
+ end
24
+
25
+ end
@@ -0,0 +1,4 @@
1
+
2
+ === 0.0.1 / YYYY-MM-DD
3
+
4
+ * Initial release
@@ -0,0 +1,29 @@
1
+
2
+ = GEM_NAME
3
+
4
+ GEM_DESCRIPTION
5
+
6
+ == License:
7
+
8
+ (The MIT License)
9
+
10
+ Copyright (c) 2009 GEM_AUTHOR <GEM_EMAIL>
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining
13
+ a copy of this software and associated documentation files (the
14
+ 'Software'), to deal in the Software without restriction, including
15
+ without limitation the rights to use, copy, modify, merge, publish,
16
+ distribute, sublicense, an d/or sell copies of the Software, and to
17
+ permit persons to whom the Software is furnished to do so, subject to
18
+ the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be
21
+ included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
24
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'echoe'
5
+ require './lib/GEM_NAME.rb'
6
+
7
+ Echoe.new("GEM_NAME", GEM_CLASS::VERSION::STRING) do |p|
8
+ p.author = "GEM_AUTHOR"
9
+ p.email = "GEM_EMAIL"
10
+ p.summary = "GEM_DESCRIPTION"
11
+ p.url = "GEM_URL"
12
+ p.runtime_dependencies = []
13
+ end
14
+
15
+ Dir['tasks/**/*.rake'].sort.each { |f| load f }
@@ -0,0 +1,12 @@
1
+
2
+ == Major:
3
+
4
+ * Nothing
5
+
6
+ == Minor:
7
+
8
+ * Nothing
9
+
10
+ == Brainstorming:
11
+
12
+ * Nothing
@@ -0,0 +1,7 @@
1
+
2
+ module GEM_CLASS
3
+ module VERSION #:nodoc:
4
+ MAJOR, MINOR, TINY = [0, 0, 1]
5
+ STRING = [MAJOR, MINOR, TINY].join '.'
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2008 GEM_AUTHOR
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ $:.unshift File.dirname(__FILE__)
25
+
26
+ require 'GEM_NAME/version'
File without changes
File without changes
@@ -0,0 +1,13 @@
1
+
2
+ namespace :docs do
3
+
4
+ desc 'Remove rdoc products'
5
+ task :remove => [:clobber_docs]
6
+
7
+ desc 'Build docs, and open in browser for viewing (specify BROWSER)'
8
+ task :open do
9
+ browser = ENV["BROWSER"] || "safari"
10
+ sh "open -a #{browser} doc/index.html"
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+
2
+ desc 'Build gemspec file'
3
+ task :gemspec => [:build_gemspec]
@@ -0,0 +1,25 @@
1
+
2
+ require 'spec/rake/spectask'
3
+
4
+ desc "Run all specifications"
5
+ Spec::Rake::SpecTask.new(:spec) do |t|
6
+ t.libs << "lib"
7
+ t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
8
+ end
9
+
10
+ namespace :spec do
11
+
12
+ desc "Run all specifications verbosely"
13
+ Spec::Rake::SpecTask.new(:verbose) do |t|
14
+ t.libs << "lib"
15
+ t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
16
+ end
17
+
18
+ desc "Run specific specification verbosely (specify SPEC)"
19
+ Spec::Rake::SpecTask.new(:select) do |t|
20
+ t.libs << "lib"
21
+ t.spec_files = [ENV["SPEC"]]
22
+ t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
23
+ end
24
+
25
+ end
@@ -0,0 +1,4 @@
1
+
2
+ === 0.0.1 / YYYY-MM-DD
3
+
4
+ * Initial release
@@ -0,0 +1,33 @@
1
+
2
+ = GEM_NAME
3
+
4
+ GEM_DESCRIPTION
5
+
6
+ == Todo:
7
+
8
+ * Nothing
9
+
10
+ == License:
11
+
12
+ (The MIT License)
13
+
14
+ Copyright (c) 2008 GEM_AUTHOR
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining
17
+ a copy of this software and associated documentation files (the
18
+ 'Software'), to deal in the Software without restriction, including
19
+ without limitation the rights to use, copy, modify, merge, publish,
20
+ distribute, sublicense, an d/or sell copies of the Software, and to
21
+ permit persons to whom the Software is furnished to do so, subject to
22
+ the following conditions:
23
+
24
+ The above copyright notice and this permission notice shall be
25
+ included in all copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
28
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
30
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
31
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
32
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
33
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,10 @@
1
+
2
+ %w( rubygems rake echoe ./lib/GEM_NAME.rb ).each { |lib| require lib }
3
+
4
+ Echoe.new("GEM_NAME", GEM_CLASS::VERSION::STRING) do |p|
5
+ p.author = "GEM_AUTHOR"
6
+ p.email = "GEM_EMAIL"
7
+ p.summary = "GEM_DESCRIPTION"
8
+ p.url = "GEM_URL"
9
+ p.runtime_dependencies = []
10
+ end
@@ -0,0 +1,7 @@
1
+
2
+ module GEM_CLASS
3
+ module VERSION #:nodoc:
4
+ MAJOR, MINOR, TINY = [0, 0, 1]
5
+ STRING = [MAJOR, MINOR, TINY].join '.'
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2008 GEM_AUTHOR
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ $:.unshift File.dirname(__FILE__)
25
+
26
+ %w( GEM_NAME/version ).each { |lib| require lib }
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: visionmedia-mygem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - TJ Holowaychuk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-05 00:00:00 -08:00
13
+ default_executable: mygem
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: facets
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: visionmedia-commander
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.1
34
+ version:
35
+ description: Rubygem generation, done YOUR way.
36
+ email: tj@vision-media.ca
37
+ executables:
38
+ - mygem
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - bin/mygem
43
+ - lib/mygem/commands/init.rb
44
+ - lib/mygem/commands.rb
45
+ - lib/mygem/template.rb
46
+ - lib/mygem/templates/exceptions.rb
47
+ - lib/mygem/templates/init.rb
48
+ - lib/mygem/version.rb
49
+ - lib/mygem.rb
50
+ - README.rdoc
51
+ - tasks/docs.rake
52
+ - tasks/gemspec.rake
53
+ - tasks/mygem.rake
54
+ - tasks/spec.rake
55
+ files:
56
+ - bin/mygem
57
+ - History.rdoc
58
+ - lib/mygem/commands/init.rb
59
+ - lib/mygem/commands.rb
60
+ - lib/mygem/template.rb
61
+ - lib/mygem/templates/exceptions.rb
62
+ - lib/mygem/templates/init.rb
63
+ - lib/mygem/version.rb
64
+ - lib/mygem.rb
65
+ - Manifest
66
+ - my-test-gem/README.rdoc
67
+ - my-test-gem/spec/spec_helper.rb
68
+ - Rakefile
69
+ - README.rdoc
70
+ - spec/fixtures/_replace_tokens.rb
71
+ - spec/fixtures/foo/bar/cookies.rb
72
+ - spec/fixtures/foo/GEM/GEM_something.rb
73
+ - spec/mygem_spec.rb
74
+ - spec/spec_helper.rb
75
+ - tasks/docs.rake
76
+ - tasks/gemspec.rake
77
+ - tasks/mygem.rake
78
+ - tasks/spec.rake
79
+ - templates/default/History.rdoc
80
+ - templates/default/lib/GEM/version.rb
81
+ - templates/default/lib/GEM.rb
82
+ - templates/default/Rakefile
83
+ - templates/default/README.rdoc
84
+ - templates/default/spec/GEM_spec.rb
85
+ - templates/default/spec/spec_helper.rb
86
+ - templates/default/tasks/docs.rake
87
+ - templates/default/tasks/gemspec.rake
88
+ - templates/default/tasks/spec.rake
89
+ - templates/default/Todo.rdoc
90
+ - templates/small/History.rdoc
91
+ - templates/small/lib/GEM/version.rb
92
+ - templates/small/lib/GEM.rb
93
+ - templates/small/Rakefile
94
+ - templates/small/README.rdoc
95
+ - Todo.rdoc
96
+ - mygem.gemspec
97
+ has_rdoc: true
98
+ homepage: http://github.com/visionmedia/mygem
99
+ post_install_message:
100
+ rdoc_options:
101
+ - --line-numbers
102
+ - --inline-source
103
+ - --title
104
+ - Mygem
105
+ - --main
106
+ - README.rdoc
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: "0"
114
+ version:
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: "1.2"
120
+ version:
121
+ requirements: []
122
+
123
+ rubyforge_project: mygem
124
+ rubygems_version: 1.2.0
125
+ signing_key:
126
+ specification_version: 2
127
+ summary: Rubygem generation, done YOUR way.
128
+ test_files: []
129
+