Module: Renee::Core::URLGeneration
- Included in:
- ClassMethods
- Defined in:
- lib/renee_core/url_generation.rb
Overview
URL generator for creating paths and URLs within your application.
Instance Method Summary collapse
-
#path(name, *args) ⇒ Object
Generates a path for a given name.
-
#prefix(prefix, defaults = nil, &blk) ⇒ Object
Allows the creation of generation contexts.
-
#register(name, pattern, defaults = nil) ⇒ Object
Registers new paths for generation.
-
#url(name, *args) ⇒ Object
Generates a url for a given name.
Instance Method Details
#path(name, *args) ⇒ Object
Generates a path for a given name.
53 54 55 56 |
# File 'lib/renee_core/url_generation.rb', line 53 def path(name, *args) generator = url_generators[name] generator ? generator.path(*args) : raise("Generator for #{name} doesn't exist") end |
#prefix(prefix, defaults = nil, &blk) ⇒ Object
Allows the creation of generation contexts.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/renee_core/url_generation.rb', line 30 def prefix(prefix, defaults = nil, &blk) generator = self subgenerator = Class.new { include URLGeneration define_method(:url_generators) { generator.send(:url_generators) } }.new subgenerator.instance_variable_set(:@generation_prefix, "#{@generation_prefix}#{prefix}") subgenerator.instance_variable_set(:@generation_defaults, defaults_for_generation(defaults)) if block_given? old_prefix, old_defaults = @generation_prefix, @generation_defaults @generation_prefix, @generation_defaults = "#{@generation_prefix}#{prefix}", defaults_for_generation(defaults) subgenerator.instance_eval(&blk) @generation_prefix, @generation_defaults = old_prefix, old_defaults end subgenerator end |
#register(name, pattern, defaults = nil) ⇒ Object
Registers new paths for generation.
17 18 19 |
# File 'lib/renee_core/url_generation.rb', line 17 def register(name, pattern, defaults = nil) url_generators[name] = Generator.new("#{@generation_prefix}#{pattern}", defaults_for_generation(defaults)) end |
#url(name, *args) ⇒ Object
Generates a url for a given name.
61 62 63 64 |
# File 'lib/renee_core/url_generation.rb', line 61 def url(name, *args) generator = url_generators[name] generator ? generator.url(*args) : raise("Generator for #{name} doesn't exist") end |