tolken 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: b3982f597caf542d522bb931de37a824bfb4bfa7f07f79e018b49136e14dd8e3
4
- data.tar.gz: 55ccc2f5ed3b4def93576e4433237ca3366d865d848b844ab4ce77bff4836b5a
3
+ metadata.gz: 9e3b810d92ead0e93a5131e336d22f2f66425549eb0df62a013b27506450d086
4
+ data.tar.gz: 8137c3c286daf8052cc07584d01ddffc3db1f5a2e1e2379f88bc2d73b032c081
5
5
  SHA512:
6
- metadata.gz: 61ba31f2e6211d202b888924f7d193ca2ca1ccd5b8a6cca7f988484aea10b05f0764e6380dfc7884d95d8768901111778d38982b6256149d7fafb4c69ee0766a
7
- data.tar.gz: 074a77eaaee80949ab13957dcd22aa19ee7a415bb5d124e01b878ad2100bb311f037552d805bad25c5952513d4396733f4f75c0b77523622cc42f1b5abf7d7e0
6
+ metadata.gz: 9578b5db99672f9c51af74dea5d88b8640c2420cd635a12dffcf95151af7d660be82ca7286119a1a50319029d51bdde0b8b63a71c1985bf4ea802b0736555413
7
+ data.tar.gz: c8d80d8c6a40691716920b95e5bd4dcb4f028edd9b9ddc76e9471df5a691be3a9dd3c061ff948673a424a61e054d584b9272de033d64badadaeb7e8b4053ef01
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tolken (0.1.0)
4
+ tolken (0.3.0)
5
5
  rails (= 5.2.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  # Tolken
2
2
  Tolken is a Ruby on Rails Gem that allows you to translate database fields using Postgres' jsob data type.
3
3
 
4
- Tolken's API is more verbose than most similar gems. The philosophy is that you should be aware of when you're dealing with translatable fields and what language you're interested in in any given moment. This comes from experience working with gems such as [Globalize](https://github.com/globalize/globalize), while it might fit some projects we've found that the magic that starts out as a convenience quickly becomes a liability.
5
-
6
- In Tolken a translatable field is just a Ruby hash which makes it easy to reason about. See *Usage* for details.
4
+ Tolken's API is more verbose than most similar gems. The idea is that you should be aware of when you're dealing with translatable fields and what language you're interested in in any given moment. In Tolken a translatable field is just a Ruby hash which makes it easy to reason about. See *Usage* for details.
7
5
 
8
6
  [![Build Status](https://travis-ci.org/varvet/tolken.svg?branch=master)](https://travis-ci.org/varvet/tolken)
9
7
  [![Maintainability](https://api.codeclimate.com/v1/badges/72c772179a8baa586f7f/maintainability)](https://codeclimate.com/github/varvet/tolken/maintainability)
@@ -68,7 +66,11 @@ post = Post.create(title: { en: "News", sv: "Nyheter" })
68
66
  post.title # => { en: "News", sv: "Nyheter" }
69
67
  post.title(:en) # => "News"
70
68
  post.title(:sv) # => "Nyheter"
69
+ post.title("sv") # => "Nyheter"
70
+ post.title[:en] # => "News"
71
+ post.title["en"] # => "News"
71
72
  post.title(:dk) # ArgumentError, "Invalid locale dk"
73
+ post.title[:dk] # => nil
72
74
  post.title(:de) # => nil
73
75
 
74
76
  post.title = { en: "News", sv: "Nyheter" }
@@ -91,10 +93,10 @@ post.errors.messages # => { name_sv: ["can't be blank"] }
91
93
  Tolken checks that all `I18n.available_locales` has present values.
92
94
 
93
95
  ### View Forms
94
- Tolken has opt-in support for integrating with [SimpleForm](https://github.com/plataformatec/simple_form). To opt-in update your Gemfile:
96
+ While creating form inputs for your locale versions are as simple as adding `[<locale>]` to the html name attribute Tolken provides opt-in support for integrating with [SimpleForm](https://github.com/plataformatec/simple_form). To opt-in update your Gemfile:
95
97
 
96
98
  ```ruby
97
- gem "tolken", require: "tolken/simle_form"
99
+ gem "tolken", require: "tolken/simple_form"
98
100
  ```
99
101
 
100
102
  Now if you add a simple_form field for a translatable field SimpleForm will generate an input per language version:
@@ -112,6 +114,19 @@ By default a text input field is generated. If you want another type you can ove
112
114
  <%= form.input :title, type: :text %>
113
115
  ```
114
116
 
117
+ Without simple form your inputs might look something like:
118
+
119
+ ```html
120
+ <input name="post[title][en]" id="post_title_en">
121
+ <input name="post[title][sv]" id="post_title_sv">
122
+ ```
123
+
124
+ Don't forget whitelist the nested locale params in your controller:
125
+
126
+ ```rb
127
+ params.require(:post).permit(title: I18n.available_locales)
128
+ ```
129
+
115
130
  This will instead render one text area per language version.
116
131
 
117
132
  The specs for [translates](spec/tolken/translates_spec.rb) is a good resource of additional usage examples.
@@ -127,7 +142,11 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
127
142
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
128
143
 
129
144
  ## Contributing
130
- Bug reports and pull requests are welcome on GitHub at https://github.com/varvet/tolken. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. To create a pull request follow these steps:
145
+ Bug reports and pull requests are welcome on GitHub at https://github.com/varvet/tolken. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
146
+
147
+ If you use and like Tolken but find yourself adding features that you're missing in Tolken please consider submitting a pull request!
148
+
149
+ To create a pull request follow these steps:
131
150
 
132
151
  $ git clone git@github.com:varvet/tolken.git
133
152
  $ cd tolken
File without changes
@@ -7,7 +7,10 @@ module Tolken
7
7
  serialize(field_name, HashSerializer)
8
8
 
9
9
  if options[:presence]
10
- store_accessor(field_name, *I18n.available_locales.map { |locale| "#{field_name}_#{locale}" })
10
+ validation_names = I18n.available_locales.map { |locale| "#{field_name}_#{locale}" }
11
+ readers = store_accessor(field_name, *validation_names)
12
+ private(*(readers + readers.map { |name| "#{name}=" }))
13
+
11
14
  define_validator(field_name) if options[:presence]
12
15
  end
13
16
  end
@@ -16,10 +19,10 @@ module Tolken
16
19
 
17
20
  def define_getter(field_name)
18
21
  define_method(field_name) do |locale = nil|
19
- return self[field_name.to_sym] unless locale
22
+ return self[field_name] unless locale
20
23
 
21
24
  begin
22
- self[field_name.to_sym].fetch(locale.to_s)
25
+ self[field_name].fetch(locale.to_s)
23
26
  rescue IndexError
24
27
  raise ArgumentError, "Invalid locale #{locale}" unless I18n.available_locales.include?(locale.to_sym)
25
28
  nil
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tolken
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/tolken.gemspec CHANGED
@@ -7,8 +7,8 @@ require "tolken/version"
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = "tolken"
9
9
  spec.version = Tolken::VERSION
10
- spec.authors = ["Nicklas Ramhöj, Julia Fridberg"]
11
- spec.email = ["nicklas.ramhoj@varvet.com, julia.fridberg@varvet.com"]
10
+ spec.authors = ["Nicklas Ramhöj, Julia Friberg"]
11
+ spec.email = ["nicklas.ramhoj@varvet.com, julia.friberg@varvet.com"]
12
12
 
13
13
  spec.summary = "A down-to-earth database translation Gem for Rails using psql jsonb"
14
14
  spec.description = """
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tolken
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
- - Nicklas Ramhöj, Julia Fridberg
7
+ - Nicklas Ramhöj, Julia Friberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-09 00:00:00.000000000 Z
11
+ date: 2018-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -173,7 +173,7 @@ description: "\n A down-to-earth database translation Gem for Rails using psq
173
173
  a translatable field is just a Ruby hash which makes it easy to reason about.\n
174
174
  \ "
175
175
  email:
176
- - nicklas.ramhoj@varvet.com, julia.fridberg@varvet.com
176
+ - nicklas.ramhoj@varvet.com, julia.friberg@varvet.com
177
177
  executables: []
178
178
  extensions: []
179
179
  extra_rdoc_files: []
@@ -191,7 +191,7 @@ files:
191
191
  - bin/setup
192
192
  - lib/tolken.rb
193
193
  - lib/tolken/hash_serializer.rb
194
- - lib/tolken/simle_form.rb
194
+ - lib/tolken/simple_form.rb
195
195
  - lib/tolken/translates.rb
196
196
  - lib/tolken/version.rb
197
197
  - tolken.gemspec