haml-i18n-extractor 0.0.21 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/TODO +1 -0
- data/bin/haml-i18n-extractor +14 -19
- data/haml-i18n-extractor.gemspec +2 -0
- data/lib/haml-i18n-extractor/cli.rb +40 -0
- data/lib/haml-i18n-extractor/extractor.rb +6 -5
- data/lib/haml-i18n-extractor/prompter.rb +4 -0
- data/lib/haml-i18n-extractor/version.rb +1 -1
- data/lib/haml-i18n-extractor/workflow.rb +21 -10
- data/lib/haml-i18n-extractor.rb +2 -0
- data/test/cli_test.rb +31 -0
- data/test/extractor_test.rb +12 -12
- data/test/prompter_test.rb +3 -3
- data/test/workflow_test.rb +11 -9
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjgwZDJiZjM2NDdkYmUwZDNlODFmNmY4NWYwZWYzMmVjNGM0YjVmMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjZhOTA5YTVmMDE2YmQxMzcyNmUxMDk3NzFkODNkN2FmMWY5MGM1OQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzU2NTgwNDVlMTE5NDlkMzFhMmViNTYwY2FhZmFiNzJhNTVjNGIzNmM0MTli
|
10
|
+
NWZlYjc2ZDg5MTM2ZDU5NTEwNjQyZDdlNWRiYjIxMGZjNDIwYWMyNzk1MmRk
|
11
|
+
OGRiMmJmNmE3ZjcwNmM4YTA4ZDQ0ZmI2MWFlZjQ1NGExODhkN2Y=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWRmZjIwNzUyZWM1ODhmYWQ0N2Q3ODk3MmYxZGE0NjBiNmQ5ODI3MmUyYzgz
|
14
|
+
Y2NjZTE3MzI5ZjU1YjU1NjQ3YjgyZTM5M2NmNTRmMDgzNzhiNGNjOTM5MjRk
|
15
|
+
MzE0OWE5YjVhMTNkMjNlNzU5ZDQ0MzFhZDI4N2NjMDljMjZjMDI=
|
data/TODO
CHANGED
data/bin/haml-i18n-extractor
CHANGED
@@ -2,27 +2,22 @@
|
|
2
2
|
|
3
3
|
require 'haml-i18n-extractor'
|
4
4
|
|
5
|
-
|
6
|
-
puts "Usage: <haml-i18n-extractor> --version"
|
7
|
-
puts "Usage: <haml-i18n-extractor> [path]"
|
8
|
-
puts "Usage: <haml-i18n-extractor> [filename] --no-prompt"
|
9
|
-
abort
|
10
|
-
end
|
5
|
+
@prompter = Haml::I18n::Extractor::Prompter.new
|
11
6
|
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
option_parser = Trollop::Parser.new do
|
8
|
+
version "Current version: #{Haml::I18n::Extractor::VERSION}"
|
9
|
+
opt :interactive, "interactive mode", :short => 'i'
|
10
|
+
opt :non_interactive, "non interactive mode", :short => 'n'
|
11
|
+
opt :path, "path", :type => String
|
15
12
|
end
|
16
13
|
|
17
|
-
|
14
|
+
opts = Trollop::with_standard_exception_handling option_parser do
|
15
|
+
raise Trollop::HelpNeeded if ARGV.empty?
|
16
|
+
option_parser.parse ARGV
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
extractor = Haml::I18n::Extractor.new(pth, :type => :overwrite, :prompt_per_line => false)
|
24
|
-
extractor.run
|
25
|
-
elsif File.exists?(pth)
|
26
|
-
extractor = Haml::I18n::Extractor.new(pth, :type => :overwrite, :prompt_per_line => true)
|
27
|
-
extractor.run
|
19
|
+
begin
|
20
|
+
Haml::I18n::Extractor::CLI.new(opts).start
|
21
|
+
rescue Haml::I18n::Extractor::CLI::CliError
|
22
|
+
@prompter.puts("please try again")
|
28
23
|
end
|
data/haml-i18n-extractor.gemspec
CHANGED
@@ -21,8 +21,10 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_dependency "haml"
|
22
22
|
gem.add_dependency "activesupport"
|
23
23
|
gem.add_dependency "highline"
|
24
|
+
gem.add_dependency "trollop", "1.16.2"
|
24
25
|
|
25
26
|
gem.add_development_dependency 'rbench'
|
27
|
+
gem.add_development_dependency 'm'
|
26
28
|
gem.add_development_dependency 'pry'
|
27
29
|
gem.add_development_dependency 'minitest'
|
28
30
|
gem.add_development_dependency 'nokogiri'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class Haml::I18n::Extractor
|
2
|
+
class CLI
|
3
|
+
|
4
|
+
class CliError < StandardError; end
|
5
|
+
|
6
|
+
def initialize(opts)
|
7
|
+
@options = opts || {}
|
8
|
+
@prompter = Haml::I18n::Extractor::Prompter.new # may as well
|
9
|
+
end
|
10
|
+
|
11
|
+
def start
|
12
|
+
check_interactive_or_not_passed
|
13
|
+
if @options[:path]
|
14
|
+
check_interactive_or_not_passed
|
15
|
+
pth = File.expand_path(@options[:path])
|
16
|
+
|
17
|
+
if File.directory?(pth)
|
18
|
+
workflow = Haml::I18n::Extractor::Workflow.new(pth, @options)
|
19
|
+
workflow.run
|
20
|
+
elsif File.exists?(pth) && @options[:interactive]
|
21
|
+
extractor = Haml::I18n::Extractor.new(pth, :type => :overwrite, :interactive => true)
|
22
|
+
extractor.run
|
23
|
+
elsif File.exists?(pth) && @options[:non_interactive]
|
24
|
+
extractor = Haml::I18n::Extractor.new(pth, :type => :overwrite, :interactive => false)
|
25
|
+
extractor.run
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def check_interactive_or_not_passed
|
33
|
+
if !@options[:interactive] && !@options[:non_interactive]
|
34
|
+
@prompter.puts("You must choose either one of interactive mode or non interactive mode.")
|
35
|
+
@prompter.puts("See haml-i18n-extractor --help")
|
36
|
+
raise CliError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -20,8 +20,9 @@ module Haml
|
|
20
20
|
DEFAULT_LINE_LOCALE_HASH = { :modified_line => nil,:keyname => nil,:replaced_text => nil, :path => nil }
|
21
21
|
|
22
22
|
def initialize(haml_path, opts = {})
|
23
|
-
@
|
24
|
-
@
|
23
|
+
@options = opts
|
24
|
+
@type = @options[:type]
|
25
|
+
@interactive = @options[:interactive]
|
25
26
|
@prompter = Haml::I18n::Extractor::Prompter.new
|
26
27
|
@haml_reader = Haml::I18n::Extractor::HamlReader.new(haml_path)
|
27
28
|
validate_haml(@haml_reader.body)
|
@@ -79,7 +80,7 @@ module Haml
|
|
79
80
|
|
80
81
|
user_action = Haml::I18n::Extractor::UserAction.new('y') # default if no prompting: just do it.
|
81
82
|
if should_be_replaced
|
82
|
-
if
|
83
|
+
if interactive?
|
83
84
|
user_action = @prompter.ask_user(orig_line,text_to_replace)
|
84
85
|
end
|
85
86
|
end
|
@@ -100,8 +101,8 @@ module Haml
|
|
100
101
|
return should_be_replaced
|
101
102
|
end
|
102
103
|
|
103
|
-
def
|
104
|
-
!!@
|
104
|
+
def interactive?
|
105
|
+
!!@interactive
|
105
106
|
end
|
106
107
|
|
107
108
|
private
|
@@ -5,8 +5,9 @@ module Haml
|
|
5
5
|
|
6
6
|
attr_reader :extractors
|
7
7
|
|
8
|
-
def initialize(project_path)
|
8
|
+
def initialize(project_path, options = {})
|
9
9
|
@extractors = []
|
10
|
+
@passed_options = options
|
10
11
|
@project_path = project_path
|
11
12
|
@prompter = Haml::I18n::Extractor::Prompter.new
|
12
13
|
unless File.directory?(@project_path)
|
@@ -14,6 +15,10 @@ module Haml
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
18
|
+
def interactive?
|
19
|
+
!!@passed_options[:interactive]
|
20
|
+
end
|
21
|
+
|
17
22
|
def files
|
18
23
|
@haml_files ||= Dir.glob(@project_path + "/**/*").select do |file|
|
19
24
|
file.match /.haml$/
|
@@ -32,16 +37,22 @@ module Haml
|
|
32
37
|
end
|
33
38
|
|
34
39
|
def run
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
if interactive?
|
41
|
+
start_message
|
42
|
+
files.each do |haml_path|
|
43
|
+
type = process_file?(haml_path)
|
44
|
+
if type
|
45
|
+
process(haml_path, type)
|
46
|
+
else
|
47
|
+
@prompter.not_processing(haml_path)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end_message
|
51
|
+
else
|
52
|
+
files.each do |haml_path|
|
53
|
+
process(haml_path, :overwrite)
|
42
54
|
end
|
43
55
|
end
|
44
|
-
end_message
|
45
56
|
end
|
46
57
|
|
47
58
|
private
|
@@ -57,7 +68,7 @@ module Haml
|
|
57
68
|
def process(haml_path, type)
|
58
69
|
@prompter.process(haml_path, type)
|
59
70
|
options = {:type => type} # overwrite or dump haml
|
60
|
-
options.merge!({:
|
71
|
+
options.merge!({:interactive => @passed_options[:interactive]}) # per-line prompts
|
61
72
|
begin
|
62
73
|
@extractor = Haml::I18n::Extractor.new(haml_path, options)
|
63
74
|
@extractors << @extractor
|
data/lib/haml-i18n-extractor.rb
CHANGED
data/test/cli_test.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Haml
|
4
|
+
class CLITest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
test "it needs an explicit interactive or non-interactive option" do
|
7
|
+
opts = {:non_interactive => nil, :interactive => nil}
|
8
|
+
with_highline do
|
9
|
+
begin
|
10
|
+
Haml::I18n::Extractor::CLI.new(opts).start
|
11
|
+
rescue Haml::I18n::Extractor::CLI::CliError
|
12
|
+
assert @output.string.match(/--help/), "passing interactive or not"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
test "with a interactive option it needs a path" do
|
18
|
+
opts = {:non_interactive => nil, :path => nil}
|
19
|
+
with_highline do
|
20
|
+
begin
|
21
|
+
Haml::I18n::Extractor::CLI.new(opts).start
|
22
|
+
rescue Haml::I18n::Extractor::CLI::CliError
|
23
|
+
assert @output.string.match(/--help/), "passing interactive or not needs path"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
data/test/extractor_test.rb
CHANGED
@@ -18,15 +18,15 @@ module Haml
|
|
18
18
|
assert_equal h.haml_writer.overwrite?, false
|
19
19
|
end
|
20
20
|
|
21
|
-
test "with a
|
22
|
-
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :
|
23
|
-
assert_equal h.
|
21
|
+
test "with a interactive option which prompts the user-per line" do
|
22
|
+
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
|
23
|
+
assert_equal h.interactive?, true
|
24
24
|
h = Haml::I18n::Extractor.new(file_path("ex1.haml"))
|
25
|
-
assert_equal h.
|
25
|
+
assert_equal h.interactive?, false
|
26
26
|
end
|
27
27
|
|
28
|
-
test "with a
|
29
|
-
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :
|
28
|
+
test "with a interactive option takes user input into consideration for haml" do
|
29
|
+
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
|
30
30
|
user_input = "D" # dump
|
31
31
|
File.readlines(file_path("ex1.haml")).size.times do
|
32
32
|
user_input << "n" # do not replace lines
|
@@ -38,8 +38,8 @@ module Haml
|
|
38
38
|
assert_equal File.read(h.haml_writer.path), File.read(file_path("ex1.haml"))
|
39
39
|
end
|
40
40
|
|
41
|
-
test "with a
|
42
|
-
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :
|
41
|
+
test "with a interactive option takes user input N as next and stops processing file" do
|
42
|
+
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
|
43
43
|
user_input = "D" # dump
|
44
44
|
File.readlines(file_path("ex1.haml")).size.times do
|
45
45
|
user_input << "N" # just move on to next file
|
@@ -51,9 +51,9 @@ module Haml
|
|
51
51
|
assert_equal File.read(h.haml_writer.path), File.read(file_path("ex1.haml"))
|
52
52
|
end
|
53
53
|
|
54
|
-
test "with a
|
54
|
+
test "with a interactive option takes user input into consideration for yaml" do
|
55
55
|
TestHelper.hax_shit
|
56
|
-
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :
|
56
|
+
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
|
57
57
|
user_input = "D" # dump
|
58
58
|
File.readlines(file_path("ex1.haml")).size.times do
|
59
59
|
user_input << "n" # do not replace lines
|
@@ -65,12 +65,12 @@ module Haml
|
|
65
65
|
assert_equal YAML.load(File.read(h.yaml_tool.locale_file)), {}
|
66
66
|
end
|
67
67
|
|
68
|
-
test "with a
|
68
|
+
test "with a interactive option user can tag a line for later review" do
|
69
69
|
TestHelper.hax_shit
|
70
70
|
if File.exist?(Haml::I18n::Extractor::TaggingTool::DB)
|
71
71
|
assert_equal File.readlines(Haml::I18n::Extractor::TaggingTool::DB), []
|
72
72
|
end
|
73
|
-
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :
|
73
|
+
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
|
74
74
|
user_input = "D" # dump
|
75
75
|
File.readlines(file_path("ex1.haml")).size.times do
|
76
76
|
user_input << "t" # tag the lines
|
data/test/prompter_test.rb
CHANGED
@@ -4,19 +4,19 @@ module Haml
|
|
4
4
|
# misnomer, this is also testing UserAction
|
5
5
|
class PrompterAndUserActionTest < MiniTest::Unit::TestCase
|
6
6
|
|
7
|
-
|
7
|
+
test "asks_to_process_line_yes" do
|
8
8
|
with_highline("y") do
|
9
9
|
assert_equal Haml::I18n::Extractor::Prompter.new.ask_user("orig", "replace").replace_line?, true
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
test "asks_to_process_line_no" do
|
14
14
|
with_highline("n") do
|
15
15
|
assert_equal Haml::I18n::Extractor::Prompter.new.ask_user("orig", "replace").no_replace?, true
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
test "test_asks_to_process_line_tag" do
|
20
20
|
with_highline("t") do
|
21
21
|
assert_equal Haml::I18n::Extractor::Prompter.new.ask_user("orig", "replace").tag?, true
|
22
22
|
end
|
data/test/workflow_test.rb
CHANGED
@@ -12,26 +12,28 @@ module Haml
|
|
12
12
|
TestHelper.teardown_project_directory!
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
test "it_should_work_on_a_directory_mkay" do
|
16
|
+
begin
|
17
|
+
filename = "#{TestHelper::PROJECT_DIR}app/views/bar/thang.haml"
|
18
|
+
bad_worfklow = Haml::I18n::Extractor::Workflow.new(filename)
|
19
|
+
assert false, "should raise"
|
20
|
+
rescue Haml::I18n::Extractor::NotADirectory
|
21
|
+
assert true, "workflow works on a directory bubba."
|
22
|
+
end
|
21
23
|
end
|
22
24
|
|
23
|
-
|
25
|
+
test "it_finds_all_haml_files" do
|
24
26
|
assert_equal @workflow.files.size, 6
|
25
27
|
end
|
26
28
|
|
27
|
-
|
29
|
+
test "outputs_stats" do
|
28
30
|
with_highline do
|
29
31
|
@workflow.start_message
|
30
32
|
assert @output.string.match(/Found 6 haml files/), "Outputs stats"
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
|
36
|
+
test "yaml_file_in_config" do
|
35
37
|
TestHelper.mock_full_project_user_interaction!
|
36
38
|
end
|
37
39
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml-i18n-extractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shai Rosenfeld
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: trollop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.16.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.16.2
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rbench
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - ! '>='
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: m
|
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'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: pry
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,6 +212,7 @@ files:
|
|
184
212
|
- demo/haml-i18n-extractor-demo.swf
|
185
213
|
- haml-i18n-extractor.gemspec
|
186
214
|
- lib/haml-i18n-extractor.rb
|
215
|
+
- lib/haml-i18n-extractor/cli.rb
|
187
216
|
- lib/haml-i18n-extractor/core-ext/hash.rb
|
188
217
|
- lib/haml-i18n-extractor/extractor.rb
|
189
218
|
- lib/haml-i18n-extractor/haml_reader.rb
|
@@ -197,6 +226,7 @@ files:
|
|
197
226
|
- lib/haml-i18n-extractor/version.rb
|
198
227
|
- lib/haml-i18n-extractor/workflow.rb
|
199
228
|
- lib/haml-i18n-extractor/yaml_tool.rb
|
229
|
+
- test/cli_test.rb
|
200
230
|
- test/extractor_test.rb
|
201
231
|
- test/haml_reader_test.rb
|
202
232
|
- test/haml_writer_test.rb
|
@@ -237,6 +267,7 @@ signing_key:
|
|
237
267
|
specification_version: 4
|
238
268
|
summary: Parse the texts out of the haml files into localization files
|
239
269
|
test_files:
|
270
|
+
- test/cli_test.rb
|
240
271
|
- test/extractor_test.rb
|
241
272
|
- test/haml_reader_test.rb
|
242
273
|
- test/haml_writer_test.rb
|
@@ -253,3 +284,4 @@ test_files:
|
|
253
284
|
- test/text_replacer_test.rb
|
254
285
|
- test/workflow_test.rb
|
255
286
|
- test/yaml_tool_test.rb
|
287
|
+
has_rdoc:
|