ore 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,13 +1,16 @@
1
- require 'ore/config'
2
- require 'ore/template'
1
+ require 'yaml'
3
2
 
4
3
  module Ore
5
4
  #
6
- # @api semipublic
5
+ # Value object to contain `~/.ore/options.yml` data.
7
6
  #
8
- # @since 0.9.0
7
+ # @since 0.11.0
9
8
  #
10
- module Options
9
+ class Options
10
+
11
+ # Default markup
12
+ DEFAULT_MARKUP = 'markdown'
13
+
11
14
  # Default version
12
15
  DEFAULT_VERSION = '0.1.0'
13
16
 
@@ -17,47 +20,75 @@ module Ore
17
20
  # Default description
18
21
  DEFAULT_DESCRIPTION = %q{TODO: Description}
19
22
 
20
- # Default License
21
- DEFAULT_LICENSE = 'MIT'
23
+ # Default templates
24
+ DEFAULT_TEMPLATES = [
25
+ :git,
26
+ :mit,
27
+ :bundler,
28
+ :rubygems_tasks,
29
+ :rdoc,
30
+ :rspec
31
+ ]
22
32
 
23
- def self.included(base)
24
- base.extend ClassMethods
25
- end
33
+ # Default options
34
+ DEFAULTS = {
35
+ markup: DEFAULT_MARKUP,
36
+ version: DEFAULT_VERSION,
37
+ summary: DEFAULT_SUMMARY,
38
+ description: DEFAULT_DESCRIPTION
39
+ }
40
+ DEFAULT_TEMPLATES.each { |name| DEFAULTS[name] = true }
26
41
 
27
42
  #
28
- # Default options for the generator.
29
- #
30
- # @return [Hash{Symbol => Object}]
31
- # The option names and default values.
32
- #
33
- def self.defaults
34
- @@defaults ||= {
35
- :templates => [],
36
- :version => DEFAULT_VERSION,
37
- :summary => DEFAULT_SUMMARY,
38
- :description => DEFAULT_DESCRIPTION,
39
- :license => DEFAULT_LICENSE,
40
- :gemspec => true,
41
- :rubygems_tasks => true,
42
- :rdoc => true,
43
- :rspec => true,
44
- :git => true
45
- }.merge(Config.options)
43
+ # Initializes the options.
44
+ #
45
+ # @param [Hash{Symbol => Object}] options
46
+ # The options hash.
47
+ #
48
+ def initialize(options={})
49
+ @options = DEFAULTS.merge(options)
46
50
  end
47
51
 
48
- module ClassMethods
49
- #
50
- # Defines a generator option.
51
- #
52
- # @param [Symbol] name
53
- # The name of the option.
54
- #
55
- # @param [Hash{Symbol => Object}] options
56
- # The Thor options of the option.
57
- #
58
- def generator_option(name,options={})
59
- class_option(name,options.merge(:default => Options.defaults[name]))
52
+ #
53
+ # Loads the options from a YAML file.
54
+ #
55
+ # @param [String] path
56
+ # Path to the options file.
57
+ #
58
+ # @return [Options]
59
+ # The loaded options.
60
+ #
61
+ # @raise [RuntimeError]
62
+ # The file contained malformed YAML.
63
+ #
64
+ def self.load(path)
65
+ data = YAML.load_file(path)
66
+
67
+ unless data.kind_of?(Hash)
68
+ raise("#{path} must contain a YAML encoded Hash")
60
69
  end
70
+
71
+ options = {}
72
+
73
+ data.each do |key,value|
74
+ options[key.to_sym] = value
75
+ end
76
+
77
+ return new(options)
61
78
  end
79
+
80
+ #
81
+ # Accesses an option.
82
+ #
83
+ # @param [Symbol] key
84
+ # The option name.
85
+ #
86
+ # @return [Object]
87
+ # The option value.
88
+ #
89
+ def [](key)
90
+ @options[key]
91
+ end
92
+
62
93
  end
63
94
  end
@@ -1,4 +1,5 @@
1
1
  require 'ore/template/exceptions/invalid_template'
2
+ require 'ore/template/markup'
2
3
 
3
4
  require 'yaml'
4
5
  require 'find'
@@ -17,13 +18,6 @@ module Ore
17
18
  # Files or directory names to ignore
18
19
  IGNORE = ['.git', CONFIG_FILE]
19
20
 
20
- # The known markup languages and file extensions
21
- MARKUPS = {
22
- :markdown => %w[.md .markdown],
23
- :textile => %w[.tt .textile],
24
- :rdoc => %w[.rdoc]
25
- }
26
-
27
21
  # The path of the template directory
28
22
  attr_reader :path
29
23
 
@@ -247,7 +241,7 @@ module Ore
247
241
  # Specifies whether the file is formatting.
248
242
  #
249
243
  def formatted?(path)
250
- MARKUPS.values.any? { |exts| exts.include?(File.extname(path)) }
244
+ Markup::EXTS.values.any? { |exts| exts.include?(File.extname(path)) }
251
245
  end
252
246
 
253
247
  #
@@ -263,7 +257,7 @@ module Ore
263
257
  # Specifies whether the file contains the given formatting.
264
258
  #
265
259
  def formatted_like?(path,markup)
266
- MARKUPS[markup].include?(File.extname(path))
260
+ Markup::EXTS[markup].include?(File.extname(path))
267
261
  end
268
262
 
269
263
  end
@@ -1,10 +1,19 @@
1
+ require 'ore/template/helpers/markdown'
2
+ require 'ore/template/helpers/textile'
3
+ require 'ore/template/helpers/rdoc'
4
+
1
5
  module Ore
2
6
  module Template
3
7
  #
4
8
  # Helper methods that can be used within ERb templates.
5
9
  #
6
10
  module Helpers
7
- protected
11
+ # Markup helpers
12
+ MARKUP = {
13
+ markdown: Markdown,
14
+ textile: Textile,
15
+ rdoc: RDoc
16
+ }
8
17
 
9
18
  #
10
19
  # Renders all include files with the given name.
@@ -219,11 +228,26 @@ module Ore
219
228
  # @param [Integer] spaces
220
229
  # The number of spaces to indent by.
221
230
  #
231
+ # @yield []
232
+ # The given block will be used as the text.
233
+ #
222
234
  # @return [String]
223
235
  # The indentation string.
224
236
  #
225
237
  def indent(n,spaces=2)
226
- (' ' * spaces) * n
238
+ @indent ||= 0
239
+ @indent += (spaces * n)
240
+
241
+ margin = ' ' * @indent
242
+
243
+ text = if block_given?
244
+ yield.each_line.map { |line| margin + line }.join
245
+ else
246
+ margin
247
+ end
248
+
249
+ @indent -= (spaces * n)
250
+ return text
227
251
  end
228
252
 
229
253
  #
@@ -0,0 +1,96 @@
1
+ module Ore
2
+ module Template
3
+ module Helpers
4
+ #
5
+ # @api semipublic
6
+ #
7
+ # @since 0.10.0
8
+ #
9
+ module Markdown
10
+ #
11
+ # Emits a markdown link.
12
+ #
13
+ # @param [String, nil] text
14
+ #
15
+ # @param [String] url
16
+ #
17
+ # @return [String]
18
+ #
19
+ def link_to(text,url)
20
+ "[#{text}](#{url})"
21
+ end
22
+
23
+ #
24
+ # Emits a markdown image.
25
+ #
26
+ # @param [String] url
27
+ #
28
+ # @param [String, nil] alt
29
+ #
30
+ # @return [String]
31
+ #
32
+ def image(url,alt=nil)
33
+ "![#{alt}](#{url})"
34
+ end
35
+
36
+ #
37
+ # Emits a markdown h1 heading.
38
+ #
39
+ # @param [String] title
40
+ #
41
+ # @return [String]
42
+ #
43
+ def h1(title)
44
+ "# #{title}"
45
+ end
46
+
47
+ #
48
+ # Emits a markdown h2 heading.
49
+ #
50
+ # @param [String] title
51
+ #
52
+ # @return [String]
53
+ #
54
+ def h2(title)
55
+ "## #{title}"
56
+ end
57
+
58
+ #
59
+ # Emits a markdown h3 heading.
60
+ #
61
+ # @param [String] title
62
+ #
63
+ # @return [String]
64
+ #
65
+ def h3(title)
66
+ "### #{title}"
67
+ end
68
+
69
+ #
70
+ # Emits a markdown h4 heading.
71
+ #
72
+ # @param [String] title
73
+ #
74
+ # @return [String]
75
+ #
76
+ def h4(title)
77
+ "#### #{title}"
78
+ end
79
+
80
+ #
81
+ # Emits a markdown code block.
82
+ #
83
+ # @param [String] code
84
+ #
85
+ # @yield []
86
+ # The return value of the given block will be used as the code.
87
+ #
88
+ # @return [String]
89
+ #
90
+ def pre(code)
91
+ code.each_line.map { |line| " #{line}" }.join
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,96 @@
1
+ module Ore
2
+ module Template
3
+ module Helpers
4
+ #
5
+ # @api semipublic
6
+ #
7
+ # @since 0.10.0
8
+ #
9
+ module RDoc
10
+ #
11
+ # Emits a RDoc link.
12
+ #
13
+ # @param [String, nil] text
14
+ #
15
+ # @param [String] url
16
+ #
17
+ # @return [String]
18
+ #
19
+ def link_to(text,url)
20
+ "{#{text}}[#{url}]"
21
+ end
22
+
23
+ #
24
+ # Emits a RDoc image.
25
+ #
26
+ # @param [String] url
27
+ #
28
+ # @param [String, nil] alt
29
+ #
30
+ # @return [String]
31
+ #
32
+ def image(url,alt=nil)
33
+ "{#{alt}}[rdoc-image:#{url}]"
34
+ end
35
+
36
+ #
37
+ # Emits a RDoc h1 heading.
38
+ #
39
+ # @param [String] title
40
+ #
41
+ # @return [String]
42
+ #
43
+ def h1(title)
44
+ "= #{title}"
45
+ end
46
+
47
+ #
48
+ # Emits a RDoc h2 heading.
49
+ #
50
+ # @param [String] title
51
+ #
52
+ # @return [String]
53
+ #
54
+ def h2(title)
55
+ "== #{title}"
56
+ end
57
+
58
+ #
59
+ # Emits a RDoc h3 heading.
60
+ #
61
+ # @param [String] title
62
+ #
63
+ # @return [String]
64
+ #
65
+ def h3(title)
66
+ "=== #{title}"
67
+ end
68
+
69
+ #
70
+ # Emits a RDoc h4 heading.
71
+ #
72
+ # @param [String] title
73
+ #
74
+ # @return [String]
75
+ #
76
+ def h4(title)
77
+ "==== #{title}"
78
+ end
79
+
80
+ #
81
+ # Emits a RDoc code block.
82
+ #
83
+ # @param [String] code
84
+ #
85
+ # @yield []
86
+ # The return value of the given block will be used as the code.
87
+ #
88
+ # @return [String]
89
+ #
90
+ def pre(code)
91
+ code.each_line.map { |line| " #{line}" }.join
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,106 @@
1
+ module Ore
2
+ module Template
3
+ module Helpers
4
+ #
5
+ # @api semipublic
6
+ #
7
+ # @since 0.10.0
8
+ #
9
+ module Textile
10
+ #
11
+ # Emits a Textile link.
12
+ #
13
+ # @param [String, nil] text
14
+ #
15
+ # @param [String] url
16
+ #
17
+ # @return [String]
18
+ #
19
+ def link_to(text,url)
20
+ if text
21
+ "#{text.dump}:#{url}"
22
+ else
23
+ url
24
+ end
25
+ end
26
+
27
+ #
28
+ # Emits a Textile image tag.
29
+ #
30
+ # @param [String] url
31
+ #
32
+ # @param [String, nil] alt
33
+ #
34
+ # @return [String]
35
+ #
36
+ def image(url,alt=nil)
37
+ if alt then "!#{url}(#{alt})!"
38
+ else "!#{url}!"
39
+ end
40
+ end
41
+
42
+ #
43
+ # Emits a Textile h1 heading.
44
+ #
45
+ # @param [String] title
46
+ #
47
+ # @return [String]
48
+ #
49
+ def h1(title)
50
+ "h1. #{title}"
51
+ end
52
+
53
+ #
54
+ # Emits a Textile h2 heading.
55
+ #
56
+ # @param [String] title
57
+ #
58
+ # @return [String]
59
+ #
60
+ def h2(title)
61
+ "h2. #{title}"
62
+ end
63
+
64
+ #
65
+ # Emits a Textile h3 heading.
66
+ #
67
+ # @param [String] title
68
+ #
69
+ # @return [String]
70
+ #
71
+ def h3(title)
72
+ "h3. #{title}"
73
+ end
74
+
75
+ #
76
+ # Emits a Textile h4 heading.
77
+ #
78
+ # @param [String] title
79
+ #
80
+ # @return [String]
81
+ #
82
+ def h4(title)
83
+ "h4. #{title}"
84
+ end
85
+
86
+ #
87
+ # Emits a Textile code block.
88
+ #
89
+ # @param [String] code
90
+ #
91
+ # @yield []
92
+ # The return value of the given block will be used as the code.
93
+ #
94
+ # @return [String]
95
+ #
96
+ def pre(code)
97
+ if code =~ /#{$/}\s*#{$/}/
98
+ "bc.. #{code}"
99
+ else
100
+ "bc. #{code}"
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end