ore 0.10.0 → 0.11.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.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -5
  3. data/.gitmodules +54 -0
  4. data/ChangeLog.md +90 -21
  5. data/Gemfile +12 -0
  6. data/LICENSE.txt +1 -1
  7. data/README.md +61 -27
  8. data/Rakefile +23 -24
  9. data/data/ore/abbreviations.txt +47 -0
  10. data/data/ore/common_namespaces.yml +13 -0
  11. data/data/ore/templates/apache/LICENSE.txt +202 -0
  12. data/data/ore/templates/apache/NOTICE.txt.erb +5 -0
  13. data/data/ore/templates/apache/lib/[namespace_path]/_copyright.erb +18 -0
  14. data/data/ore/templates/apache/template.yml +3 -0
  15. data/data/ore/templates/bsd/LICENSE.txt.erb +23 -0
  16. data/data/ore/templates/bsd/template.yml +6 -0
  17. data/data/ore/templates/bundler/Gemfile.erb +1 -1
  18. data/data/ore/templates/bundler/_tasks.erb +3 -0
  19. data/data/ore/templates/bundler/template.yml +5 -4
  20. data/data/ore/templates/code_climate/_badges.erb +1 -0
  21. data/data/ore/templates/code_climate/template.yml +2 -0
  22. data/data/ore/templates/{base → gem}/ChangeLog.md.erb +0 -0
  23. data/data/ore/templates/{base → gem}/ChangeLog.rdoc.erb +0 -0
  24. data/data/ore/templates/{base → gem}/ChangeLog.tt.erb +0 -0
  25. data/data/ore/templates/{base → gem}/README.md.erb +10 -4
  26. data/data/ore/templates/{base → gem}/README.rdoc.erb +12 -2
  27. data/data/ore/templates/{base → gem}/README.tt.erb +10 -4
  28. data/data/ore/templates/gem/Rakefile.erb +15 -0
  29. data/data/ore/templates/{gemspec → gem}/[name].gemspec.erb +21 -1
  30. data/data/ore/templates/{base → gem}/lib/[namespace_path].rb.erb +0 -0
  31. data/data/ore/templates/{base → gem}/lib/[namespace_path]/version.rb.erb +4 -0
  32. data/data/ore/templates/gem/template.yml +5 -0
  33. data/data/ore/templates/gem_package_task/template.yml +3 -0
  34. data/data/ore/templates/gemspec_yml/[name].gemspec.erb +1 -1
  35. data/data/ore/templates/gpl/COPYING.txt +674 -0
  36. data/data/ore/templates/gpl/lib/[namespace_path]/_copyright.erb +20 -0
  37. data/data/ore/templates/gpl/template.yml +7 -0
  38. data/data/ore/templates/lgpl/COPYING.txt +165 -0
  39. data/data/ore/templates/lgpl/lib/[namespace_path]/_copyright.erb +20 -0
  40. data/data/ore/templates/lgpl/template.yml +6 -0
  41. data/data/ore/templates/minitest/_tasks.erb +7 -0
  42. data/data/ore/templates/minitest/template.yml +6 -0
  43. data/data/ore/templates/minitest/test/helper.rb.erb +11 -0
  44. data/data/ore/templates/{mini_test → minitest}/test/test_[name].rb.erb +1 -1
  45. data/data/ore/templates/{base → mit}/LICENSE.txt.erb +0 -0
  46. data/data/ore/templates/mit/template.yml +8 -0
  47. data/data/ore/templates/rdoc/.document.erb +6 -0
  48. data/data/ore/templates/rdoc/.rdoc_options.erb +16 -0
  49. data/data/ore/templates/rdoc/_tasks.erb +5 -9
  50. data/data/ore/templates/rdoc/template.yml +2 -5
  51. data/data/ore/templates/rspec/_tasks.erb +1 -2
  52. data/data/ore/templates/rspec/spec/[namespace_dir]_spec.rb.erb +1 -1
  53. data/data/ore/templates/rspec/spec/spec_helper.rb.erb +0 -3
  54. data/data/ore/templates/rspec/template.yml +2 -2
  55. data/data/ore/templates/rubygems_tasks/_tasks.erb +0 -1
  56. data/data/ore/templates/rubygems_tasks/template.yml +3 -0
  57. data/data/ore/templates/test_unit/template.yml +1 -1
  58. data/data/ore/templates/test_unit/test/helper.rb.erb +3 -13
  59. data/data/ore/templates/travis/.travis.yml +6 -0
  60. data/data/ore/templates/travis/_badges.erb +1 -0
  61. data/data/ore/templates/yard/.document.erb +3 -1
  62. data/data/ore/templates/yard/_tasks.erb +2 -3
  63. data/data/ore/templates/yard/template.yml +2 -1
  64. data/gemspec.yml +6 -7
  65. data/lib/ore/actions.rb +1 -1
  66. data/lib/ore/cli.rb +1 -0
  67. data/lib/ore/config.rb +33 -41
  68. data/lib/ore/generator.rb +104 -66
  69. data/lib/ore/naming.rb +12 -19
  70. data/lib/ore/options.rb +71 -40
  71. data/lib/ore/template/directory.rb +3 -9
  72. data/lib/ore/template/helpers.rb +26 -2
  73. data/lib/ore/template/helpers/markdown.rb +96 -0
  74. data/lib/ore/template/helpers/rdoc.rb +96 -0
  75. data/lib/ore/template/helpers/textile.rb +106 -0
  76. data/lib/ore/template/markup.rb +19 -0
  77. data/lib/ore/version.rb +1 -1
  78. data/ore.gemspec +11 -0
  79. data/spec/gemspec_examples.rb +8 -8
  80. data/spec/generator_spec.rb +231 -181
  81. data/spec/helpers/generator.rb +5 -1
  82. data/spec/naming_spec.rb +11 -11
  83. data/spec/spec_helper.rb +0 -1
  84. data/spec/template/helpers/markdown_spec.rb +84 -0
  85. data/spec/template/helpers/rdoc_spec.rb +84 -0
  86. data/spec/template/helpers/textile_spec.rb +92 -0
  87. metadata +84 -85
  88. data/.gemtest +0 -0
  89. data/data/ore/templates/base/Rakefile.erb +0 -25
  90. data/data/ore/templates/base/template.yml +0 -2
  91. data/data/ore/templates/bundler_tasks/_tasks.erb +0 -1
  92. data/data/ore/templates/bundler_tasks/template.yml +0 -6
  93. data/data/ore/templates/gemspec/template.yml +0 -2
  94. data/data/ore/templates/gemspec_yml/template.yml +0 -2
  95. data/data/ore/templates/mini_test/template.yml +0 -3
  96. data/data/ore/templates/mini_test/test/helper.rb.erb +0 -26
  97. data/data/ore/templates/rdoc/.document +0 -4
@@ -3,13 +3,12 @@ require 'yard'
3
3
  YARD::Rake::YardocTask.new
4
4
  <%- else -%>
5
5
  begin
6
- gem 'yard', '<%= @development_dependencies['yard'] %>'
7
6
  require 'yard'
8
7
 
9
- YARD::Rake::YardocTask.new
8
+ YARD::Rake::YardocTask.new
10
9
  rescue LoadError => e
11
10
  task :yard do
12
- abort "Please run `gem install yard` to install YARD."
11
+ warn e.message
13
12
  end
14
13
  end
15
14
  <%- end -%>
@@ -2,7 +2,8 @@ disable:
2
2
  - rdoc
3
3
 
4
4
  ignore:
5
- - doc/
5
+ - /doc/
6
+ - /.yardoc/
6
7
 
7
8
  development_dependencies:
8
9
  yard: ~> 0.8
@@ -1,9 +1,8 @@
1
1
  name: ore
2
- summary: Mine beautiful RubyGems from Ore
2
+ summary: Generate perfect Ruby gems
3
3
  description:
4
- Ore is a flexible Ruby project generator. Unlike other Ruby project
5
- generators, Ore provides many builtin templates and allows custom
6
- templates to be installed from Git repositories.
4
+ Ore is a fully configurable and extendable Ruby gem generator. With Ore you
5
+ spend less time editing files, and more time writing code.
7
6
 
8
7
  license: MIT
9
8
  authors: Postmodern
@@ -25,10 +24,10 @@ post_install_message: |
25
24
 
26
25
  **************************************************************************
27
26
 
27
+ required_ruby_version: ">= 1.9.1"
28
+
28
29
  dependencies:
29
30
  thor: ~> 0.15
30
31
 
31
32
  development_dependencies:
32
- rubygems-tasks: ~> 0.2
33
- rspec: ~> 2.4
34
- yard: ~> 0.8
33
+ bundler: ~> 1.0
@@ -21,7 +21,7 @@ module Ore
21
21
  # @see http://rubydoc.info/gems/thor/Thor/Actions#run-instance_method
22
22
  #
23
23
  def run(command,config={})
24
- super(command,config.merge(:capture => true))
24
+ super(command,config.merge(capture: true))
25
25
  end
26
26
 
27
27
  #
@@ -1,4 +1,5 @@
1
1
  require 'ore/config'
2
+ require 'ore/generator'
2
3
  require 'ore/version'
3
4
 
4
5
  require 'thor'
@@ -1,5 +1,4 @@
1
- require 'rubygems'
2
- require 'pathname'
1
+ require 'ore/options'
3
2
 
4
3
  module Ore
5
4
  module Config
@@ -15,34 +14,40 @@ module Ore
15
14
  # Custom Ore Templates directory
16
15
  TEMPLATES_DIR = File.join(PATH,'templates')
17
16
 
18
- # The `data/` directory for Ore
19
- DATA_DIR = File.expand_path(File.join('..','..','data'),File.dirname(__FILE__))
17
+ # The `data/ore` directory for Ore
18
+ DATA_DIR = File.expand_path(File.join('..','..','data','ore'),File.dirname(__FILE__))
20
19
 
21
- # Specifies whether user settings will be loaded
22
- @@enabled = true
20
+ # The `data/ore/templates` directory for Ore
21
+ BUILTIN_TEMPLATES_DIR = File.join(DATA_DIR,'templates')
23
22
 
23
+ @enabled = true
24
+
25
+ #
26
+ # Enables access to user config.
24
27
  #
25
- # Enables access to user settings.
28
+ # @api private
26
29
  #
27
30
  # @since 0.5.0
28
31
  #
29
- def Config.enable!
30
- @@enabled = true
32
+ def self.enable!
33
+ @enabled = true
31
34
  end
32
35
 
33
36
  #
34
- # Disables access to user settings.
37
+ # Disables access to user config.
38
+ #
39
+ # @api private
35
40
  #
36
41
  # @since 0.5.0
37
42
  #
38
- def Config.disable!
39
- @@enabled = false
43
+ def self.disable!
44
+ @enabled = false
40
45
  end
41
46
 
42
47
  #
43
48
  # Loads the default options from `~/.ore/options.yml`.
44
49
  #
45
- # @return [Hash]
50
+ # @return [Options]
46
51
  # The loaded default options.
47
52
  #
48
53
  # @raise [RuntimeError]
@@ -50,23 +55,12 @@ module Ore
50
55
  #
51
56
  # @since 0.9.0
52
57
  #
53
- def Config.options
54
- options = {}
55
-
56
- if (@@enabled && File.file?(OPTIONS_FILE))
57
- new_options = YAML.load_file(OPTIONS_FILE)
58
-
59
- # default options must be a Hash
60
- unless new_options.kind_of?(Hash)
61
- raise("#{OPTIONS_FILE} must contain a YAML encoded Hash")
62
- end
63
-
64
- new_options.each do |name,value|
65
- options[name.to_sym] = value
66
- end
67
- end
68
-
69
- return options
58
+ def self.options
59
+ @options ||= if @enabled && File.file?(OPTIONS_FILE)
60
+ Options.load(OPTIONS_FILE)
61
+ else
62
+ Options.new
63
+ end
70
64
  end
71
65
 
72
66
  #
@@ -78,11 +72,9 @@ module Ore
78
72
  # @yieldparam [String] path
79
73
  # The path of a Ore template directory.
80
74
  #
81
- def Config.builtin_templates
82
- path = File.join(DATA_DIR,'ore','templates')
83
-
84
- if File.directory?(path)
85
- Dir.glob("#{path}/*") do |template|
75
+ def self.builtin_templates
76
+ if File.directory?(BUILTIN_TEMPLATES_DIR)
77
+ Dir.glob("#{BUILTIN_TEMPLATES_DIR}/*") do |template|
86
78
  yield template if File.directory?(template)
87
79
  end
88
80
  end
@@ -97,12 +89,12 @@ module Ore
97
89
  # @yieldparam [String] path
98
90
  # The path of a Ore template directory.
99
91
  #
100
- def Config.installed_templates
101
- if @@enabled
102
- if File.directory?(TEMPLATES_DIR)
103
- Dir.glob("#{TEMPLATES_DIR}/*") do |template|
104
- yield template if File.directory?(template)
105
- end
92
+ def self.installed_templates
93
+ return unless @enabled
94
+
95
+ if File.directory?(TEMPLATES_DIR)
96
+ Dir.glob("#{TEMPLATES_DIR}/*") do |template|
97
+ yield template if File.directory?(template)
106
98
  end
107
99
  end
108
100
  end
@@ -1,5 +1,4 @@
1
1
  require 'ore/config'
2
- require 'ore/options'
3
2
  require 'ore/actions'
4
3
  require 'ore/naming'
5
4
  require 'ore/template'
@@ -13,12 +12,63 @@ module Ore
13
12
  class Generator < Thor::Group
14
13
 
15
14
  include Thor::Actions
16
- include Options
17
15
  include Actions
18
16
  include Naming
19
17
  include Template::Interpolations
20
18
  include Template::Helpers
21
19
 
20
+ #
21
+ # Defines a generator option.
22
+ #
23
+ # @param [Symbol] name
24
+ #
25
+ # @param [Hash] options
26
+ #
27
+ def self.generator_option(name,options={})
28
+ default = options.fetch(:default,Config.options[name])
29
+
30
+ class_option(name,options.merge(default: default))
31
+ end
32
+
33
+ Template.templates.each_key do |name|
34
+ # skip the `base` template
35
+ next if name == :gem
36
+
37
+ generator_option name, type: :boolean, group: :template
38
+ end
39
+
40
+ # disable the Thor namespace
41
+ namespace ''
42
+
43
+ # define the options
44
+ generator_option :markup, type: :string,
45
+ banner: 'markdown|textile|rdoc'
46
+ generator_option :markdown, type: :boolean
47
+ generator_option :textile, type: :boolean
48
+ generator_option :templates, type: :array,
49
+ default: [],
50
+ aliases: '-T',
51
+ banner: 'TEMPLATE [...]'
52
+ generator_option :name, type: :string, aliases: '-n'
53
+ generator_option :namespace, type: :string, aliases: '-N'
54
+ generator_option :version, type: :string,
55
+ aliases: '-V'
56
+ generator_option :summary, type: :string,
57
+ aliases: '-s'
58
+ generator_option :description, type: :string,
59
+ aliases: '-D'
60
+ generator_option :author, type: :string,
61
+ aliases: '-A',
62
+ banner: 'NAME'
63
+ generator_option :authors, type: :array,
64
+ aliases: '-a',
65
+ banner: 'NAME [...]'
66
+ generator_option :email, type: :string, aliases: '-e'
67
+ generator_option :homepage, type: :string, aliases: %w[-U --website]
68
+ generator_option :bug_tracker, type: :string, aliases: '-B'
69
+
70
+ argument :path, required: true
71
+
22
72
  # The enabled templates.
23
73
  attr_reader :enabled_templates
24
74
 
@@ -34,36 +84,6 @@ module Ore
34
84
  # The generated files.
35
85
  attr_reader :generated_files
36
86
 
37
- # disable the Thor namespace
38
- namespace ''
39
-
40
- Template.templates.each_key do |name|
41
- # skip the `base` template
42
- next if name == :base
43
-
44
- generator_option name, :type => :boolean
45
- end
46
-
47
- # define the options
48
- generator_option :markdown, :type => :boolean
49
- generator_option :textile, :type => :boolean
50
- generator_option :templates, :type => :array,
51
- :aliases => '-T',
52
- :banner => 'TEMPLATE [...]'
53
- generator_option :name, :type => :string, :aliases => '-n'
54
- generator_option :version, :type => :string, :aliases => '-V'
55
- generator_option :summary, :aliases => '-s'
56
- generator_option :description, :aliases => '-D'
57
- generator_option :authors, :type => :array,
58
- :aliases => '-a',
59
- :banner => 'NAME [...]'
60
- generator_option :email, :type => :string, :aliases => '-e'
61
- generator_option :homepage, :type => :string, :aliases => '-U'
62
- generator_option :bug_tracker, :type => :string, :aliases => '-B'
63
- generator_option :license, :aliases => '-L'
64
-
65
- argument :path, :required => true
66
-
67
87
  #
68
88
  # Generates a new project.
69
89
  #
@@ -73,36 +93,15 @@ module Ore
73
93
  enable_templates!
74
94
  initialize_variables!
75
95
 
96
+ extend Template::Helpers::MARKUP.fetch(@markup)
97
+
76
98
  unless options.quiet?
77
99
  say "Generating #{self.destination_root}", :green
78
100
  end
79
101
 
80
102
  generate_directories!
81
103
  generate_files!
82
-
83
- in_root do
84
- case @scm
85
- when :git
86
- unless File.directory?('.git')
87
- run 'git init'
88
- run 'git add .'
89
- run 'git commit -m "Initial commit."'
90
- end
91
- when :hg
92
- unless File.directory?('.hg')
93
- run 'hg init'
94
- run 'hg add .'
95
- run 'hg commit -m "Initial commit."'
96
- end
97
- when :svn
98
- @ignore.each do |pattern|
99
- run "svn propset svn:ignore #{pattern.dump}"
100
- end
101
-
102
- run 'svn add .'
103
- run 'svn commit -m "Initial commit."'
104
- end
105
- end
104
+ initialize_scm!
106
105
  end
107
106
 
108
107
  protected
@@ -176,10 +175,10 @@ module Ore
176
175
  @enabled_templates = Set[]
177
176
  @disabled_templates = Set[]
178
177
 
179
- enable_template :base
178
+ enable_template :gem
180
179
 
181
180
  # enable the default templates first
182
- Options.defaults.each_key do |name|
181
+ Options::DEFAULT_TEMPLATES.each do |name|
183
182
  if (Template.template?(name) && options[name])
184
183
  enable_template(name)
185
184
  end
@@ -233,7 +232,7 @@ module Ore
233
232
  @module_depth = @modules.length
234
233
  @module = @modules.last
235
234
 
236
- @namespace = namespace_of(@name)
235
+ @namespace = options.namespace || namespace_of(@name)
237
236
  @namespace_dirs = namespace_dirs_of(@name)
238
237
  @namespace_path = namespace_path_of(@name)
239
238
  @namespace_dir = @namespace_dirs.last
@@ -241,9 +240,12 @@ module Ore
241
240
  @version = options.version
242
241
  @summary = options.summary
243
242
  @description = options.description
244
- @license = options.license
245
243
 
246
- @authors = (options.authors || [@scm_user || ENV['USER']])
244
+ @authors = if options.author || options.author
245
+ [*options.author, *options.authors]
246
+ else
247
+ [@scm_user || ENV['USERNAME'] || ENV['USER'].capitalize]
248
+ end
247
249
  @author = @authors.first
248
250
 
249
251
  @email = (options.email || @scm_email)
@@ -262,10 +264,15 @@ module Ore
262
264
  "https://#{@uri.host}#{@uri.path}/issues"
263
265
  end
264
266
 
265
- @markup, @markup_ext = if options.markdown? then [:markdown, 'md']
266
- elsif options.textile? then [:textile, 'tt']
267
- else [:rdoc, 'rdoc']
268
- end
267
+ @markup = if options.markdown? then :markdown
268
+ elsif options.textile? then :textile
269
+ elsif options.markup? then options.markup.to_sym
270
+ end
271
+
272
+ @markup_ext = Template::Markup::EXT.fetch(@markup) do
273
+ say "Unknown markup: #{@markup}", :red
274
+ exit -1
275
+ end
269
276
 
270
277
  @date = Date.today
271
278
  @year = @date.year
@@ -316,7 +323,7 @@ module Ore
316
323
 
317
324
  # then render the templates
318
325
  template.each_template(@markup) do |dest,file|
319
- generate_file dest, file, :template => true
326
+ generate_file dest, file, template: true
320
327
  end
321
328
  end
322
329
 
@@ -329,5 +336,36 @@ module Ore
329
336
  end
330
337
  end
331
338
 
339
+ #
340
+ # Initializes the project repository and commits all files.
341
+ #
342
+ # @since 0.10.0
343
+ #
344
+ def initialize_scm!
345
+ in_root do
346
+ case @scm
347
+ when :git
348
+ unless File.directory?('.git')
349
+ run 'git init'
350
+ run 'git add .'
351
+ run 'git commit -m "Initial commit."'
352
+ end
353
+ when :hg
354
+ unless File.directory?('.hg')
355
+ run 'hg init'
356
+ run 'hg add .'
357
+ run 'hg commit -m "Initial commit."'
358
+ end
359
+ when :svn
360
+ @ignore.each do |pattern|
361
+ run "svn propset svn:ignore #{pattern.dump}"
362
+ end
363
+
364
+ run 'svn add .'
365
+ run 'svn commit -m "Initial commit."'
366
+ end
367
+ end
368
+ end
369
+
332
370
  end
333
371
  end
@@ -1,3 +1,7 @@
1
+ require 'ore/config'
2
+
3
+ require 'yaml'
4
+
1
5
  module Ore
2
6
  #
3
7
  # Provides methods for guessing the namespaces and directories
@@ -32,25 +36,14 @@ module Ore
32
36
  # Words used in project names, but never in directory names
33
37
  IGNORE_NAMESPACES = %w[core ruby rb java]
34
38
 
35
- # Common acronyms used in namespaces
36
- NAMESPACE_ACRONYMS = %w[
37
- ffi yard i18n
38
- http https ftp smtp imap pop3 ssh ssl tcp udp dns rpc
39
- url uri www css html xhtml xml xsl json yaml csv
40
- posix unix bsd
41
- cpp asm
42
- ]
39
+ # Common abbrevations used in namespaces
40
+ COMMON_ABBREVIATIONS = Hash[File.readlines(File.join(Config::DATA_DIR,'abbreviations.txt')).map { |abbrev|
41
+ abbrev.chomp!
42
+ [abbrev.downcase, abbrev]
43
+ }]
43
44
 
44
45
  # Common project prefixes and namespaces
45
- COMMON_NAMESPACES = {
46
- 'rubygems' => 'Gem',
47
- 'ar' => 'ActiveRecord',
48
- 'dm' => 'DataMapper',
49
- 'js' => 'JavaScript',
50
- 'msgpack' => 'MsgPack',
51
- 'github' => 'GitHub',
52
- 'rdoc' => 'RDoc'
53
- }
46
+ COMMON_NAMESPACES = YAML.load_file(File.join(Config::DATA_DIR,'common_namespaces.yml'))
54
47
 
55
48
  #
56
49
  # Splits the project name into individual names.
@@ -81,8 +74,8 @@ module Ore
81
74
  def module_of(word)
82
75
  if COMMON_NAMESPACES.has_key?(word)
83
76
  COMMON_NAMESPACES[word]
84
- elsif NAMESPACE_ACRONYMS.include?(word)
85
- word.upcase
77
+ elsif COMMON_ABBREVIATIONS.has_key?(word)
78
+ COMMON_ABBREVIATIONS[word]
86
79
  else
87
80
  word.capitalize
88
81
  end