haml-i18n-extractor 0.0.18 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDY5MTVjZmVhOWM2YWE1NGMxZmQ2OTYzMjZkZWM3MmZjY2FiODgxNQ==
4
+ NzYwYzZlM2U0ZTJjZjRjMTI4NzUzOGQ5YTJhZTZjNmJkN2RjZWM5MA==
5
5
  data.tar.gz: !binary |-
6
- NWNlYTJhNTA1MTI4YmRmOTVjOTQ4MWE1NWNhMDc5ZTQyYmViZjc1OA==
6
+ ZTI2N2EzYmQxN2YyMzZmNjU1OGY5N2Q1MGY4ZWYwNGNiODcwOWVlNg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZGIwNWE4ZTU3Y2I2YjBiMjY5OTE1Y2EyOGI1MmZkZGFkNDRkNmY5Mjg5NDMy
10
- MGNiMjhjOGVmOTQ3ZTA2NjdmM2U2NTE2ZWE1YjVkZTRjNGY2NWMxODc2MjRm
11
- MmJmMmU1ODFkMDRlMTNmODMxMmNhMDdiN2Y3NDY3NTQ1YzI0NDk=
9
+ YmJjOTk2ZmU0YTI2MzZmZWZkZTI4YjQ5MzVjOTNhNmRiZTE5ZWQwYzkxY2Zi
10
+ ZjE4NmNlZGI0NWFmYjQ4NjAwMWY1ZDE5YmIxMjg1NGMzN2UzNjMzNmExNWFh
11
+ ZGIwZGI0ZmU5NzQ0YmFmNDEwOTg3YWFkMTE0N2Q3NDE0NTliZDU=
12
12
  data.tar.gz: !binary |-
13
- YTgwMTUyNzQ3NGQxMWM0ODRkZTNhN2EyMDQwMmI1ZjQ0NTg2MTlmMmM0ZWU2
14
- ZjRmMDA1ODE4YzAxNjQ4YzYwOTRmMmRlZjE3MDE4YmM3MjRiNGIxNjM0Y2M2
15
- MmRiYTEyODIwODg1YTYyY2YxM2FmZDk5YjI3ZmZiNWVlZGE1ZGI=
13
+ M2IzYjJjNTdjMzMwYTU5NmJhODgxMTA4YzNiNDUzOTA4Yjk1MDNjZDc1MGE1
14
+ YTU2YWNkMmIxY2Q0MGEyMGM3OWMxODhiMjc4YmMyMDExM2U5NzZjYjQzYjI2
15
+ OTk1ZWNmYzVkNGE1MmY1NTJkNGVhOTNkMTk1MDg5NWEyMGEwMDI=
@@ -9,6 +9,7 @@ module Haml
9
9
  class InvalidSyntax < StandardError ; end
10
10
  class NotADirectory < StandardError ; end
11
11
  class NotDefinedLineType < StandardError ; end
12
+ class AbortFile < StandardError ; end
12
13
 
13
14
  LINE_TYPES_ALL = [:text, :not_text, :loud, :silent, :element]
14
15
  LINE_TYPES_ADD_EVAL = [:text, :element]
@@ -54,8 +55,14 @@ module Haml
54
55
  end
55
56
 
56
57
  def new_body
57
- @haml_reader.lines.each_with_index do |orig_line, line_no|
58
- process_line(orig_line,line_no)
58
+ begin
59
+ @haml_reader.lines.each_with_index do |orig_line, line_no|
60
+ @current_line_no = line_no
61
+ process_line(orig_line,line_no)
62
+ end
63
+ rescue AbortFile
64
+ @prompter.moving_to_next_file
65
+ add_rest_of_file_to_body(@current_line_no)
59
66
  end
60
67
  @body.join("\n")
61
68
  end
@@ -68,7 +75,7 @@ module Haml
68
75
  orig_line.chomp!
69
76
  orig_line, whitespace = handle_line_whitespace(orig_line)
70
77
  line_type, line_match = handle_line_finding(orig_line)
71
- should_be_replaced, text_to_replace, line_locale_hash = handle_line_replacing(orig_line, line_match, line_type, line_no)
78
+ should_be_replaced, text_to_replace, line_locale_hash = gather_replacement_info(orig_line, line_match, line_type, line_no)
72
79
 
73
80
  user_action = Haml::I18n::Extractor::UserAction.new('y') # default if no prompting: just do it.
74
81
  if should_be_replaced
@@ -80,6 +87,8 @@ module Haml
80
87
  if user_action.tag?
81
88
  @tagging_tool.write(line_locale_hash[:path], line_no)
82
89
  add_to_body("#{whitespace}#{orig_line}")
90
+ elsif user_action.next?
91
+ raise AbortFile, "stopping to process the rest of the file"
83
92
  elsif user_action.replace_line?
84
93
  append_to_locale_hash(line_no, line_locale_hash)
85
94
  add_to_body("#{whitespace}#{text_to_replace}")
@@ -97,7 +106,13 @@ module Haml
97
106
 
98
107
  private
99
108
 
100
- def handle_line_replacing(orig_line, line_match, line_type, line_no)
109
+ def add_rest_of_file_to_body(line_no)
110
+ @haml_reader.lines[line_no..@haml_reader.lines.size-1].map do |orig_ln|
111
+ add_to_body(orig_ln.chomp)
112
+ end
113
+ end
114
+
115
+ def gather_replacement_info(orig_line, line_match, line_type, line_no)
101
116
  if line_match && !line_match.empty?
102
117
  replacer = Haml::I18n::Extractor::TextReplacer.new(orig_line, line_match, line_type)
103
118
  hash = replacer.replace_hash.dup.merge!({:path => @haml_reader.path })
@@ -17,10 +17,10 @@ module Haml
17
17
  say("\n")
18
18
  say(replaced_line.inspect)
19
19
  say("\n")
20
- answer = ask(highlight('[y]es/[n]o/[t]ag?')) do |q|
20
+ answer = ask(highlight('[y]es/[n]o/[t]ag/[N]ext?')) do |q|
21
21
  q.echo = false
22
22
  q.character = true
23
- q.validate = /\A[ynt]\Z/
23
+ q.validate = /\A[yntN]\Z/
24
24
  end
25
25
  Haml::I18n::Extractor::UserAction.new(answer)
26
26
  end
@@ -78,6 +78,9 @@ module Haml
78
78
  return :dump if answer == 'D'
79
79
  end
80
80
 
81
+ def moving_to_next_file
82
+ say("Next received! Saved changes done so far, moving to the next file.\n")
83
+ end
81
84
  end
82
85
  end
83
86
  end
@@ -32,9 +32,9 @@ module Haml
32
32
  #@input == 'D'
33
33
  #end
34
34
 
35
- #def next?
36
- #@input == 'N'
37
- #end
35
+ def next?
36
+ @input == 'N'
37
+ end
38
38
 
39
39
  end
40
40
  end
@@ -1,7 +1,7 @@
1
1
  module Haml
2
2
  module I18n
3
3
  class Extractor
4
- VERSION = "0.0.18"
4
+ VERSION = "0.0.19"
5
5
  end
6
6
  end
7
7
  end
@@ -38,6 +38,19 @@ 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)
43
+ user_input = "D" # dump
44
+ File.readlines(file_path("ex1.haml")).size.times do
45
+ user_input << "N" # just move on to next file
46
+ end
47
+ with_highline(user_input) do
48
+ h.run
49
+ end
50
+ # no changes were made cause user was all like 'uhhh, move to next file'
51
+ assert_equal File.read(h.haml_writer.path), File.read(file_path("ex1.haml"))
52
+ end
53
+
41
54
  test "with a prompt_per_line option takes user input into consideration for yaml" do
42
55
  hax_shit
43
56
  h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :prompt_per_line => true)
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.18
4
+ version: 0.0.19
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-01 00:00:00.000000000 Z
11
+ date: 2013-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tilt