blacklight-locale_picker 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.travis.yml +8 -0
- data/Gemfile +49 -0
- data/LICENSE +13 -0
- data/README.md +32 -0
- data/Rakefile +46 -0
- data/app/controllers/concerns/blacklight/locale_picker/concern.rb +24 -0
- data/app/helpers/blacklight/locale_picker/locale_helper.rb +30 -0
- data/app/views/shared/_locale_picker.html.erb +18 -0
- data/blacklight-locale_picker.gemspec +32 -0
- data/config/locales/locale_picker.en.yml +12 -0
- data/lib/blacklight/locale_picker.rb +6 -0
- data/lib/blacklight/locale_picker/engine.rb +11 -0
- data/lib/blacklight/locale_picker/version.rb +5 -0
- data/lib/generators/blacklight/locale_picker/install_generator.rb +23 -0
- data/lib/tasks/blacklight/locale_picker_tasks.rake +4 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 17a822c82012ee32b19b4c03ccfd2e213cd050bd7e08d902e816e8e997d525ea
|
4
|
+
data.tar.gz: 452e5def5ab4cc417158e52236ebbbd4074b825f520a6f699672db8c00837c3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0456f053e837749f2c369119215f22fb492c245c2b9b739ae81e48bb414f7a93aa69538bd1af8392e854b0ed06e269efe6afc1a65f28e873e99fe875e2acab69
|
7
|
+
data.tar.gz: ccc0749116ec7960106507d169c77e564ea111d895fe566c2f889eeaa3fe6097c57402cbe3ff697e82a61a8a766112bc65951175386bc79371bad8c742b86857
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
|
+
|
4
|
+
# Declare your gem's dependencies in blacklight-locale_picker.gemspec.
|
5
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
6
|
+
# development dependencies will be added by default to the :development group.
|
7
|
+
gemspec
|
8
|
+
|
9
|
+
# Declare any dependencies that are still in development here instead of in
|
10
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
11
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
12
|
+
# your gem to rubygems.org.
|
13
|
+
|
14
|
+
# To use a debugger
|
15
|
+
# gem 'byebug', group: [:development, :test]
|
16
|
+
# BEGIN ENGINE_CART BLOCK
|
17
|
+
# engine_cart: 2.3.0
|
18
|
+
# engine_cart stanza: 0.10.0
|
19
|
+
# the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app.
|
20
|
+
file = File.expand_path('Gemfile', ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path('.internal_test_app', File.dirname(__FILE__)))
|
21
|
+
if File.exist?(file)
|
22
|
+
begin
|
23
|
+
eval_gemfile file
|
24
|
+
rescue Bundler::GemfileError => e
|
25
|
+
Bundler.ui.warn '[EngineCart] Skipping Rails application dependencies:'
|
26
|
+
Bundler.ui.warn e.message
|
27
|
+
end
|
28
|
+
else
|
29
|
+
Bundler.ui.warn "[EngineCart] Unable to find test application dependencies in #{file}, using placeholder dependencies"
|
30
|
+
|
31
|
+
if ENV['RAILS_VERSION']
|
32
|
+
if ENV['RAILS_VERSION'] == 'edge'
|
33
|
+
gem 'rails', github: 'rails/rails'
|
34
|
+
ENV['ENGINE_CART_RAILS_OPTIONS'] = '--edge --skip-turbolinks'
|
35
|
+
else
|
36
|
+
gem 'rails', ENV['RAILS_VERSION']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
case ENV['RAILS_VERSION']
|
41
|
+
when /^4.2/
|
42
|
+
gem 'responders', '~> 2.0'
|
43
|
+
gem 'sass-rails', '>= 5.0'
|
44
|
+
gem 'coffee-rails', '~> 4.1.0'
|
45
|
+
when /^4.[01]/
|
46
|
+
gem 'sass-rails', '< 5.0'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
# END ENGINE_CART BLOCK
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2019 The Board of Trustees of the Leland Stanford Junior University.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Blacklight::LocalePicker
|
2
|
+
A dropdown locale switcher for Blacklight apps
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'blacklight-locale_picker'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install blacklight-locale_picker
|
22
|
+
```
|
23
|
+
|
24
|
+
And then run the install generator:
|
25
|
+
```bash
|
26
|
+
$ rails generate blacklight:locale_picker:install
|
27
|
+
```
|
28
|
+
## Configuration
|
29
|
+
To add locales to your application, add an initializer.
|
30
|
+
```
|
31
|
+
Blacklight::LocalePicker::Engine.config.available_locales = [:en, :es]
|
32
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
require 'engine_cart/rake_task'
|
9
|
+
|
10
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
11
|
+
rdoc.rdoc_dir = 'rdoc'
|
12
|
+
rdoc.title = 'Blacklight::LocalePicker'
|
13
|
+
rdoc.options << '--line-numbers'
|
14
|
+
rdoc.rdoc_files.include('README.md')
|
15
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'bundler/gem_tasks'
|
19
|
+
|
20
|
+
require 'solr_wrapper'
|
21
|
+
|
22
|
+
require 'rspec/core/rake_task'
|
23
|
+
RSpec::Core::RakeTask.new(:spec)
|
24
|
+
|
25
|
+
require 'rubocop/rake_task'
|
26
|
+
RuboCop::RakeTask.new(:rubocop)
|
27
|
+
|
28
|
+
require 'engine_cart/rake_task'
|
29
|
+
|
30
|
+
task ci: ['engine_cart:generate'] do
|
31
|
+
ENV['environment'] = 'test'
|
32
|
+
|
33
|
+
SolrWrapper.wrap(port: '8983') do |solr|
|
34
|
+
solr.with_collection(name: 'blacklight-core', dir: File.join(File.expand_path(File.dirname(__FILE__)), '.internal_test_app', 'solr', 'conf')) do
|
35
|
+
within_test_app do
|
36
|
+
system 'bundle install'
|
37
|
+
system 'bundle exec rake db:migrate'
|
38
|
+
end
|
39
|
+
|
40
|
+
# run the tests
|
41
|
+
Rake::Task['spec'].invoke
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
task default: :ci
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# A module to add set locales that is sent to application controller
|
5
|
+
module Blacklight::LocalePicker::Concern
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
included do
|
8
|
+
before_action :set_locale
|
9
|
+
|
10
|
+
def default_url_options
|
11
|
+
{ locale: (I18n.locale unless I18n.default_locale == I18n.locale) }
|
12
|
+
end
|
13
|
+
|
14
|
+
before_action do
|
15
|
+
blacklight_config.add_nav_action(:locale, partial: 'shared/locale_picker')
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def set_locale
|
21
|
+
I18n.locale = params[:locale] || I18n.default_locale
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Helpers for building the locale picker
|
2
|
+
module Blacklight::LocalePicker::LocaleHelper
|
3
|
+
# Locales to display in the locale picker; by default, it picks up
|
4
|
+
# the information from the engine configuration
|
5
|
+
def available_locales
|
6
|
+
Blacklight::LocalePicker::Engine.config.available_locales
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns the url for the current page in the new locale. This may be
|
10
|
+
# overridden in downstream applications where our naive use of `url_for`
|
11
|
+
# is insufficient to generate the expected routes
|
12
|
+
def current_page_for_locale(locale)
|
13
|
+
initial_exception = nil
|
14
|
+
|
15
|
+
([self] + additional_locale_routing_scopes).each do |scope|
|
16
|
+
return scope.public_send(:url_for, locale: locale)
|
17
|
+
rescue ActionController::UrlGenerationError => e
|
18
|
+
initial_exception ||= e
|
19
|
+
end
|
20
|
+
|
21
|
+
raise initial_exception
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns an array of routing scopes (e.g. mounted engines) to attempt to use
|
25
|
+
# for switching locale-specific routes. This is likely overridden in complex
|
26
|
+
# applications to add scopes for additional mounted engines
|
27
|
+
def additional_locale_routing_scopes
|
28
|
+
[blacklight]
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% if available_locales.many? %>
|
2
|
+
<li class="nav-item dropdown">
|
3
|
+
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" aria-controls="language-dropdown-menu">
|
4
|
+
<span class="sr-only"><%= t('blacklight.toolbar.language_switch') %></span>
|
5
|
+
<span><%= t("locales.#{I18n.locale}") %></span>
|
6
|
+
<b class="caret"></b>
|
7
|
+
</a>
|
8
|
+
<ul id="language-dropdown-menu" class="dropdown-menu" role="menu">
|
9
|
+
<li role="presentation" class="dropdown-header"><%= t('blacklight.toolbar.language_switch') %></li>
|
10
|
+
<li role="presentation" class="divider"></li>
|
11
|
+
<% available_locales.each do |locale| %>
|
12
|
+
<li role="presentation" lang="<%= locale %>">
|
13
|
+
<%= link_to t("locales.#{locale}"), current_page_for_locale(locale), class: 'dropdown-item' %>
|
14
|
+
</li>
|
15
|
+
<% end %>
|
16
|
+
</ul>
|
17
|
+
</li>
|
18
|
+
<% end %>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
$:.push File.expand_path("lib", __dir__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "blacklight/locale_picker/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "blacklight-locale_picker"
|
9
|
+
spec.version = Blacklight::LocalePicker::VERSION
|
10
|
+
spec.authors = ["Camille Villa", "Chris Beer"]
|
11
|
+
spec.email = ["cvilla100@gmail.com", "chris@cbeer.info"]
|
12
|
+
spec.homepage = "https://github.com/projectblacklight/blacklight-locale_picker"
|
13
|
+
spec.summary = ""
|
14
|
+
spec.description = ""
|
15
|
+
spec.license = "Apache-2.0"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency "rails", "~> 5.2.3"
|
25
|
+
|
26
|
+
spec.add_development_dependency "capybara"
|
27
|
+
spec.add_development_dependency "engine_cart"
|
28
|
+
spec.add_development_dependency "rspec-rails"
|
29
|
+
spec.add_development_dependency "rubocop"
|
30
|
+
spec.add_development_dependency "sqlite3"
|
31
|
+
spec.add_development_dependency "solr_wrapper"
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module Blacklight::LocalePicker
|
6
|
+
##
|
7
|
+
# Blacklight::LocalePicker install generator
|
8
|
+
class Install < Rails::Generators::Base
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
def add_locale_picker_to_controller
|
12
|
+
inject_into_file 'app/controllers/application_controller.rb', after: 'include Blacklight::Controller' do
|
13
|
+
"\n include Blacklight::LocalePicker::Concern"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_locale_picker_helpers
|
18
|
+
inject_into_file 'app/helpers/application_helper.rb', after: 'module ApplicationHelper' do
|
19
|
+
"\n include Blacklight::LocalePicker::LocaleHelper"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blacklight-locale_picker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Camille Villa
|
8
|
+
- Chris Beer
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-08-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 5.2.3
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 5.2.3
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: capybara
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: engine_cart
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec-rails
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rubocop
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: sqlite3
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: solr_wrapper
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
description: ''
|
113
|
+
email:
|
114
|
+
- cvilla100@gmail.com
|
115
|
+
- chris@cbeer.info
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- app/controllers/concerns/blacklight/locale_picker/concern.rb
|
127
|
+
- app/helpers/blacklight/locale_picker/locale_helper.rb
|
128
|
+
- app/views/shared/_locale_picker.html.erb
|
129
|
+
- blacklight-locale_picker.gemspec
|
130
|
+
- config/locales/locale_picker.en.yml
|
131
|
+
- lib/blacklight/locale_picker.rb
|
132
|
+
- lib/blacklight/locale_picker/engine.rb
|
133
|
+
- lib/blacklight/locale_picker/version.rb
|
134
|
+
- lib/generators/blacklight/locale_picker/install_generator.rb
|
135
|
+
- lib/tasks/blacklight/locale_picker_tasks.rake
|
136
|
+
homepage: https://github.com/projectblacklight/blacklight-locale_picker
|
137
|
+
licenses:
|
138
|
+
- Apache-2.0
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubygems_version: 3.0.3
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: ''
|
159
|
+
test_files: []
|