Sha256: 32c02c819a2ee0ce14f95b235278c15b4ddd994c5547686f7390d6695c50b630

Contents?: true

Size: 1.78 KB

Versions: 8

Compression:

Stored size: 1.78 KB

Contents

module NavigationHelpers
  
  # This hash can be extended with regular expressions
  # and path values
  #
  #   PathMatchers[/styles/i] = 'admin_styles_path'
  #
  PathMatchers = {} unless defined?(PathMatchers)
  
  # Maps a name to a path. Used by the
  #
  #   When /^I go to (.+)$/ do |page_name|
  #
  # step definition in web_steps.rb
  #
  def path_to(page_name, format=nil)
    PathMatchers.each do |path_matcher, value|
      if path_matcher =~ normalize_page_name(page_name)
        return send(value, {:format => format})
      end
    end
    case normalize_page_name(page_name)
    when /^\/(.*)/
      $1
    when /the home\s?page/
      '/'
    when /the (\S+) (|admin )page as (\w+)/
      path_to($1, $3)
    when /the (\S+) ($:|admin )page/
      path_to($1)
    when /first/
      '/first'
    when /new child/
      '/my-child'
    when /great-grandchild/
      '/parent/child/grandchild/great-grandchild'
    when /sitemap/i
      admin_pages_path(:format => format)
    when /login/i
      login_path(:format => format)
    when /preferences/i
      admin_preferences_path(:format => format)
    when /login/i
      login_path(:format => format)
    when /users/i
      admin_users_path(:format => format)
    when /pages/i
      admin_pages_path(:format => format)
    when /layouts/i
      admin_layouts_path(:format => format)
    when /users/i
      admin_users_path(:format => format)
    when /configuration/i
      admin_configuration_path(:format => format)
    when /extensions/i
      admin_extensions_path(:format => format)
    else
      raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
        "Now, go and add a mapping in #{__FILE__}"
    end
  end
  
  def normalize_page_name(page_name)
    page_name.gsub(/^["']+(.*?)["']+$/,'\1')
  end
end

World(NavigationHelpers)

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
radiant-1.1.4 features/support/paths.rb
radiant-1.1.3 features/support/paths.rb
radiant-1.1.2 features/support/paths.rb
radiant-1.1.1 features/support/paths.rb
radiant-1.1.0 features/support/paths.rb
radiant-1.1.0.rc1 features/support/paths.rb
radiant-1.1.0.beta features/support/paths.rb
radiant-1.1.0.alpha features/support/paths.rb