Sha256: ee0ac7b305308568c808791aa885d513a0b20be3953a118003b3058c158b57bf
Contents?: true
Size: 1.12 KB
Versions: 12
Compression:
Stored size: 1.12 KB
Contents
class Card module Env module Location # card_path makes a relative path site-absolute (if not already) # card_url makes it a full url (if not already) 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 def card_url rel rel.match?(/^https?:/) ? rel : "#{Env.origin}#{card_path rel}" end def cardname_from_url url return unless (cardname = cardname_from_url_regexp) m = url.match cardname m ? Card::Name[m[:mark]] : nil end def relative_url_root Cardio.config.relative_url_root end private def cardname_from_url_regexp return unless Env.origin.present? %r{#{Regexp.escape Env.origin}/(?<mark>[^?]+)} end extend Location # allows calls on Location constant, eg Location.card_url end end end
Version data entries
12 entries across 12 versions & 1 rubygems