hamlet 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/hamlet.gemspec +1 -1
- data/lib/hamlet/parser.rb +23 -10
- data/test/slim/test_code_structure.rb +4 -5
- data/test/slim/test_text_interpolation.rb +1 -1
- metadata +23 -23
data/hamlet.gemspec
CHANGED
data/lib/hamlet/parser.rb
CHANGED
@@ -95,11 +95,6 @@ module Hamlet
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def parse_line_indicators
|
98
|
-
if @needs_space and not @line[0] == '>'
|
99
|
-
@stacks.last << [:slim, :interpolate, "\n" ]
|
100
|
-
@stacks.last << [:newline]
|
101
|
-
end
|
102
|
-
@needs_space = false
|
103
98
|
case @line[0]
|
104
99
|
when '-' # code block.
|
105
100
|
block = [:multi]
|
@@ -107,6 +102,7 @@ module Hamlet
|
|
107
102
|
@stacks.last << [:slim, :control, parse_broken_line, block]
|
108
103
|
@stacks << block
|
109
104
|
when '=' # output block.
|
105
|
+
@needs_space = true
|
110
106
|
@line =~ /\A=(=?)('?)/
|
111
107
|
@line = $'
|
112
108
|
block = [:multi]
|
@@ -114,16 +110,24 @@ module Hamlet
|
|
114
110
|
@stacks.last << [:static, ' '] unless $2.empty?
|
115
111
|
@stacks << block
|
116
112
|
when '<'
|
113
|
+
if @needs_space && !(@line[0] == '>')
|
114
|
+
@stacks.last << [:slim, :interpolate, "\n" ]
|
115
|
+
@stacks.last << [:newline]
|
116
|
+
end
|
117
|
+
@needs_space = false
|
117
118
|
case @line
|
118
119
|
when /\A<(\w+):\s*\Z/ # Embedded template. It is treated as block.
|
120
|
+
@needs_space = false
|
119
121
|
block = [:multi]
|
120
122
|
@stacks.last << [:newline] << [:slim, :embedded, $1, block]
|
121
123
|
@stacks << block
|
122
124
|
parse_text_block(nil, :from_embedded)
|
123
125
|
return # Don't append newline, this has already been done before
|
124
126
|
when /\A<([#\.]|\w[:\w-]*)/ # HTML tag.
|
127
|
+
@needs_space = false
|
125
128
|
parse_tag($1)
|
126
129
|
when /\A<!--( ?)(.*)\Z/ # HTML comment
|
130
|
+
@needs_space = false
|
127
131
|
block = [:multi]
|
128
132
|
@stacks.last << [:html, :comment, block]
|
129
133
|
@stacks << block
|
@@ -131,11 +135,21 @@ module Hamlet
|
|
131
135
|
parse_text_block($2.empty? ? nil : @indents.last + $1.size + 2)
|
132
136
|
end
|
133
137
|
else
|
134
|
-
if @line
|
135
|
-
|
136
|
-
@
|
137
|
-
|
138
|
+
if @line[0] == '#' and @line[1] != '{'
|
139
|
+
@needs_space = false
|
140
|
+
if @line =~ %r!\A#\[\s*(.*?)\s*\]\s*\Z! # HTML conditional comment
|
141
|
+
block = [:multi]
|
142
|
+
@stacks.last << [:slim, :condcomment, $1, block]
|
143
|
+
@stacks << block
|
144
|
+
else
|
145
|
+
# otherwise the entire line is commented - ignore
|
146
|
+
end
|
138
147
|
else
|
148
|
+
if @needs_space and not @line[0] == '>'
|
149
|
+
@stacks.last << [:slim, :interpolate, "\n" ]
|
150
|
+
@stacks.last << [:newline]
|
151
|
+
end
|
152
|
+
@needs_space = true
|
139
153
|
push_text
|
140
154
|
end
|
141
155
|
end
|
@@ -143,7 +157,6 @@ module Hamlet
|
|
143
157
|
end
|
144
158
|
|
145
159
|
def push_text
|
146
|
-
@needs_space = true
|
147
160
|
if @line[0] == '>'
|
148
161
|
@line.slice!(0)
|
149
162
|
end
|
@@ -22,7 +22,7 @@ class TestSlimCodeStructure < TestSlim
|
|
22
22
|
<p>The second paragraph
|
23
23
|
}
|
24
24
|
|
25
|
-
assert_html
|
25
|
+
assert_html "<div><p>The first paragraph</p>\n<p>The second paragraph</p></div>", source
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_render_with_parameterized_conditional
|
@@ -33,7 +33,6 @@ class TestSlimCodeStructure < TestSlim
|
|
33
33
|
- else
|
34
34
|
<p>The second paragraph
|
35
35
|
}
|
36
|
-
|
37
36
|
assert_html '<div><p>The second paragraph</p></div>', source
|
38
37
|
end
|
39
38
|
|
@@ -46,7 +45,7 @@ class TestSlimCodeStructure < TestSlim
|
|
46
45
|
= var
|
47
46
|
}
|
48
47
|
|
49
|
-
assert_html
|
48
|
+
assert_html "<div><p>The first paragraph</p>\n42</div>", source
|
50
49
|
end
|
51
50
|
|
52
51
|
def test_render_with_inline_condition
|
@@ -65,7 +64,7 @@ class TestSlimCodeStructure < TestSlim
|
|
65
64
|
1
|
66
65
|
- when 42
|
67
66
|
42
|
68
|
-
|
67
|
+
> is the answer
|
69
68
|
}
|
70
69
|
|
71
70
|
assert_html '<p>42 is the answer</p>', source
|
@@ -79,7 +78,7 @@ class TestSlimCodeStructure < TestSlim
|
|
79
78
|
<p>World
|
80
79
|
}
|
81
80
|
|
82
|
-
assert_html
|
81
|
+
assert_html "<p>Hello</p>\n<p>World</p>", source
|
83
82
|
end
|
84
83
|
|
85
84
|
def test_render_with_yield
|
@@ -26,7 +26,7 @@ class TestSlimTextInterpolation < TestSlim
|
|
26
26
|
>A message from the compiler: #{hello_world}
|
27
27
|
}
|
28
28
|
|
29
|
-
assert_html
|
29
|
+
assert_html "<p>Hello World from @env with \"quotes\"</p>\n<p>A message from the compiler: Hello World from @env</p>", source
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_interpolation_in_tag
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamlet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-10-31 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: slim
|
16
|
-
requirement: &
|
16
|
+
requirement: &3510300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *3510300
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &3485740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.8.7
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *3485740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sass
|
38
|
-
requirement: &
|
38
|
+
requirement: &3484820 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 3.1.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *3484820
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: minitest
|
49
|
-
requirement: &
|
49
|
+
requirement: &3483240 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *3483240
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: kramdown
|
60
|
-
requirement: &
|
60
|
+
requirement: &3481080 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *3481080
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yard
|
71
|
-
requirement: &
|
71
|
+
requirement: &3480000 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *3480000
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: creole
|
82
|
-
requirement: &
|
82
|
+
requirement: &3441840 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *3441840
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: builder
|
93
|
-
requirement: &
|
93
|
+
requirement: &3440200 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *3440200
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: pry
|
104
|
-
requirement: &
|
104
|
+
requirement: &3439100 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *3439100
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: ruby-debug19
|
115
|
-
requirement: &
|
115
|
+
requirement: &3437320 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *3437320
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: rcov
|
126
|
-
requirement: &
|
126
|
+
requirement: &3434540 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,7 +131,7 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *3434540
|
135
135
|
description: Hamlet is a template language whose goal is reduce HTML syntax to the
|
136
136
|
essential parts.
|
137
137
|
email:
|