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.
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
@@ -0,0 +1,96 @@
1
+ generator_path 'built_in/generators'
2
+ template_path 'built_in/templates'
3
+ plugin_path 'built_in/plugins'
4
+ plugin_path Cog.gems_root_dir, true
5
+
6
+ language :c do |l|
7
+ l.name 'C'
8
+ l.comment '//'
9
+ l.multiline_comment '/*', '*/'
10
+ l.extension :c, :h
11
+ l.include_guard_begin {|name| "#ifndef #{name.underscore.upcase}\n#define #{name.underscore.upcase}"}
12
+ l.include_guard_end {|name| "#endif"}
13
+ end
14
+
15
+ language 'c++' do |l|
16
+ l.name 'C++'
17
+ l.comment_style :c
18
+ l.include_guard_style :c
19
+ l.extension :h, :hh, :hpp, :hxx, 'h++', :cc, :cpp, :cxx, 'c++'
20
+ l.use_named_scope {|name| "using namespace #{name};"}
21
+ l.named_scope_begin {|name| "namespace #{name} {"}
22
+ l.named_scope_end {|name| "} // namespace #{name}"}
23
+ end
24
+
25
+ language 'c#' do |l|
26
+ l.name 'C#'
27
+ l.comment_style :c
28
+ l.extension :cs
29
+ l.named_scope_begin {|name| "namespace #{name} {"}
30
+ l.named_scope_end {|name| "} // namespace #{name}"}
31
+ end
32
+
33
+ language :css do |l|
34
+ l.name 'Cascading Style Sheets'
35
+ l.multiline_comment '/*', '*/'
36
+ l.extension :css
37
+ end
38
+
39
+ language :html do |l|
40
+ l.name 'Hyper-text Markup Language'
41
+ l.comment_style :xml
42
+ l.extension :html
43
+ l.named_scope_begin {|name| "<div id='#{name}' class='cog-named-scope'>"}
44
+ l.named_scope_end {|name| "</div><!-- end of named scope #{name} -->"}
45
+ end
46
+
47
+ language :java do |l|
48
+ l.name 'Java'
49
+ l.comment_style :c
50
+ l.extension :java
51
+ l.named_scope_begin {|name| "package #{name};"}
52
+ l.named_scope_end {|name| "// end of package #{name}"}
53
+ end
54
+
55
+ language :javascript do |l|
56
+ l.name 'JavaScript'
57
+ l.comment_style :c
58
+ l.extension :js
59
+ l.named_scope_begin {|name| "var #{name} = { // named scope"}
60
+ l.named_scope_end {|name| "}; // end of named scope #{name}"}
61
+ end
62
+
63
+ language :objc do |l|
64
+ l.name 'Objective-C'
65
+ l.comment_style :c
66
+ l.extension :h, :m, :mm
67
+ end
68
+
69
+ language :python do |l|
70
+ l.name 'Python'
71
+ l.comment '#'
72
+ l.multiline_comment "'''", "'''"
73
+ l.extension :py
74
+ end
75
+
76
+ language :qt do |l|
77
+ l.name 'Qt Project'
78
+ l.comment '#'
79
+ l.extension :pro, :pri
80
+ end
81
+
82
+ language :ruby do |l|
83
+ l.comment '#'
84
+ l.multiline_comment '=begin', '=end'
85
+ l.extension :rb
86
+ l.named_scope_begin {|name| "module #{name} # named scope"}
87
+ l.named_scope_end {|name| "end # named scope #{name}"}
88
+ end
89
+
90
+ language :xml do |l|
91
+ l.name 'Extensible Markup Language'
92
+ l.multiline_comment '<!--', '-->'
93
+ l.extension :xml
94
+ l.named_scope_begin {|name| "<cog:named-scope id='#{name}'>"}
95
+ l.named_scope_end {|name| "</cog:named-scope><!-- #{name} -->"}
96
+ end
data/bin/cog CHANGED
@@ -1,10 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'gli'
3
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
3
  require 'cog'
5
- require 'active_support/core_ext'
6
- require 'fileutils'
7
- require 'rainbow'
8
4
 
9
5
  include GLI::App
10
6
 
@@ -13,18 +9,13 @@ program_desc 'This is a utility to help you write code generators.'
13
9
  desc 'Current version of cog'
14
10
  version Cog::VERSION
15
11
 
16
- desc 'Output more detailed information when running a command'
17
- switch [:verbose]
12
+ desc 'When listing files, show the full path to the file'
13
+ switch :fullpaths
18
14
 
19
15
  desc 'Set the Cogfile explicitly'
20
16
  arg_name 'path'
21
17
  flag :cogfile
22
18
 
23
- desc 'Set the active tool'
24
- arg_name 'name'
25
- default_value 'basic'
26
- flag [:tool, :t]
27
-
28
19
  desc 'Suppress the use of color in output'
29
20
  switch :colorless
30
21
 
@@ -44,7 +35,7 @@ command [:generator, :gen] do |c|
44
35
  c.desc 'List project generators'
45
36
  c.command :list do |sub|
46
37
  sub.action do |gopt, opt, args|
47
- x = Cog::Controllers::GeneratorController.list :verbose => gopt[:v]
38
+ x = Cog::Controllers::GeneratorController.list
48
39
  puts x.join "\n" unless x.empty?
49
40
  end
50
41
  end
@@ -56,13 +47,18 @@ command [:generator, :gen] do |c|
56
47
  sub.default_value 'in Cogfile'
57
48
  sub.flag [:language, :l]
58
49
 
50
+ sub.desc 'Specify the plugin which will be used to create the generator'
51
+ sub.arg_name 'name'
52
+ sub.default_value 'basic'
53
+ sub.flag [:plugin, :p]
54
+
59
55
  sub.action do |gopt, opt, args|
60
56
  args.each do |name|
61
57
  if opt[:language] && opt[:language] != 'in Cogfile'
62
58
  lang = Cog::Languages.get_language opt[:language]
63
59
  Cog.target_language = lang
64
60
  end
65
- Cog::Controllers::GeneratorController.create name
61
+ Cog::Controllers::GeneratorController.create name, :plugin_name => opt[:plugin]
66
62
  end
67
63
  end
68
64
  end
@@ -72,35 +68,37 @@ command [:generator, :gen] do |c|
72
68
  c.arg_name 'name'
73
69
  c.command :run do |sub|
74
70
  sub.action do |gopt, opt, args|
75
- raise Cog::Errors::ActionRequiresProject.new('run generator') unless Cog.project?
76
71
  Cog::Embeds.gather_from_project
77
- args = Cog::Controllers::GeneratorController.list if args.empty?
78
- args.each do |name|
79
- Cog::Controllers::GeneratorController.run name
72
+ if args.empty?
73
+ Cog::Controllers::GeneratorController.run_all
74
+ else
75
+ args.each do |name|
76
+ Cog::Controllers::GeneratorController.run name
77
+ end
80
78
  end
81
79
  end
82
80
  end
83
81
  end
84
82
 
85
- desc 'List or create DSLs known as cog tools'
86
- command :tool do |c|
83
+ desc 'List or create DSLs known as cog plugins'
84
+ command :plugin do |c|
87
85
 
88
86
  c.default_command :list
89
87
 
90
- c.desc 'List the available tools'
88
+ c.desc 'List the available plugins'
91
89
  c.command :list do |sub|
92
90
  sub.action do |gopt, opt, args|
93
- x = Cog::Controllers::ToolController.list :verbose => gopt[:verbose]
91
+ x = Cog::Controllers::PluginController.list
94
92
  puts x.join "\n" unless x.empty?
95
93
  end
96
94
  end
97
95
 
98
- c.desc 'Create a new tool'
99
- c.arg_name 'tool_name'
96
+ c.desc 'Create a new plugin'
97
+ c.arg_name 'plugin_name'
100
98
  c.command :new do |sub|
101
99
  sub.action do |gopt, opt, args|
102
100
  args.each do |name|
103
- Cog::Controllers::ToolController.create name
101
+ Cog::Controllers::PluginController.create name
104
102
  end
105
103
  end
106
104
  end
@@ -114,24 +112,17 @@ command [:template, :tm] do |c|
114
112
  c.desc 'List the available templates'
115
113
  c.command :list do |sub|
116
114
  sub.action do |gopt, opt, args|
117
- x = Cog::Controllers::TemplateController.list :verbose => gopt[:verbose]
115
+ x = Cog::Controllers::TemplateController.list
118
116
  puts x.join "\n" unless x.empty?
119
117
  end
120
118
  end
121
119
 
122
120
  c.desc 'Create a new project template'
123
121
  c.command :new do |sub|
124
- sub.desc 'Force override of existing built-in or tool templates'
125
- sub.switch ['force-override', :f]
126
-
122
+
127
123
  sub.action do |gopt, opt, args|
128
124
  args.each do |name|
129
- begin
130
- Cog::Controllers::TemplateController.create name, :force_override => opt[:f]
131
- rescue Cog::Errors::DuplicateTemplate => e
132
- STDERR.write "Use --force-override to copy the original template into your project templates\n"
133
- raise
134
- end
125
+ Cog::Controllers::TemplateController.create name, :force_override => opt[:f]
135
126
  end
136
127
  end
137
128
  end
@@ -161,11 +152,11 @@ pre do |gopt, command, opt, args|
161
152
  STDERR.write "No such Cogfile at #{gopt[:cogfile]}\n"
162
153
  false
163
154
  else
164
- Cog.prepare :cogfile_path => gopt[:cogfile]
165
- unless command.name == :init
166
- Cog.register_tools
167
- Cog.activate_tool gopt[:tool]
168
- end
155
+ Cog.prepare(
156
+ :minimal => command.name == :init,
157
+ :project_cogfile_path => gopt[:cogfile],
158
+ :fullpaths => gopt[:fullpaths]
159
+ )
169
160
  true
170
161
  end
171
162
  end
@@ -0,0 +1,3 @@
1
+ embed 'sort' do |c|
2
+ c.body.split("\n").sort.join("\n")
3
+ end
@@ -0,0 +1,6 @@
1
+ template_path 'templates'
2
+
3
+ stamp_generator do |name, dest|
4
+ @name = name
5
+ stamp 'basic/generator.rb', dest, :absolute_destination => true
6
+ end
@@ -0,0 +1 @@
1
+ # This is the <%= @name %> generator
@@ -0,0 +1,40 @@
1
+ # All paths are relative to the directory containing this file.
2
+
3
+ <% if @cogfile_type == :plugin %>
4
+ stamp_generator do |name, dest|
5
+ @name = name
6
+ stamp '<%= @plugin_name %>/generator.rb', dest, :absolute_destination => true
7
+ end
8
+
9
+ autoload_plugin :<%= @plugin_module %>, 'lib/<%= @plugin_name %>'
10
+
11
+ <% end %>
12
+ <% if @cogfile_type == :project %>
13
+ # Define the directory to which code is generated
14
+ project_path 'lib'
15
+
16
+ <% end %>
17
+ # Define a directory in which to find generators
18
+ generator_path '<%= @prefix %>generators'
19
+
20
+ # Define a directory in which to find templates
21
+ template_path '<%= @prefix %>templates'
22
+
23
+ <% unless @cogfile_type == :plugin %>
24
+ # Define a directory in which to find plugins
25
+ plugin_path '<%= @prefix %>plugins'
26
+
27
+ <% end %>
28
+ <% if @cogfile_type == :project %>
29
+ # Explicitly specify a mapping from file extensions to languages
30
+ #
31
+ # key => value pairs from this mapping will override the default
32
+ # language map supplied by +cog+
33
+ #
34
+ # Type `cog language list` to see a list of supported languages
35
+ # and the current file extension mappings
36
+ language_extensions({
37
+ :h => 'c++',
38
+ })
39
+
40
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <%= @plugin_module %>.widget '<%%= @name %>' do |w|
2
+ w.context = 'this is the context'
3
+ end
@@ -1,22 +1,15 @@
1
1
  $LOAD_PATH << File.join(File.dirname(__FILE__))
2
- require '<%= @tool_name %>/version'
3
2
  require 'cog'
4
3
 
5
- # Custom cog tool <%= @tool_name %>
6
- module <%= @tool_module %>
4
+ # Custom cog plugin <%= @plugin_name %>
5
+ module <%= @plugin_module %>
7
6
 
8
7
  # Root of the DSL
9
8
  # Feel free to rename this to something more appropriate
10
9
  def self.widget(generator_name, &block)
11
10
  w = Widget.new generator_name
12
11
  block.call w
13
-
14
- # Activate <%= @tool_name %> while rendering templates
15
- # so that cog will be able to find <%= @tool_name %> templates
16
- Cog.activate_tool '<%= @tool_name %>' do
17
- w.generate
18
- end
19
-
12
+ w.generate
20
13
  nil
21
14
  end
22
15
 
@@ -34,7 +27,7 @@ module <%= @tool_module %>
34
27
  end
35
28
 
36
29
  def generate
37
- stamp '<%= @tool_name %>/<%= @tool_name %>.txt', "generated_#{@generator_name}.txt"
30
+ puts "TODO: write generator code for <%= @plugin_name %>"
38
31
  end
39
32
  end
40
33
  end
data/lib/cog.rb CHANGED
@@ -1,23 +1,37 @@
1
- require 'cog/config'
2
- require 'cog/controllers'
3
- require 'cog/embeds'
1
+ require 'active_support/core_ext'
2
+ require 'fileutils'
3
+ require 'rainbow'
4
+
4
5
  require 'cog/errors'
5
- require 'cog/generator'
6
- require 'cog/helpers'
7
- require 'cog/languages'
8
- require 'cog/tool'
9
- require 'cog/version'
6
+ require 'cog/native_extensions'
10
7
 
11
- # This top level module serves as a singleton instance of the {Config} interface.
8
+ # This top level module serves as a singleton instance of the {Config} interface. It is configured with various cogfiles, which are evaluated as instances of {DSL::Cogfile}.
12
9
  module Cog
13
10
 
11
+ autoload :Config, 'cog/config'
12
+ autoload :Controllers, 'cog/controllers'
13
+ autoload :DSL, 'cog/dsl'
14
+ autoload :EmbedContext, 'cog/embed_context'
15
+ autoload :Embeds, 'cog/embeds'
16
+ autoload :Generator, 'cog/generator'
17
+ autoload :GeneratorSandbox, 'cog/generator_sandbox'
18
+ autoload :Helpers, 'cog/helpers'
19
+ autoload :Language, 'cog/language'
20
+ autoload :Plugin, 'cog/plugin'
21
+ autoload :VERSION, 'cog/version'
22
+
14
23
  extend Config
15
24
 
16
25
  # Prepare the project in the present working directory for use with +cog+
17
26
  # @return [nil]
18
27
  def self.initialize_project
19
- Generator.copy_file_if_missing File.join(Cog.gem_dir, 'Default.cogfile'), 'Cogfile'
20
- Cog.prepare :force_reset => true
28
+ @cogfile_type = :project
29
+ @prefix = 'cog/'
30
+ Generator.stamp 'cog/Cogfile', 'Cogfile', :absolute_destination => true, :binding => binding, :once => true
31
+
32
+ @cogfile_type = :user
33
+ @prefix = ''
34
+ Generator.stamp 'cog/Cogfile', user_cogfile, :absolute_destination => true, :binding => binding, :once => true
21
35
  nil
22
36
  end
23
37
 
@@ -1,24 +1,24 @@
1
- require 'cog/config/cogfile'
2
- require 'cog/config/language_methods'
3
- require 'cog/config/project_methods'
4
- require 'cog/config/tool_methods'
5
- require 'cog/languages'
6
- require 'cog/errors'
7
- require 'cog/tool'
8
-
9
1
  module Cog
10
2
 
11
3
  # This is a low level interface. It is mainly used by the {Generator} methods to determine where to find things, and where to put them.
12
- # When +cog+ is used in a project it will be configured with a {Cogfile}. The Cogfile is processed during a call to {#prepare}.
13
4
  module Config
14
- include ProjectMethods
15
- include LanguageMethods
16
- include ToolMethods
17
5
 
18
- # @return [String] Location of the built-in templates
19
- def cog_templates_path
20
- File.join Cog.gem_dir, 'templates'
21
- end
6
+ autoload :LanguageConfig, 'cog/config/language_config'
7
+ autoload :ProjectConfig, 'cog/config/project_config'
8
+ autoload :PluginConfig, 'cog/config/plugin_config'
9
+
10
+ include ProjectConfig
11
+ include LanguageConfig
12
+ include PluginConfig
13
+
14
+ # @return [Array<String>] directories in which to find generators
15
+ attr_reader :generator_path
16
+
17
+ # @return [Array<String>] directories in which to find templates
18
+ attr_reader :template_path
19
+
20
+ # @return [Array<String>] directories in which to find plugins
21
+ attr_reader :plugin_path
22
22
 
23
23
  # @return [String] Location of the installed cog gem
24
24
  def gem_dir
@@ -31,53 +31,110 @@ module Cog
31
31
  spec.gem_dir
32
32
  end
33
33
  end
34
+
35
+ # @return [String,nil] if installed as a gem, return the parent directory of the gem's location
36
+ def gems_root_dir
37
+ x = gem_dir
38
+ File.expand_path(File.join(x, '..')) unless File.exists?(File.join(x, 'Gemfile'))
39
+ end
40
+
41
+ # @return [String] Path to <tt>${HOME}/.cog</tt>
42
+ def user_dir
43
+ File.expand_path File.join(ENV['HOME'], '.cog')
44
+ end
45
+
46
+ # @return [String] Path to the current user's cogfile
47
+ def user_cogfile
48
+ File.join user_dir, 'Cogfile'
49
+ end
34
50
 
35
- # A list of directories in which to find ERB template files
36
- #
37
- # Templates should be looked for in the following order as determined by the list returned from this method
38
- #
39
- # * {#project_templates_path} which is present if {#project?}
40
- # * {Tool#templates_path} for each registered tool (in no particular order)
41
- # * {#cog_templates_path} which is *always* present
42
- #
43
- # @return [Array<String>] a list of directories order with ascending priority
44
- def template_paths
45
- [@project_templates_path, active_tool && active_tool.templates_path, Cog.cog_templates_path].compact
51
+ # @return [Boolean] when listing files, full paths should be shown
52
+ def show_fullpaths?
53
+ @fullpaths
46
54
  end
47
-
55
+
48
56
  # Must be called once before using cog.
49
57
  # In the context of a command-line invocation, this method will be called automatically. Outside of that context, for example in a unit test, it will have to be called manually.
50
- # @option opt [String] :cogfile_path (nil) explicitly specify the location of the project {Cogfile}. If not provided, it will be searched for. If none can be found, {#project?} will be +false+
51
- # @option opt [Boolean] :force_reset (false) unless this is +true+, calling prepare a second time will fail
58
+ # @option opt [Boolean] :fullpaths (false) when listing files, full paths should be shown
59
+ # @option opt [Boolean] :minimal (false) only load the built-in Cogfile
60
+ # @option opt [String] :project_cogfile_path (nil) explicitly specify the location of the project {DSL::Cogfile}. If not provided, it will be searched for. If none can be found, {#project?} will be +false+
52
61
  def prepare(opt={})
53
62
  throw :ConfigInstanceAlreadyPrepared if @prepared && !opt[:force_reset]
54
63
  @prepared = true
55
- @cogfile_path = nil
56
- @project_root = nil
57
- @project_generators_path = nil
58
- @project_templates_path = nil
59
- @project_source_path = nil
60
- @tools = {}
61
- @active_tools = [] # active tool stack
62
- @target_language = Languages::Language.new
63
- @active_languages = [Languages::Language.new] # active language stack
64
- @language_extension_map = Languages::DEFAULT_LANGUAGE_EXTENSION_MAP
65
- opt[:cogfile_path] ||= find_default_cogfile
66
- if opt[:cogfile_path]
67
- @cogfile_path = File.expand_path opt[:cogfile_path]
68
- @project_root = File.dirname @cogfile_path
69
- cogfile = Cogfile.new self
70
- cogfile.interpret
71
- end
64
+ @fullpaths = opt[:fullpaths]
65
+ @project_path = nil
66
+ @project_generator_path = nil
67
+ @project_plugin_path = nil
68
+ @project_template_path = nil
69
+ @generator_path = []
70
+ @plugin_path = []
71
+ @template_path = []
72
+ @plugins = {}
73
+ @target_language = Language.new
74
+ @active_languages = [Language.new] # active language stack
75
+ @language = {}
76
+ @language_extension_map = {}
77
+
78
+ process_cogfiles opt
79
+ post_cogfile_processing
80
+ build_language_extension_map
72
81
  end
73
82
 
74
83
  private
75
84
 
76
- # The {Cogfile} will be looked for in the present working directory. If none
85
+ # @option opt [Boolean] :minimal (false) only load the built-in Cogfile
86
+ # @option opt [String] :project_cogfile_path (nil) project cogfile
87
+ def process_cogfiles(opt={})
88
+ @project_cogfile_path = opt[:project_cogfile_path] || find_default_cogfile
89
+ if @project_cogfile_path
90
+ @project_cogfile_path = File.expand_path @project_cogfile_path
91
+ @project_root = File.dirname @project_cogfile_path
92
+ end
93
+ process_cogfile built_in_cogfile
94
+ return if opt[:minimal]
95
+ process_cogfile user_cogfile if File.exists? user_cogfile
96
+ process_cogfile @project_cogfile_path, :plugin_path_only => true if @project_cogfile_path
97
+ plugins.each do |plugin|
98
+ process_cogfile plugin.cogfile_path, :plugin => plugin
99
+ end
100
+ process_cogfile @project_cogfile_path, :project => true if @project_cogfile_path
101
+ end
102
+
103
+ # @param path [String] path to the cogfile
104
+ # @option opt [Boolean] :plugin_path_only (false) only process +plugin_path+ calls in the given cogfile
105
+ # @option opt [Boolean] :active_plugin (false) process the +stamp_generator+ call in the given cogfile
106
+ # @option opt [Plugin] :plugin (nil) indicate that the cogfile is for the given plugin
107
+ def process_cogfile(path, opt={})
108
+ cogfile = DSL::Cogfile.new self, path, opt
109
+ cogfile.interpret
110
+ end
111
+
112
+ def post_cogfile_processing
113
+ @language.each_value do |lang|
114
+ if lang.comment_style != lang.key
115
+ other = @language[lang.comment_style]
116
+ lang.apply_comment_style other
117
+ end
118
+ if lang.include_guard_style != lang.key
119
+ other = @language[lang.include_guard_style]
120
+ lang.apply_include_guard_style other
121
+ end
122
+ end
123
+ end
124
+
125
+ def build_language_extension_map
126
+ @language.each_value do |lang|
127
+ lang.extensions.each do |ext|
128
+ @language_extension_map[ext] = lang.key unless @language_extension_map.member?(ext)
129
+ end
130
+ end
131
+ end
132
+
133
+ # The {DSL::Cogfile} will be looked for in the present working directory. If none
77
134
  # is found there the parent directory will be checked, and then the
78
135
  # grandparent, and so on.
79
136
  #
80
- # @return [Config] the singleton instance
137
+ # @return [Config, nil] the singleton instance
81
138
  def find_default_cogfile
82
139
  parts = Dir.pwd.split File::SEPARATOR
83
140
  i = parts.length
@@ -87,5 +144,11 @@ module Cog
87
144
  path = File.join(parts.slice(0, i) + ['Cogfile']) if i >= 0
88
145
  (path && File.exists?(path)) ? path : nil
89
146
  end
147
+
148
+ # @return [String] path to the built-in cogfile
149
+ def built_in_cogfile
150
+ File.join gem_dir, 'BuiltIn.cogfile'
151
+ end
152
+
90
153
  end
91
154
  end