ducklink 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/ducklink.rb +14 -15
  2. data/lib/ducklink/version.rb +1 -1
  3. metadata +1 -1
@@ -3,8 +3,8 @@ require 'uri'
3
3
  require 'cgi'
4
4
 
5
5
  module Ducklink
6
- def self.decorate(url)
7
- Decorator.decorate(url)
6
+ def self.decorate(url, context = {})
7
+ Decorator.decorate(url, context)
8
8
  end
9
9
 
10
10
  class Decorator
@@ -24,14 +24,13 @@ module Ducklink
24
24
  end
25
25
 
26
26
  def decorate(url, context = {})
27
- params, block = hosts[URI.parse(url).host]
27
+ params, block = hosts[URI.parse(url).host] rescue nil
28
28
  return url unless params
29
-
29
+
30
30
  params.set :url, url
31
31
  params.instance_exec context, &block
32
-
33
- format = params[:format]
34
- format.scan(/\{\{([a-z_]+?)\}\}/i).inject(format) do |result, matches|
32
+
33
+ params.template.scan(/\{\{([a-z_]+?)\}\}/i).inject(params.template) do |result, matches|
35
34
  params[matches.first] ? result.gsub("{{#{matches.first}}}", params[matches.first]) : result
36
35
  end
37
36
  end
@@ -45,20 +44,20 @@ module Ducklink
45
44
  @settings = settings
46
45
  end
47
46
 
48
- def format(format)
49
- set :format, format
47
+ def set(key, value)
48
+ settings[key.to_s] = value.to_s
50
49
  end
51
50
 
52
- def group(&block)
53
- Params.new(settings.clone).instance_exec &block
51
+ def [](key)
52
+ settings[key.to_s]
54
53
  end
55
54
 
56
- def set(key, value)
57
- @settings[key.to_s] = value.to_s
55
+ def template(template = nil)
56
+ template ? set(:template, template) : self[:template]
58
57
  end
59
58
 
60
- def [](key)
61
- @settings[key.to_s]
59
+ def group(&block)
60
+ Params.new(settings.clone).instance_exec &block
62
61
  end
63
62
 
64
63
  def host(*domains, &block)
@@ -1,3 +1,3 @@
1
1
  module Ducklink
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ducklink
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Henry Garner