cog 0.2.1 → 0.2.2
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 +6 -6
- data/lib/cog.rb +7 -11
- data/lib/cog/built_in_tools/basic.rb +1 -1
- data/lib/cog/built_in_tools/basic/cog_tool.rb +5 -12
- data/lib/cog/config.rb +47 -200
- data/lib/cog/config/cogfile.rb +5 -7
- data/lib/cog/config/lang_info.rb +1 -1
- data/lib/cog/config/language_methods.rb +71 -0
- data/lib/cog/config/project_methods.rb +35 -0
- data/lib/cog/config/tool_methods.rb +94 -0
- data/lib/cog/controllers/generator_controller.rb +7 -8
- data/lib/cog/controllers/template_controller.rb +18 -21
- data/lib/cog/controllers/tool_controller.rb +19 -22
- data/lib/cog/embed_context.rb +131 -0
- data/lib/cog/embeds.rb +84 -58
- data/lib/cog/embeds/file_scanner.rb +28 -5
- data/lib/cog/errors.rb +3 -0
- data/lib/cog/generator.rb +65 -31
- data/lib/cog/generator/file_methods.rb +1 -1
- data/lib/cog/generator/filters.rb +1 -1
- data/lib/cog/generator/language_methods.rb +3 -3
- data/lib/cog/helpers/string.rb +3 -3
- data/lib/cog/languages.rb +2 -0
- data/lib/cog/languages/c_language.rb +3 -27
- data/lib/cog/languages/c_plus_plus_language.rb +3 -8
- data/lib/cog/languages/c_sharp_language.rb +3 -16
- data/lib/cog/languages/java_language.rb +3 -16
- data/lib/cog/languages/java_script_language.rb +3 -16
- data/lib/cog/languages/language.rb +12 -12
- data/lib/cog/languages/mixins.rb +10 -0
- data/lib/cog/languages/mixins/c_style_comments.rb +23 -0
- data/lib/cog/languages/mixins/hash_comments.rb +19 -0
- data/lib/cog/languages/python_language.rb +2 -33
- data/lib/cog/languages/qt_project_language.rb +3 -34
- data/lib/cog/languages/ruby_language.rb +6 -31
- data/lib/cog/spec_helpers/matchers/match_maker.rb +10 -6
- data/lib/cog/tool.rb +61 -0
- data/lib/cog/tool/dsl.rb +26 -0
- data/lib/cog/version.rb +1 -1
- data/templates/basic/generator.rb.erb +1 -7
- data/templates/cog/custom_tool/cog_tool.rb.erb +10 -8
- data/templates/cog/custom_tool/generator.rb.erb.erb +3 -3
- data/templates/cog/custom_tool/tool.rb.erb +1 -1
- metadata +13 -16
- data/lib/cog/config/tool.rb +0 -99
- data/lib/cog/embeds/context.rb +0 -86
- data/templates/basic/template.c.erb.erb +0 -1
- data/templates/basic/template.cpp.erb.erb +0 -6
- data/templates/basic/template.cs.erb.erb +0 -6
- data/templates/basic/template.h.erb.erb +0 -1
- data/templates/basic/template.hpp.erb.erb +0 -6
- data/templates/basic/template.java.erb.erb +0 -1
- data/templates/basic/template.js.erb.erb +0 -1
- data/templates/basic/template.py.erb.erb +0 -1
- data/templates/basic/template.rb.erb.erb +0 -6
- data/templates/basic/template.txt.erb.erb +0 -1
@@ -73,17 +73,13 @@ module Cog
|
|
73
73
|
# @api developer
|
74
74
|
# @return [String] positive interpretation of the {#message} block result
|
75
75
|
def failure_message
|
76
|
-
|
77
|
-
msg = msg.gsub /\[([^\|\]]*)(?:\|([^\]]*)\])?/, '\1'
|
78
|
-
"expected #{@invocation} #{msg}\n#{trace}"
|
76
|
+
_failure_message '\1'
|
79
77
|
end
|
80
78
|
|
81
79
|
# @api developer
|
82
80
|
# @return [String] negative interpretation of the {#message} block result
|
83
81
|
def negative_failure_message
|
84
|
-
|
85
|
-
msg = msg.gsub /\[([^\|\]]*)(?:\|([^\]]*)\])?/, '\2'
|
86
|
-
"expected #{@invocation} #{msg}\n#{trace}"
|
82
|
+
_failure_message '\2'
|
87
83
|
end
|
88
84
|
|
89
85
|
# @api developer
|
@@ -91,6 +87,14 @@ module Cog
|
|
91
87
|
def trace
|
92
88
|
"STDOUT:\n#{@lines.join "\n"}\nSTDERR:\n#{@error.join "\n"}"
|
93
89
|
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def _failure_message(repl)
|
94
|
+
msg = instance_eval &@msg_block
|
95
|
+
msg = msg.gsub /\[([^\|\]]*)(?:\|([^\]]*)\])?/, '\2'
|
96
|
+
"expected #{@invocation} #{msg}\n#{trace}"
|
97
|
+
end
|
94
98
|
end
|
95
99
|
|
96
100
|
# Makes it easier to write RSpec matchers for testing +cog+ command invocations
|
data/lib/cog/tool.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'cog/tool/dsl'
|
2
|
+
require 'cog/errors'
|
3
|
+
|
4
|
+
module Cog
|
5
|
+
|
6
|
+
class Tool
|
7
|
+
|
8
|
+
# @return [String] name of the tool
|
9
|
+
attr_reader :name
|
10
|
+
|
11
|
+
# @return [String] explicit path to the tool
|
12
|
+
attr_reader :path
|
13
|
+
|
14
|
+
# @return [String] directory in which to find tool templates
|
15
|
+
attr_reader :templates_path
|
16
|
+
|
17
|
+
# @return [Boolean] the tool needs to be explicitly required
|
18
|
+
attr_reader :explicit_require
|
19
|
+
|
20
|
+
# @api developer
|
21
|
+
# @return [GeneratorStamper]
|
22
|
+
attr_reader :generator_stamper
|
23
|
+
|
24
|
+
# @param path [String] path to the <tt>cog_tool.rb</tt> file
|
25
|
+
# @option opt [Boolean] :built_in (false) if +true+, {#templates_path} will be +nil+ for this tool, as the templates should be included with +cog+
|
26
|
+
# @option opt [Boolean] :explicit_require (false) the tool needs to be explicitly required
|
27
|
+
def initialize(path, opt={})
|
28
|
+
unless File.basename(path) == 'cog_tool.rb' && File.exists?(path)
|
29
|
+
raise Errors::InvalidToolConfiguration.new(path)
|
30
|
+
end
|
31
|
+
dir = File.dirname(path)
|
32
|
+
@name = File.basename dir
|
33
|
+
@path = File.expand_path File.join(dir, '..', "#{@name}.rb")
|
34
|
+
@explicit_require = opt[:explicit_require]
|
35
|
+
unless opt[:built_in]
|
36
|
+
@templates_path = File.expand_path File.join(dir, '..', '..', 'cog', 'templates')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Fully load the tool
|
41
|
+
def load
|
42
|
+
require @path
|
43
|
+
end
|
44
|
+
|
45
|
+
# Stamp the generator
|
46
|
+
# @param name [String] name of the generator to stamp
|
47
|
+
# @param dest [String] file system path where the file will be created
|
48
|
+
# @return [nil]
|
49
|
+
def stamp_generator(name, dest)
|
50
|
+
raise Errors::ToolMissingDefinition.new('stamp_generator') if @stamp_generator_block.nil?
|
51
|
+
@stamp_generator_block.call name.to_s, dest.to_s
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
# Sort tools by name
|
56
|
+
def <=>(other)
|
57
|
+
@name <=> other.name
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/lib/cog/tool/dsl.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Cog
|
2
|
+
class Tool
|
3
|
+
|
4
|
+
# Domain-specific language for defining cog tools
|
5
|
+
class DSL
|
6
|
+
|
7
|
+
# @api developer
|
8
|
+
# @param tool [Tool] the tool which is being defined
|
9
|
+
def initialize(tool)
|
10
|
+
@tool = tool
|
11
|
+
end
|
12
|
+
|
13
|
+
# Define a block to call when stamping a generator for this tool
|
14
|
+
# @yieldparam name [String] name of the generator to stamp
|
15
|
+
# @yieldparam dest [String] file system path where the file will be created
|
16
|
+
# @yieldreturn [nil]
|
17
|
+
# @return [nil]
|
18
|
+
def stamp_generator(&block)
|
19
|
+
@tool.instance_eval do
|
20
|
+
@stamp_generator_block = block
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/cog/version.rb
CHANGED
@@ -1,10 +1,4 @@
|
|
1
1
|
require 'cog'
|
2
2
|
include Cog::Generator
|
3
3
|
|
4
|
-
#
|
5
|
-
@class = '<%= name.gsub ' ', '' %>'
|
6
|
-
|
7
|
-
# Render the templates
|
8
|
-
<% @language.module_extensions.each do |ext| %>
|
9
|
-
stamp '<%= name %>.<%= ext %>', 'generated_<%= name %>.<%= ext %>'
|
10
|
-
<% end %>
|
4
|
+
# This is the <%= @name %> generator
|
@@ -1,15 +1,17 @@
|
|
1
1
|
require 'cog'
|
2
|
+
include Cog::Generator
|
2
3
|
|
3
4
|
# Register <%= @tool_name %> as a tool with cog
|
4
|
-
Cog
|
5
|
+
Cog.register_tool __FILE__ do |tool|
|
5
6
|
|
6
|
-
# Define
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
# Define a method which creates a <%= @tool_name %> generator
|
8
|
+
tool.stamp_generator do |name, dest|
|
9
|
+
|
10
|
+
# Setup context for the template
|
11
|
+
@name = name # Generator name
|
12
|
+
|
13
|
+
# Create the generator file
|
14
|
+
stamp '<%= @tool_name %>/generator.rb', dest, :absolute_destination => true
|
13
15
|
end
|
14
16
|
|
15
17
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
<%% if
|
2
|
-
require '<%%=
|
1
|
+
<%% if Cog.active_tool.explicit_require %>
|
2
|
+
require '<%%= Cog.active_tool.path %>'
|
3
3
|
<%% else %>
|
4
|
-
require '<%%=
|
4
|
+
require '<%%= Cog.active_tool.name %>'
|
5
5
|
<%% end %>
|
6
6
|
|
7
7
|
<%= @tool_module %>.widget '<%%= @name %>' do |w|
|
@@ -13,7 +13,7 @@ module <%= @tool_module %>
|
|
13
13
|
|
14
14
|
# Activate <%= @tool_name %> while rendering templates
|
15
15
|
# so that cog will be able to find <%= @tool_name %> templates
|
16
|
-
Cog
|
16
|
+
Cog.activate_tool '<%= @tool_name %>' do
|
17
17
|
w.generate
|
18
18
|
end
|
19
19
|
|
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: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
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-12-
|
18
|
+
date: 2012-12-15 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: gli
|
@@ -114,16 +114,6 @@ files:
|
|
114
114
|
- Default.cogfile
|
115
115
|
- LICENSE
|
116
116
|
- templates/basic/generator.rb.erb
|
117
|
-
- templates/basic/template.c.erb.erb
|
118
|
-
- templates/basic/template.cpp.erb.erb
|
119
|
-
- templates/basic/template.cs.erb.erb
|
120
|
-
- templates/basic/template.h.erb.erb
|
121
|
-
- templates/basic/template.hpp.erb.erb
|
122
|
-
- templates/basic/template.java.erb.erb
|
123
|
-
- templates/basic/template.js.erb.erb
|
124
|
-
- templates/basic/template.py.erb.erb
|
125
|
-
- templates/basic/template.rb.erb.erb
|
126
|
-
- templates/basic/template.txt.erb.erb
|
127
117
|
- templates/cog/custom_tool/cog_tool.rb.erb
|
128
118
|
- templates/cog/custom_tool/Gemfile.erb
|
129
119
|
- templates/cog/custom_tool/generator.rb.erb.erb
|
@@ -140,13 +130,15 @@ files:
|
|
140
130
|
- lib/cog/built_in_tools.rb
|
141
131
|
- lib/cog/config/cogfile.rb
|
142
132
|
- lib/cog/config/lang_info.rb
|
143
|
-
- lib/cog/config/
|
133
|
+
- lib/cog/config/language_methods.rb
|
134
|
+
- lib/cog/config/project_methods.rb
|
135
|
+
- lib/cog/config/tool_methods.rb
|
144
136
|
- lib/cog/config.rb
|
145
137
|
- lib/cog/controllers/generator_controller.rb
|
146
138
|
- lib/cog/controllers/template_controller.rb
|
147
139
|
- lib/cog/controllers/tool_controller.rb
|
148
140
|
- lib/cog/controllers.rb
|
149
|
-
- lib/cog/
|
141
|
+
- lib/cog/embed_context.rb
|
150
142
|
- lib/cog/embeds/file_scanner.rb
|
151
143
|
- lib/cog/embeds.rb
|
152
144
|
- lib/cog/errors.rb
|
@@ -164,6 +156,9 @@ files:
|
|
164
156
|
- lib/cog/languages/java_language.rb
|
165
157
|
- lib/cog/languages/java_script_language.rb
|
166
158
|
- lib/cog/languages/language.rb
|
159
|
+
- lib/cog/languages/mixins/c_style_comments.rb
|
160
|
+
- lib/cog/languages/mixins/hash_comments.rb
|
161
|
+
- lib/cog/languages/mixins.rb
|
167
162
|
- lib/cog/languages/python_language.rb
|
168
163
|
- lib/cog/languages/qt_project_language.rb
|
169
164
|
- lib/cog/languages/ruby_language.rb
|
@@ -172,6 +167,8 @@ files:
|
|
172
167
|
- lib/cog/spec_helpers/matchers.rb
|
173
168
|
- lib/cog/spec_helpers/runner.rb
|
174
169
|
- lib/cog/spec_helpers.rb
|
170
|
+
- lib/cog/tool/dsl.rb
|
171
|
+
- lib/cog/tool.rb
|
175
172
|
- lib/cog/version.rb
|
176
173
|
- lib/cog.rb
|
177
174
|
- yard-templates/default/fulldoc/html/css/common.css
|
data/lib/cog/config/tool.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
require 'cog/errors'
|
2
|
-
require 'cog/generator'
|
3
|
-
|
4
|
-
module Cog
|
5
|
-
class Config
|
6
|
-
|
7
|
-
class Tool
|
8
|
-
|
9
|
-
# @return [String] name of the tool
|
10
|
-
attr_reader :name
|
11
|
-
|
12
|
-
# @return [String] explicit path to the tool
|
13
|
-
attr_reader :path
|
14
|
-
|
15
|
-
# @return [String] directory in which to find tool templates
|
16
|
-
attr_reader :templates_path
|
17
|
-
|
18
|
-
# @return [Boolean] the tool needs to be explicitly required
|
19
|
-
attr_reader :explicit_require
|
20
|
-
|
21
|
-
# @param path [String] path to the <tt>cog_tool.rb</tt> file
|
22
|
-
# @option opt [Boolean] :built_in (false) if +true+, {#templates_path} will be +nil+ for this tool, as the templates should be included with +cog+
|
23
|
-
# @option opt [Boolean] :explicit_require (false) the tool needs to be explicitly required
|
24
|
-
def initialize(path, opt={})
|
25
|
-
unless File.basename(path) == 'cog_tool.rb' && File.exists?(path)
|
26
|
-
raise Errors::InvalidToolConfiguration.new(path)
|
27
|
-
end
|
28
|
-
dir = File.dirname(path)
|
29
|
-
@name = File.basename dir
|
30
|
-
@path = File.expand_path File.join(dir, '..', "#{@name}.rb")
|
31
|
-
@explicit_require = opt[:explicit_require]
|
32
|
-
unless opt[:built_in]
|
33
|
-
@templates_path = File.expand_path File.join(dir, '..', '..', 'cog', 'templates')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Fully load the tool
|
38
|
-
def load
|
39
|
-
require @path
|
40
|
-
end
|
41
|
-
|
42
|
-
# Encapsulates the block which stamps the generator for this tool
|
43
|
-
class GeneratorStamper
|
44
|
-
|
45
|
-
include Generator
|
46
|
-
|
47
|
-
# @return [Config] singleton instance
|
48
|
-
attr_accessor :config
|
49
|
-
|
50
|
-
# @return [String] path to the generator file which should be created
|
51
|
-
attr_reader :generator_dest
|
52
|
-
|
53
|
-
# @return [String] +underscore_version+ of the generator name
|
54
|
-
attr_reader :name
|
55
|
-
|
56
|
-
# @return [Tool] the tool for which this stamps generators
|
57
|
-
attr_reader :tool
|
58
|
-
|
59
|
-
# @return [String] +CamelizedVersion+ of the generator name
|
60
|
-
def camelized
|
61
|
-
@name.camelize
|
62
|
-
end
|
63
|
-
|
64
|
-
# @api developer
|
65
|
-
# @param tool [Tool]
|
66
|
-
# @param block [Block]
|
67
|
-
def initialize(tool, block)
|
68
|
-
@tool = tool
|
69
|
-
@block = block
|
70
|
-
end
|
71
|
-
|
72
|
-
# Stamp the generator
|
73
|
-
# @api developer
|
74
|
-
def stamp_generator(name, generator_dest, config)
|
75
|
-
@name = name.to_s.underscore
|
76
|
-
@config = config
|
77
|
-
@generator_dest = generator_dest
|
78
|
-
instance_eval &@block
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# @api developer
|
83
|
-
# @return [GeneratorStamper]
|
84
|
-
attr_reader :generator_stamper
|
85
|
-
|
86
|
-
# Define a block to call when stamping a generator for this tool
|
87
|
-
#
|
88
|
-
# @yield The block should do the work of stamping the generator file, and any custom templates. The block's +self+ object will be a {GeneratorStamper}
|
89
|
-
def stamp_generator(&block)
|
90
|
-
@generator_stamper = GeneratorStamper.new self, block
|
91
|
-
end
|
92
|
-
|
93
|
-
# Sort tools by name
|
94
|
-
def <=>(other)
|
95
|
-
@name <=> other.name
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
data/lib/cog/embeds/context.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'cog/config'
|
2
|
-
|
3
|
-
module Cog
|
4
|
-
module Embeds
|
5
|
-
|
6
|
-
# Describes the environment of an embed statement including the file in which it was found, the line number, the language, an more.
|
7
|
-
class Context
|
8
|
-
|
9
|
-
# @return [Fixnum] line number at which the directive was found
|
10
|
-
attr_accessor :lineno
|
11
|
-
|
12
|
-
# @return [String] the value for the given key
|
13
|
-
attr_reader :name
|
14
|
-
|
15
|
-
# @param path [String] path to the file in which the cog directive was found
|
16
|
-
def initialize(name, path)
|
17
|
-
@name = name
|
18
|
-
@options = {}
|
19
|
-
@path = path
|
20
|
-
end
|
21
|
-
|
22
|
-
# @return [Array<String>] arguments passed to the directive
|
23
|
-
def args
|
24
|
-
@args
|
25
|
-
end
|
26
|
-
|
27
|
-
# @return [String] for block directives, the body of text which occurs between the curly braces.
|
28
|
-
# @example
|
29
|
-
# // cog: snippet(my-snip) {
|
30
|
-
# body
|
31
|
-
# // cog: }
|
32
|
-
def body
|
33
|
-
@body
|
34
|
-
end
|
35
|
-
|
36
|
-
# @return [String] the filename extension
|
37
|
-
def extension
|
38
|
-
@ext ||= File.extname(filename).slice(1..-1)
|
39
|
-
end
|
40
|
-
|
41
|
-
# @return [String] basename of the file in which the cog directive was found
|
42
|
-
def filename
|
43
|
-
@filename ||= File.basename @path
|
44
|
-
end
|
45
|
-
|
46
|
-
# @return [Languages::Language] the language of the file
|
47
|
-
def language
|
48
|
-
@lang ||= Config.instance.language_for_extension extension
|
49
|
-
end
|
50
|
-
|
51
|
-
# @return [Boolean] was the once switch used?
|
52
|
-
def once?
|
53
|
-
@once
|
54
|
-
end
|
55
|
-
|
56
|
-
# @api developer
|
57
|
-
# @param value [String, nil] set the body to this value
|
58
|
-
def body=(value)
|
59
|
-
@body = value
|
60
|
-
end
|
61
|
-
|
62
|
-
# @api developer
|
63
|
-
# @param value [Boolean] was the once switch used?
|
64
|
-
def once=(value)
|
65
|
-
@once = !!value
|
66
|
-
end
|
67
|
-
|
68
|
-
# @api developer
|
69
|
-
# @param value [Array<String>] arguments used with the directive
|
70
|
-
def args=(value)
|
71
|
-
@args = value
|
72
|
-
end
|
73
|
-
|
74
|
-
# @api developer
|
75
|
-
# @return [String]
|
76
|
-
def to_directive
|
77
|
-
x = "cog: #{name}"
|
78
|
-
x += args.join ' ' if args
|
79
|
-
x += " once" if once?
|
80
|
-
x
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
end
|