cog 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,31 +1,17 @@
|
|
1
1
|
require 'cog/languages/language'
|
2
|
+
require 'cog/languages/mixins/c_style_comments'
|
2
3
|
|
3
4
|
module Cog
|
4
5
|
module Languages
|
5
6
|
|
6
7
|
class CLanguage < Language
|
7
|
-
|
8
|
-
# @param nested_pattern [String] regular expression pattern (as a string) to embed in the regular expression which matches one line comments in this language
|
9
|
-
# @return [Regexp] pattern for matching one line comments in this language
|
10
|
-
def comment_pattern(nested_pattern)
|
11
|
-
/^\s*(?:\/\/|\/\*)\s*#{nested_pattern}\s*(?:\*\/)?\s*$/i
|
12
|
-
end
|
8
|
+
include Mixins::CStyleComments
|
13
9
|
|
14
10
|
# @return [Array<String>] a set of extensions needed to define a module in this language
|
15
11
|
def module_extensions
|
16
12
|
[:c, :h]
|
17
13
|
end
|
18
|
-
|
19
|
-
# @return [String] ignored in c
|
20
|
-
def named_scope_begin(name)
|
21
|
-
""
|
22
|
-
end
|
23
|
-
|
24
|
-
# @return [String] ignored in c
|
25
|
-
def named_scope_end(name)
|
26
|
-
""
|
27
|
-
end
|
28
|
-
|
14
|
+
|
29
15
|
# @param name [String] name of the module to protect
|
30
16
|
# @return [String] an include guard statement
|
31
17
|
def include_guard_begin(name)
|
@@ -38,16 +24,6 @@ module Cog
|
|
38
24
|
"#endif // #{name}"
|
39
25
|
end
|
40
26
|
|
41
|
-
protected
|
42
|
-
|
43
|
-
def one_line_comment(text)
|
44
|
-
"// #{text}"
|
45
|
-
end
|
46
|
-
|
47
|
-
def multi_line_comment(text)
|
48
|
-
"/*\n#{text}\n */"
|
49
|
-
end
|
50
|
-
|
51
27
|
end
|
52
28
|
end
|
53
29
|
end
|
@@ -1,29 +1,24 @@
|
|
1
1
|
require 'cog/languages/c_language'
|
2
|
+
require 'cog/languages/mixins/c_style_comments'
|
2
3
|
|
3
4
|
module Cog
|
4
5
|
module Languages
|
5
6
|
|
6
|
-
class CPlusPlusLanguage <
|
7
|
+
class CPlusPlusLanguage < Language
|
8
|
+
include Mixins::CStyleComments
|
7
9
|
|
8
|
-
# @return [Array<String>] a set of extensions needed to define a module in this language
|
9
10
|
def module_extensions
|
10
11
|
[:cpp, :hpp]
|
11
12
|
end
|
12
13
|
|
13
|
-
# @param name [String] name of the scope to use
|
14
|
-
# @return [String] a using statement for the named scope
|
15
14
|
def use_named_scope(name)
|
16
15
|
"using namespace #{name};"
|
17
16
|
end
|
18
17
|
|
19
|
-
# @param name [String] name of the scope
|
20
|
-
# @return [String] begin a named scope
|
21
18
|
def named_scope_begin(name)
|
22
19
|
"namespace #{name} {"
|
23
20
|
end
|
24
21
|
|
25
|
-
# @param name [String] name of the scope
|
26
|
-
# @return [String] end the given named scope
|
27
22
|
def named_scope_end(name)
|
28
23
|
"} // namespace #{name}"
|
29
24
|
end
|
@@ -1,37 +1,24 @@
|
|
1
1
|
require 'cog/languages/c_language'
|
2
|
+
require 'cog/languages/mixins/c_style_comments'
|
2
3
|
|
3
4
|
module Cog
|
4
5
|
module Languages
|
5
6
|
|
6
|
-
class CSharpLanguage <
|
7
|
+
class CSharpLanguage < Language
|
8
|
+
include Mixins::CStyleComments
|
7
9
|
|
8
|
-
# @return [Array<String>] a set of extensions needed to define a module in this language
|
9
10
|
def module_extensions
|
10
11
|
[:cs]
|
11
12
|
end
|
12
13
|
|
13
|
-
# @param name [String] name of the scope
|
14
|
-
# @return [String] begin a named scope
|
15
14
|
def named_scope_begin(name)
|
16
15
|
"namespace #{name} {"
|
17
16
|
end
|
18
17
|
|
19
|
-
# @param name [String] name of the scope
|
20
|
-
# @return [String] end the given named scope
|
21
18
|
def named_scope_end(name)
|
22
19
|
"} // namespace #{name}"
|
23
20
|
end
|
24
21
|
|
25
|
-
# @return [String] ignored for c#
|
26
|
-
def include_guard_begin(name)
|
27
|
-
""
|
28
|
-
end
|
29
|
-
|
30
|
-
# @return [String] ignored for c#
|
31
|
-
def include_guard_end(name)
|
32
|
-
""
|
33
|
-
end
|
34
|
-
|
35
22
|
end
|
36
23
|
end
|
37
24
|
end
|
@@ -1,37 +1,24 @@
|
|
1
1
|
require 'cog/languages/c_language'
|
2
|
+
require 'cog/languages/mixins/c_style_comments'
|
2
3
|
|
3
4
|
module Cog
|
4
5
|
module Languages
|
5
6
|
|
6
|
-
class JavaLanguage <
|
7
|
+
class JavaLanguage < Language
|
8
|
+
include Mixins::CStyleComments
|
7
9
|
|
8
|
-
# @return [Array<String>] a set of extensions needed to define a module in this language
|
9
10
|
def module_extensions
|
10
11
|
[:java]
|
11
12
|
end
|
12
13
|
|
13
|
-
# @param name [String] name of the scope
|
14
|
-
# @return [String] begin a named scope
|
15
14
|
def named_scope_begin(name)
|
16
15
|
"package #{name};"
|
17
16
|
end
|
18
17
|
|
19
|
-
# @param name [String] name of the scope
|
20
|
-
# @return [String] end the given named scope
|
21
18
|
def named_scope_end(name)
|
22
19
|
"// end of package: #{name}"
|
23
20
|
end
|
24
21
|
|
25
|
-
# @return [String] ignored for java
|
26
|
-
def include_guard_begin(name)
|
27
|
-
""
|
28
|
-
end
|
29
|
-
|
30
|
-
# @return [String] ignored for java
|
31
|
-
def include_guard_end(name)
|
32
|
-
""
|
33
|
-
end
|
34
|
-
|
35
22
|
end
|
36
23
|
end
|
37
24
|
end
|
@@ -1,36 +1,23 @@
|
|
1
1
|
require 'cog/languages/c_language'
|
2
|
+
require 'cog/languages/mixins/c_style_comments'
|
2
3
|
|
3
4
|
module Cog
|
4
5
|
module Languages
|
5
6
|
|
6
|
-
class JavaScriptLanguage <
|
7
|
+
class JavaScriptLanguage < Language
|
8
|
+
include Mixins::CStyleComments
|
7
9
|
|
8
|
-
# @return [Array<String>] a set of extensions needed to define a module in this language
|
9
10
|
def module_extensions
|
10
11
|
[:js]
|
11
12
|
end
|
12
13
|
|
13
|
-
# @param name [String] name of the scope
|
14
|
-
# @return [String] begin a named scope
|
15
14
|
def named_scope_begin(name)
|
16
15
|
"var #{name} = { // named scope"
|
17
16
|
end
|
18
17
|
|
19
|
-
# @param name [String] name of the scope
|
20
|
-
# @return [String] end the given named scope
|
21
18
|
def named_scope_end(name)
|
22
19
|
"}; // named scope: #{name}"
|
23
20
|
end
|
24
|
-
|
25
|
-
# @return [String] ignored for javascript
|
26
|
-
def include_guard_begin(name)
|
27
|
-
""
|
28
|
-
end
|
29
|
-
|
30
|
-
# @return [String] ignored for javascript
|
31
|
-
def include_guard_end(name)
|
32
|
-
""
|
33
|
-
end
|
34
21
|
|
35
22
|
end
|
36
23
|
end
|
@@ -20,6 +20,18 @@ module Cog
|
|
20
20
|
one_line_comment text
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
# @api developer
|
25
|
+
def one_line_comment(text)
|
26
|
+
text
|
27
|
+
end
|
28
|
+
|
29
|
+
# @api developer
|
30
|
+
def multi_line_comment(text)
|
31
|
+
text.split("\n").collect do |line|
|
32
|
+
one_line_comment line
|
33
|
+
end.join "\n"
|
34
|
+
end
|
23
35
|
|
24
36
|
# @return [Array<String>] a set of extensions needed to define a module in this language
|
25
37
|
def module_extensions
|
@@ -56,18 +68,6 @@ module Cog
|
|
56
68
|
""
|
57
69
|
end
|
58
70
|
|
59
|
-
protected
|
60
|
-
|
61
|
-
def one_line_comment(text)
|
62
|
-
text
|
63
|
-
end
|
64
|
-
|
65
|
-
def multi_line_comment(text)
|
66
|
-
text.split("\n").collect do |line|
|
67
|
-
one_line_comment line
|
68
|
-
end.join "\n"
|
69
|
-
end
|
70
|
-
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Cog
|
2
|
+
module Languages
|
3
|
+
module Mixins
|
4
|
+
|
5
|
+
# Methods for defining single and multiline c-style comments
|
6
|
+
module CStyleComments
|
7
|
+
|
8
|
+
def comment_pattern(nested_pattern)
|
9
|
+
/^\s*(?:\/\/|\/\*)\s*#{nested_pattern}\s*(?:\*\/)?\s*$/i
|
10
|
+
end
|
11
|
+
|
12
|
+
def one_line_comment(text)
|
13
|
+
"// #{text}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def multi_line_comment(text)
|
17
|
+
"/*\n#{text}\n */"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Cog
|
2
|
+
module Languages
|
3
|
+
module Mixins
|
4
|
+
|
5
|
+
# Methods for defining single line comments that begin with a hash (<tt>#</tt>)
|
6
|
+
module HashComments
|
7
|
+
|
8
|
+
def comment_pattern(nested_pattern)
|
9
|
+
/^\s*\#\s*#{nested_pattern}\s*$/i
|
10
|
+
end
|
11
|
+
|
12
|
+
def one_line_comment(text)
|
13
|
+
"# #{text}"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,47 +1,16 @@
|
|
1
1
|
require 'cog/languages/language'
|
2
|
+
require 'cog/languages/mixins/hash_comments'
|
2
3
|
|
3
4
|
module Cog
|
4
5
|
module Languages
|
5
6
|
|
6
7
|
class PythonLanguage < Language
|
8
|
+
include Mixins::HashComments
|
7
9
|
|
8
|
-
# @param nested_pattern [String] regular expression pattern (as a string) to embed in the regular expression which matches one line comments in this language
|
9
|
-
# @return [Regexp] pattern for matching one line comments in this language
|
10
|
-
def comment_pattern(nested_pattern)
|
11
|
-
/^\s*\#\s*#{nested_pattern}\s*$/i
|
12
|
-
end
|
13
|
-
|
14
|
-
# @return [Array<String>] a set of extensions needed to define a module in this language
|
15
10
|
def module_extensions
|
16
11
|
[:py]
|
17
12
|
end
|
18
13
|
|
19
|
-
# @return [String] ignored for python
|
20
|
-
def named_scope_begin(name)
|
21
|
-
""
|
22
|
-
end
|
23
|
-
|
24
|
-
# @return [String] ignored for python
|
25
|
-
def named_scope_end(name)
|
26
|
-
""
|
27
|
-
end
|
28
|
-
|
29
|
-
# @return [String] ignored for python
|
30
|
-
def include_guard_begin(name)
|
31
|
-
""
|
32
|
-
end
|
33
|
-
|
34
|
-
# @return [String] ignored for python
|
35
|
-
def include_guard_end(name)
|
36
|
-
""
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
def one_line_comment(text)
|
42
|
-
"# #{text}"
|
43
|
-
end
|
44
|
-
|
45
14
|
def multi_line_comment(text)
|
46
15
|
"'''\n#{text}\n'''"
|
47
16
|
end
|
@@ -1,45 +1,14 @@
|
|
1
1
|
require 'cog/languages/language'
|
2
|
+
require 'cog/languages/mixins/hash_comments'
|
2
3
|
|
3
4
|
module Cog
|
4
5
|
module Languages
|
5
6
|
|
6
7
|
class QtProjectLanguage < Language
|
8
|
+
include Mixins::HashComments
|
7
9
|
|
8
|
-
# @param nested_pattern [String] regular expression pattern (as a string) to embed in the regular expression which matches one line comments in this language
|
9
|
-
# @return [Regexp] pattern for matching one line comments in this language
|
10
|
-
def comment_pattern(nested_pattern)
|
11
|
-
/^\s*\#\s*#{nested_pattern}\s*$/i
|
12
|
-
end
|
13
|
-
|
14
|
-
# @return [Array<String>] a set of extensions needed to define a module in this language
|
15
10
|
def module_extensions
|
16
|
-
[:pro]
|
17
|
-
end
|
18
|
-
|
19
|
-
# @return [String] ignored for Qt Project files
|
20
|
-
def named_scope_begin(name)
|
21
|
-
""
|
22
|
-
end
|
23
|
-
|
24
|
-
# @return [String] ignored for Qt Project files
|
25
|
-
def named_scope_end(name)
|
26
|
-
""
|
27
|
-
end
|
28
|
-
|
29
|
-
# @return [String] ignored for Qt Project files
|
30
|
-
def include_guard_begin(name)
|
31
|
-
""
|
32
|
-
end
|
33
|
-
|
34
|
-
# @return [String] ignored for Qt Project files
|
35
|
-
def include_guard_end(name)
|
36
|
-
""
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
def one_line_comment(text)
|
42
|
-
"# #{text}"
|
11
|
+
[:pro, :pri]
|
43
12
|
end
|
44
13
|
|
45
14
|
end
|
@@ -1,53 +1,28 @@
|
|
1
1
|
require 'cog/languages/language'
|
2
|
+
require 'cog/languages/mixins/hash_comments'
|
2
3
|
|
3
4
|
module Cog
|
4
5
|
module Languages
|
5
6
|
|
6
7
|
class RubyLanguage < Language
|
8
|
+
include Mixins::HashComments
|
7
9
|
|
8
|
-
# @param nested_pattern [String] regular expression pattern (as a string) to embed in the regular expression which matches one line comments in this language
|
9
|
-
# @return [Regexp] pattern for matching one line comments in this language
|
10
|
-
def comment_pattern(nested_pattern)
|
11
|
-
/^\s*\#\s*#{nested_pattern}\s*$/i
|
12
|
-
end
|
13
|
-
|
14
|
-
# @return [Array<String>] a set of extensions needed to define a module in this language
|
15
10
|
def module_extensions
|
16
11
|
[:rb]
|
17
12
|
end
|
18
13
|
|
19
|
-
|
20
|
-
|
14
|
+
def multi_line_comment(text)
|
15
|
+
"=begin\n#{text}\n=end"
|
16
|
+
end
|
17
|
+
|
21
18
|
def named_scope_begin(name)
|
22
19
|
"module #{name}"
|
23
20
|
end
|
24
21
|
|
25
|
-
# @param name [String] name of the scope
|
26
|
-
# @return [String] end the given named scope
|
27
22
|
def named_scope_end(name)
|
28
23
|
"end # module #{name}"
|
29
24
|
end
|
30
25
|
|
31
|
-
# @return [String] ignored for ruby
|
32
|
-
def include_guard_begin(name)
|
33
|
-
""
|
34
|
-
end
|
35
|
-
|
36
|
-
# @return [String] ignored for ruby
|
37
|
-
def include_guard_end(name)
|
38
|
-
""
|
39
|
-
end
|
40
|
-
|
41
|
-
protected
|
42
|
-
|
43
|
-
def one_line_comment(text)
|
44
|
-
"# #{text}"
|
45
|
-
end
|
46
|
-
|
47
|
-
def multi_line_comment(text)
|
48
|
-
"=begin\n#{text}\n=end"
|
49
|
-
end
|
50
|
-
|
51
26
|
end
|
52
27
|
end
|
53
28
|
end
|