cog 0.0.20 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. data/bin/cog +54 -53
  2. data/lib/cog.rb +4 -3
  3. data/lib/cog/built_in_tools/basic.rb +10 -0
  4. data/lib/cog/built_in_tools/basic/cog_tool.rb +15 -0
  5. data/lib/cog/config.rb +111 -33
  6. data/lib/cog/config/tool.rb +99 -0
  7. data/lib/cog/controllers.rb +13 -0
  8. data/lib/cog/controllers/generator_controller.rb +45 -0
  9. data/lib/cog/controllers/template_controller.rb +31 -0
  10. data/lib/cog/controllers/tool_controller.rb +53 -0
  11. data/lib/cog/errors.rb +51 -9
  12. data/lib/cog/generator.rb +1 -74
  13. data/lib/cog/helpers.rb +1 -0
  14. data/lib/cog/helpers/cascading_template_set.rb +75 -0
  15. data/lib/cog/helpers/string.rb +9 -3
  16. data/lib/cog/version.rb +1 -1
  17. data/templates/basic/generator.rb.erb +12 -0
  18. data/templates/{cog/generator/basic-template.txt.erb.erb → basic/template.txt.erb.erb} +0 -0
  19. data/templates/cog/{tool → custom_tool}/Gemfile.erb +4 -0
  20. data/templates/cog/{tool → custom_tool}/LICENSE.erb +1 -1
  21. data/templates/cog/custom_tool/README.markdown.erb +18 -0
  22. data/templates/cog/custom_tool/Rakefile.erb +15 -0
  23. data/templates/cog/custom_tool/cog_tool.rb.erb +15 -0
  24. data/templates/cog/custom_tool/generator.rb.erb.erb +9 -0
  25. data/templates/cog/{tool → custom_tool}/template.txt.erb.erb +0 -0
  26. data/templates/cog/custom_tool/tool.gemspec.erb +18 -0
  27. data/templates/cog/{tool → custom_tool}/tool.rb.erb +5 -13
  28. data/templates/cog/{tool → custom_tool}/version.rb.erb +1 -1
  29. metadata +24 -17
  30. data/lib/cog/tool.rb +0 -81
  31. data/templates/cog/generator/basic.rb.erb +0 -12
  32. data/templates/cog/tool/API.rdoc.erb +0 -7
  33. data/templates/cog/tool/README.markdown.erb +0 -18
  34. data/templates/cog/tool/Rakefile.erb +0 -15
  35. data/templates/cog/tool/generator.rb.erb.erb +0 -6
  36. data/templates/cog/tool/tool.gemspec.erb +0 -18
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,15 @@
1
+ require 'cog'
2
+
3
+ # Register <%= @tool_name %> as a tool with cog
4
+ Cog::Config.instance.register_tool __FILE__ do |tool|
5
+
6
+ # Define how new <%= @tool_name %> generators are created
7
+ #
8
+ # Add context as required by your generator template.
9
+ #
10
+ # When the block is executed, +self+ will be an instance of Cog::Config::Tool::GeneratorStamper
11
+ tool.stamp_generator do
12
+ stamp '<%= @tool_name %>/generator.rb', generator_dest, :absolute_destination => true
13
+ end
14
+
15
+ end
@@ -0,0 +1,9 @@
1
+ <%% if tool.explicit_require %>
2
+ require '<%%= tool.path %>'
3
+ <%% else %>
4
+ require '<%%= tool.name %>'
5
+ <%% end %>
6
+
7
+ <%= @tool_module %>.widget '<%%= @name %>' do |w|
8
+ w.context = 'this is the context'
9
+ end
@@ -0,0 +1,18 @@
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.extra_rdoc_files = ['API.rdoc']
15
+ s.rdoc_options << '--title' << '<%= @tool_name %>' << '-ri'
16
+ s.add_development_dependency('rake')
17
+ s.add_development_dependency('yard')
18
+ end
@@ -1,18 +1,10 @@
1
1
  $LOAD_PATH << File.join(File.dirname(__FILE__))
2
- require '<%= @name %>/version'
2
+ require '<%= @tool_name %>/version'
3
3
  require 'cog'
4
4
 
5
- # Inject this tools templates onto the cog template lookup path
6
- # Do not remove this line
7
- Cog::Config.instance.tool_templates_path = File.expand_path(File.join(__FILE__, '..', '..', 'cog', 'templates'))
8
-
9
- # Set the template which is used to create generators for this tool
10
- # Do not remove this line
11
- Cog::Config.instance.tool_generator_template = '<%= @name %>/generator.rb'
12
-
13
- # Custom cog tool <%= @name %>
14
- module <%= @module_name %>
15
-
5
+ # Custom cog tool <%= @tool_name %>
6
+ module <%= @tool_module %>
7
+
16
8
  # Root of the DSL
17
9
  # Feel free to rename this to something more appropriate
18
10
  def self.widget(generator_name, &block)
@@ -36,7 +28,7 @@ module <%= @module_name %>
36
28
  end
37
29
 
38
30
  def generate
39
- stamp '<%= @name %>/<%= @name %>.txt', "generated_#{@generator_name}.txt"
31
+ stamp '<%= @tool_name %>/<%= @tool_name %>.txt', "generated_#{@generator_name}.txt"
40
32
  end
41
33
  end
42
34
  end
@@ -1,4 +1,4 @@
1
- module <%= @module_name %>
1
+ module <%= @tool_module %>
2
2
  unless const_defined? :VERSION
3
3
  VERSION = '0.0.1' # :nodoc:
4
4
  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: 55
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 20
10
- version: 0.0.20
10
+ version: 0.1.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-11-07 00:00:00 Z
18
+ date: 2012-11-11 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: gli
@@ -85,30 +85,37 @@ files:
85
85
  - bin/cog
86
86
  - Default.cogfile
87
87
  - LICENSE
88
- - templates/cog/generator/basic-template.txt.erb.erb
89
- - templates/cog/generator/basic.rb.erb
90
- - templates/cog/tool/API.rdoc.erb
91
- - templates/cog/tool/Gemfile.erb
92
- - templates/cog/tool/generator.rb.erb.erb
93
- - templates/cog/tool/LICENSE.erb
94
- - templates/cog/tool/Rakefile.erb
95
- - templates/cog/tool/README.markdown.erb
96
- - templates/cog/tool/template.txt.erb.erb
97
- - templates/cog/tool/tool.gemspec.erb
98
- - templates/cog/tool/tool.rb.erb
99
- - templates/cog/tool/version.rb.erb
88
+ - templates/basic/generator.rb.erb
89
+ - templates/basic/template.txt.erb.erb
90
+ - templates/cog/custom_tool/cog_tool.rb.erb
91
+ - templates/cog/custom_tool/Gemfile.erb
92
+ - templates/cog/custom_tool/generator.rb.erb.erb
93
+ - templates/cog/custom_tool/LICENSE.erb
94
+ - templates/cog/custom_tool/Rakefile.erb
95
+ - templates/cog/custom_tool/README.markdown.erb
96
+ - templates/cog/custom_tool/template.txt.erb.erb
97
+ - templates/cog/custom_tool/tool.gemspec.erb
98
+ - templates/cog/custom_tool/tool.rb.erb
99
+ - templates/cog/custom_tool/version.rb.erb
100
100
  - templates/warning.h.erb
101
+ - lib/cog/built_in_tools/basic/cog_tool.rb
102
+ - lib/cog/built_in_tools/basic.rb
101
103
  - lib/cog/config/cogfile.rb
104
+ - lib/cog/config/tool.rb
102
105
  - lib/cog/config.rb
106
+ - lib/cog/controllers/generator_controller.rb
107
+ - lib/cog/controllers/template_controller.rb
108
+ - lib/cog/controllers/tool_controller.rb
109
+ - lib/cog/controllers.rb
103
110
  - lib/cog/errors.rb
104
111
  - lib/cog/generator.rb
112
+ - lib/cog/helpers/cascading_template_set.rb
105
113
  - lib/cog/helpers/string.rb
106
114
  - lib/cog/helpers.rb
107
115
  - lib/cog/spec_helpers/matchers/match_maker.rb
108
116
  - lib/cog/spec_helpers/matchers.rb
109
117
  - lib/cog/spec_helpers/runner.rb
110
118
  - lib/cog/spec_helpers.rb
111
- - lib/cog/tool.rb
112
119
  - lib/cog/version.rb
113
120
  - lib/cog.rb
114
121
  - yard-templates/default/fulldoc/html/css/common.css
@@ -1,81 +0,0 @@
1
- require 'cog/config'
2
- require 'cog/generator'
3
- require 'rainbow'
4
-
5
- module Cog
6
-
7
- # @see https://github.com/ktonon/cog#tools Introduction to Tools
8
- class Tool
9
-
10
- # A list of available tools
11
- # @param verbose [Boolean] should full paths be listed for tools which are explicitly referenced?
12
- # @return [Array<String>] a list of strings which can be passed to +require+
13
- def self.list(verbose=false)
14
- x = (ENV['COG_TOOLS'] || '').split ':'
15
- if x.all? {|path| path.slice(-3..-1) != '.rb' || File.exists?(path)}
16
- if verbose
17
- x.collect {|path| path.slice(-3..-1) == '.rb' ? File.expand_path(path) : path}
18
- else
19
- x.collect {|path| path.slice(-3..-1) == '.rb' ? File.basename(path).slice(0..-4) : path}
20
- end
21
- else
22
- x.each do |path|
23
- if !File.exists? path
24
- STDERR.write "No such cog tool at path '#{path}'\n".color(:red)
25
- elsif !File.directory? path
26
- STDERR.write "Not a cog tool at path '#{path}'\n".color(:red)
27
- end
28
- end
29
- []
30
- end
31
- end
32
-
33
- # Generate a new tool with the given name
34
- # @param name [String] name of the tool to create. Should not conflict with other tool names
35
- # @return [Boolean] was the tool created successfully?
36
- def self.create(name)
37
- if File.exists? name
38
- STDERR.write "A #{File.directory?(name) ? :directory : :file} named '#{name}' already exists\n".color(:red)
39
- false
40
- else
41
- Object.new.instance_eval do
42
- extend Generator
43
- @name = name.to_s.downcase
44
- @module_name = name.to_s.capitalize
45
- @letter = name.to_s.slice(0,1).downcase
46
- @author = '<Your name goes here>'
47
- @email = 'youremail@...'
48
- @description = 'A one-liner'
49
- @cog_version = Cog::VERSION
50
- stamp 'cog/tool/tool.rb', "#{@name}/lib/#{@name}.rb", :absolute_destination => true
51
- stamp 'cog/tool/version.rb', "#{@name}/lib/#{@name}/version.rb", :absolute_destination => true
52
- stamp 'cog/tool/generator.rb.erb', "#{@name}/cog/templates/#{@name}/generator.rb.erb", :absolute_destination => true
53
- stamp 'cog/tool/template.txt.erb', "#{@name}/cog/templates/#{@name}/#{@name}.txt.erb", :absolute_destination => true
54
- stamp 'cog/tool/Gemfile', "#{@name}/Gemfile", :absolute_destination => true
55
- stamp 'cog/tool/Rakefile', "#{@name}/Rakefile", :absolute_destination => true
56
- stamp 'cog/tool/tool.gemspec', "#{@name}/#{@name}.gemspec", :absolute_destination => true
57
- stamp 'cog/tool/API.rdoc', "#{@name}/API.rdoc", :absolute_destination => true
58
- stamp 'cog/tool/LICENSE', "#{@name}/LICENSE", :absolute_destination => true
59
- stamp 'cog/tool/README.markdown', "#{@name}/README.markdown", :absolute_destination => true
60
- end
61
- true
62
- end
63
- end
64
-
65
- # Find an available tool with the given name
66
- # @param name [String] name of the tool to search for
67
- # @return [String] a fully qualified tool path, which can be passed to +require+
68
- def self.find(name)
69
- x = (ENV['COG_TOOLS'] || '').split ':'
70
- x.each do |path|
71
- if path.slice(-3..-1) == '.rb'
72
- short = File.basename(path).slice(0..-4)
73
- return path if short == name
74
- else
75
- return path if path == name
76
- end
77
- end
78
- end
79
-
80
- end
81
- end
@@ -1,12 +0,0 @@
1
- require 'cog'
2
-
3
- class <%= @class_name %>
4
- include Cog::Generator
5
-
6
- def generate
7
- @some_context = :my_context_value
8
- stamp '<%= @name %>.txt', 'generated_<%= @name %>.txt'
9
- end
10
- end
11
-
12
- <%= @class_name %>.new.generate
@@ -1,7 +0,0 @@
1
- = <%= @name %>
2
-
3
- These are the API docs for +<%= @name %>+, which is +cog+ tool.
4
-
5
- Please see the <tt>README.markdown</tt> file for a introduction to the
6
- +<%= @name %>+ tool. To find out more about +cog+ in general visit
7
- https://github.com/ktonon/cog#readme
@@ -1,18 +0,0 @@
1
- = <%= @name %>
2
-
3
- <%= @description %>
4
-
5
- Get it
6
- ------
7
-
8
- From a terminal
9
-
10
- ```bash
11
- gem install <%= @name %>
12
- ```
13
-
14
- or in your Gemfile
15
-
16
- ```ruby
17
- gem "<%= @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
- Rake::RDocTask.new do |rd|
7
- rd.main = "API.rdoc"
8
- rd.rdoc_files.include("API.rdoc", "lib/**/*.rb")
9
- rd.title = '<%= @module_name %> API Docs'
10
- end
11
-
12
- spec = eval(File.read('<%= @name %>.gemspec'))
13
-
14
- Gem::PackageTask.new(spec) do |pkg|
15
- end
@@ -1,6 +0,0 @@
1
- <%% if @absolute_require %>$LOAD_PATH << "<%%= @tool_parent_path %>"
2
- <%% end %>require '<%= @name %>'
3
-
4
- <%= @module_name %>.widget '<%%= @name %>' do |w|
5
- w.context = 'this is the context'
6
- end
@@ -1,18 +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','<%= @name %>/version.rb'])
3
- spec = Gem::Specification.new do |s|
4
- s.name = '<%= @name %>'
5
- s.version = <%= @module_name %>::VERSION
6
- s.author = '<%= @author %>'
7
- s.email = '<%= @email %>'
8
- s.homepage = ''
9
- s.platform = Gem::Platform::RUBY
10
- s.summary = '<%= @description %>'
11
- s.files = %w(LICENSE) + Dir.glob('cog/**/*') + Dir.glob('lib/**/*.rb')
12
- s.require_paths << 'lib'
13
- s.has_rdoc = true
14
- s.extra_rdoc_files = ['API.rdoc']
15
- s.rdoc_options << '--title' << '<%= @name %>' << '-ri'
16
- s.add_development_dependency('rake')
17
- s.add_development_dependency('rdoc')
18
- end