cog 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,17 +42,26 @@ module Cog
42
42
  lines.join "\n"
43
43
  end
44
44
 
45
- # @param name [String] name of the module
46
- # @return [String] an include guard statement for the active language
47
- def include_guard_begin(name = nil)
48
- scope_begin Scope.new(:include_guard, name)
45
+ # @param name [String] name of the scope to use
46
+ # @return [String] a using statement for the named scope
47
+ def use_named_scope(name)
48
+ Config.instance.active_language.use_named_scope(name)
49
49
  end
50
-
50
+
51
+ # @param name [String] name of the scope
52
+ # @return [String] a scope begin statement
51
53
  def named_scope_begin(name = nil)
52
54
  scope_begin Scope.new(:named_scope, name)
53
55
  end
54
56
 
55
57
  alias :named_scope_end :scope_end
58
+
59
+ # @param name [String] name of the module
60
+ # @return [String] an include guard statement for the active language
61
+ def include_guard_begin(name = nil)
62
+ scope_begin Scope.new(:include_guard, name)
63
+ end
64
+
56
65
  alias :include_guard_end :scope_end
57
66
 
58
67
  end
@@ -15,7 +15,6 @@ module Cog
15
15
  :hpp => 'c++',
16
16
  :java => 'java',
17
17
  :js => 'javascript',
18
- :php => 'php',
19
18
  :py => 'python',
20
19
  :rb => 'ruby',
21
20
  }
@@ -24,7 +23,6 @@ module Cog
24
23
  ALIAS = {
25
24
  'c++' => 'c_plus_plus',
26
25
  'c#' => 'c_sharp',
27
- 'php' => 'p_h_p',
28
26
  'javascript' => 'java_script',
29
27
  }
30
28
 
@@ -5,13 +5,39 @@ module Cog
5
5
 
6
6
  class CLanguage < Language
7
7
 
8
+ # @param text [String] some text which should be rendered as a comment
9
+ # @return [String] a comment appropriate for this language
8
10
  def comment(text)
9
11
  "/*\n#{text}\n */"
10
12
  end
11
-
13
+
14
+ # @return [Array<String>] a set of extensions needed to define a module in this language
12
15
  def module_extensions
13
16
  [:c, :h]
14
17
  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
+
29
+ # @param name [String] name of the module to protect
30
+ # @return [String] an include guard statement
31
+ def include_guard_begin(name)
32
+ "#ifndef #{name}\n#define #{name}"
33
+ end
34
+
35
+ # @param name [String] name of the module to protect
36
+ # @return [String] an include guard end statement
37
+ def include_guard_end(name)
38
+ "#endif // #{name}"
39
+ end
40
+
15
41
  end
16
42
  end
17
43
  end
@@ -5,26 +5,29 @@ module Cog
5
5
 
6
6
  class CPlusPlusLanguage < CLanguage
7
7
 
8
+ # @return [Array<String>] a set of extensions needed to define a module in this language
8
9
  def module_extensions
9
10
  [:cpp, :hpp]
10
11
  end
12
+
13
+ # @param name [String] name of the scope to use
14
+ # @return [String] a using statement for the named scope
15
+ def use_named_scope(name)
16
+ "using namespace #{name};"
17
+ end
11
18
 
19
+ # @param name [String] name of the scope
20
+ # @return [String] begin a named scope
12
21
  def named_scope_begin(name)
13
22
  "namespace #{name} {"
14
23
  end
15
24
 
25
+ # @param name [String] name of the scope
26
+ # @return [String] end the given named scope
16
27
  def named_scope_end(name)
17
28
  "} // namespace #{name}"
18
29
  end
19
30
 
20
- def include_guard_begin(name)
21
- "#ifndef #{name}\n#define #{name}"
22
- end
23
-
24
- def include_guard_end(name)
25
- "#end // #{name}"
26
- end
27
-
28
31
  end
29
32
  end
30
33
  end
@@ -5,9 +5,33 @@ module Cog
5
5
 
6
6
  class CSharpLanguage < CLanguage
7
7
 
8
+ # @return [Array<String>] a set of extensions needed to define a module in this language
8
9
  def module_extensions
9
10
  [:cs]
10
11
  end
12
+
13
+ # @param name [String] name of the scope
14
+ # @return [String] begin a named scope
15
+ def named_scope_begin(name)
16
+ "namespace #{name} {"
17
+ end
18
+
19
+ # @param name [String] name of the scope
20
+ # @return [String] end the given named scope
21
+ def named_scope_end(name)
22
+ "} // namespace #{name}"
23
+ end
24
+
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
+
11
35
  end
12
36
  end
13
37
  end
@@ -5,9 +5,33 @@ module Cog
5
5
 
6
6
  class JavaLanguage < CLanguage
7
7
 
8
+ # @return [Array<String>] a set of extensions needed to define a module in this language
8
9
  def module_extensions
9
10
  [:java]
10
11
  end
12
+
13
+ # @param name [String] name of the scope
14
+ # @return [String] begin a named scope
15
+ def named_scope_begin(name)
16
+ "package #{name};"
17
+ end
18
+
19
+ # @param name [String] name of the scope
20
+ # @return [String] end the given named scope
21
+ def named_scope_end(name)
22
+ "// end of package: #{name}"
23
+ end
24
+
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
+
11
35
  end
12
36
  end
13
37
  end
@@ -5,9 +5,33 @@ module Cog
5
5
 
6
6
  class JavaScriptLanguage < CLanguage
7
7
 
8
+ # @return [Array<String>] a set of extensions needed to define a module in this language
8
9
  def module_extensions
9
10
  [:js]
10
11
  end
12
+
13
+ # @param name [String] name of the scope
14
+ # @return [String] begin a named scope
15
+ def named_scope_begin(name)
16
+ "var #{name} = { // named scope"
17
+ end
18
+
19
+ # @param name [String] name of the scope
20
+ # @return [String] end the given named scope
21
+ def named_scope_end(name)
22
+ "}; // named scope: #{name}"
23
+ 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
+
11
35
  end
12
36
  end
13
37
  end
@@ -11,11 +11,17 @@ module Cog
11
11
  text
12
12
  end
13
13
 
14
- # @return a set of extensions needed to define a module in this language
14
+ # @return [Array<String>] a set of extensions needed to define a module in this language
15
15
  def module_extensions
16
16
  [:txt]
17
17
  end
18
18
 
19
+ # @param name [String] name of the scope to use
20
+ # @return [String] a using statement for the named scope
21
+ def use_named_scope(name)
22
+ ""
23
+ end
24
+
19
25
  # @param name [String] name of the scope
20
26
  # @return [String] begin a named scope
21
27
  def named_scope_begin(name)
@@ -5,13 +5,37 @@ module Cog
5
5
 
6
6
  class PythonLanguage < Language
7
7
 
8
+ # @param text [String] some text which should be rendered as a comment
9
+ # @return [String] a comment appropriate for this language
8
10
  def comment(text)
9
11
  "'''\n#{text}\n'''"
10
12
  end
11
-
13
+
14
+ # @return [Array<String>] a set of extensions needed to define a module in this language
12
15
  def module_extensions
13
16
  [:py]
14
17
  end
18
+
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
+
15
39
  end
16
40
  end
17
41
  end
@@ -5,13 +5,39 @@ module Cog
5
5
 
6
6
  class RubyLanguage < Language
7
7
 
8
+ # @param text [String] some text which should be rendered as a comment
9
+ # @return [String] a comment appropriate for this language
8
10
  def comment(text)
9
11
  "=begin\n#{text}\n=end"
10
12
  end
11
-
13
+
14
+ # @return [Array<String>] a set of extensions needed to define a module in this language
12
15
  def module_extensions
13
16
  [:rb]
14
17
  end
18
+
19
+ # @param name [String] name of the scope
20
+ # @return [String] begin a named scope
21
+ def named_scope_begin(name)
22
+ "module #{name}"
23
+ end
24
+
25
+ # @param name [String] name of the scope
26
+ # @return [String] end the given named scope
27
+ def named_scope_end(name)
28
+ "end # module #{name}"
29
+ end
30
+
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
+
15
41
  end
16
42
  end
17
43
  end
@@ -1,5 +1,5 @@
1
1
  module Cog
2
2
  unless const_defined? :VERSION
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  <%%= warning %>
2
2
 
3
- class <%%= @class %>
3
+ class <%%= @class %>
4
4
  {
5
5
  <%%= @class %>();
6
6
  };
@@ -5,7 +5,7 @@
5
5
  This is a generated file. DO NOT EDIT THIS FILE! Your changes will
6
6
  be lost the next time this file is regenerated.
7
7
 
8
- This file was generating using cog
8
+ This file was generated using cog
9
9
  https://github.com/ktonon/cog
10
10
 
11
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: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kevin Tonon
@@ -121,7 +121,6 @@ files:
121
121
  - templates/basic/template.hpp.erb.erb
122
122
  - templates/basic/template.java.erb.erb
123
123
  - templates/basic/template.js.erb.erb
124
- - templates/basic/template.php.erb.erb
125
124
  - templates/basic/template.py.erb.erb
126
125
  - templates/basic/template.rb.erb.erb
127
126
  - templates/basic/template.txt.erb.erb
@@ -162,7 +161,6 @@ files:
162
161
  - lib/cog/languages/java_language.rb
163
162
  - lib/cog/languages/java_script_language.rb
164
163
  - lib/cog/languages/language.rb
165
- - lib/cog/languages/p_h_p_language.rb
166
164
  - lib/cog/languages/python_language.rb
167
165
  - lib/cog/languages/ruby_language.rb
168
166
  - lib/cog/languages.rb
@@ -1,13 +0,0 @@
1
- require 'cog/languages/c_language'
2
-
3
- module Cog
4
- module Languages
5
-
6
- class PHPLanguage < CLanguage
7
-
8
- def module_extensions
9
- [:php]
10
- end
11
- end
12
- end
13
- end
@@ -1 +0,0 @@
1
- <%%= warning %>