haml-i18n-extractor 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.tags.haml-i18n-extractor +0 -0
- data/README.md +32 -27
- data/TODO +8 -30
- data/demo/haml-i18n-extractor-demo.swf +0 -0
- data/haml-i18n-extractor.gemspec +3 -0
- data/lib/haml-i18n-extractor/extractor.rb +14 -8
- data/lib/haml-i18n-extractor/prompter.rb +26 -15
- data/lib/haml-i18n-extractor/tagging_tool.rb +21 -0
- data/lib/haml-i18n-extractor/text_replacer.rb +2 -2
- data/lib/haml-i18n-extractor/user_action.rb +42 -0
- data/lib/haml-i18n-extractor/version.rb +1 -1
- data/lib/haml-i18n-extractor/workflow.rb +3 -3
- data/lib/haml-i18n-extractor.rb +2 -0
- data/test/extractor_test.rb +20 -0
- data/test/prompter_test.rb +10 -3
- data/test/tagging_tool_test.rb +26 -0
- data/test/text_replacer_test.rb +3 -2
- data/test/workflow_test.rb +1 -19
- metadata +50 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjYzZTc2Yjc3NjllMWFhY2NmNTM3YjhmMWZjNzU2YjU1YzQ2N2Y1Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDE5MDJiZjliOGI0YjQ2ZWQwNzYyYjU1NjU2OTE5ZDY4NDcwM2EzNQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Mjc0NzM0NmVkODVhZjBkNTFhNzc0NjliZmE1MzJjM2M5ODhjYTU0NTRlMzIx
|
10
|
+
MmNkYTcxOTE4NTQzMWFlYTM3NTk2YzFiYzVhYjdjZDQxNjkyMjdiNDAwMzEx
|
11
|
+
OWIwMTVmODljNDk2MDQyNWI5ZWE4MzUwYzM4NDNkMTdkYTNlOWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmRiNGRlNzJhNzU2YWJlODEyM2MwN2MyMzc4ZGY5YTU0NzQzOTg5MWNmNGFj
|
14
|
+
ZDQ0YjAzODhmNGYxODlkZTQ0MDdkZWJhOWFhN2MwN2JmYTMyM2UyMWQ1OGYz
|
15
|
+
ZDJmOTllOGRkYTMzOTgyYThiYjRjNjU1MjhkYzI5OTU2NDkwMWU=
|
File without changes
|
data/README.md
CHANGED
@@ -2,18 +2,17 @@
|
|
2
2
|
|
3
3
|
Extract strings likely to be translated from haml templates for I18n translation. Replace the text, create yaml files, do all things you thought macros would solve, but didn't end up really saving THAT much time. Automate that pain away.
|
4
4
|
|
5
|
-
|
5
|
+
# Idempotent
|
6
6
|
|
7
|
-
|
7
|
+
It's idempotent, which means you can run this library/executable against the same haml file after you've already translated the keys, and it won't try to retranslate already translated text. Pretty cool.
|
8
8
|
|
9
|
-
|
9
|
+
## Usage
|
10
10
|
|
11
|
-
|
11
|
+
You can use the binary which is an interactive prompting mode included in this library, or just use the code directly. See below for more examples.
|
12
12
|
|
13
|
+
## Examples
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
- You can use the lib directly:
|
15
|
+
- Per file basis. You can use the lib directly in your code, as such:
|
17
16
|
|
18
17
|
<pre>
|
19
18
|
begin
|
@@ -24,26 +23,25 @@ rescue Haml::I18n::Extractor::InvalidSyntax
|
|
24
23
|
end
|
25
24
|
</pre>
|
26
25
|
|
27
|
-
-
|
26
|
+
- Per-project basis, with the binary. See demo below for usage of the binary.
|
27
|
+
|
28
|
+
`cd your-rails-app-to-translate && haml-i18n-extractor .`
|
28
29
|
|
29
|
-
|
30
|
+
## Demo using interactive mode
|
30
31
|
|
31
|
-
|
32
|
+
Check out the quite brief movie/swf file demo of this lib's executable in `demo/` . You should be able to see it online here, considering your browser supports swf:
|
32
33
|
|
33
|
-
|
34
|
-
2) place a tmp haml file.
|
35
|
-
3) pass, move on to the next haml file.
|
34
|
+
[Demo](http://shairosenfeld.com/haml-i18n-extractor-demo.swf)
|
36
35
|
|
37
|
-
Then it will ask you on a line-per-line basis if you wish to replace that line or not. It's WIP, but it does work, so - Run the binary and see!
|
38
36
|
|
39
37
|
## Example output
|
40
38
|
|
41
|
-
This should be a before and after picture of using this lib, whether
|
39
|
+
This should be a before and after picture of using this lib, whether using the interactive mode or plain ruby.
|
42
40
|
|
43
41
|
- Before running (old haml):
|
44
42
|
|
45
43
|
<pre>
|
46
|
-
shai@comp ~/p/project
|
44
|
+
shai@comp ~/p/project master $ cat app/views/admin/notifications/index.html.haml
|
47
45
|
%h1 Consumer Notifications
|
48
46
|
|
49
47
|
.nav= will_paginate(@consumer_notifications)
|
@@ -55,7 +53,6 @@ This should be a before and after picture of using this lib, whether directly in
|
|
55
53
|
%th Data
|
56
54
|
%th Success
|
57
55
|
%th Reported To
|
58
|
-
%th.last
|
59
56
|
- @consumer_notifications.each do |cn|
|
60
57
|
%tr
|
61
58
|
%td.type= cn.notification.type
|
@@ -68,12 +65,12 @@ This should be a before and after picture of using this lib, whether directly in
|
|
68
65
|
|
69
66
|
- After running (new haml, new yaml):
|
70
67
|
|
71
|
-
Note how some of the strings are replaced, and the ones that shouldn't, aren't. Yup. Beautiful, right?
|
68
|
+
Note how some of the strings are replaced, and the ones that shouldn't, aren't. Yup. Beautiful, for 2 and half seconds of work, right?
|
72
69
|
|
73
70
|
Haml:
|
74
71
|
|
75
72
|
<pre>
|
76
|
-
shai@comp ~/p/project
|
73
|
+
shai@comp ~/p/project master $ cat app/views/admin/notifications/index.html.i18n-extractor.haml
|
77
74
|
%h1= t('.consumer_notifications')
|
78
75
|
|
79
76
|
.nav= will_paginate(@consumer_notifications)
|
@@ -85,7 +82,6 @@ Haml:
|
|
85
82
|
%th= t('.data')
|
86
83
|
%th= t('.success')
|
87
84
|
%th= t('.reported_to')
|
88
|
-
%th.last= t('.nbsp;')
|
89
85
|
- @consumer_notifications.each do |cn|
|
90
86
|
%tr
|
91
87
|
%td.type= cn.notification.type
|
@@ -96,25 +92,34 @@ Haml:
|
|
96
92
|
.nav= will_paginate(@consumer_notifications)
|
97
93
|
</pre>
|
98
94
|
|
99
|
-
Yaml:
|
95
|
+
Yaml:
|
100
96
|
|
101
97
|
<pre>
|
102
|
-
shai@comp ~/p/project
|
103
|
-
---
|
104
|
-
en:
|
105
|
-
notifications:
|
98
|
+
shai@comp ~/p/project master $ cat config/locales/en.yml
|
99
|
+
---
|
100
|
+
en:
|
101
|
+
notifications:
|
106
102
|
consumer_notifications: Consumer Notifications
|
107
103
|
type: Type
|
108
104
|
identifier: Identifier
|
109
105
|
data: Data
|
110
106
|
success: Success
|
111
107
|
reported_to: Reported To
|
112
|
-
nbsp;: ! ' '
|
113
108
|
</pre>
|
114
109
|
|
110
|
+
|
111
|
+
## Installation
|
112
|
+
|
113
|
+
`gem install haml-i18n-extractor`
|
114
|
+
|
115
|
+
If you want the latest code aka edge, you can also simply clone this repo and install the gem from the root of the repo:
|
116
|
+
|
117
|
+
`gem uninstall -x haml-i18n-extractor; rm *gem; gem build *gemspec; gem install --local *gem`
|
118
|
+
|
115
119
|
## Feedback
|
116
120
|
|
117
|
-
Can use github issues to address any concern you have, or simply email me, with the contact info here: [http://shairosenfeld.com/](http://shairosenfeld.com/)
|
121
|
+
Can use github issues to address any concern you have, or simply email me, with the contact info here: [http://shairosenfeld.com/](http://shairosenfeld.com/).
|
122
|
+
You may find me on freenode #haml-i18n-extractor although I don't check it that often. Also on twitter you can find me with the same username as my GH one.
|
118
123
|
|
119
124
|
## Contributing
|
120
125
|
|
data/TODO
CHANGED
@@ -1,37 +1,15 @@
|
|
1
|
-
|
1
|
+
* Improvements
|
2
2
|
|
3
|
-
- Remove the ex1.output ex1.i18n-extractor duplication. (or move to tmp dir):
|
4
|
-
Move to test/tmp a-la the way workflow is working.
|
5
|
-
- Ensure that yaml file gets written to the right directory, and does a deep merge.
|
3
|
+
- Remove the ex1.output ex1.i18n-extractor duplication. (or move to tmp dir): Move to test/tmp a-la the way workflow is working.
|
6
4
|
- Add {} to disallowed characters
|
7
5
|
- Add yaml fixtures and compare those
|
8
|
-
- handled email suffixes (foo.en.html.haml etc)
|
9
6
|
- admin/bla should be namespaced such as: en.admin.bla vs just en.bla in the yml file?
|
10
|
-
- add herbgobbler (ERB) and this to another more generalized repo for translating templates?
|
11
7
|
- Refactor tests: split out what is integration vs unit, too much coupling.
|
8
|
+
- Prompter.new should just be a singleton.
|
9
|
+
- rm hax_shit, move to setup/teardown, shutdown/startup
|
10
|
+
- rm the :overwrite, :dump stuff to UserAction?
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
## workflow todo's
|
16
|
-
|
17
|
-
make sure yaml keys are in one file
|
18
|
-
|
19
|
-
either way when yaml is written, it should just write itself to config/locales/en.yml
|
20
|
-
wether its one-off, or project mode. and that's something yaml_tool should do.
|
21
|
-
merge itself in.
|
22
|
-
concept of project directory of whereever we expect that to be?
|
12
|
+
* Ideas
|
23
13
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
<ruby>
|
28
|
-
|
29
|
-
require 'yaml'
|
30
|
-
require 'pp'
|
31
|
-
ActiveSupport::HashWithIndifferentAccess = HashWithIndifferentAccess # hack when it writes out the yaml, it should not be with_indifferent_access
|
32
|
-
all_yaml = Dir.glob('*yml').collect{|x| File.read(x) }
|
33
|
-
locale_hash = Hash.new
|
34
|
-
all_yaml.map{|y| YAML.load(y) }.map{|x| locale_hash.deep_merge!(x)}
|
35
|
-
pp locale_hash; "file.write it"
|
36
|
-
|
37
|
-
</ruby>
|
14
|
+
- handled email suffixes (foo.en.html.haml etc)
|
15
|
+
- add herbgobbler (ERB) and this to another more generalized repo for translating templates?
|
Binary file
|
data/haml-i18n-extractor.gemspec
CHANGED
@@ -26,5 +26,8 @@ Gem::Specification.new do |gem|
|
|
26
26
|
gem.add_development_dependency 'pry'
|
27
27
|
gem.add_development_dependency 'minitest'
|
28
28
|
gem.add_development_dependency 'nokogiri'
|
29
|
+
gem.add_development_dependency 'rake'
|
30
|
+
gem.add_development_dependency 'actionpack'
|
31
|
+
gem.add_development_dependency 'rails'
|
29
32
|
|
30
33
|
end
|
@@ -21,10 +21,12 @@ module Haml
|
|
21
21
|
def initialize(haml_path, opts = {})
|
22
22
|
@type = opts[:type]
|
23
23
|
@prompt_per_line = opts[:prompt_per_line]
|
24
|
+
@prompter = Haml::I18n::Extractor::Prompter.new
|
24
25
|
@haml_reader = Haml::I18n::Extractor::HamlReader.new(haml_path)
|
25
26
|
validate_haml(@haml_reader.body)
|
26
27
|
@haml_writer = Haml::I18n::Extractor::HamlWriter.new(haml_path, {:type => @type})
|
27
28
|
@yaml_tool = Haml::I18n::Extractor::YamlTool.new
|
29
|
+
@tagging_tool ||= Haml::I18n::Extractor::TaggingTool.new
|
28
30
|
# hold all the processed lines
|
29
31
|
@body = []
|
30
32
|
# holds a line_no => {info_about_line_replacemnts_or_not}
|
@@ -51,7 +53,7 @@ module Haml
|
|
51
53
|
assign_yaml
|
52
54
|
end
|
53
55
|
|
54
|
-
|
56
|
+
def new_body
|
55
57
|
@haml_reader.lines.each_with_index do |orig_line, line_no|
|
56
58
|
process_line(orig_line,line_no)
|
57
59
|
end
|
@@ -67,20 +69,24 @@ module Haml
|
|
67
69
|
orig_line, whitespace = handle_line_whitespace(orig_line)
|
68
70
|
line_type, line_match = handle_line_finding(orig_line)
|
69
71
|
should_be_replaced, text_to_replace, line_locale_hash = handle_line_replacing(orig_line, line_match, line_type, line_no)
|
72
|
+
|
73
|
+
user_action = Haml::I18n::Extractor::UserAction.new('y') # default if no prompting: just do it.
|
70
74
|
if should_be_replaced
|
71
75
|
if prompt_per_line?
|
72
|
-
|
73
|
-
else
|
74
|
-
user_approves = true
|
76
|
+
user_action = @prompter.ask_user(orig_line,text_to_replace)
|
75
77
|
end
|
76
78
|
end
|
77
|
-
|
79
|
+
|
80
|
+
if user_action.tag?
|
81
|
+
@tagging_tool.write(line_locale_hash[:path], line_no)
|
82
|
+
elsif user_action.replace_line?
|
78
83
|
append_to_locale_hash(line_no, line_locale_hash)
|
79
84
|
add_to_body("#{whitespace}#{text_to_replace}")
|
80
|
-
|
85
|
+
elsif user_action.no_replace?
|
81
86
|
append_to_locale_hash(line_no, DEFAULT_LINE_LOCALE_HASH)
|
82
87
|
add_to_body("#{whitespace}#{orig_line}")
|
83
88
|
end
|
89
|
+
|
84
90
|
return should_be_replaced
|
85
91
|
end
|
86
92
|
|
@@ -123,8 +129,8 @@ module Haml
|
|
123
129
|
def validate_haml(haml)
|
124
130
|
parser = Haml::Parser.new(haml, Haml::Options.new)
|
125
131
|
parser.parse
|
126
|
-
|
127
|
-
|
132
|
+
rescue Haml::SyntaxError
|
133
|
+
raise InvalidSyntax, "invalid syntax for haml #{@haml_reader.path}"
|
128
134
|
end
|
129
135
|
|
130
136
|
end
|
@@ -17,25 +17,36 @@ module Haml
|
|
17
17
|
say("\n")
|
18
18
|
say(replaced_line.inspect)
|
19
19
|
say("\n")
|
20
|
-
answer = ask(highlight('y/n?')) do |q|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
answer = ask(highlight('[y]es/[n]o/[t]ag?')) do |q|
|
21
|
+
q.echo = false
|
22
|
+
q.character = true
|
23
|
+
q.validate = /\A[ynt]\Z/
|
24
24
|
end
|
25
|
-
answer
|
25
|
+
Haml::I18n::Extractor::UserAction.new(answer)
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
say(
|
28
|
+
def start_message(file_count, file_names)
|
29
|
+
say("Hello there kind sir! Read this if its your first time:")
|
30
|
+
say("(1) overwrite a file")
|
31
|
+
say("(2) dump the file to a temp file")
|
32
|
+
say("(3) Skip processing it")
|
33
|
+
say("Once you are processing a file, you should be able to:")
|
34
|
+
say("(1) replace the line with what it's found. this will add yaml info as well.")
|
35
|
+
say("(2) skip - don't replace the line and put yaml info.")
|
36
|
+
say("(3) tag - keep a reminder of this place in the code and put it in a file for later review.")
|
37
|
+
say(highlight("Okay then! Found #{file_count} haml files!\n\n", :red))
|
30
38
|
say("#{file_names}\n\n")
|
31
39
|
end
|
32
40
|
|
33
|
-
def
|
34
|
-
say(
|
41
|
+
def end_message
|
42
|
+
say("\n\n\n")
|
43
|
+
say(highlight("Now run a git diff or such and see what changed!"))
|
44
|
+
say(highlight("Check #{Haml::I18n::Extractor::TaggingTool::DB} if you have tagged any lines."))
|
45
|
+
say("PS: If you have any feedback or ideas how this would be better, feel free to open an issue on github. See README for more info.")
|
35
46
|
end
|
36
47
|
|
37
|
-
def
|
38
|
-
say(highlight("\n\n
|
48
|
+
def process(haml_path, type)
|
49
|
+
say(highlight("#{type}-d file") + " #{haml_path}\n\n")
|
39
50
|
end
|
40
51
|
|
41
52
|
def not_processing(haml_path)
|
@@ -58,10 +69,10 @@ module Haml
|
|
58
69
|
choices = CHOICES.keys.map(&:to_s)
|
59
70
|
prompt = "Your choice #{highlight(choices)}?"
|
60
71
|
answer = ask(prompt) do |q|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
72
|
+
q.echo = false
|
73
|
+
q.character = true
|
74
|
+
q.validate = /\A[#{choices}r]\Z/
|
75
|
+
end
|
65
76
|
return :overwrite if answer == 'O'
|
66
77
|
return :overwrite if answer == 'R' # cheat 'replace'
|
67
78
|
return :dump if answer == 'D'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Haml
|
2
|
+
module I18n
|
3
|
+
class Extractor
|
4
|
+
class TaggingTool
|
5
|
+
|
6
|
+
DB = ".tags.haml-i18n-extractor"
|
7
|
+
def initialize
|
8
|
+
@file = File.open(DB, "a+")
|
9
|
+
end
|
10
|
+
|
11
|
+
def write(path, lineno)
|
12
|
+
tag = "#{path}:#{lineno}\n"
|
13
|
+
@file.write(tag)
|
14
|
+
@file.flush
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -9,7 +9,7 @@ module Haml
|
|
9
9
|
# limit the number of chars
|
10
10
|
LIMIT_KEY_NAME = 30
|
11
11
|
# do not pollute the key space it will make it invalid yaml
|
12
|
-
NOT_ALLOWED_IN_KEYNAME = %w( ~ ` ! @ # $ % ^ & * - ( ) , )
|
12
|
+
NOT_ALLOWED_IN_KEYNAME = %w( ~ ` ! @ # $ % ^ & * - ( ) , ? { } )
|
13
13
|
|
14
14
|
def initialize(full_line, text_to_replace,line_type)
|
15
15
|
@full_line = full_line
|
@@ -75,4 +75,4 @@ module Haml
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
78
|
-
end
|
78
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Haml
|
2
|
+
module I18n
|
3
|
+
class Extractor
|
4
|
+
class UserAction
|
5
|
+
|
6
|
+
class Unsupported < StandardError ; end
|
7
|
+
# overwrite, dump, next, yes, no, tag
|
8
|
+
SUPPORTED = %w(O D N y n t)
|
9
|
+
|
10
|
+
def initialize(input)
|
11
|
+
raise Unsupported, "Only #{SUPPORTED.join(",")} are allowed for user input" unless SUPPORTED.include?(input)
|
12
|
+
@input = input
|
13
|
+
end
|
14
|
+
|
15
|
+
def tag?
|
16
|
+
@input == 't'
|
17
|
+
end
|
18
|
+
|
19
|
+
def replace_line?
|
20
|
+
@input == 'y'
|
21
|
+
end
|
22
|
+
|
23
|
+
def no_replace?
|
24
|
+
@input == 'n'
|
25
|
+
end
|
26
|
+
|
27
|
+
#def overwrite?
|
28
|
+
#@input == 'O' || @input == 'R' # cheat replace
|
29
|
+
#end
|
30
|
+
|
31
|
+
#def dump?
|
32
|
+
#@input == 'D'
|
33
|
+
#end
|
34
|
+
|
35
|
+
#def next?
|
36
|
+
#@input == 'N'
|
37
|
+
#end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -17,10 +17,10 @@ module Haml
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def start_message
|
21
21
|
file_count = files.size
|
22
22
|
file_names = files.join("\n")
|
23
|
-
@prompter.
|
23
|
+
@prompter.start_message(file_count, file_names)
|
24
24
|
end
|
25
25
|
|
26
26
|
def process_file?(file)
|
@@ -29,7 +29,7 @@ module Haml
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def run
|
32
|
-
|
32
|
+
start_message
|
33
33
|
files.each do |haml_path|
|
34
34
|
type = process_file?(haml_path)
|
35
35
|
if type
|
data/lib/haml-i18n-extractor.rb
CHANGED
@@ -7,4 +7,6 @@ require "haml-i18n-extractor/haml_writer"
|
|
7
7
|
require "haml-i18n-extractor/yaml_tool"
|
8
8
|
require "haml-i18n-extractor/extractor"
|
9
9
|
require "haml-i18n-extractor/prompter"
|
10
|
+
require "haml-i18n-extractor/user_action"
|
11
|
+
require "haml-i18n-extractor/tagging_tool"
|
10
12
|
require "haml-i18n-extractor/workflow"
|
data/test/extractor_test.rb
CHANGED
@@ -52,6 +52,23 @@ module Haml
|
|
52
52
|
assert_equal YAML.load(File.read(h.yaml_tool.locale_file)), {}
|
53
53
|
end
|
54
54
|
|
55
|
+
test "with a prompt_per_line option user can tag a line for later review" do
|
56
|
+
hax_shit
|
57
|
+
if File.exist?(Haml::I18n::Extractor::TaggingTool::DB)
|
58
|
+
assert_equal File.readlines(Haml::I18n::Extractor::TaggingTool::DB), []
|
59
|
+
end
|
60
|
+
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :prompt_per_line => true)
|
61
|
+
user_input = "D" # dump
|
62
|
+
File.readlines(file_path("ex1.haml")).size.times do
|
63
|
+
user_input << "t" # tag the lines
|
64
|
+
end
|
65
|
+
with_highline(user_input) do
|
66
|
+
h.run
|
67
|
+
end
|
68
|
+
assert_equal File.readlines(Haml::I18n::Extractor::TaggingTool::DB).size, 7 # 7 replaceable lines in ex1
|
69
|
+
end
|
70
|
+
|
71
|
+
|
55
72
|
test "can not initialize if the haml is not valid syntax" do
|
56
73
|
begin
|
57
74
|
Haml::I18n::Extractor.new(file_path("bad.haml"))
|
@@ -76,6 +93,9 @@ module Haml
|
|
76
93
|
def hax_shit
|
77
94
|
Dir.glob("*yml").map {|p| FileUtils.rm(p) } # HAX, TODO: handle with yaml files correctly (config/en.yml)
|
78
95
|
Dir.glob("config/locales/*yml").map {|p| FileUtils.rm(p) } # HAX, TODO: handle with yaml files correctly (config/en.yml)
|
96
|
+
if File.exists?(Haml::I18n::Extractor::TaggingTool::DB)
|
97
|
+
FileUtils.rm_rf(Haml::I18n::Extractor::TaggingTool::DB) # HAX, TODO: setup/teardown
|
98
|
+
end
|
79
99
|
end
|
80
100
|
|
81
101
|
test "it writes the locale info to an out file when run" do
|
data/test/prompter_test.rb
CHANGED
@@ -1,17 +1,24 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
module Haml
|
4
|
-
|
4
|
+
# misnomer, this is also testing UserAction
|
5
|
+
class PrompterAndUserActionTest < MiniTest::Unit::TestCase
|
5
6
|
|
6
7
|
def test_asks_to_process_line_yes
|
7
8
|
with_highline("y") do
|
8
|
-
assert_equal Haml::I18n::Extractor::Prompter.new.ask_user("orig", "replace")
|
9
|
+
assert_equal Haml::I18n::Extractor::Prompter.new.ask_user("orig", "replace").replace_line?, true
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
13
|
def test_asks_to_process_line_no
|
13
14
|
with_highline("n") do
|
14
|
-
assert_equal Haml::I18n::Extractor::Prompter.new.ask_user("orig", "replace")
|
15
|
+
assert_equal Haml::I18n::Extractor::Prompter.new.ask_user("orig", "replace").no_replace?, true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_asks_to_process_line_tag
|
20
|
+
with_highline("t") do
|
21
|
+
assert_equal Haml::I18n::Extractor::Prompter.new.ask_user("orig", "replace").tag?, true
|
15
22
|
end
|
16
23
|
end
|
17
24
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Haml
|
5
|
+
class TaggingToolTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
FILE = Haml::I18n::Extractor::TaggingTool::DB
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
FileUtils.rm_rf(FILE)
|
11
|
+
end
|
12
|
+
|
13
|
+
test "It uses a file which it uses to keep track of user tagged lines" do
|
14
|
+
assert ! File.exists?(FILE), "no tagging file should exist"
|
15
|
+
Haml::I18n::Extractor::TaggingTool.new
|
16
|
+
assert File.exists?(FILE), "tagging file should be created on init"
|
17
|
+
end
|
18
|
+
|
19
|
+
test "It can write in a format" do
|
20
|
+
tag_tool = Haml::I18n::Extractor::TaggingTool.new
|
21
|
+
tag_tool.write("/foo/bar/baz.txt", 49)
|
22
|
+
assert File.readlines(FILE).include?("/foo/bar/baz.txt:49\n"), "should write info"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/test/text_replacer_test.rb
CHANGED
@@ -58,9 +58,10 @@ module Haml
|
|
58
58
|
end
|
59
59
|
|
60
60
|
test "it does not allow weird characters in the keyname" do
|
61
|
-
|
61
|
+
weird_line = "this (is `ch@racter ~ ma?dne{}ss!"
|
62
|
+
replacer = Haml::I18n::Extractor::TextReplacer.new(weird_line, weird_line, :text)
|
62
63
|
assert_equal replacer.replace_hash, { :modified_line => "= t('.this_is_chracter_madness')",
|
63
|
-
:keyname => "t('.this_is_chracter_madness')", :replaced_text =>
|
64
|
+
:keyname => "t('.this_is_chracter_madness')", :replaced_text => weird_line }
|
64
65
|
end
|
65
66
|
|
66
67
|
end
|
data/test/workflow_test.rb
CHANGED
@@ -38,29 +38,11 @@ module Haml
|
|
38
38
|
|
39
39
|
def test_outputs_stats
|
40
40
|
with_highline do
|
41
|
-
@workflow.
|
41
|
+
@workflow.start_message
|
42
42
|
assert @output.string.match(/Found 4 haml files/), "Outputs stats"
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def test_asks_to_process_file_yes
|
47
|
-
with_highline("O") do
|
48
|
-
assert_equal @workflow.process_file?(@workflow.files.first), :overwrite
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_asks_to_process_file_no
|
53
|
-
with_highline("N") do
|
54
|
-
assert_equal @workflow.process_file?(@workflow.files.first), nil
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_asks_to_process_file_dump
|
59
|
-
with_highline("D") do
|
60
|
-
assert_equal @workflow.process_file?(@workflow.files.first), :dump
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
46
|
def test_yaml_file_in_config
|
65
47
|
with_highline(full_project_user_interaction) do
|
66
48
|
@workflow.run
|
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.0.16
|
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-
|
11
|
+
date: 2013-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -122,6 +122,48 @@ dependencies:
|
|
122
122
|
- - ! '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake
|
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
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: actionpack
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ! '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rails
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ! '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
125
167
|
description: Parse the texts out of the haml files into localization files
|
126
168
|
email:
|
127
169
|
- shaiguitar@gmail.com
|
@@ -132,12 +174,14 @@ extra_rdoc_files: []
|
|
132
174
|
files:
|
133
175
|
- .gitignore
|
134
176
|
- .rvmrc
|
177
|
+
- .tags.haml-i18n-extractor
|
135
178
|
- Gemfile
|
136
179
|
- LICENSE
|
137
180
|
- README.md
|
138
181
|
- Rakefile
|
139
182
|
- TODO
|
140
183
|
- bin/haml-i18n-extractor
|
184
|
+
- demo/haml-i18n-extractor-demo.swf
|
141
185
|
- haml-i18n-extractor.gemspec
|
142
186
|
- lib/haml-i18n-extractor.rb
|
143
187
|
- lib/haml-i18n-extractor/core-ext/hash.rb
|
@@ -146,8 +190,10 @@ files:
|
|
146
190
|
- lib/haml-i18n-extractor/haml_writer.rb
|
147
191
|
- lib/haml-i18n-extractor/helpers.rb
|
148
192
|
- lib/haml-i18n-extractor/prompter.rb
|
193
|
+
- lib/haml-i18n-extractor/tagging_tool.rb
|
149
194
|
- lib/haml-i18n-extractor/text_finder.rb
|
150
195
|
- lib/haml-i18n-extractor/text_replacer.rb
|
196
|
+
- lib/haml-i18n-extractor/user_action.rb
|
151
197
|
- lib/haml-i18n-extractor/version.rb
|
152
198
|
- lib/haml-i18n-extractor/workflow.rb
|
153
199
|
- lib/haml-i18n-extractor/yaml_tool.rb
|
@@ -160,6 +206,7 @@ files:
|
|
160
206
|
- test/support/ex1.output.haml
|
161
207
|
- test/support/nothing_to_translate.haml
|
162
208
|
- test/support/nothing_to_translate.i18n-extractor.haml
|
209
|
+
- test/tagging_tool_test.rb
|
163
210
|
- test/test_helper.rb
|
164
211
|
- test/text_finder_test.rb
|
165
212
|
- test/text_replacer_test.rb
|
@@ -198,6 +245,7 @@ test_files:
|
|
198
245
|
- test/support/ex1.output.haml
|
199
246
|
- test/support/nothing_to_translate.haml
|
200
247
|
- test/support/nothing_to_translate.i18n-extractor.haml
|
248
|
+
- test/tagging_tool_test.rb
|
201
249
|
- test/test_helper.rb
|
202
250
|
- test/text_finder_test.rb
|
203
251
|
- test/text_replacer_test.rb
|