link_header 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +8 -0
- data/README.rdoc +2 -2
- data/lib/link_header.rb +20 -2
- metadata +4 -4
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
= link_header README
|
2
2
|
|
3
|
-
Parse and format HTTP link headers as described in the draft spec http://tools.ietf.org/id/draft-nottingham-http-link-header-06.txt
|
3
|
+
Parse and format HTTP link headers as described in the draft spec http://tools.ietf.org/id/draft-nottingham-http-link-header-06.txt, also the equivalent HTML link elements.
|
4
4
|
|
5
5
|
== Description
|
6
6
|
|
7
|
-
Converts conforming link headers to and from text, LinkHeader objects and corresponding (JSON-friendly) Array representations.
|
7
|
+
Converts conforming link headers to and from text, LinkHeader objects and corresponding (JSON-friendly) Array representations, also HTML link elements.
|
8
8
|
|
9
9
|
== Installation
|
10
10
|
|
data/lib/link_header.rb
CHANGED
@@ -6,7 +6,7 @@ require "strscan"
|
|
6
6
|
#
|
7
7
|
class LinkHeader
|
8
8
|
# rubygem version
|
9
|
-
VERSION = "0.0.
|
9
|
+
VERSION = "0.0.5"
|
10
10
|
|
11
11
|
# An array of Link objects
|
12
12
|
attr_reader :links
|
@@ -99,6 +99,9 @@ class LinkHeader
|
|
99
99
|
new(links)
|
100
100
|
end
|
101
101
|
|
102
|
+
#
|
103
|
+
# Find a member link that has the given attributes
|
104
|
+
#
|
102
105
|
def find_link(*attr_pairs)
|
103
106
|
links.detect do |link|
|
104
107
|
!attr_pairs.detect do |pair|
|
@@ -106,6 +109,13 @@ class LinkHeader
|
|
106
109
|
end
|
107
110
|
end
|
108
111
|
end
|
112
|
+
|
113
|
+
#
|
114
|
+
# Render as a list of HTML link elements
|
115
|
+
#
|
116
|
+
def to_html(separator="\n")
|
117
|
+
links.map{|link| link.to_html}.join(separator)
|
118
|
+
end
|
109
119
|
|
110
120
|
#
|
111
121
|
# Represents a link - an href and a list of attributes (key value pairs)
|
@@ -173,7 +183,6 @@ class LinkHeader
|
|
173
183
|
# Convert to string representation as per the link header spec. This includes backspace-escaping doublequote characters in
|
174
184
|
# quoted attribute values.
|
175
185
|
#
|
176
|
-
#
|
177
186
|
# Convert to string representation as per the link header spec
|
178
187
|
#
|
179
188
|
# LinkHeader::Link.new(["http://example.com/foo", [["rel", "self"]]]).to_s
|
@@ -182,5 +191,14 @@ class LinkHeader
|
|
182
191
|
def to_s
|
183
192
|
(["<#{href}>"] + attr_pairs.map{|k, v| "#{k}=\"#{v.gsub(/"/, '\"')}\""}).join('; ')
|
184
193
|
end
|
194
|
+
|
195
|
+
#
|
196
|
+
# Bonus! Render as an HTML link element
|
197
|
+
#
|
198
|
+
# LinkHeader::Link.new(["http://example.com/foo", [["rel", "self"]]]).to_html
|
199
|
+
# #=> '<link href="http://example.com/foo" rel="self">'
|
200
|
+
def to_html
|
201
|
+
([%Q(<link href="#{href}")] + attr_pairs.map{|k, v| "#{k}=\"#{v.gsub(/"/, '\"')}\""}).join(' ')
|
202
|
+
end
|
185
203
|
end
|
186
204
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: link_header
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
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-
|
12
|
+
date: 2009-07-30 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 2.3.2
|
34
34
|
version:
|
35
|
-
description: Converts conforming link headers to and from text, LinkHeader objects and corresponding (JSON-friendly) Array representations.
|
35
|
+
description: Converts conforming link headers to and from text, LinkHeader objects and corresponding (JSON-friendly) Array representations, also HTML link elements.
|
36
36
|
email:
|
37
37
|
- mjb@asplake.co.uk
|
38
38
|
executables: []
|
@@ -85,7 +85,7 @@ rubyforge_project: link-header
|
|
85
85
|
rubygems_version: 1.3.5
|
86
86
|
signing_key:
|
87
87
|
specification_version: 3
|
88
|
-
summary: Converts conforming link headers to and from text, LinkHeader objects and corresponding (JSON-friendly) Array representations.
|
88
|
+
summary: Converts conforming link headers to and from text, LinkHeader objects and corresponding (JSON-friendly) Array representations, also HTML link elements.
|
89
89
|
test_files:
|
90
90
|
- test/test_helper.rb
|
91
91
|
- test/test_link_header.rb
|