Class: SitemapGenerator::Interpreter
- Inherits:
-
Object
- Object
- SitemapGenerator::Interpreter
- Includes:
- ActionController::UrlWriter
- Defined in:
- lib/sitemap_generator/interpreter.rb
Overview
Provide a class for evaluating blocks, making the URL helpers from the framework and API methods available to it.
Class Method Summary collapse
-
.run(opts = {}, &block) ⇒ Object
Run the interpreter on a config file using the default
SitemapGenerator::Sitemap
sitemap object.
Instance Method Summary collapse
- #add(*args) ⇒ Object
- #add_to_index(*args) ⇒ Object
-
#eval(opts = {}, &block) ⇒ Object
Evaluate the block in the interpreter.
-
#group(*args, &block) ⇒ Object
Start a new group of sitemaps.
-
#initialize(opts = {}, &block) ⇒ Interpreter
constructor
Call with a block to evaluate a dynamic config.
-
#sitemap ⇒ Object
Return the LinkSet instance so that you can access it from within the ‘create` block without having to use the yield_sitemap option.
Constructor Details
#initialize(opts = {}, &block) ⇒ Interpreter
Call with a block to evaluate a dynamic config. The only method exposed for you is ‘add` to add a link to the sitemap object attached to this interpreter.
Options
-
link_set
- a LinkSet instance to use. Default is SitemapGenerator::Sitemap.
All other options are passed to the LinkSet by setting them using accessor methods.
23 24 25 26 27 28 |
# File 'lib/sitemap_generator/interpreter.rb', line 23 def initialize(opts={}, &block) opts = SitemapGenerator::Utilities.reverse_merge(opts, :link_set => SitemapGenerator::Sitemap) @linkset = opts.delete :link_set @linkset.send(:set_options, opts) eval(&block) if block_given? end |
Class Method Details
.run(opts = {}, &block) ⇒ Object
Run the interpreter on a config file using the default SitemapGenerator::Sitemap
sitemap object.
Options
-
:config_file
- full path to the config file to evaluate. Default is config/sitemap.rb in your application’s root directory.
All other options are passed to new
.
71 72 73 74 75 76 77 78 |
# File 'lib/sitemap_generator/interpreter.rb', line 71 def self.run(opts={}, &block) opts = opts.dup config_file = opts.delete(:config_file) config_file ||= SitemapGenerator.app.root + 'config/sitemap.rb' interpreter = self.new(opts) interpreter.instance_eval(File.read(config_file), config_file.to_s) interpreter end |
Instance Method Details
#add(*args) ⇒ Object
30 31 32 |
# File 'lib/sitemap_generator/interpreter.rb', line 30 def add(*args) @linkset.add(*args) end |
#add_to_index(*args) ⇒ Object
34 35 36 |
# File 'lib/sitemap_generator/interpreter.rb', line 34 def add_to_index(*args) @linkset.add_to_index(*args) end |
#eval(opts = {}, &block) ⇒ Object
Evaluate the block in the interpreter. Pass :yield_sitemap => true to yield the Interpreter instance to the block…for old-style calling.
54 55 56 57 58 59 60 61 62 |
# File 'lib/sitemap_generator/interpreter.rb', line 54 def eval(opts={}, &block) if block_given? if opts[:yield_sitemap] yield @linkset else instance_eval(&block) end end end |
#group(*args, &block) ⇒ Object
Start a new group of sitemaps. Any of the options to SitemapGenerator.new may be passed. Pass a block with calls to add
to add links to the sitemaps.
All groups use the same sitemap index.
42 43 44 |
# File 'lib/sitemap_generator/interpreter.rb', line 42 def group(*args, &block) @linkset.group(*args, &block) end |
#sitemap ⇒ Object
Return the LinkSet instance so that you can access it from within the ‘create` block without having to use the yield_sitemap option.
48 49 50 |
# File 'lib/sitemap_generator/interpreter.rb', line 48 def sitemap @linkset end |