haml-i18n-extractor 0.0.21 → 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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTUxZGE3Mzk4ZWNhNTQ1NmI2ZmYzOGFkNTc0ZDYxMTM3Y2U3NDY3Mw==
4
+ MjgwZDJiZjM2NDdkYmUwZDNlODFmNmY4NWYwZWYzMmVjNGM0YjVmMA==
5
5
  data.tar.gz: !binary |-
6
- ZTA1MDJlOWZiZmZjZWFkNTFiZmFjOWE3MWI2YzM4ZGIzZmYzZjA4YQ==
6
+ NjZhOTA5YTVmMDE2YmQxMzcyNmUxMDk3NzFkODNkN2FmMWY5MGM1OQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YjJiYzFhZWNiZjhkODQxYTU3YTQ3MzhmYjJiY2I4MDA1ZmJjNzJmNTVhMDZi
10
- ZGY3ODJlMDc1ZThmM2M1NDJlZWExODZlMzg2YThmMDM2Y2VmZDQ0ZGJlMTU1
11
- NmYxNWIyNjgyNzJlNzA3N2JmYTJlMDYzZTE5MDYyNDVlMzQwMmE=
9
+ YzU2NTgwNDVlMTE5NDlkMzFhMmViNTYwY2FhZmFiNzJhNTVjNGIzNmM0MTli
10
+ NWZlYjc2ZDg5MTM2ZDU5NTEwNjQyZDdlNWRiYjIxMGZjNDIwYWMyNzk1MmRk
11
+ OGRiMmJmNmE3ZjcwNmM4YTA4ZDQ0ZmI2MWFlZjQ1NGExODhkN2Y=
12
12
  data.tar.gz: !binary |-
13
- MWVhMGQ0ZmIzZTE5NGI3YWMwYjk4YzFmYzQ1OTdmNjBiNjg5NGU4ZDI5Yjkw
14
- OGY3ODA2ZWFkNTYzM2ZhYTJkNzg2MDYyZjFlMjJhNGM4Njk4NTQyZGVmNDU3
15
- ZjE4MWY3NjA5YzJmMDRmNzZiODllYTA1MjI5YTcwNDdjNmUxM2E=
13
+ YWRmZjIwNzUyZWM1ODhmYWQ0N2Q3ODk3MmYxZGE0NjBiNmQ5ODI3MmUyYzgz
14
+ Y2NjZTE3MzI5ZjU1YjU1NjQ3YjgyZTM5M2NmNTRmMDgzNzhiNGNjOTM5MjRk
15
+ MzE0OWE5YjVhMTNkMjNlNzU5ZDQ0MzFhZDI4N2NjMDljMjZjMDI=
data/TODO CHANGED
@@ -11,6 +11,7 @@
11
11
  * Issues
12
12
 
13
13
  - CLI options: Extractor.new accepts options. pass through workflow. First up: i18n_scope (issue#5)
14
+ - add a ~/.haml-i18n-extractor file/dir/config file etc. to keep preferences of interactive mode or not?
14
15
 
15
16
  * Ideas
16
17
 
@@ -2,27 +2,22 @@
2
2
 
3
3
  require 'haml-i18n-extractor'
4
4
 
5
- if ARGV.empty?
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
- if ARGV[0] == "--version"
13
- puts Haml::I18n::Extractor::VERSION
14
- abort
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
- pth = File.expand_path(ARGV[0])
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
- if File.directory?(pth)
20
- workflow = Haml::I18n::Extractor::Workflow.new(pth)
21
- workflow.run
22
- elsif File.exists?(pth) && ARGV[1] == "--no-prompt"
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
@@ -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
- @type = opts[:type]
24
- @prompt_per_line = opts[:prompt_per_line]
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 prompt_per_line?
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 prompt_per_line?
104
- !!@prompt_per_line
104
+ def interactive?
105
+ !!@interactive
105
106
  end
106
107
 
107
108
  private
@@ -8,6 +8,10 @@ module Haml
8
8
 
9
9
  include Helpers::Highline
10
10
 
11
+ def puts(txt)
12
+ say(txt)
13
+ end
14
+
11
15
  def ask_user(orig_line, replaced_line)
12
16
  say(highlight("Replace this line:"))
13
17
  say("\n")
@@ -1,7 +1,7 @@
1
1
  module Haml
2
2
  module I18n
3
3
  class Extractor
4
- VERSION = "0.0.21"
4
+ VERSION = "0.1.0"
5
5
  end
6
6
  end
7
7
  end
@@ -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
- start_message
36
- files.each do |haml_path|
37
- type = process_file?(haml_path)
38
- if type
39
- process(haml_path, type)
40
- else
41
- @prompter.not_processing(haml_path)
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!({:prompt_per_line => true}) # per-line prompts
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
@@ -10,3 +10,5 @@ require "haml-i18n-extractor/prompter"
10
10
  require "haml-i18n-extractor/user_action"
11
11
  require "haml-i18n-extractor/tagging_tool"
12
12
  require "haml-i18n-extractor/workflow"
13
+ require "haml-i18n-extractor/cli"
14
+ require "trollop"
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
+
@@ -18,15 +18,15 @@ module Haml
18
18
  assert_equal h.haml_writer.overwrite?, false
19
19
  end
20
20
 
21
- test "with a prompt_per_line option which prompts the user-per line" do
22
- h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :prompt_per_line => true)
23
- assert_equal h.prompt_per_line?, true
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.prompt_per_line?, false
25
+ assert_equal h.interactive?, false
26
26
  end
27
27
 
28
- test "with a prompt_per_line option takes user input into consideration for haml" do
29
- h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :prompt_per_line => true)
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 prompt_per_line option takes user input N as next and stops processing file" do
42
- h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :prompt_per_line => true)
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 prompt_per_line option takes user input into consideration for yaml" do
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"), :prompt_per_line => true)
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 prompt_per_line option user can tag a line for later review" do
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"), :prompt_per_line => true)
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
@@ -4,19 +4,19 @@ module Haml
4
4
  # misnomer, this is also testing UserAction
5
5
  class PrompterAndUserActionTest < MiniTest::Unit::TestCase
6
6
 
7
- def test_asks_to_process_line_yes
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
- def test_asks_to_process_line_no
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
- def test_asks_to_process_line_tag
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
@@ -12,26 +12,28 @@ module Haml
12
12
  TestHelper.teardown_project_directory!
13
13
  end
14
14
 
15
- def test_it_should_work_on_a_directory_mkay
16
- filename = "#{TestHelper::PROJECT_DIR}app/views/bar/thang.haml"
17
- bad_worfklow = Haml::I18n::Extractor::Workflow.new(filename)
18
- assert false, "should raise"
19
- rescue Haml::I18n::Extractor::NotADirectory
20
- assert true, "workflow works on a directory bubba."
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
- def test_it_finds_all_haml_files
25
+ test "it_finds_all_haml_files" do
24
26
  assert_equal @workflow.files.size, 6
25
27
  end
26
28
 
27
- def test_outputs_stats
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
- def test_yaml_file_in_config
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.21
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-29 00:00:00.000000000 Z
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: