Sha256: 89c899b6c210f5c1b3a739144ffefd88b4fd9ba49f3c859ecdcaaecebb7439f3

Contents?: true

Size: 1.33 KB

Versions: 16

Compression:

Stored size: 1.33 KB

Contents

class Card
  module Env
    module Location
      # page_path    takes a Card::Name, adds the format and query string to
      #              url_key (site-absolute)
      # card_path    makes a relative path site-absolute (if not already)
      # card_url     makes it a full url (if not already)

      # TESTME
      def page_path title, opts={}
        unless title.name?
          Rails.logger.warn "Pass only Card::Name to page_path " \
                            "(#{title} = #{title.class})"
        end
        format = opts[:format] ? ".#{opts.delete(:format)}" : ""
        action = opts[:action] ? "#{opts.delete(:action)}/" : ""
        query  = opts.present? ? "?#{opts.to_param}" : ""
        card_path "#{action}#{title.to_name.url_key}#{format}#{query}"
      end

      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 =~ %r{^(https?\:)?/}
          rel_path
        else
          "#{Card.config.relative_url_root}/#{rel_path}"
        end
      end

      def card_url rel
        if rel =~ /^https?\:/
          rel
        else
          "#{Card::Env[:protocol]}#{Card::Env[:host]}#{card_path rel}"
        end
      end

      extend Location # ??
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
card-1.94.1 lib/card/env/location.rb
card-1.94.0 lib/card/env/location.rb
card-1.93.13 lib/card/env/location.rb
card-1.93.12 lib/card/env/location.rb
card-1.93.11 lib/card/env/location.rb
card-1.93.10 lib/card/env/location.rb
card-1.93.9 lib/card/env/location.rb
card-1.93.8 lib/card/env/location.rb
card-1.93.7 lib/card/env/location.rb
card-1.93.6 lib/card/env/location.rb
card-1.93.5 lib/card/env/location.rb
card-1.93.4 lib/card/env/location.rb
card-1.93.3 lib/card/env/location.rb
card-1.93.2 lib/card/env/location.rb
card-1.93.1 lib/card/env/location.rb
card-1.93.0 lib/card/env/location.rb