cog 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/bin/cog CHANGED
@@ -37,7 +37,9 @@ command :generator do |c|
37
37
  else
38
38
  # Create
39
39
  args.each do |name|
40
- Cog::Generator.create name, options
40
+ unless Cog::Generator.create name, options
41
+ puts "Failed to create generator #{name}"
42
+ end
41
43
  end
42
44
  end
43
45
  end
data/lib/cog/generator.rb CHANGED
@@ -33,15 +33,17 @@ module Cog
33
33
  # ==== Returns
34
34
  # Whether or not the generator was created successfully
35
35
  def self.create(name, opt={})
36
- return false unless Config.instance.project?
37
- filename = File.join Config.instance.project_generators_path, "#{name}.rb"
38
- return false if File.exists? filename
39
36
  tool = (opt[:tool] || :basic).to_s
37
+ return false unless Config.instance.project?
38
+ gen_name = File.join Config.instance.project_generators_path, "#{name}.rb"
39
+ template_name = File.join Config.instance.project_templates_path, "#{name}.txt.erb"
40
+ return false if File.exists?(gen_name) || File.exists?(template_name)
40
41
  Object.new.instance_eval do
41
42
  extend Generator
42
43
  @name = name
43
44
  @class_name = name.to_s.camelize
44
- stamp 'cog/generator/basic.rb', filename
45
+ stamp 'cog/generator/basic.rb', gen_name, :absolute_destination => true
46
+ stamp 'cog/generator/basic-template.txt.erb', template_name, :absolute_destination => true
45
47
  end
46
48
  true
47
49
  end
@@ -80,17 +82,19 @@ module Cog
80
82
  #
81
83
  # ==== Options
82
84
  # * <tt>:absolute_template_path</tt> - is the +template_path+ argument absolute? (default: +false+)
85
+ # * <tt>:absolute_destination</tt> - is the +destination+ argument absolute? (default: +false+)
83
86
  def stamp(template_path, destination, opt={})
84
87
  t = get_template template_path, :absolute => opt[:absolute_template_path]
85
88
  b = opt[:binding] || binding
86
- FileUtils.mkpath File.dirname(destination) unless File.exists? destination
87
- scratch = "#{destination}.scratch"
89
+ dest = opt[:absolute_destination] ? dest : File.join(Config.instance.project_source_path, destination)
90
+ FileUtils.mkpath File.dirname(dest) unless File.exists? dest
91
+ scratch = "#{dest}.scratch"
88
92
  File.open(scratch, 'w') {|file| file.write t.result(b)}
89
- if same? destination, scratch
93
+ if same? dest, scratch
90
94
  FileUtils.rm scratch
91
95
  else
92
- puts "Generated #{destination}"
93
- FileUtils.mv scratch, destination
96
+ puts "Generated #{dest}"
97
+ FileUtils.mv scratch, dest
94
98
  end
95
99
  nil
96
100
  end
data/lib/cog/tool.rb CHANGED
@@ -22,15 +22,15 @@ module Cog
22
22
  @email = 'youremail@...'
23
23
  @description = 'A one-liner'
24
24
  @cog_version = Cog::VERSION
25
- stamp 'cog/tool/tool.rb', "#{@name}/lib/#{@name}.rb"
26
- stamp 'cog/tool/version.rb', "#{@name}/lib/#{@name}/version.rb"
27
- stamp 'cog/tool/generator.rb', "#{@name}/cog/templates/#{@name}/generator.rb.erb"
28
- stamp 'cog/tool/Gemfile', "#{@name}/Gemfile"
29
- stamp 'cog/tool/Rakefile', "#{@name}/Rakefile"
30
- stamp 'cog/tool/tool.gemspec', "#{@name}/#{@name}.gemspec"
31
- stamp 'cog/tool/API.rdoc', "#{@name}/API.rdoc"
32
- stamp 'cog/tool/LICENSE', "#{@name}/LICENSE"
33
- stamp 'cog/tool/README.markdown', "#{@name}/README.markdown"
25
+ stamp 'cog/tool/tool.rb', "#{@name}/lib/#{@name}.rb", :absolute_destination => true
26
+ stamp 'cog/tool/version.rb', "#{@name}/lib/#{@name}/version.rb", :absolute_destination => true
27
+ stamp 'cog/tool/generator.rb', "#{@name}/cog/templates/#{@name}/generator.rb.erb", :absolute_destination => true
28
+ stamp 'cog/tool/Gemfile', "#{@name}/Gemfile", :absolute_destination => true
29
+ stamp 'cog/tool/Rakefile', "#{@name}/Rakefile", :absolute_destination => true
30
+ stamp 'cog/tool/tool.gemspec', "#{@name}/#{@name}.gemspec", :absolute_destination => true
31
+ stamp 'cog/tool/API.rdoc', "#{@name}/API.rdoc", :absolute_destination => true
32
+ stamp 'cog/tool/LICENSE', "#{@name}/LICENSE", :absolute_destination => true
33
+ stamp 'cog/tool/README.markdown', "#{@name}/README.markdown", :absolute_destination => true
34
34
  end
35
35
  end
36
36
  end
data/lib/cog/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cog
2
- VERSION = '0.0.13' unless const_defined? :VERSION
2
+ VERSION = '0.0.14' unless const_defined? :VERSION
3
3
  end
@@ -0,0 +1 @@
1
+ This is some context: <%%= @some_context %>!
@@ -4,7 +4,8 @@ class <%= @class_name %>
4
4
  include Cog::Generator
5
5
 
6
6
  def generate
7
- # TODO: create a template and use stamp here to generate source code
7
+ @some_context = :my_context_value
8
+ stamp '<%= @name %>.txt', 'generated_<%= @name %>.txt'
8
9
  end
9
10
  end
10
11
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cog
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 13
10
- version: 0.0.13
9
+ - 14
10
+ version: 0.0.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kevin Tonon
@@ -57,6 +57,7 @@ files:
57
57
  - bin/cog
58
58
  - Default.cogfile
59
59
  - LICENSE
60
+ - templates/cog/generator/basic-template.txt.erb.erb
60
61
  - templates/cog/generator/basic.rb.erb
61
62
  - templates/cog/snippets/c++/generated_warning.h.erb
62
63
  - templates/cog/snippets/generated_warning.txt