described_routes 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.7.1 2009-07-30
2
+
3
+ * Refactor helper module to use new link_header gem
4
+
1
5
  == 0.7.0 2009-07-26
2
6
 
3
7
  * Discovery protocol via link headers
data/README.rdoc CHANGED
@@ -4,9 +4,9 @@
4
4
 
5
5
  Features:
6
6
  * Dynamic, framework-neutral, client-friendly <code>ResourceTemplate</code> metadata describing the path/URI structures of your whole site or of specific resources
7
- * JSON, YAML and XML formats, also a bonus plain text report
8
7
  * A link header-based discovery protocol, enabling clients to find <code>ResourceTemplate</code> metadata from the resources of any enabled controller
9
8
  * Easy integration with Rails
9
+ * JSON, YAML and XML formats, also a bonus plain text report
10
10
 
11
11
  == SYNOPSIS:
12
12
 
@@ -62,7 +62,7 @@ include full URI templates.
62
62
 
63
63
  There are two integration steps for run time support:
64
64
 
65
- 1) Include the controller, perhaps in an initializer:
65
+ 1) Somewhere in your application include the controller, perhaps in an initializer:
66
66
 
67
67
  require 'described_routes/rails_controller'
68
68
 
data/Rakefile CHANGED
@@ -13,6 +13,7 @@ $hoe = Hoe.spec 'described_routes' do
13
13
  self.url = 'http://positiveincline.com/?p=213'
14
14
  self.extra_deps = [
15
15
  ['addressable','>= 2.1.0'],
16
+ ['link_header','>= 0.0.5']
16
17
  ]
17
18
  self.extra_dev_deps = [
18
19
  ['newgem', ">= #{::Newgem::VERSION}"]
@@ -1,8 +1,11 @@
1
+ require 'link_header'
2
+
1
3
  module DescribedRoutes
2
4
  module DescribedRoutesHelper
3
- # Map rels to standard relation types, used by #link_data
5
+ # Map rels to standard relation types, used by #make_link_header
4
6
  REGISTERED_RELS = {
5
- 'edit' => 'edit'
7
+ 'edit' => 'edit',
8
+ 'up' => 'up'
6
9
  }
7
10
 
8
11
  # The default options parameter to #link_elements; controls which links appear in html link elements
@@ -41,49 +44,27 @@ module DescribedRoutes
41
44
  end
42
45
  end
43
46
 
44
- # Render link_data as <link <url> rel=<rel> ... type=<type>> elements. Add to the <head> part of your layout with:
47
+ # Render links as <link <url> rel=<rel> ... type=<type>> elements. Add to the <head> part of your layout with:
45
48
  # <%= link_elements %>
46
- def link_elements(options=LINK_ELEMENT_OPTIONS)
47
- link_data(options).map{|url, rels, attrs|
48
- [
49
- %Q(<link href="#{url}"),
50
- rels.map{|r| %Q(rel="#{r}")},
51
- attrs.map{|k, v| %Q(#{k}="#{v}")}
52
- ].join(' ')
53
- }.join("\n")
49
+ def link_elements(separator="\n", options=LINK_ELEMENT_OPTIONS)
50
+ make_link_header(options).to_html(separator)
54
51
  end
55
52
 
56
- # Render link_data as a link header. Usage:
57
- # response.headers["Link"] = link_header(options)
58
- # or use #set_link_header
59
- def link_header(options=LINK_HEADER_OPTIONS)
60
- link_data(options).map{|url, rels, attrs|
61
- [
62
- "<#{url}>",
63
- rels.map{|r| %Q(rel="#{r}")},
64
- attrs.map{|k, v| %Q(#{k}="#{v}")}
65
- ].join('; ')
66
- }.join(', ')
67
- end
68
-
69
53
  # Sets a link header in the response
70
54
  # after_filter :set_link_header
71
55
  def set_link_header(options=LINK_HEADER_OPTIONS)
72
- response.headers["Link"] = link_header(options)
56
+ response.headers["Link"] = make_link_header(options).to_s
73
57
  end
74
58
 
75
- # Returns an array of link information, each element containing
76
- # 0) a URL
77
- # 1) a list of link relation types (there can be more than one)
78
- # 2) a hash of attributes, typically just one, either "role" (for regular resources) or "meta" (for metadata resources)
79
- # The list of link relations types will contain a standard type ('self', 'up', 'describedby') &/or an extention type
59
+ # Returns a LinkHeader object that represents the required links.
60
+ #
61
+ # Link relation types ("rel" attributes) will contain a standard type ('self', 'up', 'describedby') &/or an extension type
80
62
  # in the form "described_route_url(name)#rel", using the name and rel of the resource template.
81
63
  #
82
64
  # The output is filtered by the options hash, with members :self, :describedby, :up, :related.
83
- # Rel values will include a short value (e.g. 'edit') if the template's rel has a mapping in REGISTERED_RELS.
84
65
  #
85
- def link_data(options)
86
- result = []
66
+ def make_link_header(options)
67
+ links = []
87
68
  rt = resource_template
88
69
  if rt
89
70
  type_prefix = described_routes_url + '#'
@@ -112,31 +93,39 @@ module DescribedRoutes
112
93
  end
113
94
 
114
95
  # data for rel="self"
115
- result << [request.url, ['self'], {'role' => type_prefix + rt.name}] if options[:self]
96
+ links << LinkHeader::Link.new(request.url, [['rel', 'self'], ['role', type_prefix + rt.name]]) if options[:self]
116
97
 
117
98
  # data for rel="described_by"
118
- result << [described_by_with_params, ['describedby'], {'meta' => meta}] if options[:describedby]
99
+ links << LinkHeader::Link.new(described_by_with_params, [['rel', 'describedby'], ['meta', meta]]) if options[:describedby]
119
100
 
120
101
  # data for rel="up"
102
+ # TODO move this to ResourceTemplate
121
103
  if options[:up]
122
104
  if rt.parent
123
- result << [rt.parent.uri_for(resource_parameters), ['up'], {'role' => type_prefix + rt.parent.name}]
105
+ links << LinkHeader::Link.new(rt.parent.uri_for(resource_parameters), [['rel', 'up'], ['role', type_prefix + rt.parent.name]])
124
106
  elsif rt.name != 'root'
125
- result << [root_url, ['up'], {'role' => type_prefix + 'root'}]
107
+ links << LinkHeader::Link.new(root_url, [['rel', 'up'], ['role', type_prefix + 'root']])
126
108
  end
127
109
  end
128
110
 
129
111
  # data for rel="related"
130
112
  if options[:related]
131
- related.expand_links(resource_parameters).map do |l|
113
+ related.expand_links(resource_parameters).each do |l|
132
114
  if l.name != rt.name
133
115
  rel = l.rel || l.name
134
- result << [l.uri, REGISTERED_RELS[rel].to_a + [described_by + '#' + rel], {'role' => type_prefix + l.name}]
116
+ rels = [['rel', described_by + '#' + rel]]
117
+ if l.rel
118
+ registered_rel = REGISTERED_RELS[rel]
119
+ if registered_rel
120
+ rels.unshift(['rel', registered_rel])
121
+ end
122
+ end
123
+ links << LinkHeader::Link.new(l.uri, rels + [['role', type_prefix + l.name]])
135
124
  end
136
125
  end
137
126
  end
138
127
  end
139
- result
128
+ LinkHeader.new(links)
140
129
  end
141
130
  end
142
131
  end
@@ -2,5 +2,5 @@ require 'resource_template'
2
2
 
3
3
  module DescribedRoutes
4
4
  # rubygem version
5
- VERSION = "0.7.0"
5
+ VERSION = "0.7.1"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: described_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Burrows
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-26 00:00:00 +01:00
12
+ date: 2009-07-30 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 2.1.0
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: link_header
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.5
34
+ version:
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: newgem
27
37
  type: :development
@@ -45,9 +55,9 @@ dependencies:
45
55
  description: |-
46
56
  Features:
47
57
  * Dynamic, framework-neutral, client-friendly <code>ResourceTemplate</code> metadata describing the path/URI structures of your whole site or of specific resources
48
- * JSON, YAML and XML formats, also a bonus plain text report
49
58
  * A link header-based discovery protocol, enabling clients to find <code>ResourceTemplate</code> metadata from the resources of any enabled controller
50
59
  * Easy integration with Rails
60
+ * JSON, YAML and XML formats, also a bonus plain text report
51
61
  email:
52
62
  - mjb@asplake.co.uk
53
63
  executables: []
@@ -139,7 +149,7 @@ rubyforge_project: describedroutes
139
149
  rubygems_version: 1.3.5
140
150
  signing_key:
141
151
  specification_version: 3
142
- summary: "Features: * Dynamic, framework-neutral, client-friendly <code>ResourceTemplate</code> metadata describing the path/URI structures of your whole site or of specific resources * JSON, YAML and XML formats, also a bonus plain text report * A link header-based discovery protocol, enabling clients to find <code>ResourceTemplate</code> metadata from the resources of any enabled controller * Easy integration with Rails"
152
+ summary: "Features: * Dynamic, framework-neutral, client-friendly <code>ResourceTemplate</code> metadata describing the path/URI structures of your whole site or of specific resources * A link header-based discovery protocol, enabling clients to find <code>ResourceTemplate</code> metadata from the resources of any enabled controller * Easy integration with Rails * JSON, YAML and XML formats, also a bonus plain text report"
143
153
  test_files:
144
154
  - test/test_described_routes.rb
145
155
  - test/test_helper.rb