cog 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
- # @api developer
2
1
  class Array
3
2
 
3
+ # @api developer
4
4
  # Iterate through each path in this array
5
5
  # @yieldparam source [String] readable label for the source. In the case of plugins, the plugin name
6
6
  # @yieldparam source_type [Symbol] one of :built_in, :user, :plugin, or :project
@@ -1,6 +1,6 @@
1
- # @api developer
2
1
  class String
3
2
 
3
+ # @api developer
4
4
  # @return [String] strips {Cog::Config::ProjectConfig#project_root} from the beginning of this string
5
5
  def relative_to_project_root
6
6
  if Cog.show_fullpaths?
@@ -10,6 +10,7 @@ class String
10
10
  end
11
11
  end
12
12
 
13
+ # @api developer
13
14
  # @param prefix [String] path prefix to strip from the beginning of this string
14
15
  # @return [String] this string as a file system path relative to the +prefix+
15
16
  def relative_to(prefix)
@@ -20,6 +21,7 @@ class String
20
21
  end
21
22
  end
22
23
 
24
+ # @api developer
23
25
  # @return [Cog::Plugin,nil] if this string can be interpretted as a path relative to one of the registered cog plugins, return that plugin, otherwise return +nil+
24
26
  def relative_to_which_plugin?
25
27
  Cog.plugins.each do |plugin|
@@ -28,6 +30,7 @@ class String
28
30
  nil
29
31
  end
30
32
 
33
+ # @api developer
31
34
  # @param ext [String] file extension to remove from the end of this string
32
35
  # @return [String] a copy of this string with the given extension removed. Does nothing if this string does not edit with the extension
33
36
  def without_extension(ext)
@@ -37,6 +40,7 @@ class String
37
40
  end_with?(ext) ? slice(0..(-ext.length - 1)) : dup
38
41
  end
39
42
 
43
+ # @api developer
40
44
  # @return [String, String] source and type, where type is one of <tt>:project</tt>, <tt>:user</tt>, <tt>:built_in</tt>, <tt>:gem</tt>, or <tt>:unknown</tt>
41
45
  def cog_source_and_type
42
46
  if start_with?(Cog.project_root) || start_with?(Cog.project_template_path) || start_with?(Cog.project_generator_path) || start_with?(Cog.project_plugin_path)
@@ -0,0 +1,111 @@
1
+ class Symbol
2
+ # @return [String] assuming this symbol represents a cog primitive type, returns an identifier of the mapped primitive in the {Cog::Config::LanguageConfig#active_language Cog.active_language}
3
+ # @example
4
+ # # For Objective-C
5
+ # :boolean.to_prim # => 'BOOL'
6
+ #
7
+ # # For Java
8
+ # :boolean.to_prim # => 'boolean'
9
+ #
10
+ # # For C#
11
+ # :boolean.to_prim # => 'bool'
12
+ def to_prim
13
+ Cog.active_language.to_prim(self)
14
+ end
15
+ end
16
+
17
+ # Helpers for {Bignum} and {Fixnum}
18
+ module Cognum
19
+ # @return [String] literal representation in the {Cog::Config::LanguageConfig#active_language Cog.active_language}
20
+ def to_lit
21
+ Cog.active_language.to_integer(self) || Cog.active_language.to_long(self)
22
+ end
23
+
24
+ # @param bits [Fixnum] the size of a signed integer
25
+ # @return [Boolean] whether or not this number can fit in a singed integer of the given size in the {Cog::Config::LanguageConfig#active_language Cog.active_language}
26
+ def signed?(bits)
27
+ limit = 2 ** (bits - 1)
28
+ self >= -limit && self < limit
29
+ end
30
+ end
31
+
32
+ class Bignum
33
+ include Cognum
34
+ end
35
+
36
+ class Fixnum
37
+ include Cognum
38
+ end
39
+
40
+ class Float
41
+ # @return [String] literal representation in the {Cog::Config::LanguageConfig#active_language Cog.active_language}
42
+ def to_lit
43
+ Cog.active_language.to_float(self) || Cog.active_language.to_double(self)
44
+ end
45
+ end
46
+
47
+ class String
48
+ # @return [String] literal representation in the {Cog::Config::LanguageConfig#active_language Cog.active_language}
49
+ # @example
50
+ # # For Objective-C
51
+ # "my cat walks over the keyboard".to_lit # => '@"my cat walks over the keyboard"'
52
+ #
53
+ # # For Java
54
+ # "my cat walks over the keyboard".to_lit # => '"my cat walks over the keyboard"'
55
+ def to_lit
56
+ Cog.active_language.to_char(self) || Cog.active_language.to_string(self)
57
+ end
58
+
59
+ # @return [String] a safe identifier name in the {Cog::Config::LanguageConfig#active_language Cog.active_language} so as not to conflict with any {Cog::DSL::LanguageDSL#reserved reserved words}
60
+ # @example
61
+ # # For Java
62
+ # "boolean".to_ident # => 'boolean_'
63
+ # "bool".to_ident # => 'bool'
64
+ #
65
+ # # For C#
66
+ # "boolean".to_ident # => 'boolean'
67
+ # "bool".to_ident # => 'bool_'
68
+ def to_ident
69
+ Cog.active_language.to_ident(self)
70
+ end
71
+ end
72
+
73
+ class TrueClass
74
+ # @return [String] literal representation in the {Cog::Config::LanguageConfig#active_language Cog.active_language}
75
+ # @example
76
+ # # For Objective-C
77
+ # true.to_lit # => 'YES'
78
+ #
79
+ # # For Java
80
+ # true.to_lit # => 'true'
81
+ def to_lit
82
+ Cog.active_language.to_boolean(self)
83
+ end
84
+ end
85
+
86
+ class FalseClass
87
+ # @return [String] literal representation in the {Cog::Config::LanguageConfig#active_language Cog.active_language}
88
+ # @example
89
+ # # For Objective-C
90
+ # false.to_lit # => 'NO'
91
+ #
92
+ # # For Java
93
+ # false.to_lit # => 'false'
94
+ def to_lit
95
+ Cog.active_language.to_boolean(self)
96
+ end
97
+ end
98
+
99
+ class NilClass
100
+ # @return [String] literal representation in the {Cog::Config::LanguageConfig#active_language Cog.active_language}
101
+ # @example
102
+ # # For C
103
+ # nil.to_lit # => 'NULL'
104
+ #
105
+ # # For C#
106
+ # nil.to_lit # => 'null'
107
+ def to_lit
108
+ Cog.active_language.to_null(self)
109
+ end
110
+ end
111
+
data/lib/cog/seed.rb ADDED
@@ -0,0 +1,68 @@
1
+ module Cog
2
+
3
+ # Template for a class in a target language
4
+ class Seed
5
+
6
+ include Generator
7
+
8
+ autoload :Feature, 'cog/seed/feature'
9
+ autoload :Var, 'cog/seed/var'
10
+
11
+ # @return [String] name of the class
12
+ attr_reader :name
13
+
14
+ # @return [String,nil] path to the header file
15
+ attr_reader :header_path
16
+
17
+ # @return [String,nil] name of the scope in which classes generated by this seed will be found
18
+ attr_reader :in_scope
19
+
20
+ # @api developer
21
+ # @param name [String] name of the class
22
+ def initialize(name)
23
+ @name = name.to_s.camelize.to_ident
24
+ @features = [] # [Feature]
25
+ end
26
+
27
+ # @return [String] begin the include guard
28
+ def guard
29
+ x = [@in_scope, @name].compact.collect &:upcase
30
+ include_guard_begin "__COG_SPROUT__#{x.join '_'}_H__"
31
+ end
32
+
33
+ # @return [Array<Feature>] a sorted list of features
34
+ def features
35
+ @features.sort
36
+ end
37
+
38
+ # Render the class in the currently active language
39
+ # @param path [String] file system path without the extension, relative to the project root. The extension will be determined based on the currently active language
40
+ # @option opt [String] :language key for the language to use. The language must define a seed extension
41
+ def stamp_class(path, opt={})
42
+ Cog.activate_language opt[:language] do
43
+ l = Cog.active_language
44
+ raise Errors::ActiveLanguageDoesNotSupportSeeds.new :language => l if l.nil? || l.seed_extension.nil?
45
+
46
+ @in_header = false
47
+ @header_path = if l.seed_header
48
+ "#{path}.#{l.seed_header}"
49
+ end
50
+ stamp "cog/#{l.key}/seed.#{l.seed_extension}", "#{path}.#{l.seed_extension}"
51
+ if l.seed_header
52
+ @in_header = true
53
+ stamp "cog/#{l.key}/seed.#{l.seed_header}", @header_path
54
+ end
55
+ end
56
+ end
57
+
58
+ def in_header?
59
+ @in_header
60
+ end
61
+
62
+ # Sort by name
63
+ def <=>(other)
64
+ @name <=> other
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,54 @@
1
+ module Cog
2
+ class Seed
3
+
4
+ # Template for a method in a target language
5
+ class Feature
6
+
7
+ include Generator
8
+
9
+ attr_reader :seed
10
+
11
+ # @return [String] name of the method
12
+ attr_reader :name
13
+
14
+ attr_reader :params
15
+
16
+ attr_reader :return_type
17
+
18
+ # @api developer
19
+ # @param name [String] name of the method
20
+ def initialize(seed, name, opt={})
21
+ @seed = seed
22
+ @name = name.to_s.to_ident
23
+ @abstract = false
24
+ @params = [] # [Var]
25
+ @return_type = :void
26
+ end
27
+
28
+ # @return [Boolean] is this an abstract method?
29
+ def abstract?
30
+ @abstract
31
+ end
32
+
33
+ def desc
34
+ @desc || 'Undocumented'
35
+ end
36
+
37
+ def keep_name
38
+ "#{@seed.name}_#{@name}"
39
+ end
40
+
41
+ def stamp_method
42
+ l = Cog.active_language
43
+ ext = @seed.in_header? ? l.seed_header : l.seed_extension
44
+ stamp "cog/#{l.key}/feature.#{ext}"
45
+ end
46
+
47
+ # Sort by name
48
+ def <=>(other)
49
+ @name <=> other.name
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,43 @@
1
+ module Cog
2
+ class Seed
3
+
4
+ # Template for a variable in a target language
5
+ class Var
6
+
7
+ include Generator
8
+
9
+ # @return [String] name of the variable
10
+ attr_reader :name
11
+
12
+ attr_reader :desc
13
+
14
+ attr_reader :type
15
+
16
+ attr_reader :scope
17
+
18
+ # @api developer
19
+ def initialize(type, name, opt={})
20
+ @type = type
21
+ @name = name.to_s.to_ident
22
+ @desc = opt[:desc]
23
+ @scope = opt[:scope]
24
+ end
25
+
26
+ def qualify?
27
+ @qualify
28
+ end
29
+
30
+ def stamp_decl(qualify = false)
31
+ l = Cog.active_language
32
+ @qualify = qualify && @scope
33
+ stamp "cog/#{l.key}/var_decl.#{l.seed_extension}"
34
+ end
35
+
36
+ # Sort by name
37
+ def <=>(other)
38
+ @name <=> other
39
+ end
40
+
41
+ end
42
+ end
43
+ end
data/lib/cog/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Cog
2
2
  unless const_defined? :VERSION
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
5
5
  end
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: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kevin Tonon
@@ -15,10 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-01-05 00:00:00 Z
18
+ date: 2013-01-30 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: gli
21
+ name: active_support
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
@@ -32,7 +32,7 @@ dependencies:
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: rainbow
35
+ name: gli
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
@@ -46,7 +46,7 @@ dependencies:
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- name: active_support
49
+ name: i18n
50
50
  prerelease: false
51
51
  requirement: &id003 !ruby/object:Gem::Requirement
52
52
  none: false
@@ -60,7 +60,7 @@ dependencies:
60
60
  type: :runtime
61
61
  version_requirements: *id003
62
62
  - !ruby/object:Gem::Dependency
63
- name: i18n
63
+ name: rainbow
64
64
  prerelease: false
65
65
  requirement: &id004 !ruby/object:Gem::Requirement
66
66
  none: false
@@ -88,7 +88,7 @@ dependencies:
88
88
  type: :development
89
89
  version_requirements: *id005
90
90
  - !ruby/object:Gem::Dependency
91
- name: yard
91
+ name: redcarpet
92
92
  prerelease: false
93
93
  requirement: &id006 !ruby/object:Gem::Requirement
94
94
  none: false
@@ -101,6 +101,34 @@ dependencies:
101
101
  version: "0"
102
102
  type: :development
103
103
  version_requirements: *id006
104
+ - !ruby/object:Gem::Dependency
105
+ name: rspec
106
+ prerelease: false
107
+ requirement: &id007 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ type: :development
117
+ version_requirements: *id007
118
+ - !ruby/object:Gem::Dependency
119
+ name: yard
120
+ prerelease: false
121
+ requirement: &id008 !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ type: :development
131
+ version_requirements: *id008
104
132
  description:
105
133
  email: kevin@betweenconcepts.com
106
134
  executables:
@@ -116,6 +144,11 @@ files:
116
144
  - built_in/generators/sort.rb
117
145
  - built_in/plugins/basic/Cogfile
118
146
  - built_in/plugins/basic/templates/basic/generator.rb.erb
147
+ - built_in/templates/cog/c++/feature.cpp.erb
148
+ - built_in/templates/cog/c++/feature.h.erb
149
+ - built_in/templates/cog/c++/seed.cpp.erb
150
+ - built_in/templates/cog/c++/seed.h.erb
151
+ - built_in/templates/cog/c++/var_decl.cpp.erb
119
152
  - built_in/templates/cog/Cogfile.erb
120
153
  - built_in/templates/cog/plugin/generator.rb.erb.erb
121
154
  - built_in/templates/cog/plugin/plugin.rb.erb
@@ -129,7 +162,9 @@ files:
129
162
  - lib/cog/controllers/template_controller.rb
130
163
  - lib/cog/controllers.rb
131
164
  - lib/cog/dsl/cogfile.rb
165
+ - lib/cog/dsl/feature_dsl.rb
132
166
  - lib/cog/dsl/language_dsl.rb
167
+ - lib/cog/dsl/seed_dsl.rb
133
168
  - lib/cog/dsl.rb
134
169
  - lib/cog/embed_context.rb
135
170
  - lib/cog/embeds.rb
@@ -148,6 +183,10 @@ files:
148
183
  - lib/cog/native_extensions/string.rb
149
184
  - lib/cog/native_extensions.rb
150
185
  - lib/cog/plugin.rb
186
+ - lib/cog/primitive.rb
187
+ - lib/cog/seed/feature.rb
188
+ - lib/cog/seed/var.rb
189
+ - lib/cog/seed.rb
151
190
  - lib/cog/spec_helpers/matchers/match_maker.rb
152
191
  - lib/cog/spec_helpers/matchers.rb
153
192
  - lib/cog/spec_helpers/runner.rb