trestle-mobility 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a43a43d7175e12ad8e187b457104e27f4d273a0fb94f8f83f8f6f39fb2e409fa
4
- data.tar.gz: f6b84afec6c7eb6f418ae541cc8b907a6043feeec9aebd7788f3807e8871788d
3
+ metadata.gz: 61f40dc820abfc72674027e455750a9c9b6011bed7a16ea257013407895cfe57
4
+ data.tar.gz: a6f35d96c0ce62a1b31de8441de8341a5372ea1657ce3b227256540d27ecde45
5
5
  SHA512:
6
- metadata.gz: 72d5f7c872fc6aa8b0700458cbce9de3f96ea49b658a74b4921d3a6e1948a77507dac6993de77c371433808f7c30bf95444fc09be4faaf8ef32bfdd9d16e3b7d
7
- data.tar.gz: 956dd0052b15112ed083ece196ab65642fd5f0ad01eda5f8ea2d9a1863a8718af92df66ee502c94f6099feab3da3522e8c24c668a7d5890982ed875a290bab79
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
- ### Specifying locales
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 :title, locales: %w(nl de fr)
49
+ mobility_text_field :subtitle, selected: "nl"
40
50
  ```
41
51
 
42
- Quoting Mobility's README:
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
- config.mobility.selected = "nl"
55
+ mobility_text_field :title, locales: %w(nl de fr)
54
56
  ```
55
57
 
56
- Or specify it per field:
58
+ Quoting Mobility's README:
57
59
 
58
- ```ruby
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
- ### DeepL translation
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
@@ -3,7 +3,7 @@ module Trestle
3
3
  class Configuration
4
4
  include Configurable
5
5
 
6
- option :selected
6
+ option :selected, -> { I18n.locale }, evaluate: false
7
7
  option :deepl_api_key
8
8
  end
9
9
  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: {
@@ -1,5 +1,5 @@
1
1
  module Trestle
2
2
  module Mobility
3
- VERSION = "0.5.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
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.5.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-17 00:00:00.000000000 Z
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