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
@@ -1,19 +0,0 @@
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,20 +0,0 @@
1
- require 'cog/languages/language'
2
- require 'cog/languages/mixins/hash_comments'
3
-
4
- module Cog
5
- module Languages
6
-
7
- class PythonLanguage < Language
8
- include Mixins::HashComments
9
-
10
- def module_extensions
11
- [:py]
12
- end
13
-
14
- def multi_line_comment(text)
15
- "'''\n#{text}\n'''"
16
- end
17
-
18
- end
19
- end
20
- end
@@ -1,16 +0,0 @@
1
- require 'cog/languages/language'
2
- require 'cog/languages/mixins/hash_comments'
3
-
4
- module Cog
5
- module Languages
6
-
7
- class QtProjectLanguage < Language
8
- include Mixins::HashComments
9
-
10
- def module_extensions
11
- [:pro, :pri]
12
- end
13
-
14
- end
15
- end
16
- end
@@ -1,28 +0,0 @@
1
- require 'cog/languages/language'
2
- require 'cog/languages/mixins/hash_comments'
3
-
4
- module Cog
5
- module Languages
6
-
7
- class RubyLanguage < Language
8
- include Mixins::HashComments
9
-
10
- def module_extensions
11
- [:rb]
12
- end
13
-
14
- def multi_line_comment(text)
15
- "=begin\n#{text}\n=end"
16
- end
17
-
18
- def named_scope_begin(name)
19
- "module #{name}"
20
- end
21
-
22
- def named_scope_end(name)
23
- "end # module #{name}"
24
- end
25
-
26
- end
27
- end
28
- end
@@ -1,61 +0,0 @@
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
@@ -1,26 +0,0 @@
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
@@ -1,4 +0,0 @@
1
- require 'cog'
2
- include Cog::Generator
3
-
4
- # This is the <%= @name %> generator
@@ -1,8 +0,0 @@
1
- source :rubygems
2
- gemspec
3
-
4
- gem "cog", "~> <%= @cog_version %>"
5
-
6
- # Documentation
7
- gem "yard"
8
- gem "redcarpet"
@@ -1,18 +0,0 @@
1
- Copyright (c) 2012 <%= @tool_author %>
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- this software and associated documentation files (the "Software"), to deal in
5
- the Software without restriction, including without limitation the rights to
6
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
- the Software, and to permit persons to whom the Software is furnished to do so,
8
- subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all
11
- copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,18 +0,0 @@
1
- = <%= @tool_name %>
2
-
3
- <%= @tool_description %>
4
-
5
- Get it
6
- ------
7
-
8
- From a terminal
9
-
10
- ```bash
11
- gem install <%= @tool_name %>
12
- ```
13
-
14
- or in your Gemfile
15
-
16
- ```ruby
17
- gem "<%= @tool_name %>", "~> 0.0.1"
18
- ```
@@ -1,15 +0,0 @@
1
- require 'rake/clean'
2
- require 'rubygems'
3
- require 'rubygems/package_task'
4
- require 'rdoc/task'
5
-
6
- YARD::Rake::YardocTask.new do |t|
7
- t.files = ["lib/**/*.rb", "README.markdown"]
8
- t.options = [
9
- '--query', '@api.text != "unstable" && @api.text != "developer"']
10
- end
11
-
12
- spec = eval(File.read('<%= @tool_name %>.gemspec'))
13
-
14
- Gem::PackageTask.new(spec) do |pkg|
15
- end
@@ -1,17 +0,0 @@
1
- require 'cog'
2
- include Cog::Generator
3
-
4
- # Register <%= @tool_name %> as a tool with cog
5
- Cog.register_tool __FILE__ do |tool|
6
-
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
15
- end
16
-
17
- end
@@ -1,9 +0,0 @@
1
- <%% if Cog.active_tool.explicit_require %>
2
- require '<%%= Cog.active_tool.path %>'
3
- <%% else %>
4
- require '<%%= Cog.active_tool.name %>'
5
- <%% end %>
6
-
7
- <%= @tool_module %>.widget '<%%= @name %>' do |w|
8
- w.context = 'this is the context'
9
- end
@@ -1 +0,0 @@
1
- This is a custom generator template with context: <%%= @context %>!
@@ -1,17 +0,0 @@
1
- # Ensure we require the local version and not one we might have installed already
2
- require File.join([File.dirname(__FILE__),'lib','<%= @tool_name %>/version.rb'])
3
- spec = Gem::Specification.new do |s|
4
- s.name = '<%= @tool_name %>'
5
- s.version = <%= @tool_module %>::VERSION
6
- s.author = '<%= @tool_author %>'
7
- s.email = '<%= @tool_email %>'
8
- s.homepage = ''
9
- s.platform = Gem::Platform::RUBY
10
- s.summary = '<%= @tool_description %>'
11
- s.files = %w(LICENSE) + Dir.glob('cog/**/*') + Dir.glob('lib/**/*.rb')
12
- s.require_paths << 'lib'
13
- s.has_rdoc = 'yard'
14
- s.rdoc_options << '--title' << '<%= @tool_name %>' << '-ri'
15
- s.add_development_dependency('rake')
16
- s.add_development_dependency('yard')
17
- end
@@ -1,5 +0,0 @@
1
- module <%= @tool_module %>
2
- unless const_defined? :VERSION
3
- VERSION = '0.0.1' # :nodoc:
4
- end
5
- end