antwort 0.0.12 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +12 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +28 -1
- data/README.md +1 -1
- data/antwort.gemspec +2 -2
- data/lib/antwort.rb +5 -4
- data/lib/antwort/builder/builder.rb +15 -24
- data/lib/antwort/builder/email.rb +47 -22
- data/lib/antwort/builder/flattener.rb +8 -9
- data/lib/antwort/builder/partial.rb +12 -11
- data/lib/antwort/builder/style.rb +26 -27
- data/lib/antwort/{builder.rb → builders.rb} +3 -3
- data/lib/antwort/cli.rb +0 -1
- data/lib/antwort/cli/cli.rb +42 -48
- data/lib/antwort/cli/send.rb +11 -14
- data/lib/antwort/cli/upload.rb +29 -28
- data/lib/antwort/core.rb +4 -0
- data/lib/antwort/email/build.rb +41 -0
- data/lib/antwort/email/collection.rb +41 -0
- data/lib/antwort/email/data.rb +27 -0
- data/lib/antwort/email/template.rb +88 -0
- data/lib/antwort/helpers/file_helper.rb +27 -0
- data/lib/antwort/{helpers.rb → helpers/helper.rb} +2 -2
- data/lib/antwort/helpers/logic_helper.rb +81 -0
- data/lib/antwort/helpers/markup_helper.rb +37 -0
- data/lib/antwort/{builder/helpers/sanitizers.rb → helpers/sanitizers_helper.rb} +2 -4
- data/lib/antwort/helpers/server_helper.rb +32 -0
- data/lib/antwort/{server.rb → server/server.rb} +26 -23
- data/{template/project → lib/antwort/server}/views/404.html.erb +1 -1
- data/{template/project → lib/antwort/server}/views/index.html.erb +4 -6
- data/{template/project → lib/antwort/server}/views/layout.erb +5 -5
- data/{template/project/views/markup/_button.html.erb → lib/antwort/server/views/markup/button.html.erb} +0 -0
- data/{template/project/views/markup/_image_tag.html.erb → lib/antwort/server/views/markup/image_tag.html.erb} +0 -0
- data/{template/project → lib/antwort/server}/views/server.erb +0 -0
- data/lib/antwort/version.rb +1 -1
- data/spec/builder/builder_spec.rb +17 -22
- data/spec/builder/email_spec.rb +11 -12
- data/spec/builder/flattener_spec.rb +20 -21
- data/spec/builder/helpers_logic_spec.rb +69 -73
- data/spec/builder/partial_spec.rb +42 -51
- data/spec/builder/style_spec.rb +25 -34
- data/spec/{cli_spec.rb → cli/cli_spec.rb} +8 -9
- data/spec/cli/send_spec.rb +80 -0
- data/spec/cli/upload_spec.rb +17 -9
- data/spec/email/build_spec.rb +13 -0
- data/spec/email/collection_spec.rb +56 -0
- data/spec/email/data_spec.rb +40 -0
- data/spec/email/template_spec.rb +116 -0
- data/spec/fixtures/assets/css/demo/include.scss +3 -0
- data/spec/fixtures/assets/css/demo/inline.scss +33 -0
- data/spec/fixtures/assets/css/no-images/include.scss +1 -0
- data/spec/fixtures/assets/css/no-images/inline.scss +2 -0
- data/spec/fixtures/assets/css/shared/_base.scss +64 -0
- data/spec/fixtures/assets/css/shared/_mixins.scss +25 -0
- data/spec/fixtures/assets/css/shared/_reset.scss +59 -0
- data/spec/fixtures/assets/css/shared/_vars.scss +12 -0
- data/spec/fixtures/assets/css/shared/include.scss +23 -0
- data/spec/fixtures/assets/css/shared/inline.scss +9 -0
- data/spec/fixtures/build/demo-20160101/demo.html +177 -0
- data/spec/fixtures/build/demo-20160101/source/demo.html +118 -0
- data/spec/fixtures/build/demo-20160101/source/include.css +58 -0
- data/spec/fixtures/build/demo-20160101/source/inline.css +83 -0
- data/spec/fixtures/build/demo-20160102/demo.html +177 -0
- data/spec/fixtures/build/demo-20160102/source/demo.html +118 -0
- data/spec/fixtures/build/demo-20160102/source/include.css +58 -0
- data/spec/fixtures/build/demo-20160102/source/inline.css +83 -0
- data/{template/project/data/.empty_directory → spec/fixtures/emails/1-demo/_bar.erb} +0 -0
- data/spec/fixtures/emails/1-demo/_foo.erb +0 -0
- data/spec/fixtures/emails/1-demo/index.html.erb +2 -2
- data/spec/fixtures/emails/4-custom-layout/index.html.erb +6 -0
- data/spec/fixtures/emails/4-custom-layout/layout.erb +5 -0
- data/spec/fixtures/emails/demo/index.html.erb +4 -0
- data/spec/fixtures/emails/no-images/index.html.erb +4 -0
- data/spec/fixtures/emails/shared/_foo.erb +0 -0
- data/spec/fixtures/{views → emails/shared}/layout.erb +0 -0
- data/spec/helpers/file_helper_spec.rb +30 -0
- data/spec/server/server_spec.rb +57 -0
- data/spec/spec_helper.rb +18 -7
- data/template/project/Gemfile.tt +1 -7
- metadata +92 -42
- data/lib/antwort/builder/helpers/logic.rb +0 -82
- data/lib/antwort/cli/helpers.rb +0 -44
- data/lib/antwort/server/helpers.rb +0 -67
- data/lib/antwort/server/markup.rb +0 -39
- data/spec/cli/helpers_spec.rb +0 -60
- data/spec/fixtures/build/demo-123456/build.html +0 -7
- data/spec/fixtures/build/demo-123457/build.html +0 -7
- data/spec/fixtures/build/demo-bar-123/build.html +0 -7
- data/spec/fixtures/views/404.html.erb +0 -1
- data/spec/fixtures/views/index.html.erb +0 -14
- data/spec/fixtures/views/server.erb +0 -5
- data/spec/server_spec.rb +0 -54
- data/template/project/.ruby-version +0 -1
- data/template/project/data/config.yml +0 -3
@@ -7,15 +7,15 @@
|
|
7
7
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- enable media queries for windows phone 8 -->
|
8
8
|
<meta name="format-detection" content="telephone=no"> <!-- disable auto telephone linking in iOS -->
|
9
9
|
<title><%= @title || "Email Title" %></title>
|
10
|
-
<link rel="stylesheet" type="text/css" href="/assets/<%= @template %>/inline.css">
|
11
|
-
<link rel="stylesheet" type="text/css" href="/assets/<%= @template %>/include.css">
|
10
|
+
<link rel="stylesheet" type="text/css" href="/assets/<%= @template.name %>/inline.css">
|
11
|
+
<link rel="stylesheet" type="text/css" href="/assets/<%= @template.name %>/include.css">
|
12
12
|
</head>
|
13
|
-
<body
|
13
|
+
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
|
14
14
|
|
15
15
|
<!-- 100% wrapper (grey background) -->
|
16
|
-
<table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0"
|
16
|
+
<table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">
|
17
17
|
<tr>
|
18
|
-
<td align="center" valign="top"
|
18
|
+
<td align="center" valign="top">
|
19
19
|
|
20
20
|
<br>
|
21
21
|
|
File without changes
|
File without changes
|
File without changes
|
data/lib/antwort/version.rb
CHANGED
@@ -1,30 +1,25 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Antwort::Builder do
|
4
|
-
|
5
|
-
@builder = Antwort::Builder.new
|
6
|
-
end
|
4
|
+
let(:build) { Antwort::Builder.new }
|
7
5
|
|
8
|
-
describe
|
9
|
-
it
|
10
|
-
it
|
11
|
-
it
|
12
|
-
it
|
13
|
-
it
|
14
|
-
it
|
6
|
+
describe 'Initialize' do
|
7
|
+
it 'has a template_name'
|
8
|
+
it 'has a build_id'
|
9
|
+
it 'has a markup_dir'
|
10
|
+
it 'has a source_dir'
|
11
|
+
it 'has a scss_dir'
|
12
|
+
it 'has an asset_server'
|
15
13
|
end
|
16
14
|
|
17
|
-
describe
|
18
|
-
it
|
19
|
-
it
|
20
|
-
it
|
15
|
+
describe 'Compiles' do
|
16
|
+
it 'SCSS'
|
17
|
+
it 'inline.scss'
|
18
|
+
it 'include.scss'
|
21
19
|
end
|
22
20
|
|
23
|
-
describe
|
24
|
-
it
|
25
|
-
it
|
26
|
-
it "changes relative assets URLs to use asset server"
|
27
|
-
it "preserves ` `s"
|
21
|
+
describe 'Helpers' do
|
22
|
+
it 'changes relative assets URLs to use asset server'
|
23
|
+
it 'preserves ` `s'
|
28
24
|
end
|
29
|
-
|
30
|
-
end
|
25
|
+
end
|
data/spec/builder/email_spec.rb
CHANGED
@@ -1,21 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Antwort::EmailBuilder do
|
4
4
|
before :each do
|
5
5
|
@builder = Antwort::EmailBuilder.new
|
6
6
|
end
|
7
7
|
|
8
|
-
describe
|
9
|
-
it
|
10
|
-
it
|
8
|
+
describe 'Builds' do
|
9
|
+
it 'builds HTML'
|
10
|
+
it 'inlines CSS'
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
15
|
-
it
|
16
|
-
it
|
17
|
-
it
|
18
|
-
it
|
13
|
+
describe 'Helpers' do
|
14
|
+
it 'can inline CSS'
|
15
|
+
it 'cleans up markup'
|
16
|
+
it 'removes livereload'
|
17
|
+
it 'adds in the included CSS'
|
18
|
+
it 'removes excessive newlines'
|
19
19
|
end
|
20
|
-
|
21
|
-
end
|
20
|
+
end
|
@@ -1,64 +1,63 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Antwort::Flattener do
|
4
|
-
|
5
|
-
|
6
|
-
it "saves source to a attr_reader" do
|
4
|
+
describe 'initialize' do
|
5
|
+
it 'saves source to a attr_reader' do
|
7
6
|
s = Antwort::Flattener.new('<td>')
|
8
7
|
expect(s.source).to eq('<td>')
|
9
8
|
end
|
10
9
|
|
11
|
-
describe
|
12
|
-
it
|
10
|
+
describe 'saves matches to an array' do
|
11
|
+
it 'matches single style per source' do
|
13
12
|
s = Antwort::Flattener.new('<div style="color:black">')
|
14
13
|
expect(s.styles).to eq(['color:black'])
|
15
14
|
end
|
16
|
-
it
|
15
|
+
it 'matches multiple styles per source' do
|
17
16
|
s = Antwort::Flattener.new('<td style="background-color:#cccccc"><div style="color: red">')
|
18
17
|
expect(s.styles).to eq(['background-color:#cccccc', 'color: red'])
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
describe
|
24
|
-
it
|
22
|
+
describe 'flattens css styles' do
|
23
|
+
it 'a single match' do
|
25
24
|
s = Antwort::Flattener.new('<div style="color:black;color:red;background:white;">').flatten
|
26
25
|
expect(s.flattened).to eq('<div style="color:red;background:white">')
|
27
26
|
end
|
28
27
|
|
29
|
-
describe
|
30
|
-
let
|
28
|
+
describe 'multiple styles' do
|
29
|
+
let(:style) { Antwort::Flattener.new('<td style="color:black;color:red;"><div style="background:white;">').flatten }
|
31
30
|
|
32
|
-
it
|
31
|
+
it 'stores original source as a string' do
|
33
32
|
expect(style.source).to eq('<td style="color:black;color:red;"><div style="background:white;">')
|
34
33
|
end
|
35
34
|
|
36
|
-
it
|
35
|
+
it 'stores flattened source as a string' do
|
37
36
|
expect(style.flattened).to eq('<td style="color:red"><div style="background:white">')
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
|
-
describe
|
42
|
-
it
|
40
|
+
describe 'method flattened?' do
|
41
|
+
it 'returns true if changes where made' do
|
43
42
|
s = Antwort::Flattener.new('<td style="color: red; color: black;">').flatten
|
44
43
|
expect(s.flattened?).to eq(true)
|
45
44
|
end
|
46
|
-
it
|
45
|
+
it 'returns false if chnages were not made' do
|
47
46
|
s = Antwort::Flattener.new('<td style"color:red">').flatten
|
48
47
|
expect(s.flattened?).to eq(false)
|
49
48
|
end
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
53
|
-
describe
|
54
|
-
let
|
52
|
+
describe 'code cleanup' do
|
53
|
+
let(:style) { Antwort::Flattener.new('<td style="color: black;">').flatten }
|
55
54
|
|
56
|
-
it
|
55
|
+
it 'removes trailing semicolon;' do
|
57
56
|
expect(style.flattened).to eq('<td style="color:black">')
|
58
57
|
expect(style.flattened).not_to eq('<td style="color:black;">')
|
59
58
|
end
|
60
|
-
it
|
59
|
+
it 'remove extra white space' do
|
61
60
|
expect(style.flattened).not_to eq('<td style="color: black">')
|
62
61
|
end
|
63
62
|
end
|
64
|
-
end
|
63
|
+
end
|
@@ -4,63 +4,62 @@ class Dummy
|
|
4
4
|
end
|
5
5
|
|
6
6
|
describe Antwort::LogicHelpers do
|
7
|
-
|
8
7
|
before :each do
|
9
8
|
@helper = Dummy.new
|
10
9
|
@helper.extend(Antwort::LogicHelpers)
|
11
10
|
end
|
12
11
|
|
13
|
-
describe
|
14
|
-
it
|
12
|
+
describe 'non breaking spaces' do
|
13
|
+
it 'preserves by adjusting markup' do
|
15
14
|
expect(@helper.preserve_nbsps('foo bar')).to eq('foo%nbspace%bar')
|
16
15
|
end
|
17
16
|
|
18
|
-
it
|
17
|
+
it 'can restore to proper markup' do
|
19
18
|
expect(@helper.restore_nbsps('foo%nbspace%bar')).to eq('foo bar')
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
describe
|
24
|
-
it
|
22
|
+
describe 'statements' do
|
23
|
+
it 'preserves erb markup' do
|
25
24
|
expect(@helper.preserve_logic('<% user.merge!({clear: true}) %>')).to eq('{% user.merge!({clear: true}) %}')
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
28
|
#-- Comments --
|
30
29
|
|
31
|
-
describe
|
32
|
-
it
|
30
|
+
describe 'comments' do
|
31
|
+
it 'preserves erb comments' do
|
33
32
|
h = {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
'<%# foo %>' => '{# foo #}',
|
34
|
+
'<% # foo %>' => '{# foo #}',
|
35
|
+
'<% #foo %>' => '{# foo #}',
|
36
|
+
'<%#= foo %>' => '{#= foo #}',
|
37
|
+
'<%# foo bar == cat %>' => '{# foo bar == cat #}'
|
39
38
|
}
|
40
39
|
h.each do |key, value|
|
41
40
|
expect(@helper.preserve_logic(key)).to eq(value)
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
|
-
it
|
44
|
+
it 'preserves comments despite leading/trailing spaces' do
|
46
45
|
expect(@helper.preserve_logic('<% # foo %>')).to eq('{# foo #}')
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
49
|
#-- Variables --
|
51
50
|
|
52
|
-
describe
|
53
|
-
it
|
51
|
+
describe 'variable outputs' do
|
52
|
+
it 'preserves interpolated strings' do
|
54
53
|
expect(@helper.preserve_logic('<%= "color: #{foo};" %>')).to eq('{{ "color: #{foo};" }}')
|
55
54
|
end
|
56
55
|
|
57
|
-
context
|
58
|
-
it
|
56
|
+
context 'hashes' do
|
57
|
+
it 'preserves nested' do
|
59
58
|
expect(@helper.preserve_logic('<%= foo[:bar] %>')).to eq('{{ foo.bar }}')
|
60
59
|
expect(@helper.preserve_logic('<%= foo[:bar][:cat] %>')).to eq('{{ foo.bar.cat }}')
|
61
60
|
end
|
62
61
|
|
63
|
-
it
|
62
|
+
it 'preseves string keys' do
|
64
63
|
expect(@helper.preserve_logic("<%= foo['bar'] %>")).to eq('{{ foo.bar }}')
|
65
64
|
expect(@helper.preserve_logic("<%= foo['bar']['cat'] %>")).to eq('{{ foo.bar.cat }}')
|
66
65
|
expect(@helper.preserve_logic('<%= foo["bar"] %>')).to eq('{{ foo.bar }}')
|
@@ -71,56 +70,55 @@ describe Antwort::LogicHelpers do
|
|
71
70
|
|
72
71
|
#-- Assignments --
|
73
72
|
|
74
|
-
describe
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
expect(@helper.preserve_logic("<% foo = bar %>")).to eq("{% set foo = bar %}")
|
73
|
+
describe 'preserves assignments' do
|
74
|
+
describe 'incl. variables' do
|
75
|
+
it 'well-formatted code' do
|
76
|
+
expect(@helper.preserve_logic('<% foo = bar %>')).to eq('{% set foo = bar %}')
|
79
77
|
end
|
80
78
|
|
81
|
-
it
|
82
|
-
expect(@helper.preserve_logic(
|
83
|
-
expect(@helper.preserve_logic(
|
84
|
-
expect(@helper.preserve_logic(
|
79
|
+
it 'not well-formatted code' do
|
80
|
+
expect(@helper.preserve_logic('<% foo=bar %>')).to eq('{% set foo = bar %}')
|
81
|
+
expect(@helper.preserve_logic('<% foo =bar %>')).to eq('{% set foo = bar %}')
|
82
|
+
expect(@helper.preserve_logic('<% foo=bar %>')).to eq('{% set foo = bar %}')
|
85
83
|
end
|
86
84
|
end
|
87
85
|
|
88
|
-
it
|
86
|
+
it 'incl. strings' do
|
89
87
|
expect(@helper.preserve_logic('<% foo = "bar" %>')).to eq('{% set foo = "bar" %}')
|
90
88
|
expect(@helper.preserve_logic("<% foo = 'bar' %>")).to eq("{% set foo = 'bar' %}")
|
91
89
|
end
|
92
90
|
|
93
|
-
it
|
91
|
+
it 'incl. integers' do
|
94
92
|
expect(@helper.preserve_logic('<% foo = 1 %>')).to eq('{% set foo = 1 %}')
|
95
93
|
expect(@helper.preserve_logic('<% foo=1 %>')).to eq('{% set foo = 1 %}')
|
96
94
|
end
|
97
95
|
|
98
|
-
it
|
96
|
+
it 'incl. arrays' do
|
99
97
|
h = {
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
98
|
+
'<% foo = [1] %>' => '{% set foo = [1] %}',
|
99
|
+
'<% foo = [ 1 ] %>' => '{% set foo = [ 1 ] %}',
|
100
|
+
'<% foo = [1,2] %>' => '{% set foo = [1,2] %}',
|
101
|
+
'<% foo = [1, 2, 3] %>' => '{% set foo = [1, 2, 3] %}'
|
104
102
|
}
|
105
103
|
h.each do |key, value|
|
106
104
|
expect(@helper.preserve_logic(key)).to eq(value)
|
107
105
|
end
|
108
106
|
end
|
109
107
|
|
110
|
-
it
|
108
|
+
it 'incl. objects/hashes' do
|
111
109
|
expect(@helper.preserve_logic('<% foo = { key: val } %>')).to eq('{% set foo = { key: val } %}')
|
112
110
|
end
|
113
111
|
|
114
|
-
it
|
112
|
+
it 'respects memoized assignemnts' do
|
115
113
|
expect(@helper.preserve_logic('<% foo ||= "bar" %>')).to eq('{% set foo = foo || "bar" %}')
|
116
114
|
end
|
117
115
|
end
|
118
116
|
|
119
117
|
#-- Conditionals --
|
120
118
|
|
121
|
-
describe
|
122
|
-
describe
|
123
|
-
it
|
119
|
+
describe 'conditionals' do
|
120
|
+
describe 'if' do
|
121
|
+
it '/ end' do
|
124
122
|
h = {
|
125
123
|
'<% if foo %>do something<% end %>' => '{% if foo %}do something{% end %}',
|
126
124
|
'<%if foo%>do something<%end%>' => '{% if foo %}do something{% end %}',
|
@@ -128,29 +126,29 @@ describe Antwort::LogicHelpers do
|
|
128
126
|
'<% if foo = \'bar\' %>do something<% end %>' => '{% if foo = \'bar\' %}do something{% end %}',
|
129
127
|
'<% if foo = "bar" %>do something<% end %>' => '{% if foo = "bar" %}do something{% end %}',
|
130
128
|
'<% if i < @config.products.length - 1 %>' => '{% if i < @config.products.length - 1 %}',
|
131
|
-
'<% if i<@config.products.length-1 %>'
|
129
|
+
'<% if i<@config.products.length-1 %>' => '{% if i<@config.products.length-1 %}'
|
132
130
|
}
|
133
131
|
h.each do |key, value|
|
134
132
|
expect(@helper.preserve_logic(key)).to eq(value)
|
135
133
|
end
|
136
134
|
end
|
137
135
|
|
138
|
-
it
|
136
|
+
it '/ else / end' do
|
139
137
|
expect(@helper.preserve_logic('<% if foo %>bar<% else %>cat<% end %>')).to eq('{% if foo %}bar{% else %}cat{% end %}')
|
140
138
|
end
|
141
139
|
|
142
|
-
it
|
140
|
+
it '/ elsif / else / end' do
|
143
141
|
expect(@helper.preserve_logic('<% if foo = bar %>bar<% elsif foo = cat %>cat<% else %>dog<% end %>')).to eq('{% if foo = bar %}bar{% elseif foo = cat %}cat{% else %}dog{% end %}')
|
144
142
|
end
|
145
143
|
end
|
146
144
|
|
147
|
-
describe
|
148
|
-
it
|
145
|
+
describe 'unless' do
|
146
|
+
it '/ end' do
|
149
147
|
expect(@helper.preserve_logic('<% unless foo %>')).to eq('{% if !( foo ) %}')
|
150
148
|
expect(@helper.preserve_logic('<% unless foo == bar - 1 %>')).to eq('{% if !( foo == bar - 1 ) %}')
|
151
149
|
end
|
152
150
|
|
153
|
-
it
|
151
|
+
it '/ else / end' do
|
154
152
|
expect(@helper.preserve_logic('<% unless foo == bar %>this<% else %>that<% end %>')).to eq('{% if !( foo == bar ) %}this{% else %}that{% end %}')
|
155
153
|
end
|
156
154
|
end
|
@@ -158,23 +156,23 @@ describe Antwort::LogicHelpers do
|
|
158
156
|
|
159
157
|
#-- Loops --
|
160
158
|
|
161
|
-
describe
|
162
|
-
it
|
159
|
+
describe 'loops' do
|
160
|
+
it 'preserves each loops as for loops' do
|
163
161
|
h = {
|
164
|
-
|
165
|
-
|
166
|
-
|
162
|
+
'<% cats.each do |cat| %>' => '{% for cat in cats %}',
|
163
|
+
'<% cats.each do | cat | %>' => '{% for cat in cats %}',
|
164
|
+
'<% end %>' => '{% end %}'
|
167
165
|
}
|
168
166
|
h.each do |key, value|
|
169
167
|
expect(@helper.preserve_logic(key)).to eq(value)
|
170
168
|
end
|
171
169
|
end
|
172
170
|
|
173
|
-
it
|
171
|
+
it 'preserves each_with_index' do
|
174
172
|
h = {
|
175
|
-
|
176
|
-
|
177
|
-
|
173
|
+
'<% cats.each_with_index do | cat , i | %>' => '{% for cat in cats with: {@index: i} %}',
|
174
|
+
'<% cats.each_with_index do |cat, i| %>' => '{% for cat in cats with: {@index: i} %}',
|
175
|
+
'<% cats.each_with_index do |cat,i| %>' => '{% for cat in cats with: {@index: i} %}'
|
178
176
|
}
|
179
177
|
h.each do |key, value|
|
180
178
|
expect(@helper.preserve_logic(key)).to eq(value)
|
@@ -184,13 +182,13 @@ describe Antwort::LogicHelpers do
|
|
184
182
|
|
185
183
|
#-- Helpers --
|
186
184
|
|
187
|
-
describe
|
188
|
-
it
|
185
|
+
describe 'Helpers use statements syntax, not output' do
|
186
|
+
it 'includes button' do
|
189
187
|
expect(@helper.preserve_logic("<%= button 'foo', '#' %>")).to eq("{% button 'foo', '#' %}")
|
190
188
|
expect(@helper.preserve_logic("<%= button 'foo', '#', color: 'blue' %>")).to eq("{% button 'foo', '#', color: 'blue' %}")
|
191
189
|
end
|
192
190
|
|
193
|
-
it
|
191
|
+
it 'includes image_tag' do
|
194
192
|
expect(@helper.preserve_logic("<%= image_tag 'photo.jpg', width: 100, alt: 'caption' %>")).to eq("{% image_tag 'photo.jpg', width: 100, alt: 'caption' %}")
|
195
193
|
expect(@helper.preserve_logic('<%= image_tag "#{user}-photo.jpg", width: 100, alt: "caption" %>')).to eq('{% image_tag "#{user}-photo.jpg", width: 100, alt: "caption" %}')
|
196
194
|
end
|
@@ -198,47 +196,45 @@ describe Antwort::LogicHelpers do
|
|
198
196
|
|
199
197
|
#-- Partials --
|
200
198
|
|
201
|
-
describe
|
202
|
-
it
|
199
|
+
describe 'partials are converted to friendlier include syntax' do
|
200
|
+
it 'with locals' do
|
203
201
|
expect(@helper.preserve_logic("{{ partial :'foo', locals: bar }}")).to eq("{% include 'foo' with: bar %}")
|
204
202
|
expect(@helper.preserve_logic("{{ partial :'foo', locals:bar }}")).to eq("{% include 'foo' with:bar %}")
|
205
203
|
expect(@helper.preserve_logic("{{ partial :'foo', locals: {cat: cat} }}")).to eq("{% include 'foo' with: {cat: cat} %}")
|
206
|
-
|
207
204
|
end
|
208
205
|
|
209
|
-
it
|
210
|
-
markup =
|
206
|
+
it 'including multiline' do
|
207
|
+
markup = <<-END
|
211
208
|
<%= partial :'user', locals: {
|
212
209
|
name: 'foo',
|
213
210
|
size: bar
|
214
211
|
} %>
|
215
|
-
|
216
|
-
result =
|
212
|
+
END
|
213
|
+
result = <<-END
|
217
214
|
{% include 'user' with: {
|
218
215
|
name: 'foo',
|
219
216
|
size: bar
|
220
217
|
} %}
|
221
|
-
|
218
|
+
END
|
222
219
|
|
223
220
|
expect(@helper.preserve_logic(markup)).to eq(result)
|
224
221
|
end
|
225
222
|
|
226
|
-
it
|
223
|
+
it 'without locals' do
|
227
224
|
expect(@helper.preserve_logic("{{ partial :'foo' }}")).to eq("{% include 'foo' %}")
|
228
|
-
expect(@helper.preserve_logic(
|
225
|
+
expect(@helper.preserve_logic('{{ partial :foo }}')).to eq('{% include foo %}')
|
229
226
|
end
|
230
227
|
end
|
231
228
|
|
232
|
-
describe
|
233
|
-
it
|
229
|
+
describe 'multiple statements on one line' do
|
230
|
+
it 'does not match too early' do
|
234
231
|
h = {
|
235
|
-
|
236
|
-
|
232
|
+
'<% if %>this<% else %>that<%end%>' => '{% if %}this{% else %}that{% end %}',
|
233
|
+
'<% if i==0 %><%= partial :foo %><% else %><%= partial :bar %><% end %>' => '{% if i==0 %}{% include foo %}{% else %}{% include bar %}{% end %}'
|
237
234
|
}
|
238
235
|
h.each do |key, value|
|
239
236
|
expect(@helper.preserve_logic(key)).to eq(value)
|
240
237
|
end
|
241
238
|
end
|
242
239
|
end
|
243
|
-
|
244
240
|
end
|