haml-i18n-extractor 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/TODO +6 -0
- data/lib/haml-i18n-extractor/extraction/extractor.rb +36 -26
- data/lib/haml-i18n-extractor/extraction/{exception_finder.rb → finder/exception_finder.rb} +0 -0
- data/lib/haml-i18n-extractor/extraction/{text_finder.rb → finder/text_finder.rb} +18 -12
- data/lib/haml-i18n-extractor/extraction/replacer/interpolation_helper.rb +51 -0
- data/lib/haml-i18n-extractor/extraction/replacer/replacer_result.rb +24 -0
- data/lib/haml-i18n-extractor/extraction/{text_replacer.rb → replacer/text_replacer.rb} +38 -33
- data/lib/haml-i18n-extractor/extraction/{tagging_tool.rb → tagging_writer.rb} +1 -1
- data/lib/haml-i18n-extractor/extraction/{yaml_tool.rb → yaml_writer.rb} +9 -12
- data/lib/haml-i18n-extractor/flow/prompter.rb +1 -1
- data/lib/haml-i18n-extractor/helpers.rb +38 -0
- data/lib/haml-i18n-extractor/version.rb +1 -1
- data/lib/haml-i18n-extractor.rb +8 -5
- data/scripts/renew_test_syntax +18 -0
- data/test/cli_test.rb +2 -2
- data/test/exception_finder_test.rb +2 -2
- data/test/extractor_test.rb +23 -23
- data/test/haml_parser_test.rb +3 -3
- data/test/haml_reader_test.rb +3 -3
- data/test/haml_writer_test.rb +4 -2
- data/test/integration_test.rb +13 -11
- data/test/interpolation_helper_test.rb +43 -0
- data/test/prompter_test.rb +3 -3
- data/test/support/ex1.yml +15 -0
- data/test/support/ex2.output.haml +1 -1
- data/test/support/ex5.haml +4 -0
- data/test/support/ex5.output.haml +4 -0
- data/test/support/ex5.yml +8 -0
- data/test/{tagging_tool_test.rb → tagging_writer_test.rb} +6 -6
- data/test/test_helper.rb +2 -2
- data/test/text_finder_test.rb +22 -20
- data/test/text_replacer_test.rb +29 -27
- data/test/workflow_test.rb +5 -5
- data/test/yaml_writer_test.rb +120 -0
- metadata +27 -14
- data/test/yaml_tool_test.rb +0 -110
data/test/extractor_test.rb
CHANGED
@@ -8,30 +8,30 @@ module Haml
|
|
8
8
|
@ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"))
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
def test_it_can_process_the_haml_and_replace_it_with_other_text
|
12
12
|
@ex1.run
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
def test_it_should_be_able_to_process_filters_with_the_haml_parser_now
|
16
16
|
#@FIXME
|
17
17
|
#raise 'implment me...check the finder#filters method and make sure you process the whole file at once so the parser gets it...'
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
def test_with_a_type_of_overwrite_or_dump_affecting_haml_writer
|
21
21
|
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :type => :overwrite)
|
22
22
|
assert_equal h.haml_writer.overwrite?, true
|
23
23
|
h = Haml::I18n::Extractor.new(file_path("ex1.haml"))
|
24
24
|
assert_equal h.haml_writer.overwrite?, false
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
def test_with_a_interactive_option_which_prompts_the_userper_line
|
28
28
|
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
|
29
29
|
assert_equal h.interactive?, true
|
30
30
|
h = Haml::I18n::Extractor.new(file_path("ex1.haml"))
|
31
31
|
assert_equal h.interactive?, false
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
def test_with_a_interactive_option_takes_user_input_into_consideration_for_haml
|
35
35
|
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
|
36
36
|
user_input = "D" # dump
|
37
37
|
File.readlines(file_path("ex1.haml")).size.times do
|
@@ -44,7 +44,7 @@ module Haml
|
|
44
44
|
assert_equal File.read(h.haml_writer.path), File.read(file_path("ex1.haml"))
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
def test_with_a_interactive_option_takes_user_input_n_as_next_and_stops_processing_file
|
48
48
|
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
|
49
49
|
user_input = "D" # dump
|
50
50
|
File.readlines(file_path("ex1.haml")).size.times do
|
@@ -57,7 +57,7 @@ module Haml
|
|
57
57
|
assert_equal File.read(h.haml_writer.path), File.read(file_path("ex1.haml"))
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
def test_with_a_interactive_option_takes_user_input_into_consideration_for_yaml
|
61
61
|
TestHelper.hax_shit
|
62
62
|
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
|
63
63
|
user_input = "D" # dump
|
@@ -68,13 +68,13 @@ module Haml
|
|
68
68
|
h.run
|
69
69
|
end
|
70
70
|
# no changes were made cause user was all like 'uhhh, no thxk'
|
71
|
-
assert_equal YAML.load(File.read(h.
|
71
|
+
assert_equal YAML.load(File.read(h.yaml_writer.yaml_file)), {}
|
72
72
|
end
|
73
73
|
|
74
|
-
|
74
|
+
def test_with_a_interactive_option_user_can_tag_a_line_for_later_review
|
75
75
|
TestHelper.hax_shit
|
76
|
-
if File.exist?(Haml::I18n::Extractor::
|
77
|
-
assert_equal File.readlines(Haml::I18n::Extractor::
|
76
|
+
if File.exist?(Haml::I18n::Extractor::TaggingWriter::DB)
|
77
|
+
assert_equal File.readlines(Haml::I18n::Extractor::TaggingWriter::DB), []
|
78
78
|
end
|
79
79
|
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
|
80
80
|
user_input = "D" # dump
|
@@ -84,11 +84,11 @@ module Haml
|
|
84
84
|
with_highline(user_input) do
|
85
85
|
h.run
|
86
86
|
end
|
87
|
-
assert (File.readlines(Haml::I18n::Extractor::
|
87
|
+
assert (File.readlines(Haml::I18n::Extractor::TaggingWriter::DB).size != 0), "tag lines get added to file"
|
88
88
|
end
|
89
89
|
|
90
90
|
|
91
|
-
|
91
|
+
def test_can_not_initialize_if_the_haml_is_not_valid_syntax
|
92
92
|
begin
|
93
93
|
Haml::I18n::Extractor.new(file_path("bad.haml"))
|
94
94
|
assert false, "should not get here"
|
@@ -97,30 +97,30 @@ module Haml
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
|
100
|
+
def test_it_writes_the_haml_to_an_out_file_if_valid_haml_output
|
101
101
|
FileUtils.rm_rf(@ex1.haml_writer.path)
|
102
102
|
assert_equal File.exists?(@ex1.haml_writer.path), false
|
103
103
|
@ex1.run
|
104
104
|
assert_equal File.exists?(@ex1.haml_writer.path), true
|
105
105
|
end
|
106
106
|
|
107
|
-
|
107
|
+
def test_it_writes_the_locale_info_to_an_out_file_when_run
|
108
108
|
TestHelper.hax_shit
|
109
|
-
assert_equal File.exists?(@ex1.
|
109
|
+
assert_equal File.exists?(@ex1.yaml_writer.yaml_file), false
|
110
110
|
@ex1.run
|
111
|
-
assert_equal File.exists?(@ex1.
|
112
|
-
assert_equal YAML.load(File.read(@ex1.
|
111
|
+
assert_equal File.exists?(@ex1.yaml_writer.yaml_file), true
|
112
|
+
assert_equal YAML.load(File.read(@ex1.yaml_writer.yaml_file)), @ex1.yaml_writer.yaml_hash
|
113
113
|
end
|
114
114
|
|
115
|
-
|
115
|
+
def test_sends_a_hash_over_of_replacement_info_to_its_yaml_writer_when_run
|
116
116
|
@ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"))
|
117
|
-
assert_equal @ex1.
|
117
|
+
assert_equal @ex1.yaml_writer.info_for_yaml, nil
|
118
118
|
@ex1.run
|
119
|
-
assert @ex1.
|
120
|
-
assert_equal @ex1.
|
119
|
+
assert @ex1.yaml_writer.info_for_yaml.is_a?(Hash), "its is hash of info about the files lines"
|
120
|
+
assert_equal @ex1.yaml_writer.info_for_yaml.size, @ex1.haml_reader.lines.size
|
121
121
|
end
|
122
122
|
|
123
|
-
|
123
|
+
def test_it_fails_before_it_writes_to_an_out_file_if_it_is_not_valid
|
124
124
|
begin
|
125
125
|
@ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"))
|
126
126
|
@ex1.stub(:assign_new_body, nil) do #nop
|
data/test/haml_parser_test.rb
CHANGED
@@ -7,20 +7,20 @@ module Haml
|
|
7
7
|
@body = "- if true\n bar"
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
def test_it_can_collect_metadata_about_lines
|
11
11
|
tree = Haml::I18n::Extractor::HamlParser.new(@body)
|
12
12
|
line_metadatas = tree.flattened_values
|
13
13
|
assert_equal line_metadatas.size, 2
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
def test_it_can_collect_metadata_about_lines
|
17
17
|
parser = Haml::I18n::Extractor::HamlParser.new(@body)
|
18
18
|
line_metadatas = parser.flattened_values
|
19
19
|
assert_equal line_metadatas.size, 2
|
20
20
|
end
|
21
21
|
|
22
22
|
# easy api to use index <-> lineno
|
23
|
-
|
23
|
+
def test_it_is_sorted_by_line_numbers
|
24
24
|
parser = Haml::I18n::Extractor::HamlParser.new(@body)
|
25
25
|
line_metadatas = parser.flattened_values
|
26
26
|
assert_equal line_metadatas, line_metadatas.sort_by{|m| m[:line]}
|
data/test/haml_reader_test.rb
CHANGED
@@ -17,16 +17,16 @@ module Haml
|
|
17
17
|
@reader = Haml::I18n::Extractor::HamlReader.new(TEMP_FILE_PATH)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
def test_has_a_body_and_a_path
|
21
21
|
assert_equal @reader.path, TEMP_FILE_PATH
|
22
22
|
assert_equal @reader.body, File.read(TEMP_FILE_PATH)
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
def test_has_an_array_of_lines_in_that_file
|
26
26
|
assert_equal @reader.lines.size, LINE_COUNT
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
def test_has_metadata_about_each_line
|
30
30
|
assert_equal @reader.metadata.size, LINE_COUNT
|
31
31
|
end
|
32
32
|
|
data/test/haml_writer_test.rb
CHANGED
@@ -6,6 +6,8 @@ module Haml
|
|
6
6
|
|
7
7
|
ORIG_TEMP_FILE_PATH = File.join(TestHelper::TMPDIR, "foo_haml_extractor_test.haml")
|
8
8
|
|
9
|
+
FileUtils.mkdir_p(TestHelper::TMPDIR)
|
10
|
+
|
9
11
|
def setup
|
10
12
|
File.open(ORIG_TEMP_FILE_PATH, "w") do |f|
|
11
13
|
10.times do |i|
|
@@ -18,7 +20,7 @@ module Haml
|
|
18
20
|
FileUtils.rm_rf(ORIG_TEMP_FILE_PATH)
|
19
21
|
end
|
20
22
|
|
21
|
-
|
23
|
+
def test_it_can_dump_the_file_and_that_is_the_default
|
22
24
|
@writer = Haml::I18n::Extractor::HamlWriter.new(ORIG_TEMP_FILE_PATH)
|
23
25
|
@writer.body = "This is what it is"
|
24
26
|
@writer.write_file
|
@@ -26,7 +28,7 @@ module Haml
|
|
26
28
|
assert_equal File.read(@writer.path), "This is what it is\n"
|
27
29
|
end
|
28
30
|
|
29
|
-
|
31
|
+
def test_it_can_overwrite_the_file
|
30
32
|
@writer = Haml::I18n::Extractor::HamlWriter.new(ORIG_TEMP_FILE_PATH, {:type => :overwrite})
|
31
33
|
@writer.body = "This is what it is"
|
32
34
|
@writer.write_file
|
data/test/integration_test.rb
CHANGED
@@ -12,40 +12,42 @@ module Haml
|
|
12
12
|
TestHelper.teardown_project_directory!
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
def test_it_can_handle_namespaced_views
|
16
16
|
namespaced_extractor = Haml::I18n::Extractor.extractors.select{|ex| ex.haml_writer.path.match /namespace/ }.last
|
17
|
-
assert namespaced_extractor.
|
17
|
+
assert namespaced_extractor.yaml_writer.yaml_hash["en"]["namespace"], "namespace key works"
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
def test_it_can_handle_partial_views
|
21
21
|
partial_extractor = Haml::I18n::Extractor.extractors.select{|ex| ex.haml_writer.path.match /_partial/ }.last
|
22
|
-
assert partial_extractor.
|
22
|
+
assert partial_extractor.yaml_writer.yaml_hash["en"]["view2"]["partial"], "partial filenames in yaml are w/out leading _"
|
23
23
|
end
|
24
24
|
|
25
25
|
## EXAMPLES
|
26
26
|
|
27
|
-
|
27
|
+
def test_it_can_replace_a_string_body_and_have_expected_output_ex5
|
28
|
+
expected_output = File.read(file_path("ex5.output.haml"))
|
29
|
+
assert_equal Haml::I18n::Extractor.new(file_path("ex5.haml")).new_body, expected_output
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_it_can_replace_a_string_body_and_have_expected_output_ex4
|
28
33
|
expected_output = File.read(file_path("ex4.output.haml"))
|
29
34
|
assert_equal Haml::I18n::Extractor.new(file_path("ex4.haml")).new_body, expected_output
|
30
35
|
end
|
31
36
|
|
32
|
-
|
37
|
+
def test_it_can_replace_a_string_body_and_have_expected_output_ex3
|
33
38
|
expected_output = File.read(file_path("ex3.output.haml"))
|
34
39
|
assert_equal Haml::I18n::Extractor.new(file_path("ex3.haml")).new_body, expected_output
|
35
40
|
end
|
36
41
|
|
37
|
-
|
42
|
+
def test_it_can_replace_a_string_body_and_have_expected_output_ex2
|
38
43
|
expected_output = File.read(file_path("ex2.output.haml"))
|
39
44
|
assert_equal Haml::I18n::Extractor.new(file_path("ex2.haml")).new_body, expected_output
|
40
45
|
end
|
41
46
|
|
42
|
-
|
43
|
-
test "it can replace a string body and have expected output ex1" do
|
47
|
+
def test_it_can_replace_a_string_body_and_have_expected_output_ex1
|
44
48
|
expected_output = File.read(file_path("ex1.output.haml"))
|
45
49
|
assert_equal Haml::I18n::Extractor.new(file_path("ex1.haml")).new_body, expected_output
|
46
50
|
end
|
47
51
|
|
48
|
-
|
49
|
-
|
50
52
|
end
|
51
53
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Haml
|
4
|
+
class InterpolationHelperTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def test_it_takes_text_and_returns_interpolations
|
7
|
+
replace = "this may \#{be} the \#{dup}"
|
8
|
+
t_name = "this_may_be_the_dup"
|
9
|
+
helper = Haml::I18n::Extractor::InterpolationHelper.new(replace, t_name)
|
10
|
+
assert helper.interpolations == ["be", "dup"], "can catch the interpolations"
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def test_it_takes_text_and_custom_keynames
|
15
|
+
replace = "this may \#{be} the \#{dup}"
|
16
|
+
t_name = "this_may_be_the_dup"
|
17
|
+
helper = Haml::I18n::Extractor::InterpolationHelper.new(replace, t_name)
|
18
|
+
assert helper.keyname_with_vars == "t('.this_may_be_the_dup', :be => be, :dup => dup)",
|
19
|
+
"returns custom t() with vars"
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_it_takes_text_and_returns_for_str_with_no_quotes
|
23
|
+
replace = "\\\#{is_this_hard?} what"
|
24
|
+
t_name = "is_this_hard_what"
|
25
|
+
helper = Haml::I18n::Extractor::InterpolationHelper.new(replace, t_name)
|
26
|
+
assert helper.interpolations == ["is_this_hard?"], "can catch the interpolations"
|
27
|
+
x = helper.keyname_with_vars
|
28
|
+
#puts x.inspect
|
29
|
+
assert x == "t('.is_this_hard_what', :is_this_hard => is_this_hard?)",
|
30
|
+
"returns custom t() with vars"
|
31
|
+
end
|
32
|
+
|
33
|
+
# FIXME these don't work?
|
34
|
+
#%p \#{is_this_hard?} what
|
35
|
+
#%span I don't know if this \#{is_also} what
|
36
|
+
#%p= t('.what', :is_this_hard => is_this_hard?)
|
37
|
+
#%span= t('.i_dont_know_if_this_what', :is_also => is_also)
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
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
|
+
def test_asks_to_process_line_yes
|
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
|
+
def test_asks_to_process_line_no
|
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
|
+
def test_test_asks_to_process_line_tag
|
20
20
|
with_highline("t") do
|
21
21
|
assert_equal Haml::I18n::Extractor::Prompter.new.ask_user("orig", "replace").tag?, true
|
22
22
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
support:
|
4
|
+
ex1:
|
5
|
+
some_place: Some place
|
6
|
+
admin: Admin
|
7
|
+
admin_dashboard: Admin Dashboard
|
8
|
+
stacks: Stacks
|
9
|
+
alerts: t('.alerts')
|
10
|
+
accounts: Accounts
|
11
|
+
this_linkez: this_linkez
|
12
|
+
what_is_supposed_to_be_is_supp: What is@ supposed to be, is supposed to be!
|
13
|
+
~
|
14
|
+
details: Details
|
15
|
+
random: ! '"raNdom"'
|
@@ -8,7 +8,7 @@
|
|
8
8
|
%h3
|
9
9
|
= t('.all_invoices_billable')
|
10
10
|
%span{:style => (@billable_invoices == @active_invoices) ? "color: #090" : "color: #900"}
|
11
|
-
=t('.billable_invoices_out_of_activ')
|
11
|
+
=t('.billable_invoices_out_of_activ', :billable_invoices => @billable_invoices, :active_invoices => @active_invoices)
|
12
12
|
%h3
|
13
13
|
= t('.24_hours_past_end_of_billing_m')
|
14
14
|
%span{:style => (@billing_month.past_cutoff) ? "color: #090" : "color: #900"}
|
@@ -2,23 +2,23 @@ require 'test_helper'
|
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
module Haml
|
5
|
-
class
|
5
|
+
class TaggingWriterTest < MiniTest::Unit::TestCase
|
6
6
|
|
7
|
-
FILE = Haml::I18n::Extractor::
|
7
|
+
FILE = Haml::I18n::Extractor::TaggingWriter::DB
|
8
8
|
|
9
9
|
def teardown
|
10
10
|
FileUtils.rm_rf(FILE)
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
def test_it_uses_a_file_which_it_uses_to_keep_track_of_user_tagged_lines
|
14
14
|
TestHelper.hax_shit
|
15
15
|
assert ! File.exists?(FILE), "no tagging file should exist"
|
16
|
-
Haml::I18n::Extractor::
|
16
|
+
Haml::I18n::Extractor::TaggingWriter.new
|
17
17
|
assert File.exists?(FILE), "tagging file should be created on init"
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
tag_tool = Haml::I18n::Extractor::
|
20
|
+
def test_it_can_write_in_a_format
|
21
|
+
tag_tool = Haml::I18n::Extractor::TaggingWriter.new
|
22
22
|
tag_tool.write("/foo/bar/baz.txt", 49)
|
23
23
|
assert File.readlines(FILE).include?("/foo/bar/baz.txt:49\n"), "should write info"
|
24
24
|
end
|
data/test/test_helper.rb
CHANGED
@@ -114,8 +114,8 @@ module TestHelper
|
|
114
114
|
def self.hax_shit
|
115
115
|
Dir.glob("*yml").map {|p| FileUtils.rm(p) } # HAX, TODO: handle with yaml files correctly (config/en.yml)
|
116
116
|
Dir.glob("config/locales/*yml").map {|p| FileUtils.rm(p) } # HAX, TODO: handle with yaml files correctly (config/en.yml)
|
117
|
-
if File.exists?(Haml::I18n::Extractor::
|
118
|
-
FileUtils.rm_rf(Haml::I18n::Extractor::
|
117
|
+
if File.exists?(Haml::I18n::Extractor::TaggingWriter::DB)
|
118
|
+
FileUtils.rm_rf(Haml::I18n::Extractor::TaggingWriter::DB) # HAX, TODO: setup/teardown
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
data/test/text_finder_test.rb
CHANGED
@@ -4,104 +4,104 @@ module Haml
|
|
4
4
|
class StringFinderTest < MiniTest::Unit::TestCase
|
5
5
|
|
6
6
|
# empty line
|
7
|
-
|
7
|
+
def test_empty_lines_filters_matches_with_nometadata
|
8
8
|
assert_equal find_text(""), nil
|
9
9
|
assert_equal find_type(""), nil
|
10
10
|
end
|
11
11
|
|
12
12
|
# regular text mode
|
13
|
-
|
13
|
+
def test_regular_text_without_whitespaces
|
14
14
|
assert_equal find_text("iphone"), "iphone"
|
15
15
|
assert_equal find_type("iphone"), :plain
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
def test_regular_text_with_whitespaces
|
19
19
|
assert_equal find_text("iphone4 "), "iphone4"
|
20
20
|
assert_equal find_type("iphone4 "), :plain
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
def test_scripts_with_strings
|
24
24
|
assert_equal find_text("= 'jessica'"), " 'jessica'"
|
25
25
|
assert_equal find_type("= 'jessica'"), :script
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
def test_scripts_with_no_strings
|
29
29
|
assert_equal find_text("= true"), ""
|
30
30
|
assert_equal find_type("= true"), :script
|
31
31
|
end
|
32
32
|
|
33
33
|
# html tag mode
|
34
|
-
|
34
|
+
def test_tag_text_is_an_tag
|
35
35
|
assert_equal find_text("%span Text to find"), "Text to find"
|
36
36
|
assert_equal find_type("%span Text to find"), :tag
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
def test_tag_text_with_class_is_an_tag
|
40
40
|
assert_equal find_text("%span.whatever-with-thing Text to find"), "Text to find"
|
41
41
|
assert_equal find_type("%span.whatever-with-thing Text to find"), :tag
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
def test_tag_text_with_ruby_eval_code_is_a_script_script
|
45
45
|
assert_equal find_text("%span= ruby_eval_code"), ""
|
46
46
|
assert_equal find_type("%span= ruby_eval_code"), :tag
|
47
47
|
end
|
48
48
|
|
49
|
-
|
49
|
+
def test_tag_text_with_ruby_eval_code_and_class_is_a_script_script
|
50
50
|
assert_equal find_text( "%span#whatever-with-thing= ruby_eval_code"), ""
|
51
51
|
assert_equal find_type( "%span#whatever-with-thing= ruby_eval_code"), :tag
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
def test_ruby_style_tags_ahref__httpwhatever_whatever
|
55
55
|
assert_equal find_text("%a{'href' => 'http://whatever'} whatever"), "whatever"
|
56
56
|
assert_equal find_type("%a{'href' => 'http://whatever'} whatever"), :tag
|
57
57
|
end
|
58
58
|
|
59
59
|
# script scripts / ruby eval mode
|
60
|
-
|
60
|
+
def test_script_scripts_with_strings
|
61
61
|
assert_equal find_text('= "bob"'), " \"bob\""
|
62
62
|
assert_equal find_text("= 'bob'"), " 'bob'"
|
63
63
|
assert_equal find_type("= 'bob'"), :script
|
64
64
|
end
|
65
65
|
|
66
|
-
|
66
|
+
def test_script_scripts_does_not_interpolate_ruby_vars_in_strings
|
67
67
|
assert_equal find_text('= "ruby can #{var}"'), " \"ruby can \#{var}\""
|
68
68
|
assert_equal find_type('= "ruby can #{var}"'), :script
|
69
69
|
end
|
70
70
|
|
71
71
|
# special script scripts exceptions
|
72
|
-
|
72
|
+
def test_it_finds_link_to_texts_as_an_exception_to_the_rule
|
73
73
|
assert_equal find_text('= link_to "This should be found", "/"'), "This should be found"
|
74
74
|
assert_equal find_type('= link_to "This should be found", "/"'), :script
|
75
75
|
end
|
76
76
|
|
77
|
-
|
77
|
+
def test_it_finds_link_to_texts_as_an_exception_to_the_rule_and_does_not_interpolate
|
78
78
|
assert_equal find_text('= "Statistics for #{@name}"'), " \"Statistics for \#{@name}\""
|
79
79
|
assert_equal find_type('= "Statistics for #{@name}"'), :script
|
80
80
|
end
|
81
81
|
|
82
82
|
# html tag mode with ruby evaling
|
83
|
-
|
83
|
+
def test_html_tag_with_ruby_eval_with_strings
|
84
84
|
assert_equal find_text('%p= "bob"'), "\"bob\""
|
85
85
|
assert_equal find_text("%p.what= 'bob'"), "'bob'"
|
86
86
|
assert_equal find_text("%p.what{:attr => :val}= 'bob'"), "'bob'"
|
87
87
|
assert_equal find_type("%p.what{:attr => :val}= 'bob'"), :tag
|
88
88
|
end
|
89
89
|
|
90
|
-
|
90
|
+
def test_html_tag_script_scripts_does_not_interpolate_ruby_vars_in_strings
|
91
91
|
assert_equal find_text('%p= "ruby can #{var}"'), "\"ruby can \#{var}\""
|
92
92
|
assert_equal find_text('%p.what= "ruby can #{var}"'), "\"ruby can \#{var}\""
|
93
93
|
assert_equal find_text('%p.what{:attr => :val}= "ruby can #{var}"'), "\"ruby can \#{var}\""
|
94
94
|
assert_equal find_type('%p.what{:attr => :val}= "ruby can #{var}"'), :tag
|
95
95
|
end
|
96
96
|
|
97
|
-
|
97
|
+
def test_html_tag_it_finds_link_to_texts_as_an_exception_to_the_rule
|
98
98
|
assert_equal find_text('%p= link_to "This should be found", "/"'), "This should be found"
|
99
99
|
assert_equal find_text('%p.what= link_to "This should be found", "/"'), "This should be found"
|
100
100
|
assert_equal find_text('%p.what{:attr => :val}= link_to "This should be found", "/"'), "This should be found"
|
101
101
|
assert_equal find_type('%p.what{:attr => :val}= link_to "This should be found", "/"'), :tag
|
102
102
|
end
|
103
103
|
|
104
|
-
|
104
|
+
def test_html_tag_it_finds_link_to_texts_as_an_exception_to_the_rule_and_does_not_interpolate
|
105
105
|
assert_equal find_text('%p= "Statistics for #{@name}"'), "\"Statistics for \#{@name}\""
|
106
106
|
assert_equal find_text('%p.what= "Statistics for #{@name}"'), "\"Statistics for \#{@name}\""
|
107
107
|
assert_equal find_text('%p.what{:attr => :val}= "Statistics for #{@name}"'), "\"Statistics for \#{@name}\""
|
@@ -117,12 +117,14 @@ module Haml
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def find_type(haml)
|
120
|
-
|
120
|
+
result = process_haml(haml)
|
121
|
+
type, text = [result.type, result.match]
|
121
122
|
type
|
122
123
|
end
|
123
124
|
|
124
125
|
def find_text(haml)
|
125
|
-
|
126
|
+
result = process_haml(haml)
|
127
|
+
type, text = [result.type, result.match]
|
126
128
|
text
|
127
129
|
end
|
128
130
|
|