bundlegem 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +35 -3
  3. data/bin/bundlegem +1 -0
  4. data/changelog +48 -24
  5. data/config/config +4 -0
  6. data/lib/bundlegem/cli/gem.rb +156 -154
  7. data/lib/bundlegem/configurator.rb +21 -4
  8. data/lib/bundlegem/template_manager.rb +59 -0
  9. data/{tmp_gem/tmp_gem.gemspec → lib/bundlegem/templates/c_extension_gem/#{name}.gemspec.tt} +15 -7
  10. data/lib/bundlegem/templates/c_extension_gem/.travis.yml.tt +3 -0
  11. data/lib/bundlegem/templates/c_extension_gem/CODE_OF_CONDUCT.md.tt +13 -0
  12. data/lib/bundlegem/templates/c_extension_gem/Gemfile.tt +4 -0
  13. data/lib/bundlegem/templates/c_extension_gem/LICENSE.txt.tt +21 -0
  14. data/{tmp_gem/README.md → lib/bundlegem/templates/c_extension_gem/README.md.tt} +6 -6
  15. data/lib/bundlegem/templates/c_extension_gem/Rakefile.tt +25 -0
  16. data/lib/bundlegem/templates/c_extension_gem/bin/#{name}.tt +3 -0
  17. data/{tmp_gem/bin/console → lib/bundlegem/templates/c_extension_gem/bin/console.tt} +1 -1
  18. data/{tmp_gem/changelog → lib/bundlegem/templates/c_extension_gem/changelog.tt} +0 -0
  19. data/lib/bundlegem/templates/{newgem → c_extension_gem}/ext/#{name}/#{newgem}.c.tt +0 -0
  20. data/lib/bundlegem/templates/{newgem → c_extension_gem}/ext/#{name}/#{newgem}.h.tt +0 -0
  21. data/lib/bundlegem/templates/{newgem → c_extension_gem}/ext/#{name}/extconf.rb.tt +0 -0
  22. data/lib/bundlegem/templates/{newgem → c_extension_gem}/gitignore.tt +0 -0
  23. data/lib/bundlegem/templates/c_extension_gem/lib/#{name}/version.rb.tt +7 -0
  24. data/lib/bundlegem/templates/c_extension_gem/lib/#{name}.rb.tt +12 -0
  25. data/{tmp_gem/.rspec → lib/bundlegem/templates/c_extension_gem/rspec.tt} +0 -0
  26. data/{tmp_gem/spec/tmp_gem_spec.rb → lib/bundlegem/templates/c_extension_gem/spec/#{name}_spec.rb.tt} +2 -2
  27. data/{tmp_gem/spec/spec_helper.rb → lib/bundlegem/templates/c_extension_gem/spec/spec_helper.rb.tt} +1 -1
  28. data/lib/bundlegem/templates/cli_gem/#{name}.gemspec.tt +35 -0
  29. data/lib/bundlegem/templates/cli_gem/.travis.yml.tt +3 -0
  30. data/lib/bundlegem/templates/cli_gem/CODE_OF_CONDUCT.md.tt +13 -0
  31. data/lib/bundlegem/templates/cli_gem/Gemfile.tt +4 -0
  32. data/lib/bundlegem/templates/cli_gem/LICENSE.txt.tt +21 -0
  33. data/lib/bundlegem/templates/cli_gem/README.md.tt +39 -0
  34. data/lib/bundlegem/templates/cli_gem/Rakefile.tt +25 -0
  35. data/lib/bundlegem/templates/cli_gem/bin/#{name}.tt +3 -0
  36. data/lib/bundlegem/templates/cli_gem/bin/console.tt +14 -0
  37. data/lib/bundlegem/templates/cli_gem/changelog.tt +7 -0
  38. data/lib/bundlegem/templates/cli_gem/exe/#{name}.tt +5 -0
  39. data/lib/bundlegem/templates/cli_gem/ext/#{name}/#{newgem}.c.tt +9 -0
  40. data/lib/bundlegem/templates/cli_gem/ext/#{name}/#{newgem}.h.tt +6 -0
  41. data/lib/bundlegem/templates/cli_gem/ext/#{name}/extconf.rb.tt +3 -0
  42. data/{tmp_gem/.gitignore → lib/bundlegem/templates/cli_gem/gitignore.tt} +7 -0
  43. data/lib/bundlegem/templates/cli_gem/lib/#{name}/version.rb.tt +7 -0
  44. data/lib/bundlegem/templates/cli_gem/lib/#{name}.rb.tt +9 -0
  45. data/lib/bundlegem/templates/cli_gem/rspec.tt +2 -0
  46. data/lib/bundlegem/templates/cli_gem/spec/#{name}_spec.rb.tt +11 -0
  47. data/lib/bundlegem/templates/cli_gem/spec/spec_helper.rb.tt +2 -0
  48. data/lib/bundlegem/templates/newgem/#{name}.gemspec.tt +2 -6
  49. data/lib/bundlegem/templates/newgem/.gitignore.tt +16 -0
  50. data/lib/bundlegem/templates/newgem/Rakefile.tt +32 -17
  51. data/lib/bundlegem/templates/service/lib/#{name}.rb.tt +1 -1
  52. data/lib/bundlegem/version.rb +1 -1
  53. data/lib/bundlegem.rb +29 -2
  54. data/spec/bundlegem_spec.rb +8 -2
  55. data/spec/spec_helper.rb +18 -8
  56. metadata +44 -19
  57. data/tmp_gem/.travis.yml +0 -3
  58. data/tmp_gem/Gemfile +0 -4
  59. data/tmp_gem/Rakefile +0 -1
  60. data/tmp_gem/lib/tmp_gem/version.rb +0 -3
  61. data/tmp_gem/lib/tmp_gem.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c08c0682db8e699b13f7f117349b7c7da714ede
4
- data.tar.gz: 5c15178fe7fb6594e6fead96bedc15c63b6f978e
3
+ metadata.gz: 045563549ab767462d8d41dad72cc7c1b9c36134
4
+ data.tar.gz: 2a392ed207841bf8bd6d9e886269c1e8cb7c4d96
5
5
  SHA512:
6
- metadata.gz: 5dcd12a40000b95ade8a289fbcceb95e1798f2709cb5fa25510d0e1a26d439ea4df72a04857b7fc9f5a5c857c14f7b9abeaeee80f05c7c198eeb6cd5fc204bc9
7
- data.tar.gz: 02a40f796bac379663fb5580c995acb5f9709011c38fff1e94ecc715165fd70ee61159f7279f911d40e3b21f370ac6cfce548daf108b6e77e68610fbc376fd60
6
+ metadata.gz: 5fcea6513756acc90fddb3fbfd55e0a57783eda99ef981c58dc796e5328e53f83134ca9176435a3e7a5674fed5a55543a3f8580bac0abd90a63f13580da95323
7
+ data.tar.gz: 8774029ff42caa8f7a4b1e7c34a3eff21f1134ddac23639c0d6edee7ef980efe7c4c51f807813d30d71c470d7966a355511b1ec487274ae9507332d5db35e790
data/Rakefile CHANGED
@@ -1,8 +1,40 @@
1
+ require 'rake'
2
+
1
3
  require 'bundler'
2
- require "bundler/gem_tasks"
3
- require "rspec/core/rake_task"
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+
8
+ desc "Run unit specs"
9
+ RSpec::Core::RakeTask.new(:unit) do |t|
10
+ t.rspec_opts = %w(-fd -c)
11
+ t.pattern = "./spec/unit/**/*_spec.rb"
12
+ end
13
+
14
+ desc "Run integration specs that are very high level"
15
+ RSpec::Core::RakeTask.new(:integration) do |t|
16
+ t.rspec_opts = %w(-fd -c)
17
+ t.pattern = "./spec/integration/**/*_spec.rb"
18
+ end
4
19
 
5
- RSpec::Core::RakeTask.new(:spec)
20
+ desc "Run all specs"
21
+ RSpec::Core::RakeTask.new(:spec) do |t|
22
+ t.rspec_opts = %w(-fd -c)
23
+ end
24
+
25
+ # this is for running tests that you've marked current... eg: it 'should work', :current => true do
26
+ RSpec::Core::RakeTask.new(:current) do |spec|
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rspec_opts = ['--tag current']
29
+ end
30
+
31
+ # alias for current
32
+ RSpec::Core::RakeTask.new(:c) do |spec|
33
+ spec.pattern = 'spec/**/*_spec.rb'
34
+ spec.rspec_opts = ['--tag current']
35
+ end
6
36
 
7
37
  task :default => :spec
38
+ task :test => :spec
39
+
8
40
 
data/bin/bundlegem CHANGED
@@ -35,6 +35,7 @@ end
35
35
  if ARGV[0] == "--newtemplate"
36
36
  puts "Sorry, I haven't been implemented, I don't have a lot of free time atm :("
37
37
  exit 0
38
+ Bundlegem.newtemplate(ARGV)
38
39
  end
39
40
 
40
41
 
data/changelog CHANGED
@@ -1,19 +1,43 @@
1
1
  ** 0.0.x **
2
- - Default templates:
3
- * CLI file system app,
4
- * CLI with web client
5
- - Restore the original UI that was in bundler
6
- - Ability to load templates from github
7
- - Track a list of additional web templates in this repo
8
- - Allow for it to be listed
9
- - Hint the user to cd into ~/.bundlegem/gem_templates and clone any they choose
10
- - CMD: --newtemplate to start new template
11
- - CMD: --templateize-current-directory to make the current directory into a
12
- new template
13
- - Behavior: gems in the ~/.bundlegem/gem_templates folder take precidence over
14
- built in gems? ...add prompt
15
- - Cleaning: Make create_gem build a string instead of puts so
16
- output can be squelched for testing
2
+ - Feature: Make each user defined gem have a subfolder that is the exact
3
+ project structure, so the readme for the gem can exist without fear of it
4
+ being copied into new projects
5
+ - Feature: Gem's display names are based on what's specified in their
6
+ respective root .bundlegem
7
+ - newgem template: fix Rake file and test organization
8
+ - Default templates:
9
+ * CLI file system app,
10
+ * CLI with web client
11
+ - Restore the original UI that was in bundler
12
+ - Feature: Ability to load templates from github
13
+ - Track a list of additional web templates in this repo
14
+ - Allow for it to be listed
15
+ - Hint the user to cd into ~/.bundlegem/gem_templates and clone any they choose
16
+
17
+
18
+ - Behavior: gems in the ~/.bundlegem/gem_templates folder take precidence over
19
+ built in gems? ...add prompt
20
+ - Cleaning: Make create_gem build a string instead of puts so
21
+ output can be squelched for testing
22
+ - CMD: --templateize-current-directory to make the current directory into a
23
+ new template
24
+ - CORE: refactor the built-in gems so they look pretty (templates/newgem/lib/#{name}.rb.tt)
25
+ * Need to implement partials that are stored inside the gem
26
+
27
+ - CMD: --newtemplate to start new template
28
+ - CMD: --default to set a gem_template as the default one (list should indicate this)
29
+ - list doesn't display these becasue lib/bundlegem.rb:15
30
+ - Built-in Template: cli_gem
31
+ - Built-in Template: c_ext_gem
32
+
33
+
34
+ ** 0.0.6 **
35
+ - Feature: List now indicates default template
36
+ - CORE: Created TemplateManager for working with templates
37
+ - BUG: Accidentally tracked in a test gem project and fixed tests to not
38
+ change directory into a test area for creating new gems.
39
+ - BUG: newgem template didn't have a dot in .gitignore.tt
40
+
17
41
 
18
42
 
19
43
  ** 0.0.5 **
@@ -22,7 +46,7 @@
22
46
  - Bug where sub directories were not being explicitly created
23
47
  - Added integration test just to make sure the built-in templates can be generated without problems
24
48
  - Cleaned up internal API and how the binary works
25
-
49
+
26
50
 
27
51
  ** 0.0.4 **
28
52
  - Tell the user what files are being created
@@ -30,16 +54,16 @@
30
54
 
31
55
 
32
56
  ** 0.0.3 **
33
- - CMD: --list to list templates (with descriptions)
34
- - Raise error when project name already exists, do not overwrite!
35
- - Raises error if none of the files in the template directory end in .tt
36
- - Create even empty folders
57
+ - CMD: --list to list templates (with descriptions)
58
+ - Raise error when project name already exists, do not overwrite!
59
+ - Raises error if none of the files in the template directory end in .tt
60
+ - Create even empty folders
37
61
 
38
-
62
+
39
63
  ** 0.0.2 **
40
- - Added default gem template 'service'
41
- - Better syntax of bundlegem gem_name -t template_name
42
- - CMD: --help to display a help message
64
+ - Added default gem template 'service'
65
+ - Better syntax of bundlegem gem_name -t template_name
66
+ - CMD: --help to display a help message
43
67
 
44
68
 
45
69
  ** 0.0.1 **
data/config/config ADDED
@@ -0,0 +1,4 @@
1
+ # Comments made to this file will not be preserved
2
+ ---
3
+ default_template: newgem
4
+
@@ -16,8 +16,6 @@ module Bundlegem
16
16
  end
17
17
 
18
18
  def run
19
- # Bundler.ui.confirm "Creating gem '#{name}'..."
20
-
21
19
  raise_project_with_that_name_already_exists! if File.exists?(target)
22
20
 
23
21
  underscored_name = name.tr('-', '_')
@@ -45,75 +43,12 @@ module Bundlegem
45
43
  :bundler_version => bundler_dependency_version
46
44
  }
47
45
  ensure_safe_gem_name(name, constant_array)
48
-
49
- # Hmmm... generate dynamically instead? Yes, overwritten below
50
- templates = {
51
- 'Gemfile.tt' => "Gemfile",
52
- 'changelog.tt' => "changelog",
53
- 'gitignore.tt' => ".gitignore",
54
- 'lib/#{name}.rb.tt' => "lib/#{namespaced_path}.rb",
55
- 'lib/#{name}/version.rb.tt' => "lib/#{namespaced_path}/version.rb",
56
- '#{name}.gemspec.tt' => "#{name}.gemspec",
57
- 'Rakefile.tt' => "Rakefile",
58
- 'README.md.tt' => "README.md",
59
- 'bin/console.tt' => "bin/console"
60
- }
61
-
62
-
63
- if ask_and_set(:coc, "Do you want to include a code of conduct in gems you generate?",
64
- "Codes of conduct can increase contributions to your project by contributors who " \
65
- "prefer collaborative, safe spaces. You can read more about the code of conduct at " \
66
- "contributor-covenant.org. Having a code of conduct means agreeing to the responsibility " \
67
- "of enforcing it, so be sure that you are prepared to do that. For suggestions about " \
68
- "how to enforce codes of conduct, see bit.ly/coc-enforcement."
69
- )
70
- templates.merge!("CODE_OF_CONDUCT.md.tt" => "CODE_OF_CONDUCT.md")
71
- end
72
-
73
-
74
- if ask_and_set(:mit, "Do you want to license your code permissively under the MIT license?",
75
- "This means that any other developer or company will be legally allowed to use your code " \
76
- "for free as long as they admit you created it. You can read more about the MIT license " \
77
- "at choosealicense.com/licenses/mit."
78
- )
79
- config[:mit] = true
80
- templates.merge!("LICENSE.txt.tt" => "LICENSE.txt")
81
- end
82
-
83
- if test_framework = ask_and_set_test_framework
84
- templates.merge!(".travis.yml.tt" => ".travis.yml")
85
-
86
- case test_framework
87
- when 'rspec'
88
- templates.merge!(
89
- "rspec.tt" => ".rspec",
90
- "spec/spec_helper.rb.tt" => "spec/spec_helper.rb",
91
- 'spec/#{name}_spec.rb.tt' => "spec/#{namespaced_path}_spec.rb"
92
- )
93
- when 'minitest'
94
- templates.merge!(
95
- "test/minitest_helper.rb.tt" => "test/minitest_helper.rb",
96
- "test/test_newgem.rb.tt" => "test/test_#{namespaced_path}.rb"
97
- )
98
- end
99
- end
100
-
101
- templates.merge!("exe/newgem.tt" => "exe/#{name}") if options[:bin]
102
-
103
- if options[:ext]
104
- templates.merge!(
105
- "ext/newgem/extconf.rb.tt" => "ext/#{name}/extconf.rb",
106
- "ext/newgem/newgem.h.tt" => "ext/#{name}/#{underscored_name}.h",
107
- "ext/newgem/newgem.c.tt" => "ext/#{name}/#{underscored_name}.c"
108
- )
109
- end
110
-
111
- puts "Creating new project folder\n\n"
112
46
 
113
47
  template_src = match_template_src
114
48
  template_directories = dynamically_generate_template_directories
115
- templates = dynamically_generate_templates || templates
49
+ templates = dynamically_generate_templates(config)
116
50
 
51
+ puts "Creating new project folder '#{name}'\n\n"
117
52
  create_template_directories(template_directories, target)
118
53
 
119
54
  templates.each do |src, dst|
@@ -139,7 +74,7 @@ module Bundlegem
139
74
  def dynamically_generate_template_directories
140
75
  # return nil if options["template"].nil?
141
76
 
142
- template_src = get_template_src
77
+ template_src = TemplateManager.get_template_src(options)
143
78
 
144
79
  template_dirs = {}
145
80
  Dir.glob("#{template_src}/**/*").each do |f|
@@ -150,22 +85,61 @@ module Bundlegem
150
85
  template_dirs
151
86
  end
152
87
 
153
- def dynamically_generate_templates
154
- return nil if options["template"].nil?
88
+ # This function should be eliminated over time so that other methods conform to the
89
+ # new algo for generating templates automatically.
90
+ # Really, this function generates a template_src to template_dst naming
91
+ # structure so that a later method can copy all the template files from the
92
+ # source and rename them properly
93
+ def generate_templates_for_built_in_gems(config)
94
+ # Hmmm... generate dynamically instead? Yes, overwritten below
95
+ templates = {
96
+ 'Gemfile.tt' => "Gemfile",
97
+ 'changelog.tt' => "changelog",
98
+ 'gitignore.tt' => ".gitignore",
99
+ 'lib/#{name}.rb.tt' => "lib/#{config[:namespaced_path]}.rb",
100
+ 'lib/#{name}/version.rb.tt' => "lib/#{config[:namespaced_path]}/version.rb",
101
+ '#{name}.gemspec.tt' => "#{config[:name]}.gemspec",
102
+ 'Rakefile.tt' => "Rakefile",
103
+ 'README.md.tt' => "README.md",
104
+ 'bin/console.tt' => "bin/console"
105
+ }
155
106
 
156
- template_src = get_template_src
157
-
158
- templates = {}
159
- Dir.glob("#{template_src}/**/*.tt").each do |f|
160
- base_path = f[template_src.length+1..-1]
161
- templates.merge!(base_path => base_path.gsub(/\.tt$/, "").gsub('#{name}', "#{name}") )
162
- end
163
-
164
- raise_no_files_in_template_error! if templates.empty?
107
+ prompt_coc!(templates)
108
+ prompt_mit!(templates, config)
109
+ prompt_test_framework!(templates, config)
165
110
 
111
+ templates.merge!("exe/newgem.tt" => "exe/#{config[:name]}") if config[:bin]
112
+
113
+ if config[:ext]
114
+ templates.merge!(
115
+ "ext/newgem/extconf.rb.tt" => "ext/#{config[:name]}/extconf.rb",
116
+ "ext/newgem/newgem.h.tt" => "ext/#{config[:name]}/#{config[:underscored_name]}.h",
117
+ "ext/newgem/newgem.c.tt" => "ext/#{config[:name]}/#{config[:underscored_name]}.c"
118
+ )
119
+ end
166
120
  templates
167
121
  end
168
122
 
123
+ # Figures out the translation between all the .tt file to their
124
+ # destination names
125
+ def dynamically_generate_templates(config)
126
+ #if options["template"].nil? # if it's doing some of the built in template
127
+ # return generate_templates_for_built_in_gems(config)
128
+ #else
129
+ template_src = TemplateManager.get_template_src(options)
130
+
131
+ templates = {}
132
+ Dir.glob("#{template_src}/**/{*,.*}.tt").each do |f|
133
+ base_path = f[template_src.length+1..-1]
134
+ templates.merge!(base_path => base_path.gsub(/\.tt$/, "").gsub('#{name}', "#{name}") )
135
+ end
136
+
137
+ raise_no_files_in_template_error! if templates.empty?
138
+
139
+ return templates
140
+ #end
141
+ end
142
+
169
143
  def create_template_directories(template_directories, target)
170
144
  template_directories.each do |k,v|
171
145
  d = "#{target}/#{v}"
@@ -174,51 +148,23 @@ module Bundlegem
174
148
  end
175
149
  end
176
150
 
151
+ # returns the full path of the template source
177
152
  def match_template_src
178
- template_src = get_template_src
153
+ template_src = TemplateManager.get_template_src(options)
179
154
 
180
- if template_exists_within_repo?(template_src) or File.exists?(template_src)
155
+ if File.exists?(template_src)
181
156
  return template_src # 'newgem' refers to the built in template that comes with the gem
182
157
  else
183
158
  raise_template_not_found! # else message the user that the template could not be found
184
159
  end
185
160
  end
186
-
187
- def get_template_src
188
- template_name = options["template"].nil? ? "newgem" : options["template"]
189
-
190
- if template_exists_within_repo?(template_name)
191
- gem_template_location = get_internal_template_location
192
- else
193
- gem_template_location = File.expand_path("~/.bundlegem/gem_templates")
194
- end
195
- template_src = "#{gem_template_location}/#{template_name}"
196
- end
197
161
 
198
- def template_exists_within_repo?(template_name)
199
- file_in_source?(template_name)
200
- end
201
162
 
202
- def get_internal_template_location
203
- File.expand_path("#{File.dirname(__FILE__)}/../templates")
204
- end
205
-
206
163
  def resolve_name(name)
207
164
  Pathname.pwd.join(name).basename.to_s
208
165
  end
209
166
 
210
- def ask_and_set(key, header, message)
211
- choice = options[key] # || Bundler.settings["gem.#{key}"]
212
-
213
- if choice.nil?
214
- Bundler.ui.confirm header
215
- choice = (Bundler.ui.ask("#{message} y/(n):") =~ /y|yes/)
216
- Bundler.settings.set_global("gem.#{key}", choice)
217
- end
218
-
219
- choice
220
- end
221
-
167
+
222
168
  def validate_ext_name
223
169
  return unless gem_name.index('-')
224
170
 
@@ -229,27 +175,7 @@ module Bundlegem
229
175
  exit 1
230
176
  end
231
177
 
232
- def ask_and_set_test_framework
233
- test_framework = options[:test] || Bundler.settings["gem.test"]
234
-
235
- if test_framework.nil?
236
- Bundler.ui.confirm "Do you want to generate tests with your gem?"
237
- result = Bundler.ui.ask "Type 'rspec' or 'minitest' to generate those test files now and " \
238
- "in the future. rspec/minitest/(none):"
239
- if result =~ /rspec|minitest/
240
- test_framework = result
241
- else
242
- test_framework = false
243
- end
244
- end
245
-
246
- if Bundler.settings["gem.test"].nil?
247
- Bundler.settings.set_global("gem.test", test_framework)
248
- end
249
-
250
- test_framework
251
- end
252
-
178
+
253
179
  def bundler_dependency_version
254
180
  v = Gem::Version.new(Bundler::VERSION)
255
181
  req = v.segments[0..1]
@@ -257,15 +183,7 @@ module Bundlegem
257
183
  req.join(".")
258
184
  end
259
185
 
260
- def ensure_safe_gem_name name, constant_array
261
- if name =~ /^\d/
262
- Bundler.ui.error "Invalid gem name #{name} Please give a name which does not start with numbers."
263
- exit 1
264
- elsif Object.const_defined?(constant_array.first)
265
- Bundler.ui.error "Invalid gem name #{name} constant #{constant_array.join("::")} is already in use. Please choose another gem name."
266
- exit 1
267
- end
268
- end
186
+
269
187
 
270
188
 
271
189
 
@@ -291,7 +209,7 @@ module Bundlegem
291
209
  config = args.last.is_a?(Hash) ? args.pop : {}
292
210
  destination = args.first || source.sub(/#{TEMPLATE_EXTNAME}$/, "")
293
211
 
294
- source = File.expand_path(find_in_source_paths(source.to_s))
212
+ source = File.expand_path(TemplateManager.find_in_source_paths(source.to_s))
295
213
  context = instance_eval("binding")
296
214
 
297
215
  make_file(destination, config) do
@@ -302,19 +220,7 @@ module Bundlegem
302
220
 
303
221
  end
304
222
 
305
- #
306
- # EDIT: Reworked from Thor to not rely on Thor (or do so much unneeded stuff)
307
- #
308
- def find_in_source_paths(target)
309
- src_in_source_path = "#{File.dirname(__FILE__)}/../templates/#{target}"
310
- return src_in_source_path if File.exists?(src_in_source_path)
311
- target # failed, hopefully full path to a user specified gem template file
312
- end
313
223
 
314
- def file_in_source?(target)
315
- src_in_source_path = "#{File.dirname(__FILE__)}/../templates/#{target}"
316
- File.exists?(src_in_source_path)
317
- end
318
224
 
319
225
  #
320
226
  # EDIT: Reworked from Thor to not rely on Thor (or do so much unneeded stuff)
@@ -349,6 +255,102 @@ module Bundlegem
349
255
  Bundler.ui.error err_missing_template
350
256
  exit 1
351
257
  end
258
+
259
+
260
+ ############# STUFF THAT SHOULD BE REMOVED DOWN THE ROAD
261
+
262
+ # This asks the user if they want to setup rspec or test...
263
+ # It's not class based, it's additive based... Plus bundlegem does this already
264
+ def ask_and_set_test_framework
265
+ test_framework = options[:test] || Bundler.settings["gem.test"]
266
+
267
+ if test_framework.nil?
268
+ Bundler.ui.confirm "Do you want to generate tests with your gem?"
269
+ result = Bundler.ui.ask "Type 'rspec' or 'minitest' to generate those test files now and " \
270
+ "in the future. rspec/minitest/(none):"
271
+ if result =~ /rspec|minitest/
272
+ test_framework = result
273
+ else
274
+ test_framework = false
275
+ end
276
+ end
277
+
278
+ if Bundler.settings["gem.test"].nil?
279
+ Bundler.settings.set_global("gem.test", test_framework)
280
+ end
281
+
282
+ test_framework
283
+ end
284
+
285
+ def ask_and_set(key, header, message)
286
+ choice = options[key] # || Bundler.settings["gem.#{key}"]
287
+
288
+ if choice.nil?
289
+ Bundler.ui.confirm header
290
+ choice = (Bundler.ui.ask("#{message} y/(n):") =~ /y|yes/)
291
+ Bundler.settings.set_global("gem.#{key}", choice)
292
+ end
293
+
294
+ choice
295
+ end
296
+
297
+ def prompt_coc!(templates)
298
+ if ask_and_set(:coc, "Do you want to include a code of conduct in gems you generate?",
299
+ "Codes of conduct can increase contributions to your project by contributors who " \
300
+ "prefer collaborative, safe spaces. You can read more about the code of conduct at " \
301
+ "contributor-covenant.org. Having a code of conduct means agreeing to the responsibility " \
302
+ "of enforcing it, so be sure that you are prepared to do that. For suggestions about " \
303
+ "how to enforce codes of conduct, see bit.ly/coc-enforcement."
304
+ )
305
+ templates.merge!("CODE_OF_CONDUCT.md.tt" => "CODE_OF_CONDUCT.md")
306
+ end
307
+ end
308
+
309
+ def prompt_mit!(templates, config)
310
+ if ask_and_set(:mit, "Do you want to license your code permissively under the MIT license?",
311
+ "This means that any other developer or company will be legally allowed to use your code " \
312
+ "for free as long as they admit you created it. You can read more about the MIT license " \
313
+ "at choosealicense.com/licenses/mit."
314
+ )
315
+ config[:mit] = true
316
+ templates.merge!("LICENSE.txt.tt" => "LICENSE.txt")
317
+ end
318
+ end
319
+
320
+ def prompt_test_framework!(templates, config)
321
+ namespaced_path = config[:namespaced_path]
322
+ if test_framework = ask_and_set_test_framework
323
+ templates.merge!(".travis.yml.tt" => ".travis.yml")
324
+
325
+ case test_framework
326
+ when 'rspec'
327
+ templates.merge!(
328
+ "rspec.tt" => ".rspec",
329
+ "spec/spec_helper.rb.tt" => "spec/spec_helper.rb",
330
+ 'spec/#{name}_spec.rb.tt' => "spec/#{namespaced_path}_spec.rb"
331
+ )
332
+ when 'minitest'
333
+ templates.merge!(
334
+ "test/minitest_helper.rb.tt" => "test/minitest_helper.rb",
335
+ "test/test_newgem.rb.tt" => "test/test_#{namespaced_path}.rb"
336
+ )
337
+ end
338
+ end
339
+ end
340
+
341
+ # This checks to see that the gem_name is a valid ruby gem name and will 'work'
342
+ # and won't overlap with a bundlegem constant apparently...
343
+ #
344
+ # TODO: This should be defined within the template itself in some way possibly, may have security implications
345
+ def ensure_safe_gem_name(name, constant_array)
346
+ if name =~ /^\d/
347
+ Bundler.ui.error "Invalid gem name #{name} Please give a name which does not start with numbers."
348
+ exit 1
349
+ elsif Object.const_defined?(constant_array.first)
350
+ Bundler.ui.error "Invalid gem name #{name} constant #{constant_array.join("::")} is already in use. Please choose another gem name."
351
+ exit 1
352
+ end
353
+ end
352
354
 
353
355
  end
354
356
  end
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'yaml'
2
3
 
3
4
  module Bundlegem
4
5
 
@@ -13,11 +14,23 @@ module Bundlegem
13
14
  create_config_file_if_needed!
14
15
 
15
16
  @user_defined_templates = get_user_defined_templates
16
-
17
17
  @user_downloaded_templates = get_user_downloaded_templates
18
18
 
19
- # load configurations from config file if needed...
20
- # perhaps it would contain a list of remote templates specified by the user
19
+ # load configurations from config file
20
+ @c = YAML.load_file @config_file
21
+ end
22
+
23
+ def default_template
24
+ @c["default_template"]
25
+ end
26
+
27
+ def default_template=(val)
28
+ @c["default_template"] = val
29
+ File.write(@config_file, "# Comments made to this file will not be preserved\n#{YAML.dump(@c)}")
30
+ end
31
+
32
+ def built_in_templates
33
+
21
34
  end
22
35
 
23
36
  # not implemented yet
@@ -54,7 +67,11 @@ module Bundlegem
54
67
 
55
68
  def create_config_file_if_needed!
56
69
  FileUtils.mkdir_p @user_defined_templates_path
57
- FileUtils.touch @config_file
70
+ FileUtils.cp("#{SOcreate_new_templateURCE_ROOT}/config/config", @config_file) unless File.exists? @config_file
71
+ end
72
+
73
+ def create_new_template(template_name)
74
+ puts "i'm still a stub"
58
75
  end
59
76
 
60
77
  end
@@ -0,0 +1,59 @@
1
+ require 'fileutils'
2
+
3
+ module Bundlegem
4
+
5
+ # This class handles the logic for finding templates
6
+ # in the user's dir, the gem's builtin templates
7
+ # (and on the web some day)
8
+ class TemplateManager
9
+
10
+ class << self
11
+
12
+ def create_new_template(template_name)
13
+
14
+ end
15
+
16
+
17
+ def get_default_template_name
18
+ "newgem"
19
+ end
20
+
21
+ def get_template_src(options)
22
+ template_name = options["template"].nil? ? get_default_template_name : options["template"]
23
+
24
+ if template_exists_within_repo?(template_name)
25
+ gem_template_location = get_internal_template_location
26
+ else
27
+ gem_template_location = File.expand_path("~/.bundlegem/gem_templates")
28
+ end
29
+ template_src = "#{gem_template_location}/#{template_name}"
30
+ end
31
+
32
+
33
+ def get_internal_template_location
34
+ File.expand_path("#{File.dirname(__FILE__)}/templates")
35
+ end
36
+
37
+ def template_exists_within_repo?(template_name)
38
+ TemplateManager.file_in_source?(template_name)
39
+ end
40
+
41
+ #
42
+ # EDIT: Reworked from Thor to not rely on Thor (or do so much unneeded stuff)
43
+ #
44
+ def find_in_source_paths(target)
45
+ src_in_source_path = "#{File.dirname(__FILE__)}/templates/#{target}"
46
+ return src_in_source_path if File.exists?(src_in_source_path)
47
+ target # failed, hopefully full path to a user specified gem template file
48
+ end
49
+
50
+ # Get's path to 'target' from within the gem's "templates" folder
51
+ # within the gem's source
52
+ def file_in_source?(target)
53
+ src_in_source_path = "#{File.dirname(__FILE__)}/templates/#{target}"
54
+ File.exists?(src_in_source_path)
55
+ end
56
+
57
+ end
58
+ end
59
+ end