trestle-mobility 0.2.0 → 0.3.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: b024ad069d14e6c5e42fb4a0cfc42d6e5469316f4ab1c3c3bb1e4274f34b044a
4
- data.tar.gz: 1b0ea2bb3aeac07751382ba28b6ba151fee47c3da098d948c4624b0e4deabf4e
3
+ metadata.gz: 4e6d354d0c59601aba494962abac3bd8ed37a00ec1f5b364c233cd656f962312
4
+ data.tar.gz: 488ed9a24935e94a825d96f6f9429845d8ec932abb3eaacdfd9ca9f5e5d1125b
5
5
  SHA512:
6
- metadata.gz: dcbce616ed0a7a43c1b79877da54c7804fd7634054870d1a41f46f89fd7b684b4cd4a120dc0e0af14d280c8863e8727b3ae90b39532efcdae1fdef71a557a801
7
- data.tar.gz: dcbf2ea3f704dfa59fc25a2cd6c7537ec3f467bd0f5792e673ed01979450e9f1aa7a5d7cb0abec29570791cc9feec91785af4a67e804eeadfccca15e1cfa83db
6
+ metadata.gz: '0791933b2b6732b353a663ac9dc4e0d6c2326da3a6312a4cc4627569cc93827600ad1b5da8205e2a7d528479e7d817ed68af6b5d61358d5e6073c3dceafcc7a8'
7
+ data.tar.gz: 4708fc86e840507be062dae338c3b92715872754b59c1c175209e951dfefa15dc9af0b3fc9af16faaff763281af64f9df574b634cf01772854059e1c566aa33f
data/README.md CHANGED
@@ -10,11 +10,11 @@
10
10
  - Supports Postgres container back-end
11
11
  - Probably works with other back-ends but has not been tested
12
12
 
13
- ![Trestle Mobility screenshot](/screenshot.png?raw=true "Trestle Mobility screenshot")
13
+ <img src="/screenshot.png?raw=true" width="529" height="242" alt="Trestle Mobility screenshot" />
14
14
 
15
15
  ## Usage
16
16
 
17
- Trestle Mobility requires you to enable [Mobility's `locale_accessors` plugin](https://github.com/shioyama/mobility#getset) to be enabled.
17
+ Trestle Mobility requires you to enable [Mobility's `locale_accessors` plugin](https://github.com/shioyama/mobility#getset).
18
18
 
19
19
  Assuming you've setup your models with Mobility's `translates` directives, you can use the `mobility_text_field` and `mobility_text_area` field types:
20
20
 
@@ -36,10 +36,26 @@ By default Trestle Mobility uses `I18n.available_locales` to generate the form f
36
36
  mobility_text_field :title, locales: %w(nl de fr)
37
37
  ```
38
38
 
39
- Quoting from Mobility's README:
39
+ Quoting Mobility's README:
40
40
 
41
41
  > (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.)
42
42
 
43
+ ### Default language selection
44
+
45
+ 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.
46
+
47
+ To set the default language that should be selected for all fields, add the following line to your Trestle initializer:
48
+
49
+ ```ruby
50
+ config.mobility.selected = "nl"
51
+ ```
52
+
53
+ Or specify it per field:
54
+
55
+ ```ruby
56
+ mobility_text_field :subtitle, selected: "nl"
57
+ ```
58
+
43
59
  ## Installation
44
60
 
45
61
  These instructions assume you have a working Trestle application. To integrate trestle-mobility, first add it to your application's Gemfile:
@@ -0,0 +1,46 @@
1
+ Trestle.ready(function() {
2
+ function init() {
3
+ $('.mobility').each(function() {
4
+ new Mobility(this);
5
+ })
6
+ }
7
+
8
+ function Mobility (element) {
9
+ var element = $(element);
10
+ var activeLocale = element.data('active');
11
+ var button = element.find('.mobility-active');
12
+ var inputFields = element.find('.mobility-field');
13
+ var dropdownItems = element.find('.dropdown-item');
14
+
15
+ function toggle (flag) {
16
+ $(inputFields).each(function() {
17
+ var field = $(this);
18
+ var active = field.data('locale') !== activeLocale;
19
+
20
+ field.toggleClass('hidden', active)
21
+ })
22
+
23
+ $(dropdownItems).each(function() {
24
+ var field = $(this);
25
+ var active = field.data('locale') === activeLocale;
26
+
27
+ field.toggleClass('active', active)
28
+ })
29
+
30
+ if (flag) {
31
+ button.text(flag);
32
+ }
33
+ }
34
+
35
+ element.find('.dropdown-item').on('click', function () {
36
+ var item = $(this);
37
+ activeLocale = item.data('locale');
38
+
39
+ toggle(item.text());
40
+ });
41
+
42
+ toggle()
43
+ }
44
+
45
+ init();
46
+ });
@@ -1,17 +1,13 @@
1
- <div>
2
- <ul class="nav nav-tabs" role="tablist">
3
- <% locales.each.with_index do |locale, index| %>
4
- <li role="presentation"<%= ' class=active' if index.zero? %>>
5
- <a href="#<%= "#{field_name}_#{locale}" %>" aria-controls="<%= locale %>" role="tab" data-toggle="tab"><%= EmojiFlag.new(locale) %></a>
6
- </li>
1
+ <div class="input-group mobility" data-active="<%= selected %>">
2
+ <button type="button" class="btn btn-default dropdown-toggle input-group-addon" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
3
+ <span class="mobility-active"><%= "#{EmojiFlag.new(selected)} #{selected.upcase}" %></span> <span class="caret"></span>
4
+ </button>
5
+ <ul class="dropdown-menu">
6
+ <% locales.each do |locale| %>
7
+ <li><a href="#<%= "#{field_name}_#{locale}" %>" class="dropdown-item" data-locale="<%= locale %>"><%= "#{EmojiFlag.new(locale)} #{locale.upcase}" %></a></li>
7
8
  <% end %>
8
9
  </ul>
9
-
10
- <div class="tab-content">
11
- <% locales.each.with_index do |locale, index| %>
12
- <div role="tabpanel" class="tab-pane<%= " active" if index.zero? %>" id="<%= "#{field_name}_#{locale}" %>">
13
- <%= form.text_area "#{field_name}_#{locale}", label: false, placeholder: "#{field_name.capitalize} (#{locale.upcase})", rows: rows %>
14
- </div>
15
- <% end %>
16
- </div>
10
+ <% locales.each do |locale, index| %>
11
+ <%= form.raw_text_area "#{field_name}_#{locale}", class: "form-control mobility-field#{locale == selected ? '' : ' hidden'}", placeholder: "#{field_name.to_s.humanize} (#{locale.upcase})", rows: rows, data: { locale: locale } %>
12
+ <% end %>
17
13
  </div>
@@ -1,17 +1,15 @@
1
- <div>
2
- <ul class="nav nav-tabs" role="tablist">
3
- <% locales.each.with_index do |locale, index| %>
4
- <li role="presentation"<%= ' class=active' if index.zero? %>>
5
- <a href="#<%= "#{field_name}_#{locale}" %>" aria-controls="<%= locale %>" role="tab" data-toggle="tab"><%= EmojiFlag.new(locale) %></a>
6
- </li>
7
- <% end %>
8
- </ul>
9
-
10
- <div class="tab-content">
11
- <% locales.each.with_index do |locale, index| %>
12
- <div role="tabpanel" class="tab-pane<%= " active" if index.zero? %>" id="<%= "#{field_name}_#{locale}" %>">
13
- <%= form.text_field "#{field_name}_#{locale}", label: false, placeholder: "#{field_name.capitalize} (#{locale.upcase})" %>
14
- </div>
15
- <% end %>
1
+ <div class="input-group mobility" data-active="<%= selected %>">
2
+ <div class="input-group-btn">
3
+ <button type="button" class="btn btn-default dropdown-toggle" 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">
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>
16
11
  </div>
12
+ <% locales.each do |locale| %>
13
+ <%= form.raw_text_field "#{field_name}_#{locale}", class: "form-control mobility-field#{locale == selected ? '' : ' hidden'}", placeholder: "#{field_name.to_s.humanize} (#{locale.upcase})", data: { locale: locale } %>
14
+ <% end %>
17
15
  </div>
@@ -2,6 +2,10 @@ require "trestle/mobility/text_area"
2
2
  require "trestle/mobility/text_field"
3
3
 
4
4
  Trestle.configure do |config|
5
+ config.hook(:javascripts) do
6
+ javascript_include_tag('trestle/mobility_fields.js')
7
+ end
8
+
5
9
  config.form_field :mobility_text_area, Trestle::Mobility::TextArea
6
10
  config.form_field :mobility_text_field, Trestle::Mobility::TextField
7
11
  end
@@ -0,0 +1,9 @@
1
+ module Trestle
2
+ module Mobility
3
+ class Configuration
4
+ include Configurable
5
+
6
+ option :selected
7
+ end
8
+ end
9
+ end
@@ -1,6 +1,7 @@
1
1
  module Trestle
2
2
  module Mobility
3
3
  class Engine < Rails::Engine
4
+ config.assets.precompile << 'trestle/mobility_fields.js'
4
5
  end
5
6
  end
6
7
  end
@@ -4,10 +4,16 @@ module Trestle
4
4
  def field
5
5
  instance = builder.object
6
6
  locales = options[:locales] || I18n.available_locales.sort
7
+ selected = options[:selected] || Trestle.config.mobility.selected || locales.first
7
8
  rows = options[:rows] || 5
8
9
 
9
10
  @template.render partial: "trestle/mobility/text_area",
10
- locals: { field_name: name, locales: locales, rows: rows }
11
+ locals: {
12
+ field_name: name,
13
+ locales: locales,
14
+ selected: selected,
15
+ rows: rows
16
+ }
11
17
  end
12
18
  end
13
19
  end
@@ -4,9 +4,14 @@ module Trestle
4
4
  def field
5
5
  instance = builder.object
6
6
  locales = options[:locales] || I18n.available_locales.sort
7
+ selected = options[:selected] || Trestle.config.mobility.selected || locales.first
7
8
 
8
9
  @template.render partial: "trestle/mobility/text_field",
9
- locals: { field_name: name, locales: locales }
10
+ locals: {
11
+ field_name: name,
12
+ locales: locales,
13
+ selected: selected
14
+ }
10
15
  end
11
16
  end
12
17
  end
@@ -1,5 +1,5 @@
1
1
  module Trestle
2
2
  module Mobility
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -1,4 +1,8 @@
1
1
  require "emoji_flag"
2
+
2
3
  require "trestle"
3
4
  require "trestle/mobility/version"
5
+ require "trestle/mobility/configuration"
4
6
  require "trestle/mobility/engine" if defined?(Rails)
7
+
8
+ Trestle::Configuration.option :mobility, Trestle::Mobility::Configuration.new
data/screenshot.png CHANGED
Binary file
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ["lib"]
25
25
 
26
26
  spec.add_dependency "emoji_flag", "~> 0.1"
27
+ spec.add_dependency "mobility", "~> 0.8"
27
28
 
28
29
  spec.add_development_dependency "bundler", "~> 2.0"
29
30
  spec.add_development_dependency "rake", "~> 10.0"
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.2.0
4
+ version: 0.3.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-04-08 00:00:00.000000000 Z
11
+ date: 2019-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: emoji_flag
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mobility
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -79,12 +93,14 @@ files:
79
93
  - LICENSE.md
80
94
  - README.md
81
95
  - Rakefile
96
+ - app/assets/javascript/trestle/mobility_fields.js
82
97
  - app/views/trestle/mobility/_text_area.html.erb
83
98
  - app/views/trestle/mobility/_text_field.html.erb
84
99
  - bin/console
85
100
  - bin/setup
86
101
  - config/initializers/trestle.rb
87
102
  - lib/trestle/mobility.rb
103
+ - lib/trestle/mobility/configuration.rb
88
104
  - lib/trestle/mobility/engine.rb
89
105
  - lib/trestle/mobility/text_area.rb
90
106
  - lib/trestle/mobility/text_field.rb