trestle-mobility 1.0.0 → 1.4.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: 61f40dc820abfc72674027e455750a9c9b6011bed7a16ea257013407895cfe57
4
- data.tar.gz: a6f35d96c0ce62a1b31de8441de8341a5372ea1657ce3b227256540d27ecde45
3
+ metadata.gz: e4975d7d0e80af83f7b3cfa3b7ae2b44271a480a95633d22e94bde04ab05c63c
4
+ data.tar.gz: 4e3286506ad4402daa7ae713512a3dabc427b8a228f1509cc060830e5992750a
5
5
  SHA512:
6
- metadata.gz: e3c4546221bf0a30e3d04bbf41b04513abe31177af38d1b5e9fe04b01d0ac30da33dc94e5ba96974a612badf78f7eaa70571905666ffb52e725fc211d8aa702e
7
- data.tar.gz: bdf55d61911e8923ff421fc14a1d3bb80f42fcb8e08b500dfffd9bc3b0dc7a7a83134835d14b00c7672455ab995b77870eaf1c100d88cfc8cd94c6e118d4d02d
6
+ metadata.gz: 63d50b633c31eaa5ee891bbb8b82942fbadd2a5579bb14fc7abc6e838ce05843ee9021b9e33330d66880576119fa65cc06c7fc7902bf5e833f13bb9b84d6c4f7
7
+ data.tar.gz: 7629c8c73cb70615fb7188c060c3dded5d15249264e720c54e4fd4e9375751c231c821b35ba13d65b80c65f2a162fc1b0e1ed144f7f760eb045c38c058b67f2a
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.4.0] - 2020-12-08
10
+ - Ability to customise placeholder on the fields ([#5](https://github.com/richardvenneman/trestle-mobility/pull/5), thanks [@asad-ali-bhatti](https://github.com/asad-ali-bhatti))
11
+
12
+ ## [1.3.0] - 2019-11-08
13
+ ### Added
14
+ - Support for Bootstrap 4 (that comes with Trestle 0.9.0)
15
+
16
+ ## [1.2.0] - 2019-08-14
17
+ ### Added
18
+ - Start documenting changes
19
+
20
+ ### Changed
21
+ - Support nested forms ([#3](https://github.com/richardvenneman/trestle-mobility/pull/3))
data/README.md CHANGED
@@ -9,8 +9,6 @@
9
9
  - Manage Mobility translations with a space-efficient dropdown interface in Trestle
10
10
  - Supports text fields, text area's and check boxes
11
11
  - Integrates with [DeepL Pro](https://www.deepl.com/pro.html) to automatically translate fields
12
- - Developed for usage with Mobility's Postgres container back-end
13
- - Probably works with other back-ends but has not been tested
14
12
 
15
13
  <img src="/screenshot.png?raw=true" width="529" height="242" alt="Trestle Mobility screenshot" />
16
14
 
@@ -24,7 +22,7 @@ gem 'trestle-mobility'
24
22
 
25
23
  Run `bundle install`, and then run the install generator to set up configuration options.
26
24
 
27
- $ rails generate trestle:auth:install
25
+ $ rails generate trestle:mobility:install
28
26
 
29
27
  ## Usage
30
28
 
@@ -68,3 +66,9 @@ Trestle Mobility can automatically populate empty field values with translations
68
66
  ```ruby
69
67
  config.mobility.deepl_api_key = "YOUR-API-KEY"
70
68
  ```
69
+
70
+ It is possible to pass any DeepL API options to the field (check out the [deepl-rb documentation](https://github.com/wikiti/deepl-rb#translate) section on params):
71
+
72
+ ```ruby
73
+ mobility_text_area :content, rows: 14, deepl_query_params: { tag_handling: "xml" }
74
+ ```
@@ -22,7 +22,7 @@ Trestle.init(function(e, root) {
22
22
  this.$inputFields.each(function() {
23
23
  var field = $(this);
24
24
  var active = field.data('locale') !== self.activeLocale;
25
- field.toggleClass('hidden', active)
25
+ field.toggleClass('mobility-field--hidden', active)
26
26
  })
27
27
 
28
28
  this.$dropdownItems.each(function() {
@@ -64,11 +64,13 @@ Trestle.init(function(e, root) {
64
64
  Mobility.prototype.deeplTranslate = function (fromLocale) {
65
65
  var self = this;
66
66
  var path = this.$deeplTranslationAction.data('remote-path');
67
+ var queryParams = this.$deeplTranslationAction.data('deepl-query-params');
67
68
  var data = {
68
69
  translation: {
69
70
  text: this.getFieldByLocale(fromLocale).val(),
70
71
  from_locale: fromLocale,
71
- to_locale: this.activeLocale
72
+ to_locale: this.activeLocale,
73
+ query_params: queryParams
72
74
  }
73
75
  }
74
76
 
@@ -1,28 +1,64 @@
1
1
  .mobility {
2
+ .input-group-prepend {
3
+ display: flex;
4
+
5
+ .btn {
6
+ border-top-right-radius: 0;
7
+ border-bottom-right-radius: 0;
8
+ }
9
+ }
10
+
11
+ .dropdown-toggle {
12
+ border-width: 1px;
13
+ }
14
+
15
+ .dropdown-item {
16
+ display: block;
17
+ width: 100%;
18
+ padding: .25rem 1.5rem;
19
+ clear: both;
20
+ font-weight: 400;
21
+ text-align: inherit;
22
+ white-space: nowrap;
23
+ border: 0;
24
+
25
+ &:not(:hover, .active) {
26
+ color: #212529;
27
+ background-color: transparent;
28
+ }
29
+ }
30
+
2
31
  .dropdown-item.disabled,
3
32
  .dropdown-item.disabled:visited,
4
33
  .dropdown-item.disabled:active,
5
34
  .dropdown-item.disabled:hover {
6
- background-color:#d9d9d9 !important;
7
- color:#aaa !important;
35
+ background-color: #d9d9d9 !important;
36
+ color: #aaa !important;
8
37
  opacity: 0.7;
9
38
  cursor: default;
10
39
  }
11
- }
12
40
 
13
- .mobility-checkbox {
14
- display: flex;
15
- align-items:center;
41
+ .form-control {
42
+ border-left-width: 0;
43
+ border-top-right-radius: .25rem !important;
44
+ border-bottom-right-radius: .25rem !important;
45
+ }
16
46
  }
17
47
 
18
- .mobility-checkbox__label {
19
- margin-left: 8px;
48
+ .mobility-field {
49
+ &--hidden {
50
+ display: none !important;
51
+ }
20
52
  }
21
53
 
22
-
23
- .mobility__deepl-progress {
24
- display: none;
25
- margin-right: 4px;
54
+ .mobility-checkbox {
55
+ margin-right: 0;
56
+ flex: 1;
57
+ padding: 0 8px;
58
+ border: solid #ccc;
59
+ border-width: 1px 1px 1px;
60
+ border-top-right-radius: .25rem;
61
+ border-bottom-right-radius: .25rem;
26
62
  }
27
63
 
28
64
  .mobility__deepl {
@@ -30,10 +66,8 @@
30
66
  margin-top: 4px;
31
67
  text-align: right;
32
68
 
33
- .progress {
34
- display: inline-block;
35
- width: 97px;
36
- margin-right: 4px;
69
+ .spinner-border {
70
+ display: none;
37
71
  }
38
72
 
39
73
  &--actionable {
@@ -41,7 +75,7 @@
41
75
  }
42
76
 
43
77
  &--active {
44
- .mobility__deepl-progress {
78
+ .spinner-border {
45
79
  display: inline-block;
46
80
  }
47
81
  }
@@ -3,7 +3,8 @@ class Trestle::Mobility::TranslationsController < Trestle::ApplicationController
3
3
  translation = Trestle::Mobility::Translators::DeeplTranslator.new.translate(
4
4
  translation_params[:text],
5
5
  translation_params[:from_locale],
6
- translation_params[:to_locale]
6
+ translation_params[:to_locale],
7
+ translation_params[:query_params] || {}
7
8
  )
8
9
 
9
10
  render plain: translation
@@ -11,6 +12,6 @@ class Trestle::Mobility::TranslationsController < Trestle::ApplicationController
11
12
 
12
13
  private
13
14
  def translation_params
14
- params.require(:translation).permit(:text, :from_locale, :to_locale)
15
+ params.require(:translation).permit(:text, :from_locale, :to_locale, query_params: {})
15
16
  end
16
17
  end
@@ -1,20 +1,20 @@
1
1
  <div class="form-group mobility" data-active="<%= selected %>">
2
2
  <div class="input-group">
3
- <div class="input-group-btn">
4
- <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
3
+ <div class="input-group-prepend">
4
+ <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
5
5
  <span class="mobility-active"><%= "#{EmojiFlag.new(selected)} #{selected.upcase}" %></span> <span class="caret"></span>
6
6
  </button>
7
- <ul class="dropdown-menu mobility__languages">
7
+ <div class="dropdown-menu mobility__languages">
8
8
  <% locales.each do |locale| %>
9
- <li><a href="#<%= "#{field_name}_#{locale}" %>" class="dropdown-item" data-locale="<%= locale %>"><%= "#{EmojiFlag.new(locale)} #{locale.upcase}" %></a></li>
9
+ <a href="#<%= "#{field_name}_#{locale}" %>" class="dropdown-item" data-locale="<%= locale %>"><%= "#{EmojiFlag.new(locale)} #{locale.upcase}" %></a>
10
10
  <% end %>
11
- </ul>
11
+ </div>
12
12
  </div>
13
13
  <% locales.each do |locale| %>
14
14
  <%=
15
- content_tag(:div, "#{field_name.to_s.humanize} (#{locale.upcase})", { class: "form-control mobility-checkbox mobility-field#{locale == selected ? '' : ' hidden'}", data: { locale: locale } }) do
16
- form.raw_check_box("#{field_name}_#{locale}", { class: "mobility-checkbox__input" }, "1", "0") +
17
- form.label("#{field_name}_#{locale}", "#{label} (#{locale.upcase})", class: "mobility-checkbox__label")
15
+ content_tag(:div, "#{field_name.to_s.humanize} (#{locale.upcase})", { class: "form-check form-check-inline mobility-checkbox mobility-field#{locale == selected ? '' : ' mobility-field--hidden'}", data: { locale: locale } }) do
16
+ builder.raw_check_box("#{field_name}_#{locale}", { class: "form-check-input mobility-checkbox__input" }, "1", "0") +
17
+ builder.label("#{field_name}_#{locale}", "#{label} (#{locale.upcase})", class: "form-check-label mobility-checkbox__label")
18
18
  end
19
19
  %>
20
20
  <% end %>
@@ -1,14 +1,13 @@
1
- <div class="mobility__deepl" data-remote-path="<%= trestle.translate_path %>">
2
- <small class="mobility__deepl-progress">Translating…</small>
3
-
1
+ <div class="mobility__deepl" data-remote-path="<%= trestle.translate_path %>" data-deepl-query-params="<%= deepl_query_params %>">
4
2
  <div class="btn-group">
5
- <button class="btn btn-default btn-xs dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
6
- Translate from <span class="caret"></span>
3
+ <button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
4
+ <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
5
+ Translate from
7
6
  </button>
8
- <ul class="dropdown-menu mobility__deepl-languages">
7
+ <div class="dropdown-menu mobility__deepl-languages">
9
8
  <% locales.each do |locale| %>
10
- <li><a href="javascript:void(0)" class="dropdown-item" data-locale="<%= locale %>"><%= "#{EmojiFlag.new(locale)} #{locale.upcase}" %></a></li>
9
+ <a href="javascript:void(0)" class="dropdown-item" data-locale="<%= locale %>"><%= "#{EmojiFlag.new(locale)} #{locale.upcase}" %></a>
11
10
  <% end %>
12
- </ul>
11
+ </div>
13
12
  </div>
14
13
  </div>
@@ -1,18 +1,36 @@
1
1
  <div class="form-group mobility" data-active="<%= selected %>">
2
2
  <div class="input-group">
3
- <button type="button" class="btn btn-default dropdown-toggle input-group-addon" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
4
- <span class="mobility-active"><%= "#{EmojiFlag.new(selected)} #{selected.upcase}" %></span> <span class="caret"></span>
5
- </button>
6
- <ul class="dropdown-menu mobility__languages">
7
- <% locales.each do |locale| %>
8
- <li><a href="#<%= "#{field_name}_#{locale}" %>" class="dropdown-item" data-locale="<%= locale %>"><%= "#{EmojiFlag.new(locale)} #{locale.upcase}" %></a></li>
9
- <% end %>
10
- </ul>
11
- <% locales.each do |locale, index| %>
12
- <%= form.raw_text_area "#{field_name}_#{locale}", class: "form-control mobility-field#{locale == selected ? '' : ' hidden'}", placeholder: "#{label} (#{locale.upcase})", rows: rows, data: { locale: locale } %>
3
+ <div class="input-group-prepend">
4
+ <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
5
+ <span class="mobility-active"><%= "#{EmojiFlag.new(selected)} #{selected.upcase}" %></span> <span class="caret"></span>
6
+ </button>
7
+ <div class="dropdown-menu mobility__languages">
8
+ <% locales.each do |locale| %>
9
+ <a href="#<%= "#{field_name}_#{locale}" %>" class="dropdown-item" data-locale="<%= locale %>"><%= "#{EmojiFlag.new(locale)} #{locale.upcase}" %></a>
10
+ <% end %>
11
+ </div>
12
+ </div>
13
+ <% locales.each do |locale| %>
14
+ <%=
15
+ builder.raw_text_area(
16
+ "#{field_name}_#{locale}",
17
+ options.merge(
18
+ class: "form-control mobility-field#{locale == selected ? '' : ' mobility-field--hidden'}",
19
+ placeholder: options[:placeholder] || "#{label} (#{locale.upcase})",
20
+ data: { locale: locale }
21
+ )
22
+ )
23
+ %>
13
24
  <% end %>
14
25
  </div>
15
26
 
16
- <%= render(partial: "trestle/mobility/deepl_translation_action",
17
- locals: { locales: locales }) if Trestle.config.mobility.deepl_api_key %>
27
+ <%=
28
+ render(
29
+ partial: "trestle/mobility/deepl_translation_action",
30
+ locals: {
31
+ locales: locales,
32
+ deepl_query_params: deepl_query_params.to_json
33
+ }
34
+ ) if Trestle.config.mobility.deepl_api_key
35
+ %>
18
36
  </div>
@@ -1,20 +1,36 @@
1
1
  <div class="form-group mobility" data-active="<%= selected %>">
2
2
  <div class="input-group">
3
- <div class="input-group-btn">
4
- <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
3
+ <div class="input-group-prepend">
4
+ <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
5
5
  <span class="mobility-active"><%= "#{EmojiFlag.new(selected)} #{selected.upcase}" %></span> <span class="caret"></span>
6
6
  </button>
7
- <ul class="dropdown-menu mobility__languages">
7
+ <div class="dropdown-menu mobility__languages">
8
8
  <% locales.each do |locale| %>
9
- <li><a href="#<%= "#{field_name}_#{locale}" %>" class="dropdown-item" data-locale="<%= locale %>"><%= "#{EmojiFlag.new(locale)} #{locale.upcase}" %></a></li>
9
+ <a href="#<%= "#{field_name}_#{locale}" %>" class="dropdown-item" data-locale="<%= locale %>"><%= "#{EmojiFlag.new(locale)} #{locale.upcase}" %></a>
10
10
  <% end %>
11
- </ul>
11
+ </div>
12
12
  </div>
13
13
  <% locales.each do |locale| %>
14
- <%= form.raw_text_field "#{field_name}_#{locale}", class: "form-control mobility-field#{locale == selected ? '' : ' hidden'}", placeholder: "#{label} (#{locale.upcase})", data: { locale: locale } %>
14
+ <%=
15
+ builder.raw_text_field(
16
+ "#{field_name}_#{locale}",
17
+ options.merge(
18
+ class: "form-control mobility-field#{locale == selected ? '' : ' mobility-field--hidden'}",
19
+ placeholder: options[:placeholder] || "#{label} (#{locale.upcase})",
20
+ data: { locale: locale }
21
+ )
22
+ )
23
+ %>
15
24
  <% end %>
16
25
  </div>
17
26
 
18
- <%= render(partial: "trestle/mobility/deepl_translation_action",
19
- locals: { locales: locales }) if Trestle.config.mobility.deepl_api_key %>
27
+ <%=
28
+ render(
29
+ partial: "trestle/mobility/deepl_translation_action",
30
+ locals: {
31
+ locales: locales,
32
+ deepl_query_params: deepl_query_params.to_json
33
+ }
34
+ ) if Trestle.config.mobility.deepl_api_key
35
+ %>
20
36
  </div>
@@ -9,6 +9,7 @@ module Trestle
9
9
 
10
10
  @template.render partial: "trestle/mobility/check_box",
11
11
  locals: {
12
+ builder: builder,
12
13
  field_name: name,
13
14
  label: label,
14
15
  locales: locales,
@@ -2,19 +2,25 @@ module Trestle
2
2
  module Mobility
3
3
  module Fields
4
4
  class TextArea < Trestle::Form::Field
5
+ def defaults
6
+ super.merge(rows: 5)
7
+ end
8
+
5
9
  def field
6
10
  label = options[:label] || name.to_s.humanize
7
11
  locales = options[:locales] || I18n.available_locales.sort
8
12
  selected = options[:selected] || Trestle.config.mobility.selected.call || locales.first
9
- rows = options[:rows] || 5
13
+ deepl_query_params = options[:deepl_query_params] || {}
10
14
 
11
15
  @template.render partial: "trestle/mobility/text_area",
12
16
  locals: {
17
+ builder: builder,
18
+ options: options,
13
19
  field_name: name,
14
20
  label: label,
15
21
  locales: locales,
16
22
  selected: selected,
17
- rows: rows
23
+ deepl_query_params: deepl_query_params
18
24
  }
19
25
  end
20
26
  end
@@ -6,13 +6,17 @@ module Trestle
6
6
  label = options[:label] || name.to_s.humanize
7
7
  locales = options[:locales] || I18n.available_locales.sort
8
8
  selected = options[:selected] || Trestle.config.mobility.selected.call || locales.first
9
+ deepl_query_params = options[:deepl_query_params] || {}
9
10
 
10
11
  @template.render partial: "trestle/mobility/text_field",
11
12
  locals: {
13
+ builder: builder,
14
+ options: options,
12
15
  field_name: name,
13
16
  label: label,
14
17
  locales: locales,
15
- selected: selected
18
+ selected: selected,
19
+ deepl_query_params: deepl_query_params
16
20
  }
17
21
  end
18
22
  end
@@ -12,8 +12,8 @@ module Trestle::Mobility::Translators
12
12
  configure_api_key!
13
13
  end
14
14
 
15
- def translate(text, from, to)
16
- DeepL.translate(text, from, to)
15
+ def translate(text, from, to, query_params = {})
16
+ DeepL.translate(text, from, to, query_params)
17
17
  end
18
18
 
19
19
  private
@@ -1,5 +1,5 @@
1
1
  module Trestle
2
2
  module Mobility
3
- VERSION = "1.0.0"
3
+ VERSION = "1.4.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: 1.0.0
4
+ version: 1.4.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-18 00:00:00.000000000 Z
11
+ date: 2020-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: emoji_flag
@@ -89,6 +89,7 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
91
  - ".travis.yml"
92
+ - CHANGELOG.md
92
93
  - Gemfile
93
94
  - LICENSE.md
94
95
  - README.md
@@ -135,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
136
  - !ruby/object:Gem::Version
136
137
  version: '0'
137
138
  requirements: []
138
- rubygems_version: 3.0.3
139
+ rubygems_version: 3.1.2
139
140
  signing_key:
140
141
  specification_version: 4
141
142
  summary: Mobility integration plugin for the Trestle admin framework