Class: Cog::DSL::Cogfile
- Inherits:
-
Object
- Object
- Cog::DSL::Cogfile
- Includes:
- Generator
- Defined in:
- lib/cog/dsl/cogfile.rb
Overview
In your project’s Cogfile
, self
has been set to an instance of this class. Typing cog init
will create a Cogfile
in the present working directory.
Instance Method Summary collapse
-
#autoload_plugin(identifier_name, path) ⇒ nil
Register an autoload variable in the class GeneratorSandbox.
-
#generator_path(path, absolute = false) ⇒ nil
Define a directory in which to find generators.
-
#initialize(config, path, opt = {}) ⇒ Cogfile
constructor
Initialize with an instance of Config.
-
#interpret ⇒ nil
Interpret the
Cogfile
at Config::ProjectConfig#cogfile_path. -
#language(key) {|lang| ... } ⇒ Object
Define and register a language with cog.
-
#language_extensions(map) ⇒ nil
Explicitly specify a mapping from file extensions to languages.
-
#plugin_path(path, absolute = false) ⇒ nil
Define a directory in which to find plugins.
-
#project_path(path, absolute = false) ⇒ nil
Define the directory in which to generate code.
-
#stamp_generator {|name, dest| ... } ⇒ nil
Define a block to call when stamping a generator for a plugin.
-
#template_path(path, absolute = false) ⇒ nil
Define a directory in which to find templates.
Methods included from Generator
Methods included from Generator::LanguageMethods
#end_all_scopes, #include_guard_begin, #named_scope_begin, #scope_begin, #scope_end, #use_named_scope, #warning
Methods included from Generator::Filters
Methods included from Generator::FileMethods
#copy_file_if_missing, #files_are_same?, #get_template, #touch_directory, #touch_file
Constructor Details
#initialize(config, path, opt = {}) ⇒ Cogfile
Initialize with an instance of Config
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cog/dsl/cogfile.rb', line 17 def initialize(config, path, opt={}) @cogfile_context = { :config => config, :cogfile_path => path, :cogfile_dir => File.dirname(path), :project => opt[:project], :plugin_path_only => opt[:plugin_path_only], :plugin => opt[:plugin], } end |
Instance Method Details
#autoload_plugin(identifier_name, path) ⇒ nil
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
. A call to this method will be ignored unless the containing cogfile is being treated as a plugin.
108 109 110 111 112 |
# File 'lib/cog/dsl/cogfile.rb', line 108 def autoload_plugin(identifier_name, path) if plugin? GeneratorSandbox.autoload_plugin(identifier_name, File.join(plugin.path, path)) end end |
#generator_path(path, absolute = false) ⇒ nil
Define a directory in which to find generators
50 51 52 53 |
# File 'lib/cog/dsl/cogfile.rb', line 50 def generator_path(path, absolute=false) return if plugin_path_only? add_config_path :generator, path, absolute end |
#interpret ⇒ nil
Interpret the Cogfile
at Config::ProjectConfig#cogfile_path
31 32 33 34 |
# File 'lib/cog/dsl/cogfile.rb', line 31 def interpret eval File.read(cogfile_path), binding nil end |
#language(key) {|lang| ... } ⇒ Object
Define and register a language with cog
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/cog/dsl/cogfile.rb', line 93 def language(key, &block) return if plugin_path_only? dsl = LanguageDSL.new key r = block.call dsl lang = dsl.finalize config_eval do @language[lang.key] = lang end r end |
#language_extensions(map) ⇒ nil
Explicitly specify a mapping from file extensions to languages
80 81 82 83 84 85 86 87 |
# File 'lib/cog/dsl/cogfile.rb', line 80 def language_extensions(map) return if plugin_path_only? config_eval do map.each_pair do |key, value| @language_extension_map[key.to_s.downcase] = value.to_s.downcase end end end |
#plugin_path(path, absolute = false) ⇒ nil
Define a directory in which to find plugins. A call to this method will be ignored if the containing cogfile is itself being treated as a plugin.
68 69 70 71 72 73 74 75 |
# File 'lib/cog/dsl/cogfile.rb', line 68 def plugin_path(path, absolute=false) return if plugin? path = add_config_path :plugin, path, absolute if path && File.exists?(path) raise Errors::PluginPathIsNotADirectory.new path unless File.directory?(path) @cogfile_context[:config].register_plugins path end end |
#project_path(path, absolute = false) ⇒ nil
Define the directory in which to generate code. A call to this method will be ignored if the containing cogfile is being treated as a plugin.
40 41 42 43 44 |
# File 'lib/cog/dsl/cogfile.rb', line 40 def project_path(path, absolute=false) return if plugin_path_only? || plugin? path = File.join @cogfile_context[:cogfile_dir], path unless absolute config_eval { @project_path = path } end |
#stamp_generator {|name, dest| ... } ⇒ nil
Define a block to call when stamping a generator for a plugin. A call to this method will be ignored unless the containing cogfile is being treated as a plugin.
119 120 121 |
# File 'lib/cog/dsl/cogfile.rb', line 119 def stamp_generator(&block) plugin.stamp_generator_block = block if plugin? end |
#template_path(path, absolute = false) ⇒ nil
Define a directory in which to find templates
59 60 61 62 |
# File 'lib/cog/dsl/cogfile.rb', line 59 def template_path(path, absolute=false) return if plugin_path_only? add_config_path :template, path, absolute end |