Skip to content

Commit

Permalink
Support relative paths for add_link and add_link_template
Browse files Browse the repository at this point in the history
  • Loading branch information
Avdi Grimm committed Jul 21, 2012
1 parent 043ded2 commit f600058
Show file tree
Hide file tree
Showing 13 changed files with 600 additions and 11 deletions.
20 changes: 16 additions & 4 deletions lib/leadlight/hyperlinkable.rb
Expand Up @@ -29,15 +29,19 @@ def link(key, *expand_args, &fallback)
end

def add_link(url, rel=nil, title=rel, options={})
template = LinkTemplate.new(__service__, url, rel, title, options)
link = template.expand(captures_for_variables(__captures__,
template.variables))
absolute_url = base_url + url
template = LinkTemplate.new(__service__, absolute_url, rel,
title, options)
link = template.expand(captures_for_variables(__captures__,
template.variables))
define_link_helper(rel) if rel
links << link
end

def add_link_template(template, rel=nil, title=rel, options={})
link = LinkTemplate.new(__service__, template, rel, title, options)
absolute_url = base_url + template
link = LinkTemplate.new(__service__, absolute_url.to_s, rel,
title, options)
define_link_helper(rel) if rel
links << link
end
Expand Down Expand Up @@ -131,5 +135,13 @@ def captures_for_variables(captures, variables)
h[key] = captures[key] if captures[key]
end
end

def base_url
loc = __location__.to_s
unless loc[-1] == "/"
loc = loc + "/"
end
Addressable::URI.parse(loc)
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions spec/cassettes/Leadlight/authorized_GitHub_example/test_team/.yml
Expand Up @@ -177,4 +177,42 @@ http_interactions:
Test Team","id":127491,"url":"https://api.github.com/teams/127491"}'
http_version:
recorded_at: Sat, 21 Jul 2012 05:42:23 GMT
- request:
method: get
uri: https://api.github.com/teams
body: ''
headers:
Authorization:
- <AUTH FILTERED>
Accept:
- application/json, text/x-yaml, application/xml, application/xhtml+xml, text/html,
text/plain
response:
status:
code: 404
message:
headers:
server:
- nginx/1.0.13
date:
- Sat, 21 Jul 2012 06:23:24 GMT
content-type:
- application/json; charset=utf-8
transfer-encoding:
- chunked
connection:
- close
status:
- 404 Not Found
x-ratelimit-remaining:
- '4996'
cache-control:
- ''
x-oauth-scopes:
- repo
x-ratelimit-limit:
- '5000'
body: ! '{"message":"Not Found"}'
http_version:
recorded_at: Sat, 21 Jul 2012 06:23:22 GMT
recorded_with: VCR 2.0.0.rc1

0 comments on commit f600058

Please sign in to comment.