Sha256: e7e9df62fb32c350a5a941fdc5a876bde57198f3639c4f850fae93493a2472f4

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

class Card

  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={}
      Rails.logger.warn "Pass only Card::Name to page_path #{title.class}, #{title}" unless Card::Name===title
      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
      Rails.logger.warn "Pass only strings to card_path: #{rel_path.class}, #{rel_path}" unless String===rel_path
      if rel_path =~ /^\//
        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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
card-1.16.12 lib/card/location.rb
card-1.16.11 lib/card/location.rb
card-1.16.10 lib/card/location.rb
card-1.16.9 lib/card/location.rb
card-1.16.8 lib/card/location.rb
card-1.16.7 lib/card/location.rb
card-1.16.6 lib/card/location.rb
card-1.16.5 lib/card/location.rb