minigen 0.0.1 → 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.
- data/README.md +14 -2
- data/bin/mgen +1 -1
- data/lib/minigen.rb +1 -3
- data/lib/minigen.rb~ +15 -0
- data/lib/minigen/generator.rb +44 -10
- data/lib/minigen/generator.rb~ +89 -0
- data/lib/{template → templates/base}/README.md +0 -0
- data/lib/{template → templates/base}/lib/project.rb +0 -0
- data/lib/{template → templates/base}/project.gemspec +0 -0
- data/lib/templates/shoulda/helper.rb +6 -0
- data/lib/templates/shoulda/test_project.rb +7 -0
- data/lib/{template/test → templates/tsm}/test_helper.rb +0 -0
- data/lib/{template/test/project_test.rb → templates/tsm/test_project.rb} +0 -0
- data/test/minigen_test.rb +4 -0
- metadata +28 -31
data/README.md
CHANGED
@@ -40,7 +40,11 @@ a simple, markdown formatted, readme that contains some essential points (see pa
|
|
40
40
|
|
41
41
|
### test/test_helper.rb
|
42
42
|
|
43
|
-
|
43
|
+
For now supports only two test suites:
|
44
|
+
|
45
|
+
* [Shoulda](https://github.com/thoughtbot/shoulda)
|
46
|
+
|
47
|
+
* the **supercool** [defunkt's](http://github.com/defunkt) [test/spec/mini](https://gist.github.com/307649)
|
44
48
|
|
45
49
|
### test/project_test.rb
|
46
50
|
|
@@ -50,10 +54,18 @@ a failing test
|
|
50
54
|
synopsis
|
51
55
|
--------
|
52
56
|
|
53
|
-
|
57
|
+
This command _generates_ a _new project_ using **shoulda** as test suite.
|
58
|
+
|
59
|
+
$: mgen mycoolproject shoulda
|
54
60
|
|
55
61
|
>: - Generating your project: mycoolproject
|
56
62
|
|
63
|
+
If you want **test/spec/mini**:
|
64
|
+
|
65
|
+
$: mgen mynewproject tsm
|
66
|
+
|
67
|
+
** enjoy! **
|
68
|
+
|
57
69
|
license
|
58
70
|
-------
|
59
71
|
|
data/bin/mgen
CHANGED
data/lib/minigen.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
|
3
|
-
LIBDIR = File.dirname(__FILE__)
|
4
|
-
|
5
3
|
dir = File.dirname(File.expand_path(__FILE__))
|
6
4
|
$LOAD_PATH.unshift(File.join('minigen'))
|
7
5
|
$LOAD_PATH.unshift(dir)
|
@@ -10,6 +8,6 @@ require "minigen/generator"
|
|
10
8
|
|
11
9
|
module Minigen
|
12
10
|
|
13
|
-
VERSION = "0.0.
|
11
|
+
VERSION = "0.0.2"
|
14
12
|
|
15
13
|
end
|
data/lib/minigen.rb~
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
LIBDIR = File.dirname(__FILE__)
|
4
|
+
|
5
|
+
dir = File.dirname(File.expand_path(__FILE__))
|
6
|
+
$LOAD_PATH.unshift(File.join('minigen'))
|
7
|
+
$LOAD_PATH.unshift(dir)
|
8
|
+
|
9
|
+
require "minigen/generator"
|
10
|
+
|
11
|
+
module Minigen
|
12
|
+
|
13
|
+
VERSION = "0.0.2"
|
14
|
+
|
15
|
+
end
|
data/lib/minigen/generator.rb
CHANGED
@@ -1,32 +1,66 @@
|
|
1
1
|
module Minigen
|
2
2
|
|
3
|
+
# Really needed
|
4
|
+
LIBDIR = File.dirname(__FILE__)
|
5
|
+
|
3
6
|
# Various methods to create the project skel
|
4
7
|
class Generator
|
5
8
|
|
6
9
|
# Public: Initialize a new Project
|
7
|
-
def initialize
|
8
|
-
@
|
10
|
+
def initialize options = {}
|
11
|
+
@options = options
|
12
|
+
@name = @options[:name].downcase
|
13
|
+
|
14
|
+
# The test suite, abort if empty
|
15
|
+
# Note: this is stupid
|
16
|
+
if not @options[:test].nil?
|
17
|
+
@test = @options[:test]
|
18
|
+
else
|
19
|
+
abort "You must specify a test suite"
|
20
|
+
end
|
9
21
|
|
10
22
|
# Checks if a folder exists with the name @name
|
11
23
|
# if false, exits with a message
|
12
24
|
abort "A folder with that name already exists" if File.directory? @name
|
13
25
|
|
26
|
+
puts " - \033[32mGenerating\033[0m your project: #{@name}"
|
27
|
+
|
14
28
|
# Runs the method that copies the template
|
15
29
|
copy!
|
16
30
|
|
17
31
|
end
|
18
32
|
|
19
|
-
# Private: Copies the default template to @name dir
|
33
|
+
# Private: Copies the default template to @name dir,
|
34
|
+
# the chosen test suite, and runs gsub'n'rename
|
35
|
+
#
|
36
|
+
# Returns nothing
|
20
37
|
def copy!
|
21
|
-
|
38
|
+
# Create the project diretory
|
22
39
|
Dir.mkdir @name
|
23
|
-
|
40
|
+
|
41
|
+
# Copies the base template files (e.g. readme, gemspec, etc)
|
42
|
+
FileUtils.cp_r(Dir.glob(File.join(LIBDIR, "templates/base/*")), @name)
|
43
|
+
|
44
|
+
# Copies the test suite ( see @options[:test] )
|
45
|
+
FileUtils.cp_r(Dir.glob(File.join(LIBDIR, "templates/#{@test}/*")), "#{@name}/test/")
|
46
|
+
|
47
|
+
gnr!
|
48
|
+
end
|
49
|
+
|
50
|
+
# Private: gsub'n'rename
|
51
|
+
# Joins the new project directory,
|
52
|
+
# gsubs the content of all files with the new project name
|
53
|
+
# 'nd renames all
|
54
|
+
#
|
55
|
+
# Returns nothing
|
56
|
+
def gnr!
|
24
57
|
Dir.chdir @name
|
25
58
|
Dir.glob("**/*.{rb,md,gemspec}").each {|f| ore f, "project", @name}
|
26
59
|
Dir.glob("**/*.{rb,md,gemspec}").each {|f| ore f, "Project", @name.capitalize}
|
27
|
-
File.rename "test/
|
60
|
+
File.rename "test/test_project.rb", "test/test_#{@name}.rb"
|
28
61
|
File.rename "lib/project.rb", "lib/#{@name}.rb"
|
29
62
|
File.rename "project.gemspec", "#{@name}.gemspec"
|
63
|
+
puts " - done!"
|
30
64
|
end
|
31
65
|
|
32
66
|
# Private: Opens, Reads and Edits a file
|
@@ -42,17 +76,17 @@ module Minigen
|
|
42
76
|
#
|
43
77
|
# Returns True if everything went well :D
|
44
78
|
def ore file, old, new
|
45
|
-
o = File.read(file)
|
79
|
+
o = File.read(file)
|
80
|
+
o.gsub! /#{old}/, new
|
46
81
|
n = File.new(file, "w+")
|
47
82
|
n.puts(o)
|
48
83
|
n.close
|
49
84
|
return true
|
50
85
|
end
|
51
86
|
|
52
|
-
|
53
|
-
|
54
|
-
private :copy!, :ore
|
87
|
+
private :copy!, :gnr!, :ore
|
55
88
|
|
56
89
|
end #Generator
|
57
90
|
|
58
91
|
end #Minigen
|
92
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Minigen
|
2
|
+
|
3
|
+
# Various methods to create the project skel
|
4
|
+
class Generator
|
5
|
+
|
6
|
+
# Public: Initialize a new Project
|
7
|
+
def initialize options = {}
|
8
|
+
@options = options
|
9
|
+
@name = @options[:name].downcase
|
10
|
+
|
11
|
+
# The test suite, abort if empty
|
12
|
+
# Note: this is stupid
|
13
|
+
if not @options[:test].nil?
|
14
|
+
@test = @options[:test]
|
15
|
+
else
|
16
|
+
abort "You must specify a test suite"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Checks if a folder exists with the name @name
|
20
|
+
# if false, exits with a message
|
21
|
+
abort "A folder with that name already exists" if File.directory? @name
|
22
|
+
|
23
|
+
puts " - \033[32mGenerating\033[0m your project: #{@name}"
|
24
|
+
|
25
|
+
# Runs the method that copies the template
|
26
|
+
copy!
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# Private: Copies the default template to @name dir,
|
31
|
+
# the chosen test suite, and runs gsub'n'rename
|
32
|
+
#
|
33
|
+
# Returns nothing
|
34
|
+
def copy!
|
35
|
+
# Create the project diretory
|
36
|
+
Dir.mkdir @name
|
37
|
+
|
38
|
+
# Copies the base template files (e.g. readme, gemspec, etc)
|
39
|
+
FileUtils.cp_r(Dir.glob(File.join(LIBDIR, "templates/base/*")), @name)
|
40
|
+
|
41
|
+
# Copies the test suite ( see @options[:test] )
|
42
|
+
FileUtils.cp_r(Dir.glob(File.join(LIBDIR, "templates/#{@test}/*")), "#{@name}/test/")
|
43
|
+
|
44
|
+
gnr!
|
45
|
+
end
|
46
|
+
|
47
|
+
# Private: gsub'n'rename
|
48
|
+
# Joins the new project directory,
|
49
|
+
# gsubs the content of all files with the new project name
|
50
|
+
# 'nd renames all
|
51
|
+
#
|
52
|
+
# Returns nothing
|
53
|
+
def gnr!
|
54
|
+
Dir.chdir @name
|
55
|
+
Dir.glob("**/*.{rb,md,gemspec}").each {|f| ore f, "project", @name}
|
56
|
+
Dir.glob("**/*.{rb,md,gemspec}").each {|f| ore f, "Project", @name.capitalize}
|
57
|
+
File.rename "test/test_project.rb", "test/test_#{@name}.rb"
|
58
|
+
File.rename "lib/project.rb", "lib/#{@name}.rb"
|
59
|
+
File.rename "project.gemspec", "#{@name}.gemspec"
|
60
|
+
puts " - done!"
|
61
|
+
end
|
62
|
+
|
63
|
+
# Private: Opens, Reads and Edits a file
|
64
|
+
#
|
65
|
+
# file - The file to edit
|
66
|
+
# old - The term to be replaced
|
67
|
+
# new - The new term
|
68
|
+
#
|
69
|
+
# Examples
|
70
|
+
#
|
71
|
+
# ore('README.md', 'Minigen', 'Rubygems')
|
72
|
+
# # => True
|
73
|
+
#
|
74
|
+
# Returns True if everything went well :D
|
75
|
+
def ore file, old, new
|
76
|
+
o = File.read(file)
|
77
|
+
o.gsub! /#{old}/, new
|
78
|
+
n = File.new(file, "w+")
|
79
|
+
n.puts(o)
|
80
|
+
n.close
|
81
|
+
return true
|
82
|
+
end
|
83
|
+
|
84
|
+
private :copy!, :gnr!, :ore
|
85
|
+
|
86
|
+
end #Generator
|
87
|
+
|
88
|
+
end #Minigen
|
89
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/minigen_test.rb
CHANGED
metadata
CHANGED
@@ -1,66 +1,63 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: minigen
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Ermenegildo Fiorito
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-02-10 00:00:00 +01:00
|
12
|
+
date: 2011-02-14 00:00:00.000000000 %:z
|
14
13
|
default_executable:
|
15
14
|
dependencies: []
|
16
|
-
|
17
15
|
description: a project generator that creates a simple ruby library skel
|
18
16
|
email:
|
19
|
-
executables:
|
17
|
+
executables:
|
20
18
|
- mgen
|
21
19
|
extensions: []
|
22
|
-
|
23
20
|
extra_rdoc_files: []
|
24
|
-
|
25
|
-
files:
|
21
|
+
files:
|
26
22
|
- README.md
|
23
|
+
- lib/templates/tsm/test_helper.rb
|
24
|
+
- lib/templates/tsm/test_project.rb
|
25
|
+
- lib/templates/base/README.md
|
26
|
+
- lib/templates/base/lib/project.rb
|
27
|
+
- lib/templates/base/project.gemspec
|
28
|
+
- lib/templates/shoulda/helper.rb
|
29
|
+
- lib/templates/shoulda/test_project.rb
|
30
|
+
- lib/minigen.rb~
|
31
|
+
- lib/minigen/generator.rb~
|
27
32
|
- lib/minigen/generator.rb
|
28
33
|
- lib/minigen.rb
|
29
|
-
- lib/template/test/project_test.rb
|
30
|
-
- lib/template/test/test_helper.rb
|
31
|
-
- lib/template/README.md
|
32
|
-
- lib/template/lib/project.rb
|
33
|
-
- lib/template/project.gemspec
|
34
34
|
- test/test_helper.rb
|
35
35
|
- test/minigen_test.rb
|
36
36
|
- bin/mgen
|
37
37
|
has_rdoc: true
|
38
38
|
homepage: http://github.com/fyskij/minigen#readme
|
39
39
|
licenses: []
|
40
|
-
|
41
40
|
post_install_message:
|
42
41
|
rdoc_options: []
|
43
|
-
|
44
|
-
require_paths:
|
42
|
+
require_paths:
|
45
43
|
- lib
|
46
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
45
|
none: false
|
48
|
-
requirements:
|
49
|
-
- -
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
version:
|
52
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
51
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
58
56
|
requirements: []
|
59
|
-
|
60
57
|
rubyforge_project:
|
61
58
|
rubygems_version: 1.5.0
|
62
59
|
signing_key:
|
63
60
|
specification_version: 3
|
64
61
|
summary: just another projects generator
|
65
|
-
test_files:
|
62
|
+
test_files:
|
66
63
|
- test/test_helper.rb
|