cog 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/BuiltIn.cogfile +96 -0
  2. data/bin/cog +30 -39
  3. data/built_in/generators/sort.rb +3 -0
  4. data/built_in/plugins/basic/Cogfile +6 -0
  5. data/built_in/plugins/basic/templates/basic/generator.rb.erb +1 -0
  6. data/built_in/templates/cog/Cogfile.erb +40 -0
  7. data/built_in/templates/cog/plugin/generator.rb.erb.erb +3 -0
  8. data/{templates/cog/custom_tool/tool.rb.erb → built_in/templates/cog/plugin/plugin.rb.erb} +4 -11
  9. data/{templates → built_in/templates}/warning.erb +0 -0
  10. data/lib/cog.rb +25 -11
  11. data/lib/cog/config.rb +112 -49
  12. data/lib/cog/config/{language_methods.rb → language_config.rb} +23 -27
  13. data/lib/cog/config/plugin_config.rb +31 -0
  14. data/lib/cog/config/project_config.rb +48 -0
  15. data/lib/cog/controllers.rb +6 -8
  16. data/lib/cog/controllers/generator_controller.rb +30 -21
  17. data/lib/cog/controllers/plugin_controller.rb +43 -0
  18. data/lib/cog/controllers/template_controller.rb +12 -33
  19. data/lib/cog/dsl.rb +9 -0
  20. data/lib/cog/dsl/cogfile.rb +145 -0
  21. data/lib/cog/dsl/language_dsl.rb +142 -0
  22. data/lib/cog/embed_context.rb +0 -2
  23. data/lib/cog/embeds.rb +2 -7
  24. data/lib/cog/errors.rb +11 -24
  25. data/lib/cog/generator.rb +10 -15
  26. data/lib/cog/generator/file_methods.rb +2 -2
  27. data/lib/cog/generator/filters.rb +10 -14
  28. data/lib/cog/generator/language_methods.rb +2 -3
  29. data/lib/cog/generator_sandbox.rb +32 -0
  30. data/lib/cog/helpers.rb +10 -2
  31. data/lib/cog/helpers/cascading_set.rb +104 -0
  32. data/lib/cog/{embeds → helpers}/file_scanner.rb +1 -1
  33. data/lib/cog/language.rb +140 -0
  34. data/lib/cog/native_extensions.rb +2 -0
  35. data/lib/cog/native_extensions/array.rb +19 -0
  36. data/lib/cog/native_extensions/string.rb +54 -0
  37. data/lib/cog/plugin.rb +35 -0
  38. data/lib/cog/spec_helpers.rb +36 -14
  39. data/lib/cog/spec_helpers/matchers.rb +14 -4
  40. data/lib/cog/spec_helpers/matchers/match_maker.rb +1 -1
  41. data/lib/cog/spec_helpers/runner.rb +3 -9
  42. data/lib/cog/version.rb +1 -1
  43. metadata +27 -44
  44. data/Default.cogfile +0 -25
  45. data/lib/cog/built_in_tools.rb +0 -9
  46. data/lib/cog/built_in_tools/basic.rb +0 -10
  47. data/lib/cog/built_in_tools/basic/cog_tool.rb +0 -11
  48. data/lib/cog/config/cogfile.rb +0 -117
  49. data/lib/cog/config/lang_info.rb +0 -40
  50. data/lib/cog/config/project_methods.rb +0 -35
  51. data/lib/cog/config/tool_methods.rb +0 -94
  52. data/lib/cog/controllers/tool_controller.rb +0 -50
  53. data/lib/cog/helpers/cascading_template_set.rb +0 -75
  54. data/lib/cog/helpers/string.rb +0 -26
  55. data/lib/cog/languages.rb +0 -52
  56. data/lib/cog/languages/c_language.rb +0 -29
  57. data/lib/cog/languages/c_plus_plus_language.rb +0 -28
  58. data/lib/cog/languages/c_sharp_language.rb +0 -24
  59. data/lib/cog/languages/java_language.rb +0 -24
  60. data/lib/cog/languages/java_script_language.rb +0 -24
  61. data/lib/cog/languages/language.rb +0 -73
  62. data/lib/cog/languages/mixins.rb +0 -10
  63. data/lib/cog/languages/mixins/c_style_comments.rb +0 -23
  64. data/lib/cog/languages/mixins/hash_comments.rb +0 -19
  65. data/lib/cog/languages/python_language.rb +0 -20
  66. data/lib/cog/languages/qt_project_language.rb +0 -16
  67. data/lib/cog/languages/ruby_language.rb +0 -28
  68. data/lib/cog/tool.rb +0 -61
  69. data/lib/cog/tool/dsl.rb +0 -26
  70. data/templates/basic/generator.rb.erb +0 -4
  71. data/templates/cog/custom_tool/Gemfile.erb +0 -8
  72. data/templates/cog/custom_tool/LICENSE.erb +0 -18
  73. data/templates/cog/custom_tool/README.markdown.erb +0 -18
  74. data/templates/cog/custom_tool/Rakefile.erb +0 -15
  75. data/templates/cog/custom_tool/cog_tool.rb.erb +0 -17
  76. data/templates/cog/custom_tool/generator.rb.erb.erb +0 -9
  77. data/templates/cog/custom_tool/template.txt.erb.erb +0 -1
  78. data/templates/cog/custom_tool/tool.gemspec.erb +0 -17
  79. data/templates/cog/custom_tool/version.rb.erb +0 -5
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
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-15 00:00:00 Z
18
+ date: 2012-12-30 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: gli
@@ -111,35 +111,27 @@ extra_rdoc_files: []
111
111
 
112
112
  files:
113
113
  - bin/cog
114
- - Default.cogfile
114
+ - BuiltIn.cogfile
115
115
  - LICENSE
116
- - templates/basic/generator.rb.erb
117
- - templates/cog/custom_tool/cog_tool.rb.erb
118
- - templates/cog/custom_tool/Gemfile.erb
119
- - templates/cog/custom_tool/generator.rb.erb.erb
120
- - templates/cog/custom_tool/LICENSE.erb
121
- - templates/cog/custom_tool/Rakefile.erb
122
- - templates/cog/custom_tool/README.markdown.erb
123
- - templates/cog/custom_tool/template.txt.erb.erb
124
- - templates/cog/custom_tool/tool.gemspec.erb
125
- - templates/cog/custom_tool/tool.rb.erb
126
- - templates/cog/custom_tool/version.rb.erb
127
- - templates/warning.erb
128
- - lib/cog/built_in_tools/basic/cog_tool.rb
129
- - lib/cog/built_in_tools/basic.rb
130
- - lib/cog/built_in_tools.rb
131
- - lib/cog/config/cogfile.rb
132
- - lib/cog/config/lang_info.rb
133
- - lib/cog/config/language_methods.rb
134
- - lib/cog/config/project_methods.rb
135
- - lib/cog/config/tool_methods.rb
116
+ - built_in/generators/sort.rb
117
+ - built_in/plugins/basic/Cogfile
118
+ - built_in/plugins/basic/templates/basic/generator.rb.erb
119
+ - built_in/templates/cog/Cogfile.erb
120
+ - built_in/templates/cog/plugin/generator.rb.erb.erb
121
+ - built_in/templates/cog/plugin/plugin.rb.erb
122
+ - built_in/templates/warning.erb
123
+ - lib/cog/config/language_config.rb
124
+ - lib/cog/config/plugin_config.rb
125
+ - lib/cog/config/project_config.rb
136
126
  - lib/cog/config.rb
137
127
  - lib/cog/controllers/generator_controller.rb
128
+ - lib/cog/controllers/plugin_controller.rb
138
129
  - lib/cog/controllers/template_controller.rb
139
- - lib/cog/controllers/tool_controller.rb
140
130
  - lib/cog/controllers.rb
131
+ - lib/cog/dsl/cogfile.rb
132
+ - lib/cog/dsl/language_dsl.rb
133
+ - lib/cog/dsl.rb
141
134
  - lib/cog/embed_context.rb
142
- - lib/cog/embeds/file_scanner.rb
143
135
  - lib/cog/embeds.rb
144
136
  - lib/cog/errors.rb
145
137
  - lib/cog/generator/file_methods.rb
@@ -147,28 +139,19 @@ files:
147
139
  - lib/cog/generator/language_methods/scope.rb
148
140
  - lib/cog/generator/language_methods.rb
149
141
  - lib/cog/generator.rb
150
- - lib/cog/helpers/cascading_template_set.rb
151
- - lib/cog/helpers/string.rb
142
+ - lib/cog/generator_sandbox.rb
143
+ - lib/cog/helpers/cascading_set.rb
144
+ - lib/cog/helpers/file_scanner.rb
152
145
  - lib/cog/helpers.rb
153
- - lib/cog/languages/c_language.rb
154
- - lib/cog/languages/c_plus_plus_language.rb
155
- - lib/cog/languages/c_sharp_language.rb
156
- - lib/cog/languages/java_language.rb
157
- - lib/cog/languages/java_script_language.rb
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
162
- - lib/cog/languages/python_language.rb
163
- - lib/cog/languages/qt_project_language.rb
164
- - lib/cog/languages/ruby_language.rb
165
- - lib/cog/languages.rb
146
+ - lib/cog/language.rb
147
+ - lib/cog/native_extensions/array.rb
148
+ - lib/cog/native_extensions/string.rb
149
+ - lib/cog/native_extensions.rb
150
+ - lib/cog/plugin.rb
166
151
  - lib/cog/spec_helpers/matchers/match_maker.rb
167
152
  - lib/cog/spec_helpers/matchers.rb
168
153
  - lib/cog/spec_helpers/runner.rb
169
154
  - lib/cog/spec_helpers.rb
170
- - lib/cog/tool/dsl.rb
171
- - lib/cog/tool.rb
172
155
  - lib/cog/version.rb
173
156
  - lib/cog.rb
174
157
  - yard-templates/default/fulldoc/html/css/common.css
@@ -1,25 +0,0 @@
1
- # All paths are relative to the directory containing this file.
2
-
3
- # Define the directory in which to find project generators
4
- project_generators_path 'cog/generators'
5
-
6
- # Define the directory in which to find custom project templates
7
- project_templates_path 'cog/templates'
8
-
9
- # Define the directory to which project source code is generated
10
- project_source_path 'src'
11
-
12
- # Explicitly specify a mapping from file extensions to languages
13
- #
14
- # key => value pairs from this mapping will override the default
15
- # language map supplied by +cog+
16
- #
17
- # Type `cog language list` to see a list of supported languages
18
- # and the current file extension mappings
19
- language_extensions({
20
- # :h => 'c++',
21
- })
22
-
23
- # Define the target language which should be used when
24
- # creating generators, and no language is explicitly specified
25
- default_target_language 'c++'
@@ -1,9 +0,0 @@
1
- module Cog
2
-
3
- # A place to store built-in +cog+ tools.
4
- #
5
- # Built-in tools are distributed with the +cog+ gem.
6
- module BuiltInTools
7
- end
8
-
9
- end
@@ -1,10 +0,0 @@
1
- module Cog
2
- module BuiltInTools
3
-
4
- # The default +cog+ tool.
5
- # Creates an example generator.
6
- module Basic
7
- end
8
-
9
- end
10
- end
@@ -1,11 +0,0 @@
1
- require 'cog'
2
- include Cog::Generator
3
-
4
- Cog.register_tool __FILE__, :built_in => true do |tool|
5
-
6
- tool.stamp_generator do |name, dest|
7
- @name = name
8
- stamp 'basic/generator.rb', dest, :absolute_destination => true
9
- end
10
-
11
- end
@@ -1,117 +0,0 @@
1
- require 'active_support/core_ext'
2
- require 'cog/languages'
3
-
4
- module Cog
5
- module Config
6
-
7
- # In your project's +Cogfile+, +self+ has been set to an instance of this class.
8
- # Typing <tt>cog init</tt> will create a +Cogfile+ in the present working directory.
9
- #
10
- # @example
11
- # # All paths are relative to the directory containing this file.
12
- #
13
- # # Define the directory in which to find project generators
14
- # project_generators_path 'cog/generators'
15
- #
16
- # # Define the directory in which to find custom project templates
17
- # project_templates_path 'cog/templates'
18
- #
19
- # # Define the directory to which project source code is generated
20
- # project_source_path 'src'
21
- #
22
- # # Explicitly specify a mapping from file extensions to languages
23
- # #
24
- # # key => value pairs from this mapping will override the default
25
- # # language map supplied by +cog+
26
- # #
27
- # # Type `cog language list` to see a list of supported languages
28
- # # and the current file extension mappings
29
- # language_extensions({
30
- # # :h => 'c++',
31
- # })
32
- #
33
- # # Define the target language which should be used when
34
- # # creating generators, and no language is explicitly specified
35
- # default_target_language 'c++'
36
- #
37
- class Cogfile
38
-
39
- # Initialize with an instance of {Config}
40
- # @api developer
41
- # @param config [Config] the object which will be configured by this Cogfile
42
- def initialize(config)
43
- @config = config
44
- end
45
-
46
- # Interpret the +Cogfile+ at {Config::ProjectMethods#cogfile_path}
47
- # @api developer
48
- # @return [nil]
49
- def interpret
50
- eval File.read(@config.cogfile_path), binding
51
- nil
52
- rescue Exception => e
53
- raise CogfileError.new(e.to_s)
54
- end
55
-
56
- # Define the directory in which to find project generators
57
- # @param path [String] a file system path
58
- # @param absolute [Boolean] if +false+, the path is relative to {Config::ProjectMethods#project_root}
59
- # @return [nil]
60
- def project_generators_path(path, absolute=false)
61
- @config.instance_eval do
62
- @project_generators_path = absolute ? path : File.join(project_root, path)
63
- end
64
- nil
65
- end
66
-
67
- # Define the directory in which to find custom project templates
68
- # @param path [String] a file system path
69
- # @param absolute [Boolean] if +false+, the path is relative to {Config::ProjectMethods#project_root}
70
- # @return [nil]
71
- def project_templates_path(path, absolute=false)
72
- @config.instance_eval do
73
- @project_templates_path = absolute ? path : File.join(project_root, path)
74
- end
75
- nil
76
- end
77
-
78
- # Define the directory to which project source code is generated
79
- # @param path [String] a file system path
80
- # @param absolute [Boolean] if +false+, the path is relative to {Config::ProjectMethods#project_root}
81
- # @return [nil]
82
- def project_source_path(path, absolute=false)
83
- @config.instance_eval do
84
- @project_source_path = absolute ? path : File.join(project_root, path)
85
- end
86
- nil
87
- end
88
-
89
- # Explicitly specify a mapping from file extensions to languages
90
- # @param map [Hash] key-value pairs from this mapping will override the default language map supplied by +cog+
91
- # @return [nil]
92
- def language_extensions(map)
93
- @config.instance_eval do
94
- @language_extension_map.update map
95
- end
96
- nil
97
- end
98
-
99
- # Define the target language which should be used when
100
- # creating generators, and no language is explicitly specified
101
- # @param lang_id [String] a language identifier
102
- def default_target_language(lang_id)
103
- @config.instance_eval do
104
- @target_language = Cog::Languages.get_language(lang_id)
105
- end
106
- end
107
- end
108
-
109
- # For wrapping errors which occur during the processing of a {Cogfile}
110
- class CogfileError < StandardError
111
- def message
112
- "in Cogfile, " + super
113
- end
114
- end
115
-
116
- end
117
- end
@@ -1,40 +0,0 @@
1
- module Cog
2
- module Config
3
-
4
- # Describes configuration of a supported language
5
- class LangInfo
6
- # @return [String] a language identifier
7
- attr_reader :lang_id
8
-
9
- # @return [Array<String>] a list of aliases
10
- attr_reader :aliases
11
-
12
- # @return [Array<Symbol>] a list of extension which currently map to this language
13
- attr_reader :extensions
14
-
15
- # @return [String] readable name of the language
16
- attr_reader :name
17
-
18
- # @api developer
19
- def initialize(lang_id, aliases)
20
- @lang_id = lang_id
21
- @aliases = aliases.dup
22
- @name = @aliases.empty? ? @lang_id : @aliases.join(', ')
23
- @extensions = []
24
- end
25
-
26
- # @param w [FixNum] width of the first column
27
- # @return [String] one line summary in two columns
28
- def to_s(w=nil)
29
- w ||= name.length
30
- "#{name.ljust w} -> #{@extensions.collect {|x| x.to_s}.sort.join ', '}"
31
- end
32
-
33
- # Sort by name
34
- def <=>(other)
35
- name <=> other.name
36
- end
37
- end
38
-
39
- end
40
- end
@@ -1,35 +0,0 @@
1
- module Cog
2
- module Config
3
-
4
- # {Config} methods related to projects
5
- module ProjectMethods
6
-
7
- # @return [String] path to the project's {Cogfile}
8
- attr_reader :cogfile_path
9
-
10
- # @return [String] directory in which to find project generators
11
- attr_reader :project_generators_path
12
-
13
- # @return [String] directory in which the project's {Cogfile} is found
14
- attr_reader :project_root
15
-
16
- # @return [String] directory to which project source code is generated
17
- attr_reader :project_source_path
18
-
19
- # @return [String] directory in which to find custom project templates
20
- attr_reader :project_templates_path
21
-
22
- # @return [Boolean] whether or not we operating in the context of a project
23
- def project?
24
- !@project_root.nil?
25
- end
26
-
27
- # @return [Array<String>] list of paths to files in the {#project_source_path} which are written in a supported language
28
- def supported_project_files
29
- exts = Cog.language_extensions.join ','
30
- Dir.glob "#{Cog.project_source_path}/**/*.{#{exts}}"
31
- end
32
-
33
- end
34
- end
35
- end
@@ -1,94 +0,0 @@
1
- module Cog
2
- module Config
3
-
4
- # {Config} methods related to tools
5
- module ToolMethods
6
-
7
- # @return [Tool] the active tool affects the creation of new generators
8
- def active_tool
9
- @active_tools.last
10
- end
11
-
12
- # @return [Array<Tool>] a sorted list of available tools
13
- def tools
14
- @tools.values.sort
15
- end
16
-
17
- # Register built-in and custom tools.
18
- # @api developer
19
- #
20
- # Custom tools are specified in the +COG_TOOLS+ environment variable.
21
- # @return [nil]
22
- def register_tools
23
- # Register built-in tools
24
- [:basic].each do |built_in|
25
- require File.join(Cog.gem_dir, 'lib', 'cog', 'built_in_tools', built_in.to_s, 'cog_tool.rb')
26
- end
27
- # Register custom tools defined in COG_TOOLS
28
- (ENV['COG_TOOLS'] || '').split(':').each do |path|
29
- explicit = path.end_with? '.rb'
30
- @next_tool_was_required_explicitly = explicit
31
- path = "#{path}/cog_tool" unless explicit
32
- begin
33
- require path
34
- rescue LoadError
35
- raise Errors::CouldNotLoadTool.new path
36
- end
37
- end
38
- nil
39
- end
40
-
41
- # Define a new +cog+ tool
42
- # @param path [String] path to the <tt>cog_tool.rb</tt> file. This method should be called from the <tt>cog_tool.rb</tt> file, in which case <tt>__FILE__</tt> should be used as the argument
43
- # @option opt [Boolean] :built_in (false) if +true+, then treat this tool as a built-in tool. If you are defininig a custom tool, leave this value as +false+
44
- # @yield [Tool::DSL] define the tool
45
- # @return [nil]
46
- # @example
47
- # require 'cog'
48
- # include Cog::Generator
49
- #
50
- # Cog.register_tool __FILE__ do |tool|
51
- #
52
- # # Define a method which creates the generator
53
- # tool.stamp_generator do |name, dest|
54
- #
55
- # # Setup context for the template
56
- # @name = name
57
- #
58
- # # Create the generator file
59
- # stamp 'my_tool/generator.rb', dest, :absolute_destination => true
60
- #
61
- # end
62
- # end
63
- def register_tool(path, opt={}, &block)
64
- tool = Tool.new path, :built_in => opt[:built_in], :explicit_require => @next_tool_was_required_explicitly
65
- dsl = Tool::DSL.new tool
66
- block.call dsl
67
- @tools[tool.name] = tool
68
- nil
69
- end
70
-
71
- # @api developer
72
- # @return [Boolean] whether or not a tool is registered with the given name
73
- def tool_registered?(name)
74
- @tools.member? name
75
- end
76
-
77
- # Activate the registered tool with the given name within the scope of the provided block. If no block is provided, the tool will remain active indefinitely.
78
- # @param name [String] name of the registered tool to activate
79
- # @yield the tool will be active within this block
80
- # @return [nil]
81
- def activate_tool(name, &block)
82
- name = name.to_s
83
- raise Errors::NoSuchTool.new(name) unless tool_registered?(name)
84
- @tools[name].load
85
- @active_tools << @tools[name]
86
- if block
87
- block.call
88
- @active_tools.pop
89
- end
90
- end
91
-
92
- end
93
- end
94
- end