hyper-i18n 0.99.6 → 1.0.alpha1

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: c3fb255f0c02f2541ee45b9ac84c86ab1fd063b309783f0fec29afb4e67a3ea4
4
- data.tar.gz: 5f6d7f9cfad8d88da9e902c5cc184b5fc304c3de7a9cab7bdf11125b83d21508
3
+ metadata.gz: 815d25223d341cbcf38f3ab25ac68597c68554739bb8e36d2e206ad82ed0eb04
4
+ data.tar.gz: 4e45db97954620b6d18b99a6384635a5a2d1a38004349a746d37bc138e27fcef
5
5
  SHA512:
6
- metadata.gz: 1031356addcfd1cec488ab0c3e46b8479df6212f2aefae2be18019bcd2eea39d1eb1baf9138f34dbbd5cb666bebe173e809eb44ef0acfff936d5fd112dc2b3c1
7
- data.tar.gz: 037c3891ce4c0d5230dbfde56663de5b0e8be11b4bf394fc898003f50bf3deeb8bbbcf15506ec295554260e35d40b90252b5a96d3ef83bf628625121e728e286
6
+ metadata.gz: 52565370c6593a96bfdf03ff2d652e3a6985deb996ce530e00a467db9227e5c52cb5df8eac3419d24a409bd245b69c892f41222d70c62fcdeb3efcd1532ca2a5
7
+ data.tar.gz: 39bb763c643d8e561686ed5119cb2d7a38f522626c99c6021a989ed9c4a6a2a00bcf2f5d0ebebe40567905ce4f0ddf2b6979c6774d383ff0877b9b76b3e05646
data/Gemfile CHANGED
@@ -3,7 +3,8 @@ source "https://rubygems.org"
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
  #gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master"
5
5
  gem 'hyper-spec', path: '../hyper-spec'
6
- gem 'hyperloop-config', path: '../hyperloop-config'
6
+ gem 'hyperstack-config', path: '../hyperstack-config'
7
+ gem 'hyper-state', path: '../hyper-state'
7
8
  gem 'hyper-store', path: '../hyper-store'
8
9
  gem 'hyper-component', path: '../hyper-component'
9
10
  gem 'hyper-operation', path: '../hyper-operation'
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: ../hyper-component
3
3
  specs:
4
- hyper-component (0.99.6)
5
- hyper-store (= 0.99.6)
6
- hyperloop-config (= 0.99.6)
7
- libv8 (~> 6.7.0)
8
- mini_racer (~> 0.2.4)
4
+ hyper-component (0.1)
5
+ hyper-state (= 0.1)
6
+ hyperstack-config (= 0.1)
7
+ libv8 (~> 6.3.0)
8
+ mini_racer (~> 0.1.15)
9
9
  opal (>= 0.11.0, < 0.12.0)
10
10
  opal-activesupport (~> 0.3.1)
11
11
  react-rails (>= 2.4.0, < 2.5.0)
@@ -13,30 +13,31 @@ PATH
13
13
  PATH
14
14
  remote: ../hyper-model
15
15
  specs:
16
- hyper-model (0.99.6)
16
+ hyper-model (0.1)
17
17
  activemodel
18
18
  activerecord (>= 4.0.0)
19
- hyper-component (= 0.99.6)
20
- hyper-operation (= 0.99.6)
19
+ hyper-component (= 0.1)
20
+ hyper-operation (= 0.1)
21
+ hyper-store (= 0.1)
21
22
 
22
23
  PATH
23
24
  remote: ../hyper-operation
24
25
  specs:
25
- hyper-operation (0.99.6)
26
+ hyper-operation (0.1)
26
27
  activerecord (>= 4.0.0)
27
- hyper-component (= 0.99.6)
28
+ hyper-component (= 0.1)
28
29
  mutations
29
30
  opal-activesupport (~> 0.3.1)
30
31
 
31
32
  PATH
32
33
  remote: ../hyper-spec
33
34
  specs:
34
- hyper-spec (0.99.6)
35
+ hyper-spec (0.1)
35
36
  capybara
36
37
  chromedriver-helper (= 1.2.0)
37
- libv8 (~> 6.7.0)
38
+ libv8 (~> 6.3.0)
38
39
  method_source
39
- mini_racer (~> 0.2.4)
40
+ mini_racer (~> 0.1.15)
40
41
  opal (>= 0.11.0, < 0.12.0)
41
42
  parser (>= 2.3.3.1)
42
43
  pry
@@ -44,31 +45,41 @@ PATH
44
45
  selenium-webdriver
45
46
  timecop (~> 0.8.1)
46
47
  uglifier
47
- unparser (~> 0.3.0)
48
+ unparser
48
49
  webdrivers
49
50
 
51
+ PATH
52
+ remote: ../hyper-state
53
+ specs:
54
+ hyper-state (0.1)
55
+ hyperstack-config (= 0.1)
56
+ opal (>= 0.11.0, < 0.12.0)
57
+
50
58
  PATH
51
59
  remote: ../hyper-store
52
60
  specs:
53
- hyper-store (0.99.6)
54
- hyperloop-config (= 0.99.6)
61
+ hyper-store (0.1)
62
+ hyper-state (= 0.1)
63
+ hyperstack-config (= 0.1)
55
64
  opal (>= 0.11.0, < 0.12.0)
56
65
 
57
66
  PATH
58
- remote: ../hyperloop-config
67
+ remote: ../hyperstack-config
59
68
  specs:
60
- hyperloop-config (0.99.6)
61
- libv8 (~> 6.7.0)
62
- mini_racer (~> 0.2.4)
69
+ hyperstack-config (0.1)
70
+ libv8 (~> 6.3.0)
71
+ listen (~> 3.0)
72
+ mini_racer (~> 0.1.15)
63
73
  opal (>= 0.11.0, < 0.12.0)
64
74
  opal-browser (~> 0.2.0)
65
75
  uglifier
76
+ websocket
66
77
 
67
78
  PATH
68
79
  remote: .
69
80
  specs:
70
- hyper-i18n (0.99.6)
71
- hyper-operation (= 0.99.6)
81
+ hyper-i18n (0.1.0)
82
+ hyper-operation (= 0.1.0)
72
83
  i18n
73
84
 
74
85
  GEM
@@ -119,7 +130,7 @@ GEM
119
130
  adamantium (0.2.0)
120
131
  ice_nine (~> 0.11.0)
121
132
  memoizable (~> 0.4.0)
122
- addressable (2.6.0)
133
+ addressable (2.5.2)
123
134
  public_suffix (>= 2.0.2, < 4.0)
124
135
  archive-zip (0.11.0)
125
136
  io-like (~> 0.3.0)
@@ -130,7 +141,7 @@ GEM
130
141
  babel-source (>= 4.0, < 6)
131
142
  execjs (~> 2.0)
132
143
  builder (3.2.3)
133
- capybara (3.13.2)
144
+ capybara (3.10.1)
134
145
  addressable
135
146
  mini_mime (>= 0.1.3)
136
147
  nokogiri (~> 1.8)
@@ -154,7 +165,7 @@ GEM
154
165
  equalizer (0.0.11)
155
166
  erubi (1.7.1)
156
167
  execjs (2.7.0)
157
- ffi (1.10.0)
168
+ ffi (1.9.25)
158
169
  globalid (0.4.1)
159
170
  activesupport (>= 4.2.0)
160
171
  hike (1.2.3)
@@ -166,7 +177,11 @@ GEM
166
177
  rails-dom-testing (>= 1, < 3)
167
178
  railties (>= 4.2.0)
168
179
  thor (>= 0.14, < 2.0)
169
- libv8 (6.7.288.46.1)
180
+ libv8 (6.3.292.48.1)
181
+ listen (3.1.5)
182
+ rb-fsevent (~> 0.9, >= 0.9.4)
183
+ rb-inotify (~> 0.9, >= 0.9.7)
184
+ ruby_dep (~> 1.2)
170
185
  loofah (2.2.2)
171
186
  crass (~> 1.0.2)
172
187
  nokogiri (>= 1.5.9)
@@ -180,12 +195,11 @@ GEM
180
195
  mimemagic (0.3.2)
181
196
  mini_mime (1.0.1)
182
197
  mini_portile2 (2.3.0)
183
- mini_racer (0.2.4)
184
- libv8 (>= 6.3)
198
+ mini_racer (0.1.15)
199
+ libv8 (~> 6.3)
185
200
  minitest (5.11.3)
186
- mutations (0.9.0)
201
+ mutations (0.8.3)
187
202
  activesupport
188
- net_http_ssl_fix (0.0.10)
189
203
  nio4r (2.3.1)
190
204
  nokogiri (1.8.4)
191
205
  mini_portile2 (~> 2.3.0)
@@ -254,13 +268,16 @@ GEM
254
268
  rainbow (2.2.2)
255
269
  rake
256
270
  rake (10.5.0)
271
+ rb-fsevent (0.10.3)
272
+ rb-inotify (0.9.10)
273
+ ffi (>= 0.5.0, < 2)
257
274
  react-rails (2.4.7)
258
275
  babel-transpiler (>= 0.7.0)
259
276
  connection_pool
260
277
  execjs
261
278
  railties (>= 3.2)
262
279
  tilt
263
- regexp_parser (1.3.0)
280
+ regexp_parser (1.2.0)
264
281
  rspec (3.8.0)
265
282
  rspec-core (~> 3.8.0)
266
283
  rspec-expectations (~> 3.8.0)
@@ -273,7 +290,7 @@ GEM
273
290
  rspec-mocks (3.8.0)
274
291
  diff-lcs (>= 1.2.0, < 2.0)
275
292
  rspec-support (~> 3.8.0)
276
- rspec-rails (3.8.2)
293
+ rspec-rails (3.8.1)
277
294
  actionpack (>= 3.0)
278
295
  activesupport (>= 3.0)
279
296
  railties (>= 3.0)
@@ -290,6 +307,7 @@ GEM
290
307
  ruby-progressbar (~> 1.7)
291
308
  unicode-display_width (~> 1.0, >= 1.0.1)
292
309
  ruby-progressbar (1.10.0)
310
+ ruby_dep (1.5.0)
293
311
  rubyzip (1.2.2)
294
312
  selenium-webdriver (3.141.0)
295
313
  childprocess (~> 0.5)
@@ -309,10 +327,10 @@ GEM
309
327
  timecop (0.8.1)
310
328
  tzinfo (1.2.5)
311
329
  thread_safe (~> 0.1)
312
- uglifier (4.1.20)
330
+ uglifier (4.1.19)
313
331
  execjs (>= 0.3.0, < 3)
314
332
  unicode-display_width (1.4.0)
315
- unparser (0.3.0)
333
+ unparser (0.2.8)
316
334
  abstract_type (~> 0.0.7)
317
335
  adamantium (~> 0.2.0)
318
336
  concord (~> 0.1.5)
@@ -320,11 +338,11 @@ GEM
320
338
  equalizer (~> 0.0.9)
321
339
  parser (>= 2.3.1.2, < 2.6)
322
340
  procto (~> 0.0.2)
323
- webdrivers (3.6.0)
324
- net_http_ssl_fix
341
+ webdrivers (3.4.3)
325
342
  nokogiri (~> 1.6)
326
343
  rubyzip (~> 1.0)
327
344
  selenium-webdriver (~> 3.0)
345
+ websocket (1.2.8)
328
346
  websocket-driver (0.7.0)
329
347
  websocket-extensions (>= 0.1.0)
330
348
  websocket-extensions (0.1.3)
@@ -335,15 +353,16 @@ PLATFORMS
335
353
  ruby
336
354
 
337
355
  DEPENDENCIES
338
- bundler (~> 1.16)
356
+ bundler (~> 1.16.0)
339
357
  chromedriver-helper
340
358
  hyper-component!
341
359
  hyper-i18n!
342
360
  hyper-model!
343
361
  hyper-operation!
344
362
  hyper-spec!
363
+ hyper-state!
345
364
  hyper-store!
346
- hyperloop-config!
365
+ hyperstack-config!
347
366
  opal-rails (~> 0.9.4)
348
367
  pry
349
368
  puma
@@ -353,4 +372,4 @@ DEPENDENCIES
353
372
  sqlite3
354
373
 
355
374
  BUNDLED WITH
356
- 1.17.3
375
+ 1.16.0
data/hyper-i18n.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  lib = File.expand_path('../lib', __FILE__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'hyper-i18n/version'
5
+ require 'hyperstack/i18n/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'hyper-i18n'
9
- spec.version = HyperI18n::VERSION
9
+ spec.version = Hyperstack::I18n::VERSION
10
10
  spec.authors = ['adamcreekroad']
11
11
  spec.email = ['adamgeorge.31@gmail.com']
12
12
 
13
- spec.summary = 'HyperI18n seamlessly brings Rails I18n into your Hyperloop application.'
14
- spec.homepage = 'https://www.github.com/ruby-hyperloop/hyper-i18n'
13
+ spec.summary = 'HyperI18n seamlessly brings Rails I18n into your Hyperstack application.'
14
+ spec.homepage = 'https://www.github.com/ruby-hyperstack/hyper-i18n'
15
15
  spec.license = 'MIT'
16
16
 
17
17
  spec.files = `git ls-files`.split("\n")
@@ -19,13 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_dependency 'hyper-operation', HyperI18n::VERSION
22
+ spec.add_dependency 'hyper-operation', Hyperstack::I18n::VERSION
23
23
  spec.add_dependency 'i18n'
24
24
 
25
- spec.add_development_dependency 'bundler', '~> 1.16'
25
+ spec.add_development_dependency 'bundler', '~> 1.16.0'
26
26
  spec.add_development_dependency 'chromedriver-helper'
27
- spec.add_development_dependency 'hyper-model', HyperI18n::VERSION
28
- spec.add_development_dependency 'hyper-spec', HyperI18n::VERSION
27
+ spec.add_development_dependency 'hyper-model', Hyperstack::I18n::VERSION
28
+ spec.add_development_dependency 'hyper-spec', Hyperstack::I18n::VERSION
29
29
  spec.add_development_dependency 'opal-rails', '~> 0.9.4'
30
30
  spec.add_development_dependency 'pry'
31
31
  spec.add_development_dependency 'puma'
@@ -0,0 +1,13 @@
1
+ module Hyperstack
2
+ module Component
3
+ def t(attribute, opts = {})
4
+ namespace = self.class.name.underscore.gsub(%r{::|/}, '.')
5
+
6
+ HyperI18n::I18n.t("#{namespace}.#{attribute}", opts)
7
+ end
8
+
9
+ def l(time, format = :default, opts = {})
10
+ HyperI18n::I18n.l(time, format, opts)
11
+ end
12
+ end
13
+ end
@@ -2,15 +2,15 @@
2
2
  module HyperI18n
3
3
  class I18n
4
4
  extend HelperMethods
5
- include React::IsomorphicHelpers
5
+ include Hyperstack::Component::IsomorphicHelpers
6
6
 
7
7
  before_first_mount do
8
8
  if RUBY_ENGINE != 'opal'
9
9
  @server_data_cache = { t: {}, l: {} }
10
10
  else
11
11
  unless on_opal_server? || no_initial_data?
12
- I18nStore.mutate.translations(JSON.from_object(`window.HyperI18nInitialData.t`))
13
- I18nStore.mutate.localizations(JSON.from_object(`window.HyperI18nInitialData.l`))
12
+ I18nStore.translations = JSON.from_object(`window.HyperI18nInitialData.t`)
13
+ I18nStore.localizations = JSON.from_object(`window.HyperI18nInitialData.l`)
14
14
  end
15
15
  end
16
16
  end
@@ -1,5 +1,5 @@
1
1
  module HyperI18n
2
- class Localize < Hyperloop::ServerOp
2
+ class Localize < Hyperstack::ServerOp
3
3
  include HelperMethods
4
4
 
5
5
  param :acting_user, nils: true
@@ -1,5 +1,5 @@
1
1
  module HyperI18n
2
- class Translate < Hyperloop::ServerOp
2
+ class Translate < Hyperstack::ServerOp
3
3
  param :acting_user, nils: true
4
4
  param :attribute
5
5
  param :opts
@@ -1,6 +1,10 @@
1
1
  module HyperI18n
2
- class I18nStore < Hyperloop::Store
3
- state translations: {}, scope: :class, reader: true
4
- state localizations: {}, scope: :class, reader: true
2
+ class I18nStore
3
+ include Hyperstack::State::Observable
4
+ class << self
5
+ observer(:translations) { @translations ||= {} }
6
+ observer(:localizations) { @localizations ||= {} }
7
+ state_writer :translations, :localizations
8
+ end
5
9
  end
6
10
  end
@@ -1,3 +1,3 @@
1
1
  module HyperI18n
2
- VERSION = '0.99.6'
2
+ VERSION = '1.0.alpha1'
3
3
  end
data/lib/hyper-i18n.rb CHANGED
@@ -1,26 +1,24 @@
1
- require 'hyperloop-config'
2
- Hyperloop.import 'hyper-i18n'
1
+ require 'hyperstack-config'
2
+ Hyperstack.import 'hyper-i18n'
3
3
 
4
4
  require 'hyper-component'
5
5
  require 'hyper-operation'
6
+ require 'hyper-state'
6
7
 
7
- require 'hyper-i18n/helper_methods'
8
- require 'hyper-i18n/operations/localize'
9
- require 'hyper-i18n/operations/translate'
10
- require 'hyper-i18n/i18n'
8
+ require 'hyperstack/internal/i18n/helper_methods'
9
+ require 'hyperstack/internal/i18n/localize'
10
+ require 'hyperstack/internal/i18n/translate'
11
+ require 'hyperstack/internal/i18n'
12
+ require 'hyperstack/i18n/version'
11
13
 
12
14
  if RUBY_ENGINE == 'opal'
13
- require 'hyper-store'
14
-
15
- require 'hyper-i18n/active_model/name'
16
- require 'hyper-i18n/active_record/class_methods'
17
- require 'hyper-i18n/hyperloop/component/mixin'
18
-
19
- require 'hyper-i18n/stores/i18n_store'
15
+ require 'hyperstack/ext/i18n/active_model/name'
16
+ require 'hyperstack/ext/i18n/active_record/class_methods'
17
+ require 'hyperstack/internal/i18n/store'
18
+ require 'hyperstack/i18n'
19
+ require 'hyperstack/i18n/i18n'
20
20
  else
21
21
  require 'opal'
22
22
 
23
- require 'hyper-i18n/version'
24
-
25
23
  Opal.append_path File.expand_path('../', __FILE__).untaint
26
24
  end
@@ -2,7 +2,7 @@
2
2
  module ActiveModel
3
3
  class Name
4
4
  def human
5
- HyperI18n::I18n.t("activerecord.models.#{i18n_key}")
5
+ Hyperstack::Internal::I18n.t("activerecord.models.#{i18n_key}")
6
6
  end
7
7
  end
8
8
  end
@@ -3,7 +3,7 @@ module ActiveRecord
3
3
  def human_attribute_name(attribute, opts = {})
4
4
  attribute = "activerecord.attributes.#{model_name.i18n_key}.#{attribute}"
5
5
 
6
- HyperI18n::I18n.t(attribute, opts)
6
+ Hyperstack::Internal::I18n.t(attribute, opts)
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,12 @@
1
+ if RUBY_ENGINE == 'opal'
2
+ module I18n
3
+ class << self
4
+ def t(*args)
5
+ Hyperstack::Internal::I18n.t(*args)
6
+ end
7
+ def l(*args)
8
+ Hyperstack::Internal::I18n.l(*args)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Hyperstack
2
+ module I18n
3
+ VERSION = '1.0.alpha1'
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module Hyperstack
2
+ module I18n
3
+ def t(attribute, opts = {})
4
+ namespace = self.class.name.underscore.gsub(%r{::|/}, '.')
5
+
6
+ Hyperstack::Internal::I18n.t("#{namespace}.#{attribute}", opts)
7
+ end
8
+
9
+ def l(time, format = :default, opts = {})
10
+ Hyperstack::Internal::I18n.l(time, format, opts)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ module Hyperstack
2
+ module Internal
3
+ class I18n
4
+ module HelperMethods
5
+ def formatted_date_or_time(date_or_time)
6
+ # If the date_or_time parameter is a String, we must parse it to the correct format.
7
+
8
+ return date_or_time unless date_or_time.is_a?(String)
9
+
10
+ if date_or_time =~ /^\d+\W\d+\W\d+T?\s?\d+:\d+:\d+/
11
+ Time.parse(date_or_time)
12
+ else
13
+ Date.parse(date_or_time)
14
+ end
15
+ end
16
+
17
+ def formatted_format(format)
18
+ # If a string is passed in it will use that as the pattern for formatting, ex:
19
+ #
20
+ # I18n.l(Time.now, format: "%b %d, %Y")
21
+ # => "Aug 20, 2017"
22
+ #
23
+ # If a symbol is passed in it will find that definition from the locales.
24
+
25
+ format =~ /%/ ? format : :"#{format}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ module Hyperstack
2
+ module Internal
3
+ class I18n
4
+ class Localize < Hyperstack::ServerOp
5
+ include HelperMethods
6
+
7
+ param :acting_user, nils: true
8
+ param :date_or_time
9
+ param :format
10
+ param :opts
11
+ param :localization, default: nil
12
+
13
+ def date_or_time
14
+ @date_or_time ||= formatted_date_or_time(params.date_or_time)
15
+ end
16
+
17
+ def opts
18
+ @opts ||= params.opts.with_indifferent_access.merge(format: formatted_format(params.format))
19
+ end
20
+
21
+ step do
22
+ params.localization = ::I18n.l(date_or_time, opts)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ module Hyperstack
2
+ module Internal
3
+ class I18n
4
+ class Store
5
+ include Hyperstack::State::Observable
6
+ class << self
7
+ observer(:translations) { @translations ||= {} }
8
+ observer(:localizations) { @localizations ||= {} }
9
+ state_writer :translations, :localizations
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ module Hyperstack
2
+ module Internal
3
+ class I18n
4
+ class Translate < Hyperstack::ServerOp
5
+ param :acting_user, nils: true
6
+ param :attribute
7
+ param :opts
8
+ param :translation, default: nil
9
+
10
+ def opts
11
+ params.opts.with_indifferent_access
12
+ end
13
+
14
+ step do
15
+ params.translation = ::I18n.t(params.attribute, opts)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,94 @@
1
+ module Hyperstack
2
+ module Internal
3
+ class I18n
4
+ extend HelperMethods
5
+ include Hyperstack::Component::IsomorphicHelpers
6
+
7
+ before_first_mount do
8
+ if RUBY_ENGINE != 'opal'
9
+ @server_data_cache = { t: {}, l: {} }
10
+ else
11
+ unless on_opal_server? || no_initial_data?
12
+ Store.translations = JSON.from_object(`window.HyperI18nInitialData.t`)
13
+ Store.localizations = JSON.from_object(`window.HyperI18nInitialData.l`)
14
+ end
15
+ end
16
+ end
17
+
18
+ isomorphic_method(:t) do |f, attribute, opts = {}|
19
+ f.when_on_client do
20
+ return Store.translations[attribute] if Store.translations[attribute]
21
+
22
+ Translate
23
+ .run(attribute: attribute, opts: opts)
24
+ .then do |translation|
25
+ Store.translations[attribute] = translation
26
+ Store.mutate.translations(Store.translations)
27
+ end
28
+
29
+ opts[:default] || ''
30
+ end
31
+
32
+ f.when_on_server do
33
+ @server_data_cache[:t][attribute] = ::I18n.t(attribute, opts.with_indifferent_access)
34
+ end
35
+ end
36
+
37
+ isomorphic_method(:l) do |f, date_or_time, format = :default, opts = {}|
38
+ format = formatted_format(format)
39
+ date_or_time = formatted_date_or_time(date_or_time)
40
+
41
+ f.when_on_client do
42
+ if Store.localizations[date_or_time.to_s] &&
43
+ Store.localizations[date_or_time.to_s][format]
44
+ return Store.localizations[date_or_time.to_s][format]
45
+ end
46
+
47
+ Localize
48
+ .run(date_or_time: date_or_time, format: format, opts: {})
49
+ .then do |localization|
50
+ Store.localizations[date_or_time.to_s] ||= {}
51
+ Store.localizations[date_or_time.to_s][format] = localization
52
+
53
+ Store.mutate.localizations(Store.localizations)
54
+ end
55
+
56
+ opts[:default] || ''
57
+ end
58
+
59
+ f.when_on_server do
60
+ @server_data_cache[:l][date_or_time.to_s] ||= {}
61
+
62
+ @server_data_cache[:l][date_or_time.to_s][format] =
63
+ ::I18n.l(date_or_time, opts.with_indifferent_access.merge(format: format))
64
+ end
65
+ end
66
+
67
+ if RUBY_ENGINE != 'opal'
68
+ prerender_footer do
69
+ "<script type=\"text/javascript\">\n"\
70
+ "if (typeof window.HyperI18nInitialData === 'undefined') {\n"\
71
+ " window.HyperI18nInitialData = #{initial_data_json};\n"\
72
+ "}\n"\
73
+ "</script>\n"
74
+ end
75
+ end
76
+
77
+ class << self
78
+ def no_initial_data?
79
+ `typeof window.HyperI18nInitialData === 'undefined'`
80
+ end
81
+
82
+ def initial_data_json
83
+ if @server_data_cache
84
+ @server_data_cache.as_json.to_json
85
+ else
86
+ { t: {}, l: {} }.to_json
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ # we now allow directly using I18n on client (as on server)
@@ -6,7 +6,9 @@ describe 'I18n client methods', js: true do
6
6
  class MyModel < ActiveRecord::Base
7
7
  end
8
8
  module Components
9
- class TestComponent < Hyperloop::Component
9
+ class TestComponent
10
+ include Hyperstack::Component
11
+ include Hyperstack::I18n
10
12
  render(DIV) do
11
13
  DIV(id: :tp1) { t(:the_key) }
12
14
  DIV(id: :tp2) { I18n.t(:hello) }
@@ -1 +1 @@
1
- //= require 'hyperloop-loader'
1
+ //= require 'hyperstack-loader'
@@ -1,4 +1,4 @@
1
- Hyperloop.configuration do |config|
1
+ Hyperstack.configuration do |config|
2
2
  config.transport = :none
3
3
  config.import 'hyper-model'
4
4
  end
@@ -1,4 +1,4 @@
1
1
  Rails.application.routes.draw do
2
- mount Hyperloop::Engine => "/hyperloop_engine"
2
+ mount Hyperstack::Engine => "/hyperstack_engine"
3
3
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyper-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.99.6
4
+ version: 1.0.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - adamcreekroad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-30 00:00:00.000000000 Z
11
+ date: 2018-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hyper-operation
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.99.6
19
+ version: 1.0.alpha1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.99.6
26
+ version: 1.0.alpha1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: i18n
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.16'
47
+ version: 1.16.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.16'
54
+ version: 1.16.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: chromedriver-helper
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,28 +72,28 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 0.99.6
75
+ version: 1.0.alpha1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 0.99.6
82
+ version: 1.0.alpha1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: hyper-spec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 0.99.6
89
+ version: 1.0.alpha1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 0.99.6
96
+ version: 1.0.alpha1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: opal-rails
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -195,9 +195,7 @@ dependencies:
195
195
  description:
196
196
  email:
197
197
  - adamgeorge.31@gmail.com
198
- executables:
199
- - console
200
- - setup
198
+ executables: []
201
199
  extensions: []
202
200
  extra_rdoc_files: []
203
201
  files:
@@ -206,22 +204,25 @@ files:
206
204
  - ".travis.yml"
207
205
  - Gemfile
208
206
  - Gemfile.lock
209
- - LICENSE.txt
210
- - README.md
211
207
  - Rakefile
212
- - bin/console
213
- - bin/setup
214
208
  - hyper-i18n.gemspec
215
209
  - lib/hyper-i18n.rb
216
- - lib/hyper-i18n/active_model/name.rb
217
- - lib/hyper-i18n/active_record/class_methods.rb
218
- - lib/hyper-i18n/helper_methods.rb
219
- - lib/hyper-i18n/hyperloop/component/mixin.rb
210
+ - lib/hyper-i18n/hyperstack/component.rb
220
211
  - lib/hyper-i18n/i18n.rb
221
212
  - lib/hyper-i18n/operations/localize.rb
222
213
  - lib/hyper-i18n/operations/translate.rb
223
214
  - lib/hyper-i18n/stores/i18n_store.rb
224
215
  - lib/hyper-i18n/version.rb
216
+ - lib/hyperstack/ext/i18n/active_model/name.rb
217
+ - lib/hyperstack/ext/i18n/active_record/class_methods.rb
218
+ - lib/hyperstack/i18n.rb
219
+ - lib/hyperstack/i18n/i18n.rb
220
+ - lib/hyperstack/i18n/version.rb
221
+ - lib/hyperstack/internal/i18n.rb
222
+ - lib/hyperstack/internal/i18n/helper_methods.rb
223
+ - lib/hyperstack/internal/i18n/localize.rb
224
+ - lib/hyperstack/internal/i18n/store.rb
225
+ - lib/hyperstack/internal/i18n/translate.rb
225
226
  - spec/hyper_i18n_spec.rb
226
227
  - spec/spec_helper.rb
227
228
  - spec/test_app/.gitignore
@@ -264,7 +265,7 @@ files:
264
265
  - spec/test_app/config/initializers/backtrace_silencers.rb
265
266
  - spec/test_app/config/initializers/cookies_serializer.rb
266
267
  - spec/test_app/config/initializers/filter_parameter_logging.rb
267
- - spec/test_app/config/initializers/hyperloop.rb
268
+ - spec/test_app/config/initializers/hyperstack.rb
268
269
  - spec/test_app/config/initializers/inflections.rb
269
270
  - spec/test_app/config/initializers/mime_types.rb
270
271
  - spec/test_app/config/initializers/new_framework_defaults.rb
@@ -289,7 +290,7 @@ files:
289
290
  - spec/test_app/tmp/.keep
290
291
  - spec/test_app/vendor/assets/javascripts/.keep
291
292
  - spec/test_app/vendor/assets/stylesheets/.keep
292
- homepage: https://www.github.com/ruby-hyperloop/hyper-i18n
293
+ homepage: https://www.github.com/ruby-hyperstack/hyper-i18n
293
294
  licenses:
294
295
  - MIT
295
296
  metadata: {}
@@ -304,12 +305,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
304
305
  version: '0'
305
306
  required_rubygems_version: !ruby/object:Gem::Requirement
306
307
  requirements:
307
- - - ">="
308
+ - - ">"
308
309
  - !ruby/object:Gem::Version
309
- version: '0'
310
+ version: 1.3.1
310
311
  requirements: []
311
- rubygems_version: 3.0.2
312
+ rubyforge_project:
313
+ rubygems_version: 2.7.8
312
314
  signing_key:
313
315
  specification_version: 4
314
- summary: HyperI18n seamlessly brings Rails I18n into your Hyperloop application.
316
+ summary: HyperI18n seamlessly brings Rails I18n into your Hyperstack application.
315
317
  test_files: []
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 adamcreekroad
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/README.md DELETED
@@ -1,92 +0,0 @@
1
- # HyperI18n
2
- [![Build Status](https://travis-ci.org/ruby-hyperloop/hyper-i18n.svg?branch=master)](https://travis-ci.org/ruby-hyperloop/hyper-i18n)
3
- [![Gem Version](https://badge.fury.io/rb/hyper-i18n.svg)](https://badge.fury.io/rb/hyper-i18n)
4
-
5
- ## HyperI18n gem
6
-
7
- HyperI18n seamlessly brings Rails I18n into your Hyperloop application.
8
-
9
-
10
- ## Documentation and Help
11
-
12
- + Please see the [ruby-hyperloop.org](http://ruby-hyperloop.org/) website for documentation.
13
- + Join the Hyperloop [gitter.io](https://gitter.im/ruby-hyperloop/chat) chat for help and support.
14
-
15
-
16
- ## Installation and Setup
17
-
18
- 1. Add `gem 'hyper-i18n', git: 'https://github.com/ruby-hyperloop/hyper-i18n.git'` to your `Gemfile`
19
- 2. Install the Gem: `bundle install`
20
- 3. Add `require 'hyper-i18n'` to your components manifest
21
-
22
-
23
- ## Note!
24
-
25
- This gem is in it's very early stages, and only a handful of the API has been implemented.
26
- Contributions are very welcome!
27
-
28
- ### Usage
29
-
30
- Hyper-I18n brings in the standard ActiveSupport API.
31
-
32
-
33
- #### ActiveRecord Models
34
-
35
- The methods `Model.model_name.human` and `Model.human_attribute_name` are available:
36
-
37
- ```yaml
38
- # config/locales/models/en.yml
39
- en:
40
- activerecord:
41
- models:
42
- user: 'Customer'
43
- attributes:
44
- name: 'Name'
45
- ```
46
- ```ruby
47
- User.model_name.human
48
- # 'Customer'
49
-
50
- User.human_attribute_name(:name)
51
- # 'Name'
52
- ```
53
-
54
- #### Views
55
-
56
- Hyper-I18n makes available the method `t` to components, just as ActiveSupport does for views.
57
- It also implements the same lazy-loading pattern,
58
- so if you name space your locale file the same as your components, it will just work:
59
-
60
- ```yaml
61
- # config/locales/views/en.yml
62
- en:
63
- users:
64
- show:
65
- title: 'Customer View'
66
- ```
67
- ```ruby
68
- module Users
69
- class Show < Hyperloop::Component
70
- render do
71
- H1 { t(:title) }
72
- end
73
- end
74
- end
75
-
76
- # <h1>Customer View</h1>
77
- ```
78
-
79
- ### Server Rendering
80
-
81
- HyperI18n is fully compatible with server rendering!
82
- All translations are also sent to the client, so as to bypass fetching/rendering again on the client.
83
-
84
- ## Contributing
85
-
86
- Bug reports and pull requests are welcome on GitHub at https://github.com/ruby-hyperloop/hyper-i18n.
87
- This project is intended to be a safe, welcoming space for collaboration,
88
- and contributors are expected to adhere to the [Code of Conduct](https://github.com/ruby-hyperloop/hyper-operation/blob/master/CODE_OF_CONDUCT.md) code of conduct.
89
-
90
- ## License
91
-
92
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "hyper/i18n"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,26 +0,0 @@
1
- module HyperI18n
2
- module HelperMethods
3
- def formatted_date_or_time(date_or_time)
4
- # If the date_or_time parameter is a String, we must parse it to the correct format.
5
-
6
- return date_or_time unless date_or_time.is_a?(String)
7
-
8
- if date_or_time =~ /^\d+\W\d+\W\d+T?\s?\d+:\d+:\d+/
9
- Time.parse(date_or_time)
10
- else
11
- Date.parse(date_or_time)
12
- end
13
- end
14
-
15
- def formatted_format(format)
16
- # If a string is passed in it will use that as the pattern for formatting, ex:
17
- #
18
- # I18n.l(Time.now, format: "%b %d, %Y")
19
- # => "Aug 20, 2017"
20
- #
21
- # If a symbol is passed in it will find that definition from the locales.
22
-
23
- format =~ /%/ ? format : :"#{format}"
24
- end
25
- end
26
- end
@@ -1,15 +0,0 @@
1
- module Hyperloop
2
- class Component
3
- module Mixin
4
- def t(attribute, opts = {})
5
- namespace = self.class.name.underscore.gsub(%r{::|/}, '.')
6
-
7
- HyperI18n::I18n.t("#{namespace}.#{attribute}", opts)
8
- end
9
-
10
- def l(time, format = :default, opts = {})
11
- HyperI18n::I18n.l(time, format, opts)
12
- end
13
- end
14
- end
15
- end