Sha256: 3d1c76bd9f9ef5814037a584dd8e64bfecfa04fd1ef3f9abd1f0920e93c4b19d

Contents?: true

Size: 858 Bytes

Versions: 1

Compression:

Stored size: 858 Bytes

Contents

class Shoes

  # Backwards compatibility, kind of likely to be removed
  def self.inherited(base_class)
    base_class.send :include, URL #include is private, therefore send
  end

  module URL
    attr_accessor :app

    Shoes::App.subscribe_to_dsl_methods self

    def self.included(base_class)
      base_class.extend URLDefiner
    end

    def self.urls
      @urls ||= {}
    end
  end

  module URLDefiner
    def url(page, method)
      page = convert_page_to_regex(page)
      url_class = self

      Shoes::URL.urls[page] = proc do |app, arg|
        new_url_instance = url_class.new
        new_url_instance.app = app

        if arg
          new_url_instance.send(method, arg)
        else
          new_url_instance.send method
        end
      end
    end

    private
    def convert_page_to_regex(page)
      /^#{page}$/
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoes-dsl-4.0.0.pre2 lib/shoes/url.rb