-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Rails resourceful routing concerns to inject blacklight-required …
…model and controller routing
- Loading branch information
Showing
36 changed files
with
183 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<%= link_to t('blacklight.header_links.saved_searches'), saved_searches_path %> | ||
<%= link_to t('blacklight.header_links.saved_searches'), blacklight.saved_searches_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<%= link_to t('blacklight.header_links.search_history'), search_history_path %> | ||
<%= link_to t('blacklight.header_links.search_history'), blacklight.search_history_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Blacklight::Engine.routes.draw do | ||
get "search_history", :to => "search_history#index", :as => "search_history" | ||
delete "search_history/clear", :to => "search_history#clear", :as => "clear_search_history" | ||
delete "saved_searches/clear", :to => "saved_searches#clear", :as => "clear_saved_searches" | ||
get "saved_searches", :to => "saved_searches#index", :as => "saved_searches" | ||
put "saved_searches/save/:id", :to => "saved_searches#save", :as => "save_search" | ||
delete "saved_searches/forget/:id", :to => "saved_searches#forget", :as => "forget_search" | ||
post "saved_searches/forget/:id", :to => "saved_searches#forget" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,7 @@ | ||
# -*- encoding : utf-8 -*- | ||
module Blacklight | ||
class Routes | ||
attr_reader :resources | ||
|
||
# adds as class and instance level accessors, default_route_sets | ||
# returns an array of symbols for method names that define routes. | ||
# Order is important:. (e.g. /catalog/email precedes /catalog/:id) | ||
# | ||
# Add-ons that want to add routes into default routing might | ||
# monkey-patch Blacklight::Routes, say: | ||
# | ||
# module MyWidget::Routes | ||
# extend ActiveSupport::Concern | ||
# included do |klass| | ||
# klass.default_route_sets += [:widget_routing] | ||
# end | ||
# def widget_routing(primary_resource) | ||
# add_routes do |options| | ||
# get "#{primary_resource}/widget", "#{primary_resource}#widget" | ||
# end | ||
# end | ||
# end | ||
# Blacklight::Routes.send(:include, MyWidget::Routes) | ||
class_attribute :default_route_sets | ||
self.default_route_sets = [:bookmarks, :search_history, :saved_searches, :export, :solr_document] | ||
|
||
def initialize(router, options) | ||
@router = router | ||
@options = options | ||
@resources = options.fetch(:resources, [:catalog]) | ||
end | ||
|
||
def draw | ||
route_sets.each do |r| | ||
self.send(r, primary_resource) | ||
end | ||
resources.each do |r| | ||
self.map_resource(r) | ||
end | ||
end | ||
|
||
protected | ||
|
||
def primary_resource | ||
resources.first | ||
end | ||
|
||
def add_routes &blk | ||
@router.instance_exec(@options, &blk) | ||
end | ||
|
||
def route_sets | ||
(@options[:only] || default_route_sets) - (@options[:except] || []) | ||
end | ||
|
||
|
||
|
||
module RouteSets | ||
def bookmarks(_) | ||
add_routes do |options| | ||
delete "bookmarks/clear", :to => "bookmarks#clear", :as => "clear_bookmarks" | ||
get "bookmarks/email", :as => "email_bookmarks" | ||
post "bookmarks/email" | ||
get "bookmarks/sms", :as => "sms_bookmarks" | ||
post "bookmarks/sms" | ||
get "bookmarks/citation", :as => "citation_bookmarks" | ||
|
||
args = {} | ||
args[:constraints] = options[:constraints] if options[:constraints] | ||
resources :bookmarks, args | ||
end | ||
end | ||
|
||
def search_history(_) | ||
add_routes do |options| | ||
get "search_history", :to => "search_history#index", :as => "search_history" | ||
delete "search_history/clear", :to => "search_history#clear", :as => "clear_search_history" | ||
end | ||
end | ||
|
||
|
||
def saved_searches(_) | ||
add_routes do |options| | ||
delete "saved_searches/clear", :to => "saved_searches#clear", :as => "clear_saved_searches" | ||
get "saved_searches", :to => "saved_searches#index", :as => "saved_searches" | ||
put "saved_searches/save/:id", :to => "saved_searches#save", :as => "save_search" | ||
delete "saved_searches/forget/:id", :to => "saved_searches#forget", :as => "forget_search" | ||
post "saved_searches/forget/:id", :to => "saved_searches#forget" | ||
end | ||
end | ||
|
||
def map_resource(key) | ||
add_routes do |options| | ||
get "#{key}/facet/:id", :to => "#{key}#facet", :as => "#{key}_facet" | ||
get "#{key}", :to => "#{key}#index", :as => "#{key}_index" | ||
end | ||
end | ||
|
||
def export(primary_resource) | ||
add_routes do |options| | ||
get "#{primary_resource}/opensearch", :as => "opensearch_#{primary_resource}" | ||
get "#{primary_resource}/citation", :as => "citation_#{primary_resource}" | ||
get "#{primary_resource}/email", :as => "email_#{primary_resource}" | ||
post "#{primary_resource}/email" | ||
get "#{primary_resource}/sms", :as => "sms_#{primary_resource}" | ||
post "#{primary_resource}/sms" | ||
end | ||
end | ||
|
||
def solr_document(primary_resource) | ||
add_routes do |options| | ||
|
||
args = {only: [:show]} | ||
args[:constraints] = options[:constraints] if options[:constraints] | ||
|
||
resources :solr_document, args.merge(path: primary_resource, controller: primary_resource) do | ||
member do | ||
post "track" | ||
end | ||
end | ||
|
||
# :show and :update are for backwards-compatibility with catalog_url named routes | ||
resources primary_resource, args | ||
end | ||
end | ||
end | ||
include RouteSets | ||
module Routes | ||
require 'blacklight/routes/exportable' | ||
require 'blacklight/routes/searchable' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Blacklight | ||
module Routes | ||
class Exportable | ||
def initialize(defaults = {}) | ||
@defaults = defaults | ||
end | ||
|
||
def call(mapper, options = {}) | ||
options = @defaults.merge(options) | ||
|
||
mapper.member do | ||
mapper.match 'email', via: [:get, :post] | ||
mapper.match 'sms', via: [:get, :post] | ||
mapper.get 'citation' | ||
end | ||
|
||
mapper.collection do | ||
mapper.match 'email', via: [:get, :post] | ||
mapper.match 'sms', via: [:get, :post] | ||
mapper.get 'citation' | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Blacklight | ||
module Routes | ||
class Searchable | ||
def initialize(defaults = {}) | ||
@defaults = defaults | ||
end | ||
|
||
def call(mapper, options = {}) | ||
options = @defaults.merge(options) | ||
|
||
mapper.match '/', action: 'index', as: 'search', via: [:get, :post] | ||
|
||
mapper.post ":id/track", action: 'track', as: 'track' | ||
|
||
mapper.get "opensearch" | ||
mapper.get "facet/:id", action: 'facet', as: 'facet' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.