ducklink 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ducklink.rb +14 -15
- data/lib/ducklink/version.rb +1 -1
- metadata +1 -1
data/lib/ducklink.rb
CHANGED
@@ -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
|
-
|
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
|
49
|
-
|
47
|
+
def set(key, value)
|
48
|
+
settings[key.to_s] = value.to_s
|
50
49
|
end
|
51
50
|
|
52
|
-
def
|
53
|
-
|
51
|
+
def [](key)
|
52
|
+
settings[key.to_s]
|
54
53
|
end
|
55
54
|
|
56
|
-
def
|
57
|
-
|
55
|
+
def template(template = nil)
|
56
|
+
template ? set(:template, template) : self[:template]
|
58
57
|
end
|
59
58
|
|
60
|
-
def
|
61
|
-
|
59
|
+
def group(&block)
|
60
|
+
Params.new(settings.clone).instance_exec &block
|
62
61
|
end
|
63
62
|
|
64
63
|
def host(*domains, &block)
|
data/lib/ducklink/version.rb
CHANGED