trestle-mobility 0.5.0 → 1.0.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 +4 -4
- data/README.md +19 -29
- data/lib/generators/trestle/mobility/install/install_generator.rb +32 -0
- data/lib/trestle/mobility/configuration.rb +1 -1
- data/lib/trestle/mobility/fields/check_box.rb +1 -1
- data/lib/trestle/mobility/fields/text_area.rb +1 -1
- data/lib/trestle/mobility/fields/text_field.rb +1 -1
- data/lib/trestle/mobility/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61f40dc820abfc72674027e455750a9c9b6011bed7a16ea257013407895cfe57
|
4
|
+
data.tar.gz: a6f35d96c0ce62a1b31de8441de8341a5372ea1657ce3b227256540d27ecde45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3c4546221bf0a30e3d04bbf41b04513abe31177af38d1b5e9fe04b01d0ac30da33dc94e5ba96974a612badf78f7eaa70571905666ffb52e725fc211d8aa702e
|
7
|
+
data.tar.gz: bdf55d61911e8923ff421fc14a1d3bb80f42fcb8e08b500dfffd9bc3b0dc7a7a83134835d14b00c7672455ab995b77870eaf1c100d88cfc8cd94c6e118d4d02d
|
data/README.md
CHANGED
@@ -14,6 +14,18 @@
|
|
14
14
|
|
15
15
|
<img src="/screenshot.png?raw=true" width="529" height="242" alt="Trestle Mobility screenshot" />
|
16
16
|
|
17
|
+
## Getting started
|
18
|
+
|
19
|
+
These instructions assume you have a working Trestle application. To integrate trestle-mobility, first add it to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'trestle-mobility'
|
23
|
+
```
|
24
|
+
|
25
|
+
Run `bundle install`, and then run the install generator to set up configuration options.
|
26
|
+
|
27
|
+
$ rails generate trestle:auth:install
|
28
|
+
|
17
29
|
## Usage
|
18
30
|
|
19
31
|
Trestle Mobility requires you to enable [Mobility's `locale_accessors` plugin](https://github.com/shioyama/mobility#getset).
|
@@ -31,35 +43,23 @@ Trestle.resource(:posts) do
|
|
31
43
|
end
|
32
44
|
```
|
33
45
|
|
34
|
-
|
35
|
-
|
36
|
-
By default Trestle Mobility uses `I18n.available_locales` to generate the form fields, but you can specify this on a per-field basis:
|
46
|
+
Trestle Mobility allows you to specify the language that is selected by default:
|
37
47
|
|
38
48
|
```ruby
|
39
|
-
mobility_text_field :
|
49
|
+
mobility_text_field :subtitle, selected: "nl"
|
40
50
|
```
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
> (Note however that Mobility will complain if you have I18n.enforce_available_locales set to true and you try accessing a locale not present in I18n.available_locales; set it to false if you want to allow any locale.)
|
45
|
-
|
46
|
-
### Default language selection
|
47
|
-
|
48
|
-
Trestle Mobility allows you to specify the language that is selected by default. This is possible on an application-wide basis but also per field.
|
49
|
-
|
50
|
-
To set the default language that should be selected for all fields, add the following line to your Trestle initializer:
|
52
|
+
By default Trestle Mobility uses `I18n.available_locales` to generate the form fields, but you can specify the languages on a per-field basis:
|
51
53
|
|
52
54
|
```ruby
|
53
|
-
|
55
|
+
mobility_text_field :title, locales: %w(nl de fr)
|
54
56
|
```
|
55
57
|
|
56
|
-
|
58
|
+
Quoting Mobility's README:
|
57
59
|
|
58
|
-
|
59
|
-
mobility_text_field :subtitle, selected: "nl"
|
60
|
-
```
|
60
|
+
> (Note however that Mobility will complain if you have I18n.enforce_available_locales set to true and you try accessing a locale not present in I18n.available_locales; set it to false if you want to allow any locale.)
|
61
61
|
|
62
|
-
|
62
|
+
## DeepL translation
|
63
63
|
|
64
64
|
<img src="/screenshot-deepl.png?raw=true" width="410" height="241" alt="Trestle Mobility DeepL integration screenshot" />
|
65
65
|
|
@@ -68,13 +68,3 @@ Trestle Mobility can automatically populate empty field values with translations
|
|
68
68
|
```ruby
|
69
69
|
config.mobility.deepl_api_key = "YOUR-API-KEY"
|
70
70
|
```
|
71
|
-
|
72
|
-
## Installation
|
73
|
-
|
74
|
-
These instructions assume you have a working Trestle application. To integrate trestle-mobility, first add it to your application's Gemfile:
|
75
|
-
|
76
|
-
```ruby
|
77
|
-
gem 'trestle-mobility'
|
78
|
-
```
|
79
|
-
|
80
|
-
Run `bundle install`, and then restart your Rails server.
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Trestle
|
2
|
+
module Mobility
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < ::Rails::Generators::Base
|
5
|
+
desc "Installs trestle-mobility"
|
6
|
+
|
7
|
+
def check_trestle_installed
|
8
|
+
unless ::File.exist?("config/initializers/trestle.rb")
|
9
|
+
raise Thor::Error, "The file config/initializers/trestle.rb does not appear to exist. Please run `trestle:install` first."
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def insert_configuration
|
14
|
+
inject_into_file "config/initializers/trestle.rb", before: /^end/ do
|
15
|
+
<<-RUBY.strip_heredoc.indent(2)
|
16
|
+
|
17
|
+
# == Mobility Options
|
18
|
+
#
|
19
|
+
# Specify the default selected locale
|
20
|
+
#
|
21
|
+
# config.mobility.selected = -> { I18n.locale }
|
22
|
+
|
23
|
+
# Specify your DeepL Pro API key to easily translate values
|
24
|
+
#
|
25
|
+
# config.mobility.deepl_api_key = "YOUR-API-KEY"
|
26
|
+
RUBY
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -5,7 +5,7 @@ module Trestle
|
|
5
5
|
def field
|
6
6
|
label = options[:label] || name.to_s.humanize
|
7
7
|
locales = options[:locales] || I18n.available_locales.sort
|
8
|
-
selected = options[:selected] || Trestle.config.mobility.selected || locales.first
|
8
|
+
selected = options[:selected] || Trestle.config.mobility.selected.call || locales.first
|
9
9
|
|
10
10
|
@template.render partial: "trestle/mobility/check_box",
|
11
11
|
locals: {
|
@@ -5,7 +5,7 @@ module Trestle
|
|
5
5
|
def field
|
6
6
|
label = options[:label] || name.to_s.humanize
|
7
7
|
locales = options[:locales] || I18n.available_locales.sort
|
8
|
-
selected = options[:selected] || Trestle.config.mobility.selected || locales.first
|
8
|
+
selected = options[:selected] || Trestle.config.mobility.selected.call || locales.first
|
9
9
|
rows = options[:rows] || 5
|
10
10
|
|
11
11
|
@template.render partial: "trestle/mobility/text_area",
|
@@ -5,7 +5,7 @@ module Trestle
|
|
5
5
|
def field
|
6
6
|
label = options[:label] || name.to_s.humanize
|
7
7
|
locales = options[:locales] || I18n.available_locales.sort
|
8
|
-
selected = options[:selected] || Trestle.config.mobility.selected || locales.first
|
8
|
+
selected = options[:selected] || Trestle.config.mobility.selected.call || locales.first
|
9
9
|
|
10
10
|
@template.render partial: "trestle/mobility/text_field",
|
11
11
|
locals: {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trestle-mobility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Venneman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: emoji_flag
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- bin/setup
|
105
105
|
- config/initializers/trestle.rb
|
106
106
|
- config/routes.rb
|
107
|
+
- lib/generators/trestle/mobility/install/install_generator.rb
|
107
108
|
- lib/trestle/mobility.rb
|
108
109
|
- lib/trestle/mobility/configuration.rb
|
109
110
|
- lib/trestle/mobility/engine.rb
|