dotstrings 0.1.0 → 0.1.1

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: 9c23d2110a873db44936fc87e1c89e41300a82edfdde9c8a357679c1b378cc27
4
- data.tar.gz: 81363243a7425d43383246594362b23740ee22a03b3d8d74f871cf8ea113809c
3
+ metadata.gz: 3fc37db8d1dfc887f3bba22642ab731ca37e2ea3963a7e4998fa843f8b08a1d5
4
+ data.tar.gz: a8e82e134a26188fb4ac299cf5b5d02a437f90706844e72cdfe2d6b329681eb8
5
5
  SHA512:
6
- metadata.gz: 01a9055615619969260d1012c0a027338d85d73495ac664e6ac72c4a6bb7d3368eb4554496d5622940e660ea01d44fe2949bbf3aa88149ab05b284c021792456
7
- data.tar.gz: ca19e173e63d4b820b9cd2ebbd4030ef70bb33080822738a4e290e4ce01b6f6be64c9578a858dffd8ae46d6423e343f0345611f1f1a5a04ca48a2ad9fc7b145f
6
+ metadata.gz: c21229aef0c1188c8338b4478898d45e31e11a7413d71bb6a9e7200240bc15d15c69f500b9ae031636369c98a0ba912918c706a7f4b45f03eb35c6b30f5426b3
7
+ data.tar.gz: 5a1ef97552447cdf70cac24bf943af085fcf0ffd264435180764247f9cde38e8745e42d50254082db13402088a5d11930ca043a487e66bfb9155e7164236e5e0
data/.rubocop.yml CHANGED
@@ -10,6 +10,10 @@ Style/StringLiterals:
10
10
  Enabled: true
11
11
  EnforcedStyle: single_quotes
12
12
 
13
+ Layout/FirstHashElementIndentation:
14
+ Enabled: true
15
+ EnforcedStyle: consistent
16
+
13
17
  Metrics/ClassLength:
14
18
  Enabled: true
15
19
  Max: 150
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dotstrings (0.1.0)
4
+ dotstrings (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -48,11 +48,11 @@ module DotStrings
48
48
  @items.delete_if { |item| item.key == key }
49
49
  end
50
50
 
51
- def to_s
51
+ def to_s(escape_single_quotes: false)
52
52
  result = []
53
53
 
54
54
  @items.each do |item|
55
- result << item.to_s
55
+ result << item.to_s(escape_single_quotes: escape_single_quotes)
56
56
  result << ''
57
57
  end
58
58
 
@@ -10,27 +10,31 @@ module DotStrings
10
10
  @value = value
11
11
  end
12
12
 
13
- def to_s
13
+ def to_s(escape_single_quotes: false)
14
14
  result = []
15
15
 
16
16
  result << "/* #{comment} */" unless comment.nil?
17
- result << "\"#{serialize_string(key)}\" = \"#{serialize_string(value)}\";"
17
+ result << format('"%<key>s" = "%<value>s";', {
18
+ key: serialize_string(key, escape_single_quotes: escape_single_quotes),
19
+ value: serialize_string(value, escape_single_quotes: escape_single_quotes)
20
+ })
18
21
 
19
22
  result.join("\n")
20
23
  end
21
24
 
22
25
  private
23
26
 
24
- def serialize_string(string)
27
+ def serialize_string(string, escape_single_quotes:)
25
28
  replacements = [
26
29
  ['"', '\\"'],
27
- ["'", "\\'"],
28
30
  ["\t", '\t'],
29
31
  ["\n", '\n'],
30
32
  ["\r", '\r'],
31
33
  ["\0", '\\0']
32
34
  ]
33
35
 
36
+ replacements << ["'", "\\'"] if escape_single_quotes
37
+
34
38
  replacements.each do |replacement|
35
39
  string = string.gsub(replacement[0]) { replacement[1] }
36
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DotStrings
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
data/test/test_file.rb CHANGED
@@ -58,9 +58,24 @@ class TestFile < MiniTest::Test
58
58
  "key 3" = "👻";
59
59
 
60
60
  /* Comment 4 */
61
- "\"\'\t\n\r\0" = "\"\'\t\n\r\0";
61
+ "\"'\t\n\r\0" = "\"'\t\n\r\0";
62
62
  END_OF_DOCUMENT
63
63
 
64
64
  assert_equal expected, file.to_s
65
65
  end
66
+
67
+ def test_to_string_can_escape_single_quotes
68
+ items = [
69
+ DotStrings::Item.new(comment: 'Comment', key: "key'", value: "value'")
70
+ ]
71
+
72
+ file = DotStrings::File.new(items)
73
+
74
+ expected = <<~'END_OF_DOCUMENT'
75
+ /* Comment */
76
+ "key\'" = "value\'";
77
+ END_OF_DOCUMENT
78
+
79
+ assert_equal expected, file.to_s(escape_single_quotes: true)
80
+ end
66
81
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotstrings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Torres
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-06 00:00:00.000000000 Z
11
+ date: 2022-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -154,7 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
- rubygems_version: 3.0.1
157
+ rubyforge_project:
158
+ rubygems_version: 2.7.6
158
159
  signing_key:
159
160
  specification_version: 4
160
161
  summary: Parse and create .strings files used in localization of iOS and macOS apps.