puttext 0.2.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/puttext/parser/base.rb +0 -3
- data/lib/puttext/parser/ruby.rb +12 -9
- data/puttext.gemspec +1 -1
- data/spec/unit/parser/ruby_spec.rb +30 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c7e0324ec2fadafc1532c4a71ff53f526b45251
|
4
|
+
data.tar.gz: 912c93608cc1f8a5b534c0a0cb9a9ed50989873b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bbf61f00429e95b98f21882dd3bd7093852d45bc2a08bb9b6143aa0341cf27e9bf5ff60fde4c7c4ccabbd3007966ea9181592028de35f4e381019d72fb0dbdf
|
7
|
+
data.tar.gz: 13da779357b574a70f9bc6b7ef80904287ac81c4f07a325533c27984ea8001d77d7052795b5ab6300ab723ac0af2ab369c7c7b6855424ff09a7d8b93a2d40067
|
data/Gemfile.lock
CHANGED
data/lib/puttext/parser/base.rb
CHANGED
@@ -4,9 +4,6 @@ require_relative '../po_entry'
|
|
4
4
|
|
5
5
|
module PutText
|
6
6
|
module Parser
|
7
|
-
# Thrown when any error parsing a file occurs
|
8
|
-
class ParseError < StandardError; end
|
9
|
-
|
10
7
|
class Base
|
11
8
|
# Parse gettext strings from a file in the path.
|
12
9
|
# @param [String] path the path of the file to parse.
|
data/lib/puttext/parser/ruby.rb
CHANGED
@@ -15,8 +15,10 @@ module PutText
|
|
15
15
|
METHODS = {
|
16
16
|
gettext: :regular,
|
17
17
|
_: :regular,
|
18
|
+
N_: :regular,
|
18
19
|
ngettext: :plural,
|
19
20
|
n_: :plural,
|
21
|
+
Nn_: :plural,
|
20
22
|
sgettext: :context_sep,
|
21
23
|
s_: :context_sep,
|
22
24
|
nsgettext: :context_sep_plural,
|
@@ -62,17 +64,11 @@ module PutText
|
|
62
64
|
case ast_node.type
|
63
65
|
when :str
|
64
66
|
ast_node.children[0]
|
65
|
-
else
|
66
|
-
raise ParseError,
|
67
|
-
format('unsupported AST node type: %s', ast_node.type)
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
71
70
|
def po_entry_from_ast_node(ast_node, type)
|
72
|
-
|
73
|
-
line = ast_node.location.line
|
74
|
-
|
75
|
-
entry_attrs = { references: ["#{filename}:#{line}"] }
|
71
|
+
entry_attrs = { references: [ast_node_location(ast_node)] }
|
76
72
|
|
77
73
|
PARAMS[type].each_with_index do |name, index|
|
78
74
|
next if name == :_ # skip parameters named _
|
@@ -81,7 +77,14 @@ module PutText
|
|
81
77
|
entry_attrs[name] = param if param
|
82
78
|
end
|
83
79
|
|
84
|
-
PutText::POEntry.new(entry_attrs)
|
80
|
+
PutText::POEntry.new(entry_attrs) if entry_attrs[:msgid]
|
81
|
+
end
|
82
|
+
|
83
|
+
def ast_node_location(ast_node)
|
84
|
+
filename = ast_node.location.expression.source_buffer.name
|
85
|
+
line = ast_node.location.line
|
86
|
+
|
87
|
+
"#{filename}:#{line}"
|
85
88
|
end
|
86
89
|
|
87
90
|
def find_strings_in_ast(ast_node)
|
@@ -96,7 +99,7 @@ module PutText
|
|
96
99
|
entries += find_strings_in_each_ast(ast_node.children)
|
97
100
|
end
|
98
101
|
|
99
|
-
entries
|
102
|
+
entries.compact
|
100
103
|
end
|
101
104
|
|
102
105
|
def find_strings_in_each_ast(ast_nodes)
|
data/puttext.gemspec
CHANGED
@@ -15,8 +15,10 @@ describe PutText::Parser::Ruby do
|
|
15
15
|
[
|
16
16
|
gettext('gettext'),
|
17
17
|
_('underscore'),
|
18
|
+
N_('nothing underscore'),
|
18
19
|
ngettext('1 ngettext', '%d ngettexts', 5),
|
19
20
|
n_('1 underscore', '%d underscores', 5),
|
21
|
+
Nn_('1 nothing', '%d nothings', 5),
|
20
22
|
sgettext('context|sgettext'),
|
21
23
|
s_('context---s underscore', '---'),
|
22
24
|
nsgettext('context|1 nsgettext', '%d nsgettexts', 5),
|
@@ -45,7 +47,7 @@ describe PutText::Parser::Ruby do
|
|
45
47
|
end
|
46
48
|
|
47
49
|
it 'extracts the correct number of strings' do
|
48
|
-
expect(PutText::POEntry).to have_received(:new).exactly(
|
50
|
+
expect(PutText::POEntry).to have_received(:new).exactly(14).times
|
49
51
|
end
|
50
52
|
|
51
53
|
it 'correctly extracts string from gettext calls' do
|
@@ -62,11 +64,18 @@ describe PutText::Parser::Ruby do
|
|
62
64
|
)
|
63
65
|
end
|
64
66
|
|
67
|
+
it 'correctly extracts string from N_ calls' do
|
68
|
+
expect(PutText::POEntry).to have_received(:new).with(
|
69
|
+
msgid: 'nothing underscore',
|
70
|
+
references: ['test.rb:13']
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
65
74
|
it 'correctly extracts string from ngettext calls' do
|
66
75
|
expect(PutText::POEntry).to have_received(:new).with(
|
67
76
|
msgid: '1 ngettext',
|
68
77
|
msgid_plural: '%d ngettexts',
|
69
|
-
references: ['test.rb:
|
78
|
+
references: ['test.rb:14']
|
70
79
|
)
|
71
80
|
end
|
72
81
|
|
@@ -74,14 +83,22 @@ describe PutText::Parser::Ruby do
|
|
74
83
|
expect(PutText::POEntry).to have_received(:new).with(
|
75
84
|
msgid: '1 underscore',
|
76
85
|
msgid_plural: '%d underscores',
|
77
|
-
references: ['test.rb:
|
86
|
+
references: ['test.rb:15']
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'correctly extracts string from Nn_ calls' do
|
91
|
+
expect(PutText::POEntry).to have_received(:new).with(
|
92
|
+
msgid: '1 nothing',
|
93
|
+
msgid_plural: '%d nothings',
|
94
|
+
references: ['test.rb:16']
|
78
95
|
)
|
79
96
|
end
|
80
97
|
|
81
98
|
it 'correctly extracts string from sgettext calls' do
|
82
99
|
expect(PutText::POEntry).to have_received(:new).with(
|
83
100
|
msgid: 'context|sgettext',
|
84
|
-
references: ['test.rb:
|
101
|
+
references: ['test.rb:17']
|
85
102
|
)
|
86
103
|
end
|
87
104
|
|
@@ -89,7 +106,7 @@ describe PutText::Parser::Ruby do
|
|
89
106
|
expect(PutText::POEntry).to have_received(:new).with(
|
90
107
|
msgid: 'context---s underscore',
|
91
108
|
separator: '---',
|
92
|
-
references: ['test.rb:
|
109
|
+
references: ['test.rb:18']
|
93
110
|
)
|
94
111
|
end
|
95
112
|
|
@@ -97,7 +114,7 @@ describe PutText::Parser::Ruby do
|
|
97
114
|
expect(PutText::POEntry).to have_received(:new).with(
|
98
115
|
msgid: 'context|1 nsgettext',
|
99
116
|
msgid_plural: '%d nsgettexts',
|
100
|
-
references: ['test.rb:
|
117
|
+
references: ['test.rb:19']
|
101
118
|
)
|
102
119
|
end
|
103
120
|
|
@@ -106,7 +123,7 @@ describe PutText::Parser::Ruby do
|
|
106
123
|
msgid: 'context---1 ns underscore',
|
107
124
|
msgid_plural: '%d ns underscores',
|
108
125
|
separator: '---',
|
109
|
-
references: ['test.rb:
|
126
|
+
references: ['test.rb:20']
|
110
127
|
)
|
111
128
|
end
|
112
129
|
|
@@ -114,7 +131,7 @@ describe PutText::Parser::Ruby do
|
|
114
131
|
expect(PutText::POEntry).to have_received(:new).with(
|
115
132
|
msgctxt: 'context',
|
116
133
|
msgid: 'pgettext',
|
117
|
-
references: ['test.rb:
|
134
|
+
references: ['test.rb:21']
|
118
135
|
)
|
119
136
|
end
|
120
137
|
|
@@ -122,7 +139,7 @@ describe PutText::Parser::Ruby do
|
|
122
139
|
expect(PutText::POEntry).to have_received(:new).with(
|
123
140
|
msgctxt: 'context',
|
124
141
|
msgid: 'p underscore',
|
125
|
-
references: ['test.rb:
|
142
|
+
references: ['test.rb:22']
|
126
143
|
)
|
127
144
|
end
|
128
145
|
|
@@ -131,7 +148,7 @@ describe PutText::Parser::Ruby do
|
|
131
148
|
msgctxt: 'context',
|
132
149
|
msgid: '1 npgettext',
|
133
150
|
msgid_plural: '%d npgettexts',
|
134
|
-
references: ['test.rb:
|
151
|
+
references: ['test.rb:23']
|
135
152
|
)
|
136
153
|
end
|
137
154
|
|
@@ -140,7 +157,7 @@ describe PutText::Parser::Ruby do
|
|
140
157
|
msgctxt: 'context',
|
141
158
|
msgid: '1 np underscore',
|
142
159
|
msgid_plural: '%d np underscores',
|
143
|
-
references: ['test.rb:
|
160
|
+
references: ['test.rb:24']
|
144
161
|
)
|
145
162
|
end
|
146
163
|
end
|
@@ -166,10 +183,8 @@ describe PutText::Parser::Ruby do
|
|
166
183
|
RUBY
|
167
184
|
end
|
168
185
|
|
169
|
-
it '
|
170
|
-
expect
|
171
|
-
PutText::Parser::ParseError
|
172
|
-
)
|
186
|
+
it 'skips the entry, returns an empty array' do
|
187
|
+
expect(subject.strings_from_source(ruby_code)).to eq([])
|
173
188
|
end
|
174
189
|
end
|
175
190
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puttext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mantas Norvaiša
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|