Module: RocketPants::Linking
- Defined in:
- lib/rocket_pants/controller/linking.rb
Instance Method Summary collapse
- #expose_metadata(metadata) ⇒ Object
-
#link(rel, uri, attributes = {}) ⇒ Object
Generates a Link: header with the specified rel, uri and attributes.
-
#links(links = {}) ⇒ Object
Lets you add a series of links for the current resource.
-
#page_url(page) ⇒ Object
Hook method - Implement this to link to the current resource and we’ll automatically add header links.
Instance Method Details
#expose_metadata(metadata) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rocket_pants/controller/linking.rb', line 29 def () super.tap do || if RocketPants. && (pagination = [:pagination]) links :next => (pagination[:next] && page_url(pagination[:next])), :prev => (pagination[:previous] && page_url(pagination[:previous])), :last => (pagination[:pages] && page_url(pagination[:pages])), :first => page_url(1) end end end |
#link(rel, uri, attributes = {}) ⇒ Object
Generates a Link: header with the specified rel, uri and attributes.
8 9 10 11 12 13 14 |
# File 'lib/rocket_pants/controller/linking.rb', line 8 def link(rel, uri, attributes = {}) headers['Link'] ||= [] attributes = {:rel => rel}.merge(attributes) link = "<#{uri}>" attributes.each_pair { |k, v| link << "; #{k}=\"#{v}\"" } headers['Link'] << link end |
#links(links = {}) ⇒ Object
Lets you add a series of links for the current resource.
18 19 20 21 22 |
# File 'lib/rocket_pants/controller/linking.rb', line 18 def links(links = {}) links.each_pair do |rel, uri| link rel, uri if uri end end |
#page_url(page) ⇒ Object
Hook method - Implement this to link to the current resource and we’ll automatically add header links.
25 26 27 |
# File 'lib/rocket_pants/controller/linking.rb', line 25 def page_url(page) nil end |