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
@@ -1,36 +1,32 @@
1
- require 'cog/config/lang_info'
2
-
3
1
  module Cog
4
2
  module Config
5
3
 
6
4
  # {Config} methods related to languages
7
- module LanguageMethods
8
-
9
- # @return [Languages::Lanugage] target language which should be used when creating generators, and no language is explicitly specified
10
- attr_accessor :target_language
5
+ module LanguageConfig
11
6
 
12
- # @return [Languages::Language] language which is active in the current context
7
+ # @return [Language] language which is active in the current context
13
8
  def active_language
14
9
  @active_languages.last
15
10
  end
16
11
 
17
12
  # Activate a given language within the scope of the provided block.
18
- # Either provide <tt>:id</tt> or <tt>:ext</tt> but not both. If the extension does not match any of the supported languages, the {#active_language} will not change, but the block will still be called.
19
- # @option opt [:String] :id (nil) the lanuage identifier. Type <tt>cog language list</tt> to see the possible values
13
+ # Either provide <tt>key</tt> or <tt>:ext</tt> but not both. If the extension does not match any of the supported languages, the {#active_language} will not change, but the block will still be called.
14
+ # @param key [:String] the lanuage identifier. Type <tt>cog language list</tt> to see the possible values
20
15
  # @option opt [:String] :ext (nil) a file extension which will map to a language identifier. Type <tt>cog language map</tt> to see mapped extensions
21
16
  # @yield within this block the {#active_language} will be set to the desired value
22
17
  # @return [Object] the value returned by the block
23
- def activate_language(opt={}, &block)
18
+ def activate_language(key, opt={}, &block)
24
19
  throw :ActivateLanguageRequiresABlock if block.nil?
25
- lang_id = if opt[:ext]
26
- ext = opt[:ext].to_s
20
+ opt, key = key, nil if key.is_a? Hash
21
+ key = if opt[:ext]
22
+ ext = opt[:ext].to_s.downcase
27
23
  ext = ext.slice(1..-1) if ext.start_with?('.')
28
- @language_extension_map[ext.downcase.to_sym] unless ext.empty?
24
+ @language_extension_map[ext] unless ext.empty?
29
25
  else
30
- opt[:id]
26
+ key
31
27
  end
32
- if lang_id
33
- @active_languages << Languages.get_language(lang_id)
28
+ if key
29
+ @active_languages << @language[key]
34
30
  r = block.call
35
31
  @active_languages.pop
36
32
  r
@@ -44,26 +40,26 @@ module Cog
44
40
  @language_extension_map.keys
45
41
  end
46
42
 
43
+ # @param key [String] the language key
44
+ # @return [Language] the language for the given key
45
+ def language(key)
46
+ @language[key]
47
+ end
48
+
47
49
  # @param path [String] the file system extension, or full path to a file
48
- # @return [Languages::Language, nil] the language for the given extension
50
+ # @return [Language, nil] the language for the given extension
49
51
  def language_for(path)
50
52
  ext = File.extname(path.to_s)
51
53
  ext = path.to_s if ext.empty?
52
54
  ext = ext.downcase
53
55
  ext = ext.slice(1..-1) if ext.start_with? '.'
54
- lang_id = @language_extension_map[ext.to_sym]
55
- Languages.get_language lang_id unless lang_id.nil?
56
+ key = @language_extension_map[ext]
57
+ @language[key] if key
56
58
  end
57
59
 
58
- # @return [Array<LangInfo>] current configuration of supported languages
60
+ # @return [Array<Language>] current configuration of supported languages
59
61
  def language_summary
60
- summary = {}
61
- @language_extension_map.each_pair do |ext, lang_id|
62
- lang_id = Languages::ALIAS[lang_id] || lang_id
63
- summary[lang_id] ||= LangInfo.new(lang_id, Languages::REV_ALIAS[lang_id] || [])
64
- summary[lang_id].extensions << ext
65
- end
66
- summary.values.sort
62
+ @language.values.sort
67
63
  end
68
64
 
69
65
  end
@@ -0,0 +1,31 @@
1
+ module Cog
2
+ module Config
3
+
4
+ # {Config} methods related to plugins
5
+ module PluginConfig
6
+
7
+ # @return [Plugin] the plugin registered for the given name
8
+ def plugin(name)
9
+ @plugins[name]
10
+ end
11
+
12
+ # @return [Array<Plugin>] a sorted list of available plugins
13
+ def plugins
14
+ @plugins.values.sort
15
+ end
16
+
17
+ # @api developer
18
+ # Register plugins found in the given directory
19
+ # @param path [String] path to a directory containing cog plugins
20
+ # @return [nil]
21
+ def register_plugins(path)
22
+ Dir.glob("#{path}/*/Cogfile").each do |cogfile_path|
23
+ p = Plugin.new cogfile_path
24
+ @plugins[p.name] ||= p
25
+ end
26
+ nil
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,48 @@
1
+ module Cog
2
+ module Config
3
+
4
+ # {Config} methods related to projects
5
+ module ProjectConfig
6
+
7
+ # @return [String] path to the project's {DSL::Cogfile}
8
+ attr_reader :project_cogfile_path
9
+
10
+ # @return [String] directory in which to place generated output. For example, the +destination+ parameter of {Generator#stamp} is relative to this path.
11
+ attr_reader :project_path
12
+
13
+ # @return [String] directory in which the project's {DSL::Cogfile} is found
14
+ attr_reader :project_root
15
+
16
+ # @return [String,nil] directory in which to place project generators
17
+ attr_reader :project_generator_path
18
+
19
+ # @return [String,nil] directory in which to place project plugins
20
+ attr_reader :project_plugin_path
21
+
22
+ # @return [String,nil] directory in which to place project templates
23
+ attr_reader :project_template_path
24
+
25
+ # @return [Boolean] whether or not we operating in the context of a project
26
+ def project?
27
+ !@project_root.nil?
28
+ end
29
+
30
+ # @return [Array<String>] list of paths to files in the {#project_path} which are written in a supported language
31
+ def supported_project_files
32
+ if project?
33
+ exts = Cog.language_extensions.join ','
34
+ Dir.glob "#{Cog.project_path}/**/*.{#{exts}}"
35
+ else
36
+ []
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def path_if_for_project(path)
43
+ path if path && path.start_with?(@project_root)
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -1,13 +1,11 @@
1
- require 'cog/controllers/generator_controller'
2
- require 'cog/controllers/template_controller'
3
- require 'cog/controllers/tool_controller'
4
- require 'cog/errors'
5
-
6
1
  module Cog
7
2
 
8
- # Contains controllers for managing basic +cog+ objects like generators, templates, and tools
3
+ # Contains controllers for managing basic +cog+ objects like generators, templates, and plugins
9
4
  module Controllers
10
- end
5
+
6
+ autoload :GeneratorController, 'cog/controllers/generator_controller'
7
+ autoload :TemplateController, 'cog/controllers/template_controller'
8
+ autoload :PluginController, 'cog/controllers/plugin_controller'
11
9
 
10
+ end
12
11
  end
13
-
@@ -1,8 +1,3 @@
1
- require 'cog/config'
2
- require 'cog/errors'
3
- require 'cog/helpers'
4
- require 'rainbow'
5
-
6
1
  module Cog
7
2
  module Controllers
8
3
 
@@ -11,34 +6,48 @@ module Cog
11
6
 
12
7
  # Create a new generator
13
8
  # @param name [String] the name to use for the new generator
9
+ # @option opt [String] :plugin_name (nil) plugin to use
14
10
  # @return [Boolean] was the generator successfully created?
15
- def self.create(name)
16
- raise Errors::ActionRequiresProject.new('create generator') unless Cog.project?
17
- generator_dest = File.join Cog.project_generators_path, "#{name}.rb"
18
- raise Errors::DuplicateGenerator.new(generator_dest) if File.exists?(generator_dest)
19
- Cog.active_tool.stamp_generator name, generator_dest
11
+ def self.create(name, opt={})
12
+ plugin = Cog.plugin(opt[:plugin_name])
13
+ prefix = Cog.project_generator_path
14
+ raise Errors::NoSuchPlugin.new(opt[:plugin_name]) if plugin.nil?
15
+ raise Errors::PluginMissingDefinition.new('stamp_generator') if plugin.stamp_generator_block.nil?
16
+ raise Errors::ActionRequiresProjectGeneratorPath.new('create generator') unless prefix
17
+ dest = File.join prefix, "#{name}.rb"
18
+ raise Errors::DuplicateGenerator.new(dest) if File.exists?(dest)
19
+ plugin.stamp_generator_block.call name.to_s, dest
20
20
  end
21
21
 
22
22
  # List the available project generators
23
- # @option opt [Boolean] :verbose (false) list full paths to generator files
24
23
  # @return [Array<String>] a list of generators
25
- def self.list(opt={})
26
- raise Errors::ActionRequiresProject.new('list generators') unless Cog.project?
27
- x = Dir.glob(File.join Cog.project_generators_path, '*.rb')
28
- opt[:verbose] ? x : (x.collect {|path| File.basename(path).slice(0..-4)})
24
+ def self.list
25
+ Helpers::CascadingSet.process_paths Cog.generator_path, :ext => 'rb'
29
26
  end
30
27
 
31
28
  # Run the generator with the given name
32
- # @param name [String] name of the generator as returned by {GeneratorController.list}
29
+ # @param name [String] name of the generator to run
33
30
  # @return [nil]
34
31
  def self.run(name)
35
- raise Errors::ActionRequiresProject.new('run generator') unless Cog.project?
36
- path = File.join Cog.project_generators_path, "#{name}.rb"
37
- raise Errors::NoSuchGenerator.new(name) unless File.exists?(path)
38
- require path
39
- nil
32
+ Cog.generator_path.reverse.each do |root|
33
+ path = File.join root, "#{name}.rb"
34
+ if File.exists?(path)
35
+ GeneratorSandbox.new(path).interpret
36
+ return
37
+ end
38
+ end
39
+ raise Errors::NoSuchGenerator.new(name)
40
40
  end
41
41
 
42
+ # Run all generators
43
+ # @return [nil]
44
+ def self.run_all
45
+ Cog.generator_path.each do |root|
46
+ Dir.glob("#{root}/*.rb").each do |path|
47
+ GeneratorSandbox.new(path).interpret
48
+ end
49
+ end
50
+ end
42
51
  end
43
52
  end
44
53
  end
@@ -0,0 +1,43 @@
1
+ module Cog
2
+ module Controllers
3
+
4
+ # Manage +cog+ plugins
5
+ #
6
+ # @see https://github.com/ktonon/cog#plugins Introduction to Plugins
7
+ module PluginController
8
+
9
+ # Generate a new project plugin with the given name
10
+ # @param name [String] name of the plugin to create. Should not conflict with other plugin names
11
+ # @return [nil]
12
+ def self.create(name)
13
+ raise Errors::DuplicatePlugin.new(name) unless Cog.plugin(name).nil?
14
+ @cogfile_type = :plugin
15
+ @prefix = ''
16
+ @cog_version = Cog::VERSION
17
+ @plugin_name = name.to_s.underscore
18
+ @plugin_module = name.to_s.camelize
19
+ prefix = Cog.project_plugin_path
20
+ prefix = prefix ? "#{prefix}/" : ''
21
+ opt = { :absolute_destination => true, :binding => binding }
22
+ [
23
+ ['Cogfile', 'Cogfile'],
24
+ ['plugin/plugin.rb', "lib/#{@plugin_name}.rb"],
25
+ ['plugin/generator.rb.erb', "templates/#{@plugin_name}/generator.rb.erb"],
26
+ ].each do |tm, dest|
27
+ Generator.stamp "cog/#{tm}", "#{prefix}#{@plugin_name}/#{dest}", opt
28
+ end
29
+ nil
30
+ end
31
+
32
+ # @return [Array<String>] a list of available plugins
33
+ def self.list
34
+ cs = Helpers::CascadingSet.new
35
+ Cog.plugins.each do |plugin|
36
+ cs.add_plugin plugin
37
+ end
38
+ cs.to_a
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -1,53 +1,32 @@
1
- require 'cog/config'
2
- require 'cog/errors'
3
- require 'cog/generator'
4
- require 'cog/helpers'
5
- require 'rainbow'
6
-
7
1
  module Cog
8
2
  module Controllers
9
3
 
10
4
  # Manage a project's templates
11
5
  module TemplateController
12
6
 
13
- # List the available templates
14
- # @option opt [Boolean] :verbose (false) list full template paths
15
- # @return [Array<String>] a list of templates
16
- def self.list(opt={})
17
- cts = Helpers::CascadingTemplateSet.new
18
- cts.add_templates 'built-in', :built_in, Cog.cog_templates_path, opt
19
- tool = Cog.active_tool
20
- unless tool.templates_path.nil?
21
- cts.add_templates tool.name, :tool, tool.templates_path, opt
22
- end
23
- if Cog.project?
24
- cts.add_templates 'project', :project, Cog.project_templates_path, opt
25
- end
26
- cts.to_a
27
- end
28
-
29
7
  # Create a new project template
30
8
  # @param name [String] name of the template, relative to the project's templates directory
31
- # @option opt [Boolean] :force_override (false) if a built-in or tool template with the same name already exists, should a project override be created?
9
+ # @option opt [Boolean] :force_override (false) if a built-in or plugin template with the same name already exists, should a project override be created?
32
10
  # @return [nil]
33
11
  def self.create(name, opt={})
34
- raise Errors::ActionRequiresProject.new('create template') unless Cog.project?
12
+ prefix = Cog.project_template_path
13
+ raise Errors::ActionRequiresProjectTemplatePath.new('create template') unless prefix
35
14
  name = name.without_extension :erb
36
- dest = File.join Cog.project_templates_path, "#{name}.erb"
37
-
15
+ dest = File.join prefix, "#{name}.erb"
38
16
  original = Generator.get_template name, :as_path => true
39
- return if original == dest # Nothing to create
40
- if opt[:force_override]
41
- Generator.copy_file_if_missing original, dest
42
- else
43
- raise Errors::DuplicateTemplate.new original
44
- end
17
+ Generator.copy_file_if_missing original, dest
45
18
  nil
46
19
  rescue Errors::NoSuchTemplate
47
20
  # No original, ok to create an empty template
48
- touch_file dest
21
+ Generator.touch_file dest
49
22
  nil
50
23
  end
24
+
25
+ # List the available templates
26
+ # @return [Array<String>] a list of templates
27
+ def self.list
28
+ Helpers::CascadingSet.process_paths Cog.template_path, :ext => 'erb'
29
+ end
51
30
 
52
31
  end
53
32
  end
@@ -0,0 +1,9 @@
1
+ module Cog
2
+ module DSL
3
+
4
+ autoload :Cogfile, 'cog/dsl/cogfile'
5
+ autoload :LanguageDSL, 'cog/dsl/language_dsl'
6
+ autoload :PluginDSL, 'cog/dsl/plugin_dsl'
7
+
8
+ end
9
+ end
@@ -0,0 +1,145 @@
1
+ module Cog
2
+ module DSL
3
+
4
+ # In your project's +Cogfile+, +self+ has been set to an instance of this class.
5
+ # Typing <tt>cog init</tt> will create a +Cogfile+ in the present working directory.
6
+ class Cogfile
7
+
8
+ include Generator
9
+
10
+ # Initialize with an instance of {Config}
11
+ # @api developer
12
+ # @param config [Config] the object which will be configured by this Cogfile
13
+ # @param path [String] path to the cogfile
14
+ # @option opt [Boolean] :project (false) is this the project cogfile?
15
+ # @option opt [Boolean] :plugin_path_only (false) only process +plugin_path+ calls in the given cogfile
16
+ # @option opt [Plugin] :plugin (nil) indicate that the cogfile is for the given plugin
17
+ def initialize(config, path, opt={})
18
+ @cogfile_context = {
19
+ :config => config,
20
+ :cogfile_path => path,
21
+ :cogfile_dir => File.dirname(path),
22
+ :project => opt[:project],
23
+ :plugin_path_only => opt[:plugin_path_only],
24
+ :plugin => opt[:plugin],
25
+ }
26
+ end
27
+
28
+ # Interpret the +Cogfile+ at {Config::ProjectConfig#cogfile_path}
29
+ # @api developer
30
+ # @return [nil]
31
+ def interpret
32
+ eval File.read(cogfile_path), binding
33
+ nil
34
+ end
35
+
36
+ # Define the directory in which to generate code
37
+ # @param path [String] a file system path to a directory
38
+ # @param absolute [Boolean] if +false+, the path is relative to {Config::ProjectConfig#project_root}
39
+ # @return [nil]
40
+ def project_path(path, absolute=false)
41
+ return if @cogfile_context[:plugin_path_only]
42
+ path = File.join @cogfile_context[:cogfile_dir], path unless absolute
43
+ config_eval { @project_path = path }
44
+ end
45
+
46
+ # Define a directory in which to find generators
47
+ # @param path [String] a file system path
48
+ # @param absolute [Boolean] if +false+, the path is relative to {Config::ProjectConfig#project_root}
49
+ # @return [nil]
50
+ def generator_path(path, absolute=false)
51
+ return if @cogfile_context[:plugin_path_only]
52
+ add_config_path :generator, path, absolute
53
+ end
54
+
55
+ # Define a directory in which to find templates
56
+ # @param path [String] a file system path
57
+ # @param absolute [Boolean] if +false+, the path is relative to {Config::ProjectConfig#project_root}
58
+ # @return [nil]
59
+ def template_path(path, absolute=false)
60
+ return if @cogfile_context[:plugin_path_only]
61
+ add_config_path :template, path, absolute
62
+ end
63
+
64
+ # Define a directory in which to find plugins
65
+ # @param path [String] a file system path
66
+ # @param absolute [Boolean] if +false+, the path is relative to {Config::ProjectConfig#project_root}
67
+ # @return [nil]
68
+ def plugin_path(path, absolute=false)
69
+ path = add_config_path :plugin, path, absolute
70
+ if path && File.exists?(path)
71
+ raise Errors::PluginPathIsNotADirectory.new path unless File.directory?(path)
72
+ @cogfile_context[:config].register_plugins path
73
+ end
74
+ end
75
+
76
+ # Explicitly specify a mapping from file extensions to languages
77
+ # @param map [Hash] key-value pairs from this mapping will override the default language map supplied by +cog+
78
+ # @return [nil]
79
+ def language_extensions(map)
80
+ return if @cogfile_context[:plugin_path_only]
81
+ config_eval do
82
+ map.each_pair do |key, value|
83
+ @language_extension_map[key.to_s.downcase] = value.to_s.downcase
84
+ end
85
+ end
86
+ end
87
+
88
+ # Define and register a language with cog
89
+ # @param key [String] unique case-insensitive identifier
90
+ # @yieldparam lang [LanguageDSL] an interface for defining the language
91
+ # @return [Object] the return value of the block
92
+ def language(key, &block)
93
+ return if @cogfile_context[:plugin_path_only]
94
+ dsl = LanguageDSL.new key
95
+ r = block.call dsl
96
+ lang = dsl.finalize
97
+ config_eval do
98
+ @language[lang.key] = lang
99
+ end
100
+ r
101
+ end
102
+
103
+ # Register an autoload variable in the class {GeneratorSandbox}. That way when generators are run as instances of a sandbox, they will be able to load plugins just by referencing them using the provided +identifier_name+.
104
+ # @param identifier_name [String] identifier by which the plugin can be referenced in generators
105
+ # @param path [String] path to the ruby file to load when the identifier is referenced (relative to the cogfile)
106
+ # @return [nil]
107
+ def autoload_plugin(identifier_name, path)
108
+ GeneratorSandbox.autoload_plugin(identifier_name, File.join(@cogfile_context[:plugin].path, path))
109
+ end
110
+
111
+ # Define a block to call when stamping a generator for a plugin. A call to this method should only be used in plugin cogfiles.
112
+ # @yieldparam name [String] name of the generator to stamp
113
+ # @yieldparam dest [String] file system path where the file will be created
114
+ # @yieldreturn [nil]
115
+ # @return [nil]
116
+ def stamp_generator(&block)
117
+ @cogfile_context[:plugin].stamp_generator_block = block
118
+ end
119
+
120
+ private
121
+
122
+ def cogfile_path
123
+ @cogfile_context[:cogfile_path]
124
+ end
125
+
126
+ # @return [nil]
127
+ def config_eval(&block)
128
+ @cogfile_context[:config].instance_eval &block
129
+ nil
130
+ end
131
+
132
+ # @return [String,nil] absolute path
133
+ def add_config_path(name, path, absolute)
134
+ return if path.nil?
135
+ path = File.join @cogfile_context[:cogfile_dir], path unless absolute
136
+ is_project = @cogfile_context[:project]
137
+ config_eval do
138
+ instance_variable_set("@project_#{name}_path", path) if is_project
139
+ instance_variable_get("@#{name}_path") << path
140
+ end
141
+ path
142
+ end
143
+ end
144
+ end
145
+ end