twine 1.0.5 → 1.0.6

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
- SHA256:
3
- metadata.gz: 44fd7c832c7ecf4c70ebd07f2a7471b7ec7d7dd4989cc336becd4f404a2cf7dd
4
- data.tar.gz: b947aeaac122ab7abd0d02704210ea13d52974a5e3a95e74414bec019700b184
2
+ SHA1:
3
+ metadata.gz: f6d46a283d86aa50c84b7b229f2e3159edd72816
4
+ data.tar.gz: c412942ce007dbd236cc32b4b9ceadf99734cbe4
5
5
  SHA512:
6
- metadata.gz: d726639293d96d2c053bd13d7222e1971ceb542db66956b8415301a9f075a3b429677f1f5b34ded00d9e60814c9e7b472ead5106b05dc3d08c51b25841a957c8
7
- data.tar.gz: b50fd40a63c1b804e19a4c7e4ae791ace13898080a0459e998efde4810801919fc4e24d20a689d7774814271e0925d0992a3cc5ddfdac2b9dc36f82ec5022967
6
+ metadata.gz: b44a73df4eb789f78cbec2a37cbe496f7cda95ea62b7e56c2eb189d5f26b5c0a5ef497b7c185a78961ba263df64e386a7efc2b58a58dab540eb0ea9a81b68922
7
+ data.tar.gz: c9814e961ac0c8eb36c61122c89b3d9bd321133dd8b0441e2cfdd352a65e71d74cf8cae31d0da9903988e80c524fef332dd5fc56c2d4dc622e3f581364770636
data/README.md CHANGED
@@ -80,7 +80,7 @@ Twine currently supports the following output formats:
80
80
  * [Android String Resources][androidstrings] (format: android)
81
81
  * HTML tags will be escaped by replacing `<` with `&lt`
82
82
  * Tags inside `<![CDATA[` won't be escaped.
83
- * Supports [basic styling][androidstyling] with `<b>`, `<i>`, `<u>` and `<a>` links.
83
+ * Supports [basic styling][androidstyling] according to [Android documentation](https://developer.android.com/guide/topics/resources/string-resource.html#StylingWithHTML). All of the documented tags are supported, in addition to `<a>` links.
84
84
  * These tags will *not* be escaped if the string doesn't contain placeholders. You can reference them directly in your layouts or by using [`getText()`](https://developer.android.com/reference/android/content/res/Resources.html#getText(int)) to read them programatically.
85
85
  * These tags *will* be escaped if the string contains placeholders. You can use [`getString()`](https://developer.android.com/reference/android/content/res/Resources.html#getString(int,%20java.lang.Object...)) combined with [`fromHtml`](https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String)) as shown in the [documentation][androidstyling] to display them.
86
86
  * See [\#212](https://github.com/scelis/twine/issues/212) for details.
@@ -41,7 +41,11 @@ module Twine
41
41
  end
42
42
 
43
43
  def output_path_for_language(lang)
44
- "values-#{lang}".gsub(/-(\p{Lu})/, '-r\1')
44
+ if lang == @twine_file.language_codes[0]
45
+ "values"
46
+ else
47
+ "values-#{lang}".gsub(/-(\p{Lu})/, '-r\1')
48
+ end
45
49
  end
46
50
 
47
51
  def set_translation_for_key(key, lang, value)
@@ -109,22 +113,26 @@ module Twine
109
113
 
110
114
  # http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
111
115
  def escape_value(value)
112
- inside_cdata = /<\!\[CDATA\[((?!\]\]>).)*$/ # opening CDATA tag ('<![CDATA[') not followed by a closing tag (']]>')
113
- inside_opening_anchor_tag = /<a\s?((?!>).)*$/ # anchor tag start ('<a ') not followed by a '>'
116
+ inside_cdata = /<\!\[CDATA\[((?!\]\]>).)*$/ # opening CDATA tag ('<![CDATA[') not followed by a closing tag (']]>')
117
+ inside_opening_tag = /<(a|font|span|p)\s?((?!>).)*$/ # tag start ('<a ', '<font ', '<span ' or '<p ') not followed by a '>'
114
118
 
115
119
  # escape double and single quotes and & signs
116
- value = gsub_unless(value, '"', '\\"') { |substring| substring =~ inside_cdata || substring =~ inside_opening_anchor_tag }
120
+ value = gsub_unless(value, '"', '\\"') { |substring| substring =~ inside_cdata || substring =~ inside_opening_tag }
117
121
  value = gsub_unless(value, "'", "\\'") { |substring| substring =~ inside_cdata }
118
- value = gsub_unless(value, /&/, '&amp;') { |substring| substring =~ inside_cdata || substring =~ inside_opening_anchor_tag }
122
+ value = gsub_unless(value, /&/, '&amp;') { |substring| substring =~ inside_cdata || substring =~ inside_opening_tag }
119
123
 
120
124
  # if `value` contains a placeholder, escape all angle brackets
121
125
  # if not, escape opening angle brackes unless it's a supported styling tag
122
126
  # https://github.com/scelis/twine/issues/212
123
127
  # https://stackoverflow.com/questions/3235131/#18199543
124
128
  if number_of_twine_placeholders(value) > 0
125
- angle_bracket = /<(?!(\/?(\!\[CDATA)))/ # matches all `<` but <![CDATA
126
- else
127
- angle_bracket = /<(?!(\/?(b|u|i|a|\!\[CDATA)))/ # matches all `<` but <b>, <u>, <i>, <a> and <![CDATA
129
+ # matches all `<` but <![CDATA
130
+ angle_bracket = /<(?!(\/?(\!\[CDATA)))/
131
+ else
132
+ # matches all '<' but <b>, <em>, <i>, <cite>, <dfn>, <big>, <small>, <font>, <tt>, <s>,
133
+ # <strike>, <del>, <u>, <super>, <sub>, <ul>, <li>, <br>, <div>, <span>, <p>, <a>
134
+ # and <![CDATA
135
+ angle_bracket = /<(?!(\/?(b|em|i|cite|dfn|big|small|font|tt|s|strike|del|u|super|sub|ul|li|br|div|span|p|a|\!\[CDATA)))/
128
136
  end
129
137
  value = gsub_unless(value, angle_bracket, '&lt;') { |substring| substring =~ inside_cdata }
130
138
 
@@ -1,3 +1,3 @@
1
1
  module Twine
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.6'
3
3
  end
@@ -47,26 +47,87 @@ class TestAndroidFormatter < FormatterTest
47
47
  'a "good" way' => 'a \"good\" way',
48
48
 
49
49
  '<b>bold</b>' => '<b>bold</b>',
50
+ '<em>bold</em>' => '<em>bold</em>',
51
+
50
52
  '<i>italic</i>' => '<i>italic</i>',
53
+ '<cite>italic</cite>' => '<cite>italic</cite>',
54
+ '<dfn>italic</dfn>' => '<dfn>italic</dfn>',
55
+
56
+ '<big>larger</big>' => '<big>larger</big>',
57
+ '<small>smaller</small>' => '<small>smaller</small>',
58
+
59
+ '<font color="#45C1D0">F</font>' => '<font color="#45C1D0">F</font>',
60
+
61
+ '<tt>monospaced</tt>' => '<tt>monospaced</tt>',
62
+
63
+ '<s>strike</s>' => '<s>strike</s>',
64
+ '<strike>strike</strike>' => '<strike>strike</strike>',
65
+ '<del>strike</del>' => '<del>strike</del>',
66
+
51
67
  '<u>underline</u>' => '<u>underline</u>',
52
68
 
69
+ '<super>superscript</super>'=> '<super>superscript</super>',
70
+
71
+ '<sub>subscript</sub>' => '<sub>subscript</sub>',
72
+
73
+ '<ul>bullet point</ul>' => '<ul>bullet point</ul>',
74
+ '<li>bullet point</li>' => '<li>bullet point</li>',
75
+
76
+ '<br>line break' => '<br>line break',
77
+
78
+ '<div>division</div>' => '<div>division</div>',
79
+
80
+ '<span style="color:#45C1D0">inline</span>' => '<span style="color:#45C1D0">inline</span>',
81
+
82
+ '<p>para</p>' => '<p>para</p>',
83
+ '<p dir="ltr">para</p>' => '<p dir="ltr">para</p>',
84
+
53
85
  '<b>%@</b>' => '&lt;b>%s&lt;/b>',
86
+ '<em>%@</em>' => '&lt;em>%s&lt;/em>',
87
+
54
88
  '<i>%@</i>' => '&lt;i>%s&lt;/i>',
89
+ '<cite>%@</cite>' => '&lt;cite>%s&lt;/cite>',
90
+ '<dfn>%@</dfn>' => '&lt;dfn>%s&lt;/dfn>',
91
+
92
+ '<big>%@</big>' => '&lt;big>%s&lt;/big>',
93
+ '<small>%@</small>' => '&lt;small>%s&lt;/small>',
94
+
95
+ '<font color="#45C1D0>%@</font>' => '&lt;font color="#45C1D0>%s&lt;/font>',
96
+
97
+ '<tt>%@</tt>' => '&lt;tt>%s&lt;/tt>',
98
+
99
+ '<s>%@</s>' => '&lt;s>%s&lt;/s>',
100
+ '<strike>%@</strike>' => '&lt;strike>%s&lt;/strike>',
101
+ '<del>%@</del>' => '&lt;del>%s&lt;/del>',
102
+
55
103
  '<u>%@</u>' => '&lt;u>%s&lt;/u>',
56
104
 
57
- '<span>inline</span>' => '&lt;span>inline&lt;/span>',
58
- '<p>paragraph</p>' => '&lt;p>paragraph&lt;/p>',
105
+ '<super>%@</super>' => '&lt;super>%s&lt;/super>',
106
+
107
+ '<sub>%@</sub>' => '&lt;sub>%s&lt;/sub>',
108
+
109
+ '<ul>%@</ul>' => '&lt;ul>%s&lt;/ul>',
110
+ '<li>%@</li>' => '&lt;li>%s&lt;/li>',
111
+
112
+ '<br>%@' => '&lt;br>%s',
113
+
114
+ '<div>%@</div>' => '&lt;div>%s&lt;/div>',
115
+
116
+ '<span style="color:#45C1D0">%@</span>' => '&lt;span style="color:#45C1D0">%s&lt;/span>',
117
+
118
+ '<p>%@</p>' => '&lt;p>%s&lt;/p>',
119
+ '<p dir="ltr">%@</p>' => '&lt;p dir="ltr">%s&lt;/p>',
59
120
 
60
121
  '<a href="target">link</a>' => '<a href="target">link</a>',
61
122
  '<a href="target">"link"</a>' => '<a href="target">\"link\"</a>',
62
123
  '<a href="target"></a>"out"' => '<a href="target"></a>\"out\"',
63
124
  '<a href="http://url.com?param=1&param2=3&param3=%20">link</a>' => '<a href="http://url.com?param=1&param2=3&param3=%20">link</a>',
64
125
 
65
- '<p>escaped</p><![CDATA[]]>' => '&lt;p>escaped&lt;/p><![CDATA[]]>',
66
- '<![CDATA[]]><p>escaped</p>' => '<![CDATA[]]>&lt;p>escaped&lt;/p>',
67
- '<![CDATA[<p>unescaped</p>]]>' => '<![CDATA[<p>unescaped</p>]]>',
68
- '<![CDATA[<p>unescaped with %@</p>]]>' => '<![CDATA[<p>unescaped with %s</p>]]>',
69
- '<![CDATA[]]><![CDATA[<p>unescaped</p>]]>' => '<![CDATA[]]><![CDATA[<p>unescaped</p>]]>',
126
+ '<q>escaped</q><![CDATA[]]>' => '&lt;q>escaped&lt;/q><![CDATA[]]>',
127
+ '<![CDATA[]]><q>escaped</q>' => '<![CDATA[]]>&lt;q>escaped&lt;/q>',
128
+ '<![CDATA[<q>unescaped</q>]]>' => '<![CDATA[<q>unescaped</q>]]>',
129
+ '<![CDATA[<q>unescaped with %@</q>]]>' => '<![CDATA[<q>unescaped with %s</q>]]>',
130
+ '<![CDATA[]]><![CDATA[<q>unescaped</q>]]>' => '<![CDATA[]]><![CDATA[<q>unescaped</q>]]>',
70
131
 
71
132
  '<![CDATA[&]]>' => '<![CDATA[&]]>',
72
133
  '<![CDATA[\']]>' => '<![CDATA[\']]>',
@@ -231,6 +292,13 @@ class TestAndroidFormatter < FormatterTest
231
292
  def test_output_path_with_region
232
293
  assert_equal 'values-en-rGB', @formatter.output_path_for_language('en-GB')
233
294
  end
295
+
296
+ def test_output_path_respects_default_lang
297
+ @formatter.twine_file.language_codes.concat KNOWN_LANGUAGES
298
+ non_default_language = KNOWN_LANGUAGES[1..-1].sample
299
+ assert_equal 'values', @formatter.output_path_for_language(KNOWN_LANGUAGES[0])
300
+ assert_equal "values-#{non_default_language}", @formatter.output_path_for_language(non_default_language)
301
+ end
234
302
  end
235
303
 
236
304
  class TestAppleFormatter < FormatterTest
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Celis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-24 00:00:00.000000000 Z
11
+ date: 2019-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -177,7 +177,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  - !ruby/object:Gem::Version
178
178
  version: '0'
179
179
  requirements: []
180
- rubygems_version: 3.0.1
180
+ rubyforge_project:
181
+ rubygems_version: 2.5.2.3
181
182
  signing_key:
182
183
  specification_version: 4
183
184
  summary: Manage strings and their translations for your iOS, Android and other projects.