Module: Card::Env::Location
Instance Method Summary collapse
-
#card_path(rel_path) ⇒ Object
card_path makes a relative path site-absolute (if not already) card_url makes it a full url (if not already).
- #card_url(rel) ⇒ Object
- #cardname_from_url(url) ⇒ Object
- #relative_url_root ⇒ Object
Instance Method Details
#card_path(rel_path) ⇒ Object
card_path makes a relative path site-absolute (if not already) card_url makes it a full url (if not already)
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/card/env/location.rb', line 7 def card_path rel_path unless rel_path.is_a? String Rails.logger.warn "Pass only strings to card_path. "\ "(#{rel_path} = #{rel_path.class})" end if rel_path.match? %r{^(https?:)?/} rel_path else "#{relative_url_root}/#{rel_path}" end end |
#card_url(rel) ⇒ Object
19 20 21 |
# File 'lib/card/env/location.rb', line 19 def card_url rel rel.match?(/^https?:/) ? rel : "#{Env.origin}#{card_path rel}" end |
#cardname_from_url(url) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/card/env/location.rb', line 23 def cardname_from_url url return unless (cardname = cardname_from_url_regexp) m = url.match cardname m ? Card::Name[m[:mark]] : nil end |
#relative_url_root ⇒ Object
30 31 32 |
# File 'lib/card/env/location.rb', line 30 def relative_url_root Cardio.config.relative_url_root end |