cog 0.0.13 → 0.0.14
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/bin/cog +3 -1
- data/lib/cog/generator.rb +13 -9
- data/lib/cog/tool.rb +9 -9
- data/lib/cog/version.rb +1 -1
- data/templates/cog/generator/basic-template.txt.erb.erb +1 -0
- data/templates/cog/generator/basic.rb.erb +2 -1
- metadata +4 -3
data/bin/cog
CHANGED
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',
|
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
|
-
|
87
|
-
|
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?
|
93
|
+
if same? dest, scratch
|
90
94
|
FileUtils.rm scratch
|
91
95
|
else
|
92
|
-
puts "Generated #{
|
93
|
-
FileUtils.mv scratch,
|
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
@@ -0,0 +1 @@
|
|
1
|
+
This is some context: <%%= @some_context %>!
|
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:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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
|