cog 0.0.8 → 0.0.9
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/API.rdoc +9 -7
- data/Default.cogfile +3 -0
- data/bin/cog +21 -22
- data/lib/cog.rb +1 -1
- data/lib/cog/cogfile.rb +65 -0
- data/lib/cog/config.rb +40 -75
- data/lib/cog/meta.rb +9 -0
- data/lib/cog/meta/gen_gen.rb +85 -0
- data/lib/cog/meta/mirror_gen.rb +39 -0
- data/lib/cog/mixins/uses_templates.rb +54 -5
- data/lib/cog/spec_helpers/matchers.rb +3 -2
- data/lib/cog_version.rb +1 -1
- data/templates/c++/mirror-abstract.h.erb +6 -0
- data/templates/c++/mirror-impl.cpp.erb +1 -0
- data/templates/mirror.rb.erb +10 -0
- data/templates/snippets/c++/generated_warning.h.erb +9 -0
- data/templates/snippets/generated_warning.txt +7 -0
- metadata +11 -6
- data/lib/cog/template_controller.rb +0 -74
data/API.rdoc
CHANGED
@@ -16,13 +16,15 @@ when you issue this command from a shell in the root directory of your project:
|
|
16
16
|
and it will look something like this:
|
17
17
|
|
18
18
|
# All paths are relative to the directory containing this file.
|
19
|
-
|
20
|
-
# The directory in which to
|
21
|
-
|
22
|
-
|
23
|
-
# The directory in which
|
24
|
-
|
25
|
-
|
19
|
+
|
20
|
+
# The directory in which to place Ruby generators and +ERB+ templates.
|
21
|
+
cog_dir 'cog'
|
22
|
+
|
23
|
+
# The directory in which to place generated application code.
|
24
|
+
app_dir 'src'
|
25
|
+
|
26
|
+
# The default language in which to generate source code.
|
27
|
+
language 'c++'
|
26
28
|
|
27
29
|
== Testing
|
28
30
|
|
data/Default.cogfile
CHANGED
data/bin/cog
CHANGED
@@ -12,12 +12,13 @@ unless File.respond_to? :realpath
|
|
12
12
|
end
|
13
13
|
$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
|
14
14
|
require 'rubygems'
|
15
|
+
require 'active_support/core_ext'
|
15
16
|
require 'cog'
|
16
17
|
require 'cog_version'
|
17
18
|
require 'gli'
|
18
19
|
require 'fileutils'
|
19
20
|
|
20
|
-
include GLI
|
21
|
+
include GLI::App
|
21
22
|
|
22
23
|
program_desc 'This is a utility to help you write code generators.'
|
23
24
|
|
@@ -34,26 +35,24 @@ command :init do |c|
|
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
desc 'Create a new mirror class'
|
38
|
-
arg_name 'ClassName'
|
39
|
-
command :mirror do |c|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
38
|
+
# desc 'Create a new mirror class'
|
39
|
+
# arg_name 'ClassName'
|
40
|
+
# command :mirror do |c|
|
41
|
+
# c.desc 'The target language (see languages command)'
|
42
|
+
# c.arg_name 'language'
|
43
|
+
# c.flag [:language, :l]
|
44
|
+
#
|
45
|
+
# c.desc 'Slash (/) separated prefix for generator, templates, and app code'
|
46
|
+
# c.arg_name 'path'
|
47
|
+
# c.flag [:package, :p]
|
48
|
+
#
|
49
|
+
# c.action do |g,opt,a|
|
50
|
+
# a.each do |class_name|
|
51
|
+
# mirror_gen = Cog::Meta::MirrorGen.new class_name
|
52
|
+
# mirror_gen.stamp opt
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
# end
|
57
56
|
|
58
57
|
desc 'List supported languages'
|
59
58
|
command :languages do |c|
|
@@ -93,4 +92,4 @@ on_error do |exception|
|
|
93
92
|
true
|
94
93
|
end
|
95
94
|
|
96
|
-
exit
|
95
|
+
exit run(ARGV)
|
data/lib/cog.rb
CHANGED
data/lib/cog/cogfile.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Cog
|
2
|
+
|
3
|
+
# In your project's +Cogfile+, +self+ has been set to an instance of this class.
|
4
|
+
#
|
5
|
+
# ==== Example +Cogfile+
|
6
|
+
# cog_dir 'cog'
|
7
|
+
# app_dir 'src'
|
8
|
+
# language 'c++'
|
9
|
+
#
|
10
|
+
# Typing `cog init` will create a +Cogfile+ in the present working directory.
|
11
|
+
#
|
12
|
+
# +Cogfile+ files are used to configure an instance of Config.
|
13
|
+
class Cogfile
|
14
|
+
|
15
|
+
def initialize(config) # :nodoc:
|
16
|
+
@config = config
|
17
|
+
end
|
18
|
+
|
19
|
+
# Interpret the Cogfile and initialize @config
|
20
|
+
def interpret # :nodoc:
|
21
|
+
eval File.read(@config.cogfile_path), binding
|
22
|
+
rescue Exception => e
|
23
|
+
raise CogfileError.new(e.to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Define the directory in which to place Ruby generators and +ERB+ templates.
|
27
|
+
# ==== Arguments
|
28
|
+
# * +path+ - A file system path
|
29
|
+
# * +absolute+ - If false, the path is relative to the directory containing the +Cogfile+
|
30
|
+
def cog_dir(path, absolute=false)
|
31
|
+
@config.instance_eval do
|
32
|
+
@cog_dir = absolute ? path : File.join(project_root, path)
|
33
|
+
@generator_dir = File.join @cog_dir, 'generators'
|
34
|
+
@template_dir = File.join @cog_dir, 'templates'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Define the directory in which to place generated application source code.
|
39
|
+
# ==== Arguments
|
40
|
+
# * +path+ - A file system path
|
41
|
+
# * +absolute+ - If false, the path is relative to the directory containing the +Cogfile+
|
42
|
+
def app_dir(path, absolute=false)
|
43
|
+
@config.instance_eval do
|
44
|
+
@app_dir = absolute ? path : File.join(project_root, path)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Define the default language in which to generated application source code.
|
49
|
+
# ==== Arguments
|
50
|
+
# * +lang+ - A code for the language. Acceptable values are <tt>c++</tt>.
|
51
|
+
def language(lang)
|
52
|
+
@config.instance_eval do
|
53
|
+
@language = lang
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# For wrapping errors which occur during the processing of a +Cogfile+.
|
59
|
+
class CogfileError < StandardError
|
60
|
+
def message
|
61
|
+
"in Cogfile, " + super
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/lib/cog/config.rb
CHANGED
@@ -1,25 +1,50 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'singleton'
|
3
|
+
require 'cog/cogfile'
|
3
4
|
|
4
5
|
module Cog
|
5
6
|
|
6
|
-
#
|
7
|
-
#
|
7
|
+
# This interface is intended for use within generators. Instances of this type
|
8
|
+
# are initialized via Cogfile files.
|
8
9
|
class Config
|
10
|
+
|
11
|
+
# Directory to which application source code is generated.
|
12
|
+
attr_reader :app_dir
|
13
|
+
|
14
|
+
# Path to the +Cogfile+.
|
15
|
+
attr_reader :cogfile_path
|
16
|
+
|
17
|
+
# Directory in which to find Ruby source files. These are files which
|
18
|
+
# control exactly how the code is going to be generated.
|
19
|
+
attr_reader :generator_dir
|
20
|
+
|
21
|
+
# Default language in which to generated application source code.
|
22
|
+
attr_reader :language
|
9
23
|
|
10
|
-
#
|
24
|
+
# Directory in which the +Cogfile+ is found.
|
11
25
|
attr_reader :project_root
|
12
26
|
|
13
|
-
#
|
14
|
-
attr_reader :
|
27
|
+
# Directory in which to find ERB template files.
|
28
|
+
attr_reader :template_dir
|
15
29
|
|
16
|
-
#
|
17
|
-
#
|
30
|
+
# Initialize from a +Cogfile+ at the given path.
|
31
|
+
# ==== Arguments
|
32
|
+
# * +path+ - A file system path to a +Cogfile+. The file must exists.
|
33
|
+
def initialize(path)
|
34
|
+
@cogfile_path = File.expand_path path
|
35
|
+
@project_root = File.dirname @cogfile_path
|
36
|
+
cogfile = Cogfile.new self
|
37
|
+
cogfile.interpret
|
38
|
+
end
|
39
|
+
|
40
|
+
# The default configuration for the project.
|
41
|
+
#
|
42
|
+
# Initialized using the +Cogfile+ for the current project.
|
18
43
|
# The +Cogfile+ will be looked for in the present working directory. If none
|
19
44
|
# is found there the parent directory will be checked, and then the
|
20
45
|
# grandparent, and so on.
|
21
46
|
#
|
22
|
-
#
|
47
|
+
# ==== Returns
|
23
48
|
# An instance of Cogfile which has been configured with a +Cogfile+. If no
|
24
49
|
# such file was found then +nil+.
|
25
50
|
def self.for_project
|
@@ -35,78 +60,18 @@ module Cog
|
|
35
60
|
end
|
36
61
|
end
|
37
62
|
|
38
|
-
#
|
39
|
-
def
|
40
|
-
@cogfile_path = File.expand_path path
|
41
|
-
@project_root = File.dirname @cogfile_path
|
42
|
-
begin
|
43
|
-
eval File.read(path), binding
|
44
|
-
rescue Exception => e
|
45
|
-
raise CogfileError.new(e.to_s)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# The directory in which to place Ruby generators and +ERB+ templates.
|
50
|
-
#
|
51
|
-
# Can be used as a getter, or a setter within the +Cogfile+. As a setter,
|
52
|
-
# +val+ is relative to project_root unless the option <tt>:absolute</tt>
|
53
|
-
# is truthy.
|
54
|
-
def cog_dir(val=nil, opt={})
|
55
|
-
get_or_set :cog_dir, val, opt
|
56
|
-
end
|
57
|
-
|
58
|
-
# The directory in which to place generated application code.
|
59
|
-
#
|
60
|
-
# Can be used as a getter, or a setter within the +Cogfile+. As a setter,
|
61
|
-
# +val+ is relative to project_root unless the option <tt>:absolute</tt>
|
62
|
-
# is truthy.
|
63
|
-
def app_dir(val=nil, opt={})
|
64
|
-
get_or_set :app_dir, val, opt
|
65
|
-
end
|
66
|
-
|
67
|
-
# The path to the routes file which maps defines how generators map to
|
68
|
-
# generated application code.
|
69
|
-
def routes_path
|
70
|
-
File.join cog_dir, 'routes.rb'
|
71
|
-
end
|
72
|
-
|
73
|
-
# The directory in which to find Ruby source files. These are files which
|
74
|
-
# control exactly how the code is going to be generated.
|
75
|
-
def generator_dir(val=nil, opt={})
|
76
|
-
File.join cog_dir, 'generators'
|
77
|
-
end
|
78
|
-
|
79
|
-
# The directory in which to find ERB template files.
|
80
|
-
def template_dir(val=nil, opt={})
|
81
|
-
File.join cog_dir, 'templates'
|
82
|
-
end
|
83
|
-
|
84
|
-
# Location of the installed gem
|
85
|
-
def self.gem_dir
|
63
|
+
# Location of the installed cog gem
|
64
|
+
def self.gem_dir # :nodoc:
|
86
65
|
spec = Gem.loaded_specs['cog']
|
87
66
|
if spec.nil?
|
88
|
-
|
67
|
+
# The current __FILE__ is:
|
68
|
+
# ${COG_GEM_ROOT}/lib/cog/config.rb
|
69
|
+
File.expand_path File.join(File.dirname(__FILE__), '..', '..')
|
89
70
|
else
|
90
71
|
spec.gem_dir
|
91
72
|
end
|
92
73
|
end
|
93
|
-
|
94
|
-
private
|
95
|
-
def get_or_set(name, val, opt={}, &block)
|
96
|
-
if val.nil?
|
97
|
-
instance_variable_get "@#{name}"
|
98
|
-
else
|
99
|
-
val = File.join project_root, val unless opt[:absolute]
|
100
|
-
instance_variable_set "@#{name}", val
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
# For wrapping errors which occur during the processing of a +Cogfile+.
|
106
|
-
class CogfileError < StandardError
|
107
|
-
def message
|
108
|
-
"in Cogfile, " + super
|
109
|
-
end
|
110
|
-
end
|
111
74
|
|
75
|
+
end
|
76
|
+
|
112
77
|
end
|
data/lib/cog/meta.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'cog/mixins/uses_templates'
|
2
|
+
require 'cog/config'
|
3
|
+
|
4
|
+
module Cog
|
5
|
+
module Meta
|
6
|
+
|
7
|
+
# An abstract generator generator.
|
8
|
+
#
|
9
|
+
# Subclasses define generators which make other generators.
|
10
|
+
class GenGen
|
11
|
+
|
12
|
+
include Mixins::UsesTemplates
|
13
|
+
|
14
|
+
# Create a ruby generator from a template.
|
15
|
+
#
|
16
|
+
# === Parameters
|
17
|
+
# * +ruby_template+ - name of the ruby template. This is a template
|
18
|
+
# which is distributed in the cog gem. It is relative to
|
19
|
+
# <tt>templates/</tt>
|
20
|
+
# * +generator_name+ - name of the generator
|
21
|
+
#
|
22
|
+
# === Options
|
23
|
+
# * <tt>:language</tt> - only <tt>'c++'</tt> is accepted at this time
|
24
|
+
# * <tt>:package</tt> - slash (/) separated path which will prefix
|
25
|
+
# +generator_name+
|
26
|
+
# * <tt>:binding</tt> - specify an alternate binding to use when resolving
|
27
|
+
# the +ERB+ template. If none is provided +self.binding+ will be used.
|
28
|
+
def stamp_generator(ruby_template, generator_name, opt={})
|
29
|
+
template = File.join Config.gem_dir, 'templates', "#{ruby_template}.rb"
|
30
|
+
target = "#{generator_name}.rb"
|
31
|
+
target = File.join opt[:package], target if opt[:package]
|
32
|
+
target = File.join 'generators', target
|
33
|
+
stamp template,
|
34
|
+
:target => target,
|
35
|
+
:target_type => :cog,
|
36
|
+
:use_absolute_path => true,
|
37
|
+
:binding => opt[:binding]
|
38
|
+
end
|
39
|
+
|
40
|
+
# Create an app module template from a template.
|
41
|
+
#
|
42
|
+
# === Parameters
|
43
|
+
# * +source_template+ - name of the source template. This is a template
|
44
|
+
# which is distributed in the cog gem. It is relative to
|
45
|
+
# <tt>templates/{language}/</tt>, where language is specified by the
|
46
|
+
# <tt>:language</tt> option. Do not include any file extension such as
|
47
|
+
# <tt>.h</tt> (the <tt>:language</tt> will also determine this)
|
48
|
+
# * +module_name+ - name of the module. For languages like <tt>:c++</tt>,
|
49
|
+
# two templates will be generated (i.e. one <tt>.h</tt> and one
|
50
|
+
# <tt>.cpp</tt>)
|
51
|
+
#
|
52
|
+
# === Options
|
53
|
+
# * <tt>:language</tt> - only <tt>'c++'</tt> is accepted at this time
|
54
|
+
# * <tt>:package</tt> - slash (/) separated path which will prefix
|
55
|
+
# +module_name+
|
56
|
+
# * <tt>:binding</tt> - specify an alternate binding to use when resolving
|
57
|
+
# the +ERB+ template. If none is provided +self.binding+ will be used.
|
58
|
+
def stamp_module(source_template, module_name, opt={})
|
59
|
+
lang = opt[:language] || 'c++'
|
60
|
+
extensions_for_language(lang).each do |ext|
|
61
|
+
template = File.join Config.gem_dir, 'templates', lang, "#{source_template}.#{ext}"
|
62
|
+
target = "#{module_name}.#{ext}"
|
63
|
+
target = File.join opt[:package], target if opt[:package]
|
64
|
+
target = File.join 'templates', target
|
65
|
+
stamp template,
|
66
|
+
:target => target,
|
67
|
+
:target_type => :cog,
|
68
|
+
:use_absolute_path => true,
|
69
|
+
:binding => opt[:binding]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
def extensions_for_language(lang)
|
75
|
+
case lang.to_s
|
76
|
+
when /(cpp|c\+\+)/i
|
77
|
+
[:h, :cpp]
|
78
|
+
else
|
79
|
+
[]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'cog/meta/gen_gen'
|
2
|
+
|
3
|
+
module Cog
|
4
|
+
module Meta
|
5
|
+
|
6
|
+
# Generates a Cog::Mixins::Mirror and associated templates.
|
7
|
+
class MirrorGen
|
8
|
+
|
9
|
+
# Create a mirror generator
|
10
|
+
#
|
11
|
+
# === Parameters
|
12
|
+
# * +name+ - the name of the mirror. Will be forced to singular form.
|
13
|
+
def initialize(name, opt={})
|
14
|
+
@name = name.singularize
|
15
|
+
@gg = GenGen.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def filename
|
19
|
+
@name.underscore
|
20
|
+
end
|
21
|
+
|
22
|
+
def classname
|
23
|
+
@name.camelize
|
24
|
+
end
|
25
|
+
|
26
|
+
def abstract_classname
|
27
|
+
"Cog#{@name.camelize}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def stamp(opt={})
|
31
|
+
opt[:binding] = binding
|
32
|
+
@gg.stamp_generator 'mirror', filename, opt
|
33
|
+
@gg.stamp_module 'mirror-abstract', "abstract_#{filename}", opt
|
34
|
+
@gg.stamp_module 'mirror-impl', filename, opt
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -7,6 +7,18 @@ module Cog
|
|
7
7
|
# Mixin for classes that can use templates to generate code
|
8
8
|
module UsesTemplates
|
9
9
|
|
10
|
+
# File extension for a snippet of the given source code language.
|
11
|
+
# ==== Example
|
12
|
+
# snippet_extension 'c++' # => 'h'
|
13
|
+
def snippet_extension(lang = 'text')
|
14
|
+
case lang
|
15
|
+
when /(c\+\+|c|objc)/i
|
16
|
+
'h'
|
17
|
+
else
|
18
|
+
'txt'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
10
22
|
# Get the template with the given name.
|
11
23
|
#
|
12
24
|
# === Parameters
|
@@ -21,11 +33,16 @@ module Cog
|
|
21
33
|
# An instance of ERB.
|
22
34
|
def get_template(path, opt={})
|
23
35
|
path += '.erb'
|
24
|
-
|
25
|
-
|
26
|
-
|
36
|
+
prefix = if opt[:cog_template]
|
37
|
+
File.join Config.gem_dir, 'templates'
|
38
|
+
elsif !opt[:absolute]
|
39
|
+
Config.for_project.template_dir
|
40
|
+
end
|
41
|
+
path = File.join prefix, path unless prefix.nil?
|
42
|
+
raise Errors::MissingTemplate.new path unless File.exists? path
|
43
|
+
ERB.new File.read(path), 0, '>'
|
27
44
|
end
|
28
|
-
|
45
|
+
|
29
46
|
# Stamp this object using the template at the given path.
|
30
47
|
#
|
31
48
|
# === Parameters
|
@@ -78,7 +95,39 @@ module Cog
|
|
78
95
|
nil
|
79
96
|
end
|
80
97
|
end
|
81
|
-
|
98
|
+
|
99
|
+
# A warning that indicates a file is maintained by a generator
|
100
|
+
def generated_warning
|
101
|
+
lang = Config.for_project.language
|
102
|
+
t = get_template "snippets/#{lang}/generated_warning.#{snippet_extension lang}", :cog_template => true
|
103
|
+
t.result(binding)
|
104
|
+
end
|
105
|
+
|
106
|
+
def include_guard_begin(name)
|
107
|
+
full = "COG_INCLUDE_GUARD_#{name.upcase}"
|
108
|
+
"#ifndef #{full}\n#define #{full}"
|
109
|
+
end
|
110
|
+
|
111
|
+
def include_guard_end
|
112
|
+
"#endif // COG_INCLUDE_GUARD_[...]"
|
113
|
+
end
|
114
|
+
|
115
|
+
def namespace_begin(name)
|
116
|
+
return if name.nil?
|
117
|
+
case Config.for_project.language
|
118
|
+
when /c\+\+/
|
119
|
+
"namespace #{name} {"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def namespace_end(name)
|
124
|
+
return if name.nil?
|
125
|
+
case Config.for_project.language
|
126
|
+
when /c\+\+/
|
127
|
+
"} // namespace #{name}"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
82
131
|
private
|
83
132
|
def same?(original, scratch) # :nodoc:
|
84
133
|
if File.exists? original
|
@@ -10,8 +10,9 @@ module Cog
|
|
10
10
|
def matches?(runner)
|
11
11
|
@runner = runner
|
12
12
|
@runner.exec do |i,o,e|
|
13
|
-
@first_line = o.
|
14
|
-
|
13
|
+
@first_line = o.readline
|
14
|
+
@second_line = o.readline
|
15
|
+
/help.*code gen/ =~ @second_line
|
15
16
|
end
|
16
17
|
end
|
17
18
|
def failure_message
|
data/lib/cog_version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
class
|
data/templates/mirror.rb.erb
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
/* --------------------------------------------------------------------------
|
2
|
+
WARNING
|
3
|
+
|
4
|
+
This is a generated file. DO NOT EDIT THIS FILE! Your changes will be lost
|
5
|
+
the next time this file is regenerated.
|
6
|
+
|
7
|
+
This file was generating using cog
|
8
|
+
https://github.com/ktonon/cog
|
9
|
+
-------------------------------------------------------------------------- */
|
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: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 9
|
10
|
+
version: 0.0.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kevin Tonon
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-10-27 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rake
|
@@ -61,14 +61,19 @@ files:
|
|
61
61
|
- templates/c++/mirror-impl.cpp.erb
|
62
62
|
- templates/c++/mirror-impl.h.erb
|
63
63
|
- templates/mirror.rb.erb
|
64
|
+
- templates/snippets/c++/generated_warning.h.erb
|
65
|
+
- templates/snippets/generated_warning.txt
|
66
|
+
- lib/cog/cogfile.rb
|
64
67
|
- lib/cog/config.rb
|
68
|
+
- lib/cog/meta/gen_gen.rb
|
69
|
+
- lib/cog/meta/mirror_gen.rb
|
70
|
+
- lib/cog/meta.rb
|
65
71
|
- lib/cog/mixins/mirror.rb
|
66
72
|
- lib/cog/mixins/uses_templates.rb
|
67
73
|
- lib/cog/mixins.rb
|
68
74
|
- lib/cog/spec_helpers/matchers.rb
|
69
75
|
- lib/cog/spec_helpers/runner.rb
|
70
76
|
- lib/cog/spec_helpers.rb
|
71
|
-
- lib/cog/template_controller.rb
|
72
77
|
- lib/cog.rb
|
73
78
|
- lib/cog_version.rb
|
74
79
|
- API.rdoc
|
@@ -106,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
111
|
requirements: []
|
107
112
|
|
108
113
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.8.
|
114
|
+
rubygems_version: 1.8.24
|
110
115
|
signing_key:
|
111
116
|
specification_version: 3
|
112
117
|
summary: This is a utility to help you write code generators.
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'cog/mixins/uses_templates'
|
2
|
-
require 'cog/config'
|
3
|
-
|
4
|
-
module Cog
|
5
|
-
|
6
|
-
class TemplateController
|
7
|
-
|
8
|
-
include Mixins::UsesTemplates
|
9
|
-
|
10
|
-
# Create a ruby generator from a template.
|
11
|
-
#
|
12
|
-
# === Parameters
|
13
|
-
# * +ruby_template+ - name of the ruby template. This is a template
|
14
|
-
# which is distributed in the cog gem. It is relative to
|
15
|
-
# <tt>templates/</tt>
|
16
|
-
# * +generator_name+ - name of the generator
|
17
|
-
#
|
18
|
-
# === Options
|
19
|
-
# * <tt>:language</tt> - only <tt>'c++'</tt> is accepted at this time
|
20
|
-
# * <tt>:package</tt> - slash (/) separated path which will prefix
|
21
|
-
# +generator_name+
|
22
|
-
def stamp_generator(ruby_template, generator_name, opt={})
|
23
|
-
template = File.join Config.gem_dir, 'templates', "#{ruby_template}.rb"
|
24
|
-
target = "#{generator_name}.rb"
|
25
|
-
target = File.join opt[:package], target if opt[:package]
|
26
|
-
target = File.join 'generators', target
|
27
|
-
stamp template,
|
28
|
-
:target => target,
|
29
|
-
:target_type => :cog,
|
30
|
-
:use_absolute_path => true
|
31
|
-
end
|
32
|
-
|
33
|
-
# Create an app module template from a template.
|
34
|
-
#
|
35
|
-
# === Parameters
|
36
|
-
# * +source_template+ - name of the source template. This is a template
|
37
|
-
# which is distributed in the cog gem. It is relative to
|
38
|
-
# <tt>templates/{language}/</tt>, where language is specified by the
|
39
|
-
# <tt>:language</tt> option. Do not include any file extension such as
|
40
|
-
# <tt>.h</tt> (the <tt>:language</tt> will also determine this)
|
41
|
-
# * +module_name+ - name of the module. For languages like <tt>:c++</tt>,
|
42
|
-
# two templates will be generated (i.e. one <tt>.h</tt> and one
|
43
|
-
# <tt>.cpp</tt>)
|
44
|
-
#
|
45
|
-
# === Options
|
46
|
-
# * <tt>:language</tt> - only <tt>'c++'</tt> is accepted at this time
|
47
|
-
# * <tt>:package</tt> - slash (/) separated path which will prefix
|
48
|
-
# +module_name+
|
49
|
-
def stamp_module(source_template, module_name, opt={})
|
50
|
-
lang = opt[:language] || 'c++'
|
51
|
-
extensions_for_language(lang).each do |ext|
|
52
|
-
template = File.join Config.gem_dir, 'templates', lang, "#{source_template}.#{ext}"
|
53
|
-
target = "#{module_name}.#{ext}"
|
54
|
-
target = File.join opt[:package], target if opt[:package]
|
55
|
-
target = File.join 'templates', target
|
56
|
-
stamp template,
|
57
|
-
:target => target,
|
58
|
-
:target_type => :cog,
|
59
|
-
:use_absolute_path => true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
def extensions_for_language(lang)
|
65
|
-
case lang.to_s
|
66
|
-
when /(cpp|c\+\+)/i
|
67
|
-
[:h, :cpp]
|
68
|
-
else
|
69
|
-
[]
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|