tr8n_core 4.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +163 -33
  3. data/lib/tr8n/application.rb +29 -27
  4. data/lib/tr8n/base.rb +2 -22
  5. data/lib/tr8n/cache.rb +9 -9
  6. data/lib/tr8n/cache_adapters/cdb.rb +2 -2
  7. data/lib/tr8n/cache_adapters/file.rb +2 -2
  8. data/lib/tr8n/cache_adapters/memcache.rb +3 -3
  9. data/lib/tr8n/cache_adapters/redis.rb +3 -3
  10. data/lib/tr8n/component.rb +1 -1
  11. data/lib/tr8n/config.rb +256 -202
  12. data/lib/tr8n/decorators/base.rb +1 -1
  13. data/lib/tr8n/decorators/default.rb +1 -1
  14. data/lib/tr8n/decorators/html.rb +4 -4
  15. data/lib/tr8n/exception.rb +1 -1
  16. data/lib/tr8n/language.rb +17 -27
  17. data/lib/tr8n/language_case.rb +4 -3
  18. data/lib/tr8n/language_case_rule.rb +1 -1
  19. data/lib/tr8n/language_context.rb +4 -2
  20. data/lib/tr8n/language_context_rule.rb +1 -1
  21. data/lib/tr8n/logger.rb +8 -3
  22. data/lib/tr8n/rules_engine/evaluator.rb +4 -7
  23. data/lib/tr8n/rules_engine/parser.rb +1 -28
  24. data/lib/tr8n/session.rb +87 -0
  25. data/lib/tr8n/source.rb +1 -1
  26. data/lib/tr8n/tokens/data.rb +2 -2
  27. data/lib/tr8n/tokens/data_tokenizer.rb +1 -1
  28. data/lib/tr8n/tokens/decoration_tokenizer.rb +1 -1
  29. data/lib/tr8n/tokens/hidden.rb +1 -1
  30. data/lib/tr8n/tokens/method.rb +1 -1
  31. data/lib/tr8n/tokens/transform.rb +2 -2
  32. data/lib/tr8n/translation.rb +2 -2
  33. data/lib/tr8n/translation_key.rb +4 -4
  34. data/lib/tr8n/translator.rb +1 -1
  35. data/lib/tr8n/utils.rb +1 -1
  36. data/lib/tr8n_core/ext/array.rb +4 -4
  37. data/lib/tr8n_core/ext/date.rb +38 -13
  38. data/lib/tr8n_core/ext/fixnum.rb +3 -3
  39. data/lib/tr8n_core/ext/hash.rb +1 -1
  40. data/lib/tr8n_core/ext/string.rb +3 -3
  41. data/lib/tr8n_core/ext/time.rb +30 -24
  42. data/lib/tr8n_core/generators/cache/base.rb +4 -4
  43. data/lib/tr8n_core/generators/cache/cdb.rb +1 -1
  44. data/lib/tr8n_core/generators/cache/file.rb +4 -3
  45. data/lib/tr8n_core/version.rb +2 -2
  46. data/lib/tr8n_core.rb +1 -1
  47. data/spec/application_spec.rb +5 -192
  48. data/spec/base_spec.rb +1 -1
  49. data/spec/config_spec.rb +21 -5
  50. data/spec/decorator_spec.rb +1 -1
  51. data/spec/decorators/base_spec.rb +1 -1
  52. data/spec/decorators/default_spec.rb +1 -1
  53. data/spec/decorators/html_spec.rb +8 -8
  54. data/spec/fixtures/languages/ru.json +36 -4
  55. data/spec/language_case_rule_spec.rb +1 -1
  56. data/spec/language_case_spec.rb +1 -1
  57. data/spec/language_context_rule_spec.rb +1 -1
  58. data/spec/language_context_spec.rb +1 -1
  59. data/spec/language_spec.rb +603 -4
  60. data/spec/rules_engine/evaluator_spec.rb +1 -1
  61. data/spec/rules_engine/parser_spec.rb +1 -1
  62. data/spec/{helper.rb → spec_helper.rb} +15 -7
  63. data/spec/tokens/data_spec.rb +2 -2
  64. data/spec/tokens/data_tokenizer_spec.rb +1 -1
  65. data/spec/tokens/decoration_tokenizer_spec.rb +1 -1
  66. data/spec/tokens/hidden_spec.rb +1 -1
  67. data/spec/tokens/method_spec.rb +1 -1
  68. data/spec/tokens/transform_spec.rb +1 -1
  69. data/spec/translation_key_spec.rb +1 -1
  70. data/spec/translation_spec.rb +1 -1
  71. data/spec/utils_spec.rb +1 -3
  72. metadata +5 -8
  73. data/config/config.yml +0 -34
  74. data/config/tokens/data.yml +0 -45
  75. data/config/tokens/decorations.yml +0 -37
  76. data/lib/tr8n_core/modules/logger.rb +0 -43
@@ -12,6 +12,10 @@ SimpleCov.start
12
12
 
13
13
  require 'tr8n_core'
14
14
 
15
+ Tr8n.configure do |config|
16
+ config.format = :text
17
+ end
18
+
15
19
  def fixtures_root
16
20
  File.join(File.dirname(__FILE__), 'fixtures')
17
21
  end
@@ -20,14 +24,18 @@ def load_json(file_path)
20
24
  JSON.parse(File.read("#{fixtures_root}/#{file_path}"))
21
25
  end
22
26
 
23
- def load_translation_keys_from_file(app, path)
24
- load_json(path).each do |jkey|
25
- load_translation_key_from_hash(app, jkey)
27
+ def load_translation_key_from_hash(app, hash)
28
+ app.cache_translation_key(Tr8n::TranslationKey.new(hash.merge(:application => app)))
29
+ end
30
+
31
+ def load_translation_key_from_array(app, arr)
32
+ arr.each do |tkey|
33
+ load_translation_key_from_hash(app, tkey)
26
34
  end
27
35
  end
28
36
 
29
- def load_translation_key_from_hash(app, hash)
30
- app.cache_translation_key(Tr8n::TranslationKey.new(hash.merge(:application => app)))
37
+ def load_translation_keys_from_file(app, path)
38
+ load_translation_key_from_array(app, load_json(path))
31
39
  end
32
40
 
33
41
  def stub_object(attrs)
@@ -44,8 +52,8 @@ def init_application(locales = [], path = 'application.json')
44
52
  locales.each do |locale|
45
53
  app.add_language(Tr8n::Language.new(load_json("languages/#{locale}.json")))
46
54
  end
47
- Tr8n.config.application = app
48
- Tr8n.config.current_language = app.language('en-US')
55
+ Tr8n.session.application = app
56
+ Tr8n.session.current_language = app.language('en-US')
49
57
  app
50
58
  end
51
59
 
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Tokens::Data do
6
6
  before do
@@ -95,7 +95,7 @@ describe Tr8n::Tokens::Data do
95
95
  users << stub_object({:first_name => "First name #{i}", :last_name => "Last name #{i}", :gender => "Male"})
96
96
  end
97
97
 
98
- Tr8n.config.with_block_options(:dry => true) do
98
+ Tr8n.session.with_block_options(:dry => true) do
99
99
  expect(token.token_value([users, :first_name], {}, @english)).to match("2 others")
100
100
 
101
101
  expect(token.token_value([users, [:first_name], {
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Tokens::DataTokenizer do
6
6
  before do
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Tokens::DecorationTokenizer do
6
6
 
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Tokens::Hidden do
6
6
  before do
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Tokens::Method do
6
6
  #before do
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Tokens::Transform do
6
6
  #before do
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::TranslationKey do
6
6
  describe "#initialize" do
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Translation do
6
6
  describe "initialize" do
data/spec/utils_spec.rb CHANGED
@@ -1,12 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Utils do
6
6
  describe "helper methods" do
7
7
  it "should return correct values" do
8
- #expect(Tr8n::Utils.root).to eq(File.expand_path("#{__dir__}/../"))
9
- expect(Tr8n::Utils.load_yaml("#{Tr8n.config.root}/config/tokens/data.yml").class).to eq(Hash)
10
8
 
11
9
  expect(
12
10
  Tr8n::Utils.normalize_tr_params("Hello {user}", "Sample label", {:user => "Michael"}, {})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tr8n_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Berkovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-07 00:00:00.000000000 Z
11
+ date: 2014-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -52,6 +52,7 @@ files:
52
52
  - lib/tr8n/logger.rb
53
53
  - lib/tr8n/rules_engine/evaluator.rb
54
54
  - lib/tr8n/rules_engine/parser.rb
55
+ - lib/tr8n/session.rb
55
56
  - lib/tr8n/source.rb
56
57
  - lib/tr8n/tokens/data.rb
57
58
  - lib/tr8n/tokens/data_tokenizer.rb
@@ -72,12 +73,8 @@ files:
72
73
  - lib/tr8n_core/generators/cache/base.rb
73
74
  - lib/tr8n_core/generators/cache/cdb.rb
74
75
  - lib/tr8n_core/generators/cache/file.rb
75
- - lib/tr8n_core/modules/logger.rb
76
76
  - lib/tr8n_core/version.rb
77
77
  - lib/tr8n_core.rb
78
- - config/config.yml
79
- - config/tokens/data.yml
80
- - config/tokens/decorations.yml
81
78
  - LICENSE
82
79
  - Rakefile
83
80
  - README.md
@@ -98,7 +95,6 @@ files:
98
95
  - spec/fixtures/translations/ru/last_names.txt
99
96
  - spec/fixtures/translations/ru/names.json
100
97
  - spec/fixtures/translations/ru/names.txt
101
- - spec/helper.rb
102
98
  - spec/language_case_rule_spec.rb
103
99
  - spec/language_case_spec.rb
104
100
  - spec/language_context_rule_spec.rb
@@ -106,6 +102,7 @@ files:
106
102
  - spec/language_spec.rb
107
103
  - spec/rules_engine/evaluator_spec.rb
108
104
  - spec/rules_engine/parser_spec.rb
105
+ - spec/spec_helper.rb
109
106
  - spec/tokens/data_spec.rb
110
107
  - spec/tokens/data_tokenizer_spec.rb
111
108
  - spec/tokens/decoration_tokenizer_spec.rb
@@ -157,7 +154,6 @@ test_files:
157
154
  - spec/fixtures/translations/ru/last_names.txt
158
155
  - spec/fixtures/translations/ru/names.json
159
156
  - spec/fixtures/translations/ru/names.txt
160
- - spec/helper.rb
161
157
  - spec/language_case_rule_spec.rb
162
158
  - spec/language_case_spec.rb
163
159
  - spec/language_context_rule_spec.rb
@@ -165,6 +161,7 @@ test_files:
165
161
  - spec/language_spec.rb
166
162
  - spec/rules_engine/evaluator_spec.rb
167
163
  - spec/rules_engine/parser_spec.rb
164
+ - spec/spec_helper.rb
168
165
  - spec/tokens/data_spec.rb
169
166
  - spec/tokens/data_tokenizer_spec.rb
170
167
  - spec/tokens/decoration_tokenizer_spec.rb
data/config/config.yml DELETED
@@ -1,34 +0,0 @@
1
- defaults:
2
- enabled: true
3
- default_locale: en-US
4
- default_level: 0
5
- application:
6
- host: http://localhost:3000
7
- key: default
8
- secret: 12345
9
- logger:
10
- enabled: true
11
- path: /log/tr8n.log
12
- cache:
13
- enabled: false
14
- adapter: file
15
- path: /cache
16
- version: 1
17
- timeout: 3600
18
- host: localhost:11211
19
- localization:
20
- default_day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
21
- default_abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
22
- default_month_names: [January, February, March, April, May, June, July, August, September, October, November, December]
23
- default_abbr_month_names: [Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
24
- custom_date_formats:
25
- default: '%m/%d/%Y' # 07/4/2008
26
- short_numeric: '%m/%d' # 07/4
27
- short_numeric_year: '%m/%d/%y' # 07/4/08
28
- long_numeric: '%m/%d/%Y' # 07/4/2008
29
- verbose: '%A, %B %d, %Y' # Friday, July 4, 2008
30
- monthname: '%B %d' # July 4
31
- monthname_year: '%B %d, %Y' # July 4, 2008
32
- monthname_abbr: '%b %d' # Jul 4
33
- monthname_abbr_year: '%b %d, %Y' # Jul 4, 2008
34
- date_time: '%m/%d/%Y at %H:%M' # 01/03/1010 at 5:30
@@ -1,45 +0,0 @@
1
- #############################################################################
2
- #
3
- # Tr8n Default Data Tokens
4
- #
5
- #############################################################################
6
-
7
- html:
8
- ndash: "&ndash;" # –
9
- mdash: "&mdash;" # —
10
- iexcl: "&iexcl;" # ¡
11
- iquest: "&iquest;" # ¿
12
- quot: "&quot;" # "
13
- ldquo: "&ldquo;" # “
14
- rdquo: "&rdquo;" # ”
15
- lsquo: "&lsquo;" # ‘
16
- rsquo: "&rsquo;" # ’
17
- laquo: "&laquo;" # «
18
- raquo: "&raquo;" # »
19
- nbsp: "&nbsp;" # space
20
- lsaquo: "&lsaquo;" # ‹
21
- rsaquo: "&rsaquo;" # ›
22
- br: "<br/>" # line break
23
- lbrace: "{"
24
- rbrace: "}"
25
- trade: "&trade;" # TM
26
-
27
- plain:
28
- ndash: "–" # –
29
- mdash: "—" # —
30
- iexcl: "¡" # ¡
31
- iquest: "¿" # ¿
32
- quot: '"' # "
33
- ldquo: "“" # “
34
- rdquo: "”" # ”
35
- lsquo: "‘" # ‘
36
- rsquo: "’" # ’
37
- laquo: "«" # «
38
- raquo: "»" # »
39
- nbsp: " " # space
40
- lsaquo: "‹" # ‹
41
- rsaquo: "›" # ›
42
- br: "\n" # line break
43
- lbrace: "{"
44
- rbrace: "}"
45
- trade: "™" # TM
@@ -1,37 +0,0 @@
1
- #############################################################################
2
- #
3
- # Tr8n Default Decoration Tokens
4
- #
5
- #############################################################################
6
-
7
- html:
8
- strong: "<strong>{$0}</strong>"
9
- bold: "<strong>{$0}</strong>"
10
- b: "<strong>{$0}</strong>"
11
- em: "<em>{$0}</em>"
12
- italic: "<i>{$0}</i>"
13
- i: "<i>{$0}</i>"
14
- link: "<a href='{$href}'>{$0}</a>"
15
- br: "<br>{$0}"
16
- strike: "<strike>{$0}</strike>"
17
- div: "<div id='{$id}' class='{$class}' style='{$style}'>{$0}</div>"
18
- span: "<span id='{$id}' class='{$class}' style='{$style}'>{$0}</span>"
19
- h1: "<h1>{$0}</h1>"
20
- h2: "<h2>{$0}</h2>"
21
- h3: "<h3>{$0}</h3>"
22
-
23
- plain:
24
- strong: "{$0}"
25
- bold: "{$0}"
26
- b: "{$0}"
27
- em: "{$0}"
28
- italic: "{$0}"
29
- i: "{$0}"
30
- link: "{$0}:{$1}"
31
- br: "\n{$0}"
32
- strike: "{$0}"
33
- div: "{$0}"
34
- span: "{$0}"
35
- h1: "{$0}"
36
- h2: "{$0}"
37
- h3: "{$0}"
@@ -1,43 +0,0 @@
1
- #--
2
- # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- module Tr8nCore
25
- module Modules
26
- module Logger
27
-
28
- def debug(msg)
29
- Tr8n::Logger.debug(msg)
30
- end
31
-
32
- def info(msg)
33
- Tr8n::Logger.info(msg)
34
- end
35
-
36
- def error(msg)
37
- Tr8n::Logger.error(msg)
38
- end
39
-
40
- end
41
- end
42
- end
43
-