Skip to content

Commit

Permalink
Merge pull request #216 from CDRH/dev
Browse files Browse the repository at this point in the history
v3.1.1
  • Loading branch information
jduss4 authored Nov 17, 2020
2 parents 107f473 + a628bbc commit 79f643e
Show file tree
Hide file tree
Showing 28 changed files with 301 additions and 63 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ Versioning](https://semver.org/spec/v2.0.0.html).
### Contributors
-->

## [v3.1.1](https://github.com/CDRH/orchid/compare/v3.1.0...v3.1.1) - splitting templates, fixing languages

### Fixed
- bug with locales yaml creation

### Added
- partials for browse, browse_facet, index, and search_preset header content for easier overriding
- displays language toggle options in respective languages, therefore English instead of en, Español instead of es, etc
- helper method `language_toggle_link` moves logic for language links out of view
- documentation for api connection and controller inheritance
- adds partials for easier overriding:
- `browse_header`
- `browse_facet_header`
- `index_header`
- `search_preset_header`
- `analytics` (head)
- `language` (head)

### Changed
- `ALL_LANGUAGES` setting changed back to `languages`
- language documentation clarified and expanded

## [v3.1.0](https://github.com/CDRH/orchid/compare/v3.0.3...v3.1.0) - search_preset, improved section links, and misc display

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
orchid (3.0.3)
orchid (3.1.1)
rails (~> 5.2.0)

GEM
Expand Down
20 changes: 20 additions & 0 deletions app/helpers/orchid/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,26 @@ def iiif(image,
"#{server}/#{project}%2F#{image_esc}/#{iiif_opts}"
end

# returns a link to switch site language preferences
def language_toggle_link(lang_code)
lang_name = t("languages.#{lang_code}", default: lang_code.upcase)

if lang_code == I18n.locale.to_s
# if this is the current site language, disable link
link_to lang_name, "#",
class: "btn btn-primary disabled",
hreflang: lang_code,
rel: "alternate",
tabindex: -1
else
link_to lang_name,
locale_link(lang_code),
class: "btn btn-default",
hreflang: lang_code,
rel: "alternate"
end
end

def locale
I18n.locale
end
Expand Down
1 change: 1 addition & 0 deletions app/views/items/_browse_facet_header.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1><%= t "browse.browse_type", default: "Browse by" %> <%= @browse_facet_info["label"] %></h1>
6 changes: 6 additions & 0 deletions app/views/items/_browse_header.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1><%= t "browse.title", default: "Browse" %></h1>

<p>
<%= link_to t("browse.all_link", default: "All Items in the Collection"), prefix_path(route_path),
class: "btn btn-lg btn-default", rel: "search" %>
</p>
2 changes: 1 addition & 1 deletion app/views/items/_date_limit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% class_in = date_selected ? "in" : "" %>
<% class_glyphicon = date_selected ? "glyphicon-chevron-down" : "glyphicon-chevron-right" %>

<div class="panel panel-default">
<div class="panel panel-default panel-filter panel-filter-date">
<div class="clearfix panel-heading" data-toggle="collapse"
data-target="#dates" role="Option"
aria-label="<%= t "search.dates.show_filters", default: "Show Date Filters" %>">
Expand Down
2 changes: 1 addition & 1 deletion app/views/items/_facets.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<% class_in = start_open ? "in" : "" %>
<% class_glyphicon = start_open ? "glyphicon-chevron-down" : "glyphicon-chevron-right" %>

<div class="panel panel-default">
<div class="panel panel-default panel-filter panel-filter-<%= info['label'].parameterize %>">

<!-- panel heading -->
<div class="clearfix panel-heading" data-toggle="collapse"
Expand Down
5 changes: 5 additions & 0 deletions app/views/items/_index_header.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% if params["q"].blank? && params["f"].blank? %>
<h1><%= t "search.all_items", default: "All Items" %></h1>
<% else %>
<h1><%= t "search.search_results", default: "Search Results" %></h1>
<% end %>
1 change: 1 addition & 0 deletions app/views/items/_search_preset_header.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1><%= @content_label || @title %></h1>
7 changes: 1 addition & 6 deletions app/views/items/browse.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<h1><% t "browse.title", default: "Browse" %></h1>

<p>
<%= link_to t("browse.all_link", default: "All Items in the Archive"), prefix_path(route_path),
class: "btn btn-lg btn-default", rel: "search" %>
</p>
<%= render_overridable "items", "browse_header" %>

<h3><%= t "browse.browse_type", default: "Browse by" %>:</h3>
<% @page_facets.each_slice(3) do |slice| %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/items/browse_facet.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- "sort_by" sort value (e.g. "count|desc")
%>

<h1><%= t "browse.browse_type", default: "Browse by" %> <%= @browse_facet_info["label"] %></h1>
<%= render_overridable "items", "browse_facet_header" %>

<nav>
<ul class="nav nav-tabs buffer-bottom" role="tablist">
Expand Down
6 changes: 1 addition & 5 deletions app/views/items/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<% if params["q"].blank? && params["f"].blank? %>
<h1><%= t "search.all_items", default: "All Items" %></h1>
<% else %>
<h1><%= t "search.search_results", default: "Search Results" %></h1>
<% end %>
<%= render_overridable("items", "index_header") %>

<div class="search_form">
<%= render_overridable("items", "search_box") %>
Expand Down
3 changes: 2 additions & 1 deletion app/views/items/search_preset.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ to docs/search_preset.md %>
- @preset_class : OPTIONAL adds CSS class on <div>
%>

<h1><%= @content_label || @title %></h1>
<%# title %>
<%= render_overridable "items", "search_preset_header" %>

<div class="row search_form search_preset search_preset_<%= @preset_class %>">

Expand Down
17 changes: 5 additions & 12 deletions app/views/layouts/body/_languages.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<% if APP_OPTS["languages"].present? && APP_OPTS["languages"][/\|/] %>
<% langs = APP_OPTS["languages"] %>

<% if langs.present? && langs[/\|/] %>
<div class="language_link btn-group" role="group" aria-label="language choice">
<% APP_OPTS["languages"].split("|").each do |lang_code| %>
<%# create link to switch languages that keeps current parameters %>
<%# TODO a11y / ARIA markup for full language names? %>
<% if lang_code == I18n.locale.to_s %>
<%= link_to lang_code.upcase, "#", class: "btn btn-primary disabled",
hreflang: lang_code, rel: "alternate", tabindex: -1 %>
<% else %>
<%# a11y / ARIA markup for full language name? %>
<%= link_to lang_code.upcase, locale_link(lang_code),
class: "btn btn-default", hreflang: lang_code, rel: "alternate" %>
<% end %>
<% langs.split("|").each do |lang_code| %>
<%= language_toggle_link(lang_code) %>
<% end %>
</div>
<% end %>
8 changes: 6 additions & 2 deletions app/views/layouts/body/_title.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
<%= link_to home_path do %>
<div class="h1">
<% if I18n.exists?("general.project_name", locale) %>
<span class="site-title"><%= t "general.project_name" %></span>
<span class="site-title">
<%= t "general.project_name", default: "Add project name to locale file" %>
</span>
<% end %>
<% if I18n.exists?("general.project_subtitle", locale) %>
<small class="site-subtitle"><%= t "general.project_subtitle" %></small>
<small class="site-subtitle">
<%= t "general.project_subtitle", default: "Add project subtitle to locale file" %>
</small>
<% end %>
</div>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/head/_analytics.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%# override this file to add your own analytics code %>
2 changes: 2 additions & 0 deletions app/views/layouts/head/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<%= t "general.project_shortname" %>
</title>
<%= render_overridable("layouts/head", "meta") %>
<%= render_overridable("layouts/head", "language") %>
<%= render_overridable("layouts/head", "analytics") %>
<%= render_overridable("layouts/head", "favicon") %>
<%= render_overridable("layouts/head", "fonts") %>
<%= render_overridable("layouts/head", "stylesheets") %>
Expand Down
10 changes: 10 additions & 0 deletions app/views/layouts/head/_language.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%# links for alternate language pages %>
<% if APP_OPTS["languages"].present? && APP_OPTS["languages"][/\|/] %>
<% APP_OPTS["languages"].split("|").each do |lang_code| %>
<%# if this is the currently selected language
then no alternative link is needed for it %>
<% next if lang_code == I18n.locale.to_s %>
<link rel="alternate" hreflang="<%= lang_code %>"
href="<%= locale_link(lang_code) %>" />
<% end %>
<% end %>
11 changes: 0 additions & 11 deletions app/views/layouts/head/_meta.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,3 @@
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<%= csrf_meta_tags %>

<%# links for alternate language pages %>
<% if APP_OPTS["languages"].present? && APP_OPTS["languages"][/\|/] %>
<% APP_OPTS["languages"].split("|").each do |lang_code| %>
<%# if this is the currently selected language
then no alternative link is needed for it %>
<% next if lang_code == I18n.locale.to_s %>
<link rel="alternate" hreflang="<%= lang_code %>"
href="<%= locale_link(lang_code) %>" />
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ en:
##########
browse:
# link to search all items
all_link: All Items in the Archive
all_link: All Items in the Collection
# label for browsing filters
browse_type: Browse by
# how to display specific filters which have no label
Expand Down
18 changes: 18 additions & 0 deletions config/locales/languages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Below is a list of languages currently supported by Orchid
#
# If you want to add an additional language, you will need
# to add it to your app's languages.yml file below in the
# langs key, then include the langs in your language's key.


langs: &langs
en: English
es: Español

en:
languages:
<<: *langs

es:
languages:
<<: *langs
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Installation](/docs/installation.md) - dependencies and generator instructions
- [Settings Overview and Basics](/docs/settings.md) - learn where and what you can change out of the box
- [Helpful Helpers](/docs/helpers.md) - specific Orchid helpers
- Testing - Run `rails test` from within the Orchid repository

## Theming and Customization

Expand Down
85 changes: 85 additions & 0 deletions docs/api_requests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# API Requests

When you are [overridding default controllers](/docs/overrides.md) or adding
new [sections](/docs/sections.md) and [search presets](/docs/search_preset.md),
you may find yourself needing to create custom API requests.

- [Accessing the Connection](#accessing-the-connection)
- [Querying](#querying)
- [The Response](#the-response)
- [Querying by ID](#querying-by-id)

## Accessing the Connection

When you first start an Orchid app, it connects to the API endpoint specified
in your `config/private.yml` file with default settings from `config/public.yml`.

That Query object is stored with a global variable:

```ruby
$api
```

Typically, you will not need to work directly with `$api`. In the
ItemsController, you are provided with an instance variable:

```ruby
@items_api
```

`@items_api` will return either `$api` or a section appropriate connection, if
you are working with sections.

The section API connection information is stored in `$api_sections`, although
you should rarely need to use it directly.

## Querying

Orchid uses the CDRH API's syntax for requests. You should familiarize yourself
with the [API documentation](https://github.com/CDRH/api) before writing custom
requests.

When you initialize your application, Orchid sets up default query parameters
using your config file settings.

This means that you do not need to specify things such as the number of items
per page, starting sort, facets, and any default filters for new queries, since
they are already built in as a convenience.

However, you may override those defaults as desired when creating a new query.

A typical query will look something like this:

```ruby
@items_api.query({ hash of options })
```

For example, the following would bring back results of Willa Cather's writing with the text "birthday":

```ruby

options = {
"f" => [ "category|Writings", "creator.name|Cather, Willa" ],
"q" => "birthday"
}
@items_api.query(options)
```

### The Response

`.query` returns a Response object which has the following methods:

- count : the number of items found
- facets : a hash with facets + facet counts you requested
- items : an array of the documents you requested
- first : the first item
- pages: the page count needed to display all the items

### Querying by ID

Although you could send a `.query({ identifier: "some.id" })` request and
select the first item, orchid provides a helpful method to get a single item:

```ruby
@items_api.get_item_by_id("some.id").first
```
Loading

0 comments on commit 79f643e

Please sign in to comment.