cog 0.2.2 → 0.3.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.
- data/BuiltIn.cogfile +96 -0
- data/bin/cog +30 -39
- data/built_in/generators/sort.rb +3 -0
- data/built_in/plugins/basic/Cogfile +6 -0
- data/built_in/plugins/basic/templates/basic/generator.rb.erb +1 -0
- data/built_in/templates/cog/Cogfile.erb +40 -0
- data/built_in/templates/cog/plugin/generator.rb.erb.erb +3 -0
- data/{templates/cog/custom_tool/tool.rb.erb → built_in/templates/cog/plugin/plugin.rb.erb} +4 -11
- data/{templates → built_in/templates}/warning.erb +0 -0
- data/lib/cog.rb +25 -11
- data/lib/cog/config.rb +112 -49
- data/lib/cog/config/{language_methods.rb → language_config.rb} +23 -27
- data/lib/cog/config/plugin_config.rb +31 -0
- data/lib/cog/config/project_config.rb +48 -0
- data/lib/cog/controllers.rb +6 -8
- data/lib/cog/controllers/generator_controller.rb +30 -21
- data/lib/cog/controllers/plugin_controller.rb +43 -0
- data/lib/cog/controllers/template_controller.rb +12 -33
- data/lib/cog/dsl.rb +9 -0
- data/lib/cog/dsl/cogfile.rb +145 -0
- data/lib/cog/dsl/language_dsl.rb +142 -0
- data/lib/cog/embed_context.rb +0 -2
- data/lib/cog/embeds.rb +2 -7
- data/lib/cog/errors.rb +11 -24
- data/lib/cog/generator.rb +10 -15
- data/lib/cog/generator/file_methods.rb +2 -2
- data/lib/cog/generator/filters.rb +10 -14
- data/lib/cog/generator/language_methods.rb +2 -3
- data/lib/cog/generator_sandbox.rb +32 -0
- data/lib/cog/helpers.rb +10 -2
- data/lib/cog/helpers/cascading_set.rb +104 -0
- data/lib/cog/{embeds → helpers}/file_scanner.rb +1 -1
- data/lib/cog/language.rb +140 -0
- data/lib/cog/native_extensions.rb +2 -0
- data/lib/cog/native_extensions/array.rb +19 -0
- data/lib/cog/native_extensions/string.rb +54 -0
- data/lib/cog/plugin.rb +35 -0
- data/lib/cog/spec_helpers.rb +36 -14
- data/lib/cog/spec_helpers/matchers.rb +14 -4
- data/lib/cog/spec_helpers/matchers/match_maker.rb +1 -1
- data/lib/cog/spec_helpers/runner.rb +3 -9
- data/lib/cog/version.rb +1 -1
- metadata +27 -44
- data/Default.cogfile +0 -25
- data/lib/cog/built_in_tools.rb +0 -9
- data/lib/cog/built_in_tools/basic.rb +0 -10
- data/lib/cog/built_in_tools/basic/cog_tool.rb +0 -11
- data/lib/cog/config/cogfile.rb +0 -117
- data/lib/cog/config/lang_info.rb +0 -40
- data/lib/cog/config/project_methods.rb +0 -35
- data/lib/cog/config/tool_methods.rb +0 -94
- data/lib/cog/controllers/tool_controller.rb +0 -50
- data/lib/cog/helpers/cascading_template_set.rb +0 -75
- data/lib/cog/helpers/string.rb +0 -26
- data/lib/cog/languages.rb +0 -52
- data/lib/cog/languages/c_language.rb +0 -29
- data/lib/cog/languages/c_plus_plus_language.rb +0 -28
- data/lib/cog/languages/c_sharp_language.rb +0 -24
- data/lib/cog/languages/java_language.rb +0 -24
- data/lib/cog/languages/java_script_language.rb +0 -24
- data/lib/cog/languages/language.rb +0 -73
- data/lib/cog/languages/mixins.rb +0 -10
- data/lib/cog/languages/mixins/c_style_comments.rb +0 -23
- data/lib/cog/languages/mixins/hash_comments.rb +0 -19
- data/lib/cog/languages/python_language.rb +0 -20
- data/lib/cog/languages/qt_project_language.rb +0 -16
- data/lib/cog/languages/ruby_language.rb +0 -28
- data/lib/cog/tool.rb +0 -61
- data/lib/cog/tool/dsl.rb +0 -26
- data/templates/basic/generator.rb.erb +0 -4
- data/templates/cog/custom_tool/Gemfile.erb +0 -8
- data/templates/cog/custom_tool/LICENSE.erb +0 -18
- data/templates/cog/custom_tool/README.markdown.erb +0 -18
- data/templates/cog/custom_tool/Rakefile.erb +0 -15
- data/templates/cog/custom_tool/cog_tool.rb.erb +0 -17
- data/templates/cog/custom_tool/generator.rb.erb.erb +0 -9
- data/templates/cog/custom_tool/template.txt.erb.erb +0 -1
- data/templates/cog/custom_tool/tool.gemspec.erb +0 -17
- 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
|
data/lib/cog/tool.rb
DELETED
@@ -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
|
data/lib/cog/tool/dsl.rb
DELETED
@@ -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,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,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 +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
|