jp_strings_finder 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2e5360d873e7e539abffef78140079257ffea65
4
+ data.tar.gz: 4ba1d251bdbfe1a5e8e86cdbcab382c8e5a98d17
5
+ SHA512:
6
+ metadata.gz: 5bc8c4b53fac9f884f5f6f2e97c1a46f457ee9e17d675abfb25700e1419b40543a9e55a40d16e41aa6acfa28d0ec64ab2231947bf9f2e7e0f90a9747db7d1443
7
+ data.tar.gz: d6aa0d57c77b6439f2168af5be016c6339d2a8a81e49d4ec9b7c24b93ac032378f1f9bd004a814962926fcf9d2b827c43aa94c6d6185cbb169b9d89d3d2a3801
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in jp_strings_finder.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Hirofumi Wakasugi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # jp_strings_finder
2
+
3
+ jp_strings_finder is an i18n util for your Japanese project which expected to get translated to other languages.
4
+
5
+ It searchs for Japanese strings in a directory or a file and reports the results like:
6
+
7
+ ```
8
+ $ jp_strings_finder app/
9
+
10
+ +--------------------------------------------+------+------------------------------------------------+
11
+ | File | Type | Strings |
12
+ +--------------------------------------------+------+------------------------------------------------+
13
+ | controllers/books_controller.rb | RUBY | 本を書いました |
14
+ +--------------------------------------------+------+------------------------------------------------+
15
+ | views/books/index.slim | SLIM | 本の一覧ですほげ |
16
+ | | | 次のページを見る |
17
+ +--------------------------------------------+------+------------------------------------------------+
18
+ There are 3 Japanese strings in 2 files
19
+ ```
20
+
21
+ jp_strings_finder currently supports the below file types:
22
+
23
+ - Ruby (`.rb`)
24
+ - ERB (`.erb`)
25
+ - Slim (`.slim`)
26
+
27
+ It fails with status code `-1` when at least 1 Japanese string is found, so it can also be used in your test.
28
+
29
+ ## Usage
30
+
31
+ ### Specifying a single file
32
+
33
+ Specifying a single file searchs for Japanese strings in the file:
34
+
35
+ ```
36
+ $ jp_strings_finder app/views/books/index.slim
37
+ ```
38
+
39
+ ### Specifying a directory
40
+
41
+ Specifying a directory recursively searchs for Japanese strings in the directory:
42
+
43
+ ```
44
+ $ jp_strings_finder app/views/
45
+ ```
46
+
47
+ In both cases, files with not supported filetype are ignore with the below message:
48
+
49
+ ```
50
+ Unsupported filetype [app/views/books/books.csv]
51
+ ```
52
+
53
+ ## Installation
54
+
55
+ Add this line to your application's Gemfile:
56
+
57
+ ```ruby
58
+ gem 'jp_strings_finder'
59
+ ```
60
+
61
+ And then execute:
62
+
63
+ $ bundle
64
+
65
+ Or install it yourself as:
66
+
67
+ $ gem install jp_strings_finder
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jp_strings_finder"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "colorize"
4
+ require "jp_strings_finder"
5
+
6
+ def find_in_file(file_path)
7
+ file_path = File.expand_path(file_path)
8
+ begin
9
+ strings = JpStringsFinder.find_in(file_path)
10
+ rescue => e
11
+ STDERR.puts e.message.colorize(:red)
12
+ return
13
+ end
14
+
15
+ unless strings.empty?
16
+ {
17
+ file: file_path,
18
+ type: JpStringsFinder::FiletypeDetector.new(file_path).filetype, #TODO: directly access to inner class is not preffered
19
+ strings: strings
20
+ }
21
+ end
22
+ end
23
+
24
+ def find_in_directory(dir_path)
25
+ dir_path = File.expand_path(dir_path)
26
+ results = []
27
+ Dir.glob(File.join(dir_path, "/**/*")) do |file_path|
28
+ next if File.directory?(file_path)
29
+ results << find_in_file(file_path)
30
+ end
31
+ results
32
+ end
33
+
34
+ path = ARGV[0]
35
+
36
+ results =
37
+ if File.directory?(path)
38
+ find_in_directory(path).compact
39
+ elsif File.file?(path)
40
+ [find_in_file(path)].compact
41
+ else
42
+ raise "[#{path}] is not found"
43
+ end
44
+
45
+ if results.empty?
46
+ STDERR.puts "Yay! There is no Japanese string exists in your app codes!".colorize(:green)
47
+ exit 0
48
+ else
49
+ JpStringsFinder::Printer.new(results.compact).print_table
50
+ exit 1
51
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "jp_strings_finder/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jp_strings_finder"
8
+ spec.version = JpStringsFinder::VERSION
9
+ spec.authors = ["Hirofumi Wakasugi"]
10
+ spec.email = ["baenej@gmail.com"]
11
+
12
+ spec.summary = "Find string literals using Japanese chanracters in them"
13
+ spec.description = "Find string literals using Japanese chanracters in them"
14
+ spec.homepage = "https://github.com/5t111111/jp_strings_finder.git"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "colorize", "~> 0.8"
25
+ spec.add_runtime_dependency "terminal-table", "~> 1.8"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.15"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "minitest", "~> 5.0"
30
+ spec.add_development_dependency "pry"
31
+ spec.add_development_dependency "pry-byebug"
32
+ spec.add_development_dependency "tapp"
33
+ spec.add_development_dependency "awesome_print"
34
+ end
@@ -0,0 +1,9 @@
1
+ require "jp_strings_finder/version"
2
+ require "jp_strings_finder/finder"
3
+ require "jp_strings_finder/printer"
4
+
5
+ module JpStringsFinder
6
+ def self.find_in(file_path)
7
+ Finder.new(file_path).find
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module JpStringsFinder
2
+ class ERBFinder
3
+ attr_reader :src
4
+
5
+ def initialize(src)
6
+ @src = src
7
+ end
8
+
9
+ # Very very rough implementation for the moment...
10
+ def find
11
+ src.split("\n")
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,19 @@
1
+ module JpStringsFinder
2
+ class FiletypeDetector
3
+ attr_reader :filetype
4
+
5
+ def initialize(file_path)
6
+ @filetype =
7
+ case File.extname(file_path)
8
+ when ".rb"
9
+ :ruby
10
+ when ".erb"
11
+ :erb
12
+ when ".slim"
13
+ :slim
14
+ else
15
+ raise "Unsupported filetype [#{file_path}]"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ require "jp_strings_finder/filetype_detector"
2
+ require "jp_strings_finder/ruby_finder"
3
+ require "jp_strings_finder/erb_finder"
4
+ require "jp_strings_finder/slim_finder"
5
+ require "jp_strings_finder/japanese_detector"
6
+
7
+ module JpStringsFinder
8
+ class Finder
9
+ attr_reader :file_path, :filetype
10
+
11
+ def initialize(file_path)
12
+ @file_path = file_path
13
+ @filetype = FiletypeDetector.new(file_path).filetype
14
+ end
15
+
16
+ def find
17
+ File.open(file_path) do |f|
18
+ finder = filetype_specific_finder.new(f.read)
19
+ finder.find.select do |str|
20
+ JapaneseDetector.contain_japanese?(str)
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def filetype_specific_finder
28
+ @filetype_specific_finder ||=
29
+ case filetype
30
+ when :ruby
31
+ RubyFinder
32
+ when :erb
33
+ ERBFinder
34
+ when :slim
35
+ SlimFinder
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,8 @@
1
+ module JpStringsFinder
2
+ class JapaneseDetector
3
+ def self.contain_japanese?(str)
4
+ jp_pattern = /[\p{Han}\p{Hiragana}\p{Katakana},.、。ー・]+/
5
+ str.match(jp_pattern)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,38 @@
1
+ require "pathname"
2
+ require "terminal-table"
3
+ require "colorize"
4
+
5
+ module JpStringsFinder
6
+ class Printer
7
+ attr_reader :list
8
+
9
+ def initialize(list)
10
+ @list = list
11
+ end
12
+
13
+ def print_table
14
+ table = Terminal::Table.new do |t|
15
+ t.headings = ['File', 'Type', 'Strings']
16
+ list.each_with_index do |hash, index|
17
+ t.add_row(
18
+ [
19
+ to_relative_path(Dir.pwd, hash[:file]),
20
+ hash[:type].upcase,
21
+ hash[:strings].join("\n")
22
+ ]
23
+ )
24
+ t.add_separator unless index == list.count - 1
25
+ end
26
+ end
27
+ puts table
28
+ strings_count = list.inject(0) { |acc, elem| acc + elem[:strings].count }
29
+ STDERR.puts "There are #{strings_count} Japanese strings in #{list.count} files".colorize(:yellow)
30
+ end
31
+
32
+ private
33
+
34
+ def to_relative_path(root, path)
35
+ Pathname.new(path).relative_path_from(Pathname.new(root)).to_s
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,30 @@
1
+ require 'ripper'
2
+
3
+ module JpStringsFinder
4
+ class RubyFinder
5
+ class RipperCustom < Ripper
6
+ attr_reader :strings
7
+
8
+ def initialize(src)
9
+ super(src)
10
+ @strings = []
11
+ end
12
+
13
+ def on_tstring_content(str)
14
+ @strings << str
15
+ end
16
+ end
17
+
18
+ attr_reader :src
19
+
20
+ def initialize(src)
21
+ @src = src
22
+ end
23
+
24
+ def find
25
+ ripper = RipperCustom.new(src)
26
+ ripper.parse
27
+ ripper.strings
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ module JpStringsFinder
2
+ class SlimFinder
3
+ attr_reader :src
4
+
5
+ def initialize(src)
6
+ @src = src
7
+ end
8
+
9
+ # Very very rough implementation for the moment...
10
+ def find
11
+ src.split("\n")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module JpStringsFinder
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jp_strings_finder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hirofumi Wakasugi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: terminal-table
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: tapp
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: awesome_print
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Find string literals using Japanese chanracters in them
140
+ email:
141
+ - baenej@gmail.com
142
+ executables:
143
+ - jp_strings_finder
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - bin/console
154
+ - bin/setup
155
+ - exe/jp_strings_finder
156
+ - jp_strings_finder.gemspec
157
+ - lib/jp_strings_finder.rb
158
+ - lib/jp_strings_finder/erb_finder.rb
159
+ - lib/jp_strings_finder/filetype_detector.rb
160
+ - lib/jp_strings_finder/finder.rb
161
+ - lib/jp_strings_finder/japanese_detector.rb
162
+ - lib/jp_strings_finder/printer.rb
163
+ - lib/jp_strings_finder/ruby_finder.rb
164
+ - lib/jp_strings_finder/slim_finder.rb
165
+ - lib/jp_strings_finder/version.rb
166
+ homepage: https://github.com/5t111111/jp_strings_finder.git
167
+ licenses:
168
+ - MIT
169
+ metadata: {}
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 2.6.11
187
+ signing_key:
188
+ specification_version: 4
189
+ summary: Find string literals using Japanese chanracters in them
190
+ test_files: []