slimkeyfy 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7b087050604856e414040ee52a0f0f6193d6262
4
- data.tar.gz: fda6549ae39e62bc4a14d90a87aa416e8a62cf8a
3
+ metadata.gz: 19d0a4d7e4a6b8c2e5a7082ef08f7c28493d4e38
4
+ data.tar.gz: 9cd1467d4e37f17a3157e2e729f3cd2781d4825c
5
5
  SHA512:
6
- metadata.gz: 1789730769336204cfd93fefaa65bd6e01c4e086d6114b79468c73f71e2582288d7baea132ae2219569782f82a428470b56b8f30efbfedd7dc144003ab41000a
7
- data.tar.gz: b115559e8670e99b43c50805b935d162d698b820a187751880bdba8c7a2fcc63f44c8f849fdf3c43facf9d0dba436075a90977b389ba386936669b0744adb2c6
6
+ metadata.gz: 19e37288365b2471c828b347197c19f6928a22fbd7232aa1f2506b08ecad70864f0fce06735c84fc52d6276b057091ec9e519a88ad497a5a6ab1f277079f3f25
7
+ data.tar.gz: edc05e14a643ba3d92f7c5b8bac7cb23579591f6c43818d510dea3d61e0fe1a85c5476f447736990802a30c13e465aa096514364668f565ec524b663b7b0ee3b
data/README.md CHANGED
@@ -31,7 +31,7 @@ group :development do
31
31
  # Github
32
32
  gem 'slimkeyfy', github: 'https://github.com/phrase/slimkeyfy.git'
33
33
  # or with concrete version
34
- gem 'slimkeyfy', '~> 0.1'
34
+ gem 'slimkeyfy', '~> 0.0.3'
35
35
  end
36
36
  ```
37
37
 
@@ -22,6 +22,8 @@ class SlimKeyfy::Transformer::SlimTransformer < SlimKeyfy::Transformer::BaseTran
22
22
  }
23
23
 
24
24
  LINK_TO = /#{HTML_ARGUMENTS[:link_to]}#{TRANSLATION}/
25
+
26
+ INTERPOLATED_VARIABLES = /\#{[^}]*}/
25
27
 
26
28
  def regex_list
27
29
  HTML_ARGUMENTS.map{|_, regex| /#{BEFORE}#{regex}#{TRANSLATION}#{AFTER}/ }
@@ -26,20 +26,37 @@ class SlimKeyfy::Transformer::Word
26
26
  as_list.drop(1)
27
27
  end
28
28
 
29
- def i18nString(translation_key)
29
+ def i18n_string(translation_key, args={})
30
+ args_string = args.inject('') do |string, (k,v)|
31
+ string += ", #{k}: (#{v})"
32
+ end
33
+
30
34
  if @extension == "rb"
31
- "t('#{@key_base}.#{translation_key}')"
35
+ "t('#{@key_base}.#{translation_key}'#{args_string})"
32
36
  else
33
- "t('.#{translation_key}')"
37
+ "t('.#{translation_key}'#{args_string})"
34
38
  end
35
39
  end
36
40
 
37
41
  def update_translation_key_hash(yaml_processor, translation)
42
+ arguments, translation = extract_arguments(translation)
38
43
  translation_key = SlimKeyfy::Slimutils::TranslationKeyGenerator.new(translation).generate_key_name
39
44
  translation_key_with_base = "#{@key_base}.#{translation_key}"
40
45
  translation_key_with_base, translation = yaml_processor.merge!(translation_key_with_base, translation) unless yaml_processor.nil?
41
46
  @translations.merge!({translation_key_with_base => translation})
42
- i18nString(extract_updated_key(translation_key_with_base))
47
+ i18n_string(extract_updated_key(translation_key_with_base), arguments)
48
+ end
49
+
50
+ def extract_arguments(translation)
51
+ args = {}
52
+ translation.scan(/\#{[^}]*}/).each_with_index do |arg, index|
53
+ stripped_arg = arg[2..-2]
54
+ key = arg[/\w+/]
55
+ key = key + index.to_s if index > 0
56
+ translation = translation.gsub(arg, "%{#{key}}")
57
+ args[key]= stripped_arg
58
+ end
59
+ [args, translation]
43
60
  end
44
61
 
45
62
  def extract_updated_key(translation_key_with_base)
@@ -1,3 +1,3 @@
1
1
  module SlimKeyfy
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimkeyfy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dynport GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-16 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec