export_strings 0.1.1.dev → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile.lock +1 -1
- data/README.md +22 -15
- data/example/example.rb +39 -1
- data/lib/export_strings/by_lex.rb +64 -0
- data/lib/export_strings/by_sexp.rb +45 -0
- data/lib/export_strings/core.rb +7 -33
- data/lib/export_strings/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01ab06d2a7a05856a986c9fd06628dfa632ff7459c2c3c64e71080eb9cdb3d4d
|
4
|
+
data.tar.gz: 247cb0c82d133169ed5af2d410b2a4dfcd1bf2a564a2957284159b8facaa2dc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 931b2c46ccf51b73a41da64f4883a9e945babd11998a7db02137f0a6a04d4d0af02d19d40c2edeacf3979cf88d055a4f7092ac7ed6b2c2587f75e307c36c3d01
|
7
|
+
data.tar.gz: 61dc2265e7c793f7c571bea68a28b9765e7755b6f82edaf1f3ad1bcb5269d3ec74edacd52727496a8e7d6a62585091720eae81023cd795dcb0fd1e4d60ce68b5
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -21,12 +21,11 @@ Or install it yourself as:
|
|
21
21
|
```rb
|
22
22
|
require 'export_strings'
|
23
23
|
|
24
|
-
|
24
|
+
ExportStrings.execute rb_file_path
|
25
25
|
|
26
26
|
=> [String, String, String, String]
|
27
27
|
```
|
28
28
|
|
29
|
-
|
30
29
|
## Example
|
31
30
|
|
32
31
|
```rb
|
@@ -43,6 +42,14 @@ class Example
|
|
43
42
|
def str2
|
44
43
|
"I like gohan. Do you like gohan.Oh Yeah."
|
45
44
|
end
|
45
|
+
|
46
|
+
def str3
|
47
|
+
"#{hello} Mikel"
|
48
|
+
end
|
49
|
+
|
50
|
+
def hello
|
51
|
+
'hello world'
|
52
|
+
end
|
46
53
|
end
|
47
54
|
|
48
55
|
# =======your irb console=======
|
@@ -51,25 +58,29 @@ require 'export_strings'
|
|
51
58
|
pp ExportStrings.execute 'example.rb'
|
52
59
|
|
53
60
|
[" SELECT *\n" + " FROM users\n" + " WHERE id > 100\n",
|
54
|
-
"I like gohan. Do you like gohan.Oh Yeah."
|
61
|
+
"I like gohan. Do you like gohan.Oh Yeah.",
|
62
|
+
"\#{hello} Mikel",
|
63
|
+
"hello world"]
|
55
64
|
|
56
|
-
=> ["
|
65
|
+
=> ["SELECT *\n FROM users\n WHERE id > 100\n", "I like gohan. Do you like gohan.Oh Yeah.", "\#{hello} Mikel", "hello world"]
|
57
66
|
|
58
|
-
|
67
|
+
pp ExportStrings.execute 'example.rb', with_embexpr: false
|
59
68
|
|
60
|
-
|
61
|
-
|
62
|
-
|
69
|
+
[" SELECT *\n" + " FROM users\n" + " WHERE id > 100\n",
|
70
|
+
"I like gohan. Do you like gohan.Oh Yeah.",
|
71
|
+
" Mikel",
|
72
|
+
"hello world"]
|
63
73
|
|
64
|
-
|
74
|
+
=> ["SELECT *\n FROM users\n WHERE id > 100\n", "I like gohan. Do you like gohan.Oh Yeah.", " Mikel", "hello world"]
|
75
|
+
```
|
65
76
|
|
66
77
|
## Schedule
|
67
78
|
|
68
79
|
### I want to develop this to make gem of format or parce.
|
69
80
|
|
70
81
|
- Implement to export from singleton_method
|
71
|
-
- Implement to export from string interpolation
|
72
|
-
- Implement to export from `hoge ? 'page' : 'peke'
|
82
|
+
- ~~Implement to export from string interpolation~~ fix
|
83
|
+
- ~~Implement to export from `hoge ? 'page' : 'peke'`~~ fix
|
73
84
|
|
74
85
|
## Contributing
|
75
86
|
|
@@ -78,7 +89,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/tashir
|
|
78
89
|
## License
|
79
90
|
|
80
91
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
81
|
-
|
82
|
-
## Code of Conduct
|
83
|
-
|
84
|
-
Everyone interacting in the ExportStrings project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/export_strings/blob/master/CODE_OF_CONDUCT.md).
|
data/example/example.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class Example
|
2
|
+
@pokemon = 'pokemon'
|
2
3
|
|
3
4
|
def str
|
4
5
|
<<-SQL
|
@@ -35,7 +36,10 @@ a asdfasdfasdfasdfsh
|
|
35
36
|
GROUP BY gender
|
36
37
|
HAVING 100 > Max(#{hogeo})
|
37
38
|
AND HAVING 1000 < Max(#{test})
|
38
|
-
|
39
|
+
AND HAVING 1000 < Max(#{String.new})
|
40
|
+
AND HAVING 1000 < Max(#{test; test})
|
41
|
+
AND HAVING 1000 < Max(#{@pokemon})
|
42
|
+
#{!!test ? 'hogeo' : 'hoge'}
|
39
43
|
"
|
40
44
|
end
|
41
45
|
|
@@ -53,5 +57,39 @@ a asdfasdfasdfasdfsh
|
|
53
57
|
def single_auot
|
54
58
|
'single_quot_str'
|
55
59
|
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Example2
|
63
|
+
def hogeo2
|
64
|
+
'test'
|
65
|
+
"test"
|
66
|
+
'test' + "test"
|
67
|
+
'test' << 'test'
|
68
|
+
end
|
56
69
|
|
70
|
+
def test2
|
71
|
+
'hi'
|
72
|
+
end
|
57
73
|
end
|
74
|
+
|
75
|
+
class Example
|
76
|
+
def str1
|
77
|
+
<<-SQL
|
78
|
+
SELECT *
|
79
|
+
FROM users
|
80
|
+
WHERE id > 100
|
81
|
+
SQL
|
82
|
+
end
|
83
|
+
|
84
|
+
def str2
|
85
|
+
"I like gohan. Do you like gohan.Oh Yeah."
|
86
|
+
end
|
87
|
+
|
88
|
+
def str3
|
89
|
+
"#{hello} Mikel"
|
90
|
+
end
|
91
|
+
|
92
|
+
def hello
|
93
|
+
'hello world'
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'ripper'
|
2
|
+
|
3
|
+
module ExportStrings
|
4
|
+
class ByLex
|
5
|
+
class << self
|
6
|
+
def execute(rb_text)
|
7
|
+
@string_flag = false
|
8
|
+
@embexpr_flag = false
|
9
|
+
@str = ''
|
10
|
+
results = []
|
11
|
+
Ripper.lex(rb_text).each do |ary_code|
|
12
|
+
code_type = ary_code[1]
|
13
|
+
code_content = ary_code[2]
|
14
|
+
if embexpr_flag(code_type)
|
15
|
+
@str << code_content
|
16
|
+
next
|
17
|
+
end
|
18
|
+
|
19
|
+
if string_flag(code_type)
|
20
|
+
next if code_type == :on_tstring_beg || code_type == :on_heredoc_beg
|
21
|
+
|
22
|
+
@str << code_content
|
23
|
+
elsif !string_flag(code_type) && !@str.empty?
|
24
|
+
results.push @str
|
25
|
+
@str = ''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
results
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# string_flag = trueのときは
|
34
|
+
# on_tstring_beg ~ on_tstring_end || on_heredoc_beg ~ on_heredoc_endまでを
|
35
|
+
# 文字列として扱う
|
36
|
+
def string_flag(code_type)
|
37
|
+
@string_flag = case code_type
|
38
|
+
when :on_tstring_beg
|
39
|
+
true
|
40
|
+
when :on_heredoc_beg
|
41
|
+
true
|
42
|
+
when :on_tstring_end
|
43
|
+
false
|
44
|
+
when :on_heredoc_end
|
45
|
+
false
|
46
|
+
else
|
47
|
+
@string_flag
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# 文字列展開対応
|
52
|
+
def embexpr_flag(code_type)
|
53
|
+
@embexpr_flag = case code_type
|
54
|
+
when :on_embexpr_beg
|
55
|
+
true
|
56
|
+
when :on_embexpr_end
|
57
|
+
false
|
58
|
+
else
|
59
|
+
@embexpr_flag
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'ripper'
|
2
|
+
|
3
|
+
module ExportStrings
|
4
|
+
# 文字列展開は含めない
|
5
|
+
class BySexp
|
6
|
+
class << self
|
7
|
+
def execute(rb_text)
|
8
|
+
str_content_nodes = recursively_push_for_str_content_nodes Ripper.sexp(rb_text), []
|
9
|
+
content_nodes2str_ary str_content_nodes
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
# 再帰的にstring_literal nodeを集めてくる
|
15
|
+
def recursively_push_for_str_content_nodes(tree, nodes)
|
16
|
+
tree.each do |node|
|
17
|
+
if node.class == Array && node[0] == :string_content
|
18
|
+
nodes << node
|
19
|
+
elsif node.class == Array
|
20
|
+
recursively_push_for_str_content_nodes(node, nodes)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
nodes
|
24
|
+
end
|
25
|
+
|
26
|
+
# nodesをstringsに変換して返す
|
27
|
+
def content_nodes2str_ary(nodes)
|
28
|
+
nodes.map { |node| str_content_node2str node, '' }
|
29
|
+
end
|
30
|
+
|
31
|
+
# 各nodeをstringに変換する
|
32
|
+
def str_content_node2str(string_content_node, str)
|
33
|
+
string_content_node.each do |leaf|
|
34
|
+
if leaf.class == Array && leaf[0] == :@tstring_content
|
35
|
+
# 通常のstringが格納される時
|
36
|
+
str << leaf[1]
|
37
|
+
elsif leaf.class == Array
|
38
|
+
str_content_node2str(leaf, str)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
str
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/export_strings/core.rb
CHANGED
@@ -1,42 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require 'export_strings/by_lex'
|
2
|
+
require 'export_strings/by_sexp'
|
2
3
|
|
3
4
|
module ExportStrings
|
4
5
|
class Core
|
5
6
|
class << self
|
6
|
-
def execute(rb_text)
|
7
|
-
|
8
|
-
recursively_push_str_nodes Ripper.sexp(rb_text)
|
9
|
-
to_strings @str_nodes
|
7
|
+
def execute(rb_text, with_embexpr: true)
|
8
|
+
with_embexpr ? ByLex.execute(rb_text) : BySexp.execute(rb_text)
|
10
9
|
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
tree.each do |node|
|
16
|
-
if node.class == Array && node[0] == :string_content
|
17
|
-
@str_nodes << node
|
18
|
-
elsif node.class == Array
|
19
|
-
recursively_push_str_nodes(node)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_strings(nodes)
|
25
|
-
nodes.map do |node|
|
26
|
-
@string = ''
|
27
|
-
str_content_node2str node
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def str_content_node2str(string_content_node)
|
32
|
-
string_content_node.each do |leaf|
|
33
|
-
if leaf.class == Array && leaf[0] == :@tstring_content
|
34
|
-
@string << leaf[1]
|
35
|
-
elsif leaf.class == Array
|
36
|
-
str_content_node2str(leaf)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
@string
|
11
|
+
# 文字列展開は除外したい時
|
12
|
+
def execute_with_out_embexpr(rb_text)
|
13
|
+
execute rb_text, with_embexpr: false
|
40
14
|
end
|
41
15
|
end
|
42
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: export_strings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tashiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -74,6 +74,8 @@ files:
|
|
74
74
|
- example/example.rb
|
75
75
|
- export_strings.gemspec
|
76
76
|
- lib/export_strings.rb
|
77
|
+
- lib/export_strings/by_lex.rb
|
78
|
+
- lib/export_strings/by_sexp.rb
|
77
79
|
- lib/export_strings/core.rb
|
78
80
|
- lib/export_strings/version.rb
|
79
81
|
homepage: https://github.com/tashirosota/ruby-export_strings
|
@@ -94,9 +96,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
96
|
version: '0'
|
95
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
98
|
requirements:
|
97
|
-
- - "
|
99
|
+
- - ">="
|
98
100
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
101
|
+
version: '0'
|
100
102
|
requirements: []
|
101
103
|
rubygems_version: 3.0.3
|
102
104
|
signing_key:
|