himl 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/README.md +76 -3
- data/lib/himl/handler.rb +1 -3
- data/lib/himl/parser.rb +12 -4
- data/lib/himl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed14ef24b0bebebbd88c3c5dd187b8a373f2aebd52b9441c83e3f86d4437ebbd
|
4
|
+
data.tar.gz: 323c1b623fb6c48909a6b553ad2885a83c5c6da514760251f554fd6f08507e08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d2151d637bf63d6c23e0f89390c660a92f63263368afbc454dc7414116054f9c82d530c1fcd25ec26ad9c72fc8b5fa233423ccb14d24620949a5f71af860d1d
|
7
|
+
data.tar.gz: 6cbc3d7b27695c328037df788cf02ef3434ae147b66f97e6748684698928c8c2c2ac3cae254bcc10298556adafe692e7aa04be2dd799fdfd9051309cd97b6227
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@ Himl is an HTML-based Indented Markup Language for Ruby.
|
|
5
5
|
|
6
6
|
## What's This?
|
7
7
|
|
8
|
-
Himl is a yet another template engine for Haml-lovers and non Haml
|
8
|
+
Himl is a yet another template engine for Haml-lovers and non Haml-lovers, deriving HTML validity from Haml and syntax intuitiveness from ERB.
|
9
9
|
|
10
10
|
|
11
11
|
## Motivation
|
@@ -24,7 +24,7 @@ HTML has tags. HTML has indentations. Why can't we just use them?
|
|
24
24
|
## Syntax
|
25
25
|
|
26
26
|
Himl syntax is a hybrid of ERB and Haml.
|
27
|
-
Himl is
|
27
|
+
Himl is basically just a kind of ERB. Indeed, Himl documents are compiled to ERB internally, then rendered by the ERB handler.
|
28
28
|
|
29
29
|
So, the following Himl template opening and closing a tag will be compiled to exactly the same ERB template.
|
30
30
|
|
@@ -86,6 +86,49 @@ ERB
|
|
86
86
|
</section>
|
87
87
|
```
|
88
88
|
|
89
|
+
Ruby blocks in the ERB tag can also automatically be closed.
|
90
|
+
|
91
|
+
Himl
|
92
|
+
```erb
|
93
|
+
<ul>
|
94
|
+
<%= @users.each do |user| %>
|
95
|
+
<li>
|
96
|
+
<%= user.name %>
|
97
|
+
```
|
98
|
+
|
99
|
+
ERB
|
100
|
+
```erb
|
101
|
+
<ul>
|
102
|
+
<%= @users.each do |user| %>
|
103
|
+
<li>
|
104
|
+
<%= user.name %>
|
105
|
+
</li>
|
106
|
+
<% end %>
|
107
|
+
</ul>
|
108
|
+
```
|
109
|
+
|
110
|
+
Or manually be closed.
|
111
|
+
|
112
|
+
Himl
|
113
|
+
```erb
|
114
|
+
<ul>
|
115
|
+
<%= @users.each do |user| %>
|
116
|
+
<li>
|
117
|
+
<%= user.name %>
|
118
|
+
<% end %>
|
119
|
+
```
|
120
|
+
|
121
|
+
ERB
|
122
|
+
```erb
|
123
|
+
<ul>
|
124
|
+
<%= @users.each do |user| %>
|
125
|
+
<li>
|
126
|
+
<%= user.name %>
|
127
|
+
</li>
|
128
|
+
<% end %>
|
129
|
+
</ul>
|
130
|
+
```
|
131
|
+
|
89
132
|
You can open and close tags in the same line.
|
90
133
|
|
91
134
|
Himl
|
@@ -117,10 +160,40 @@ ERB
|
|
117
160
|
</section>
|
118
161
|
```
|
119
162
|
|
163
|
+
More detailed syntax may be covered in [the tests](https://github.com/amatsuda/himl/blob/master/test/himl_test.rb).
|
164
|
+
|
165
|
+
|
166
|
+
## Document Validations
|
167
|
+
|
168
|
+
Himl's strongest advantage is not that you just can reduce the template LOC, but the engine validates the structure of the document and detects some syntax errors.
|
169
|
+
For example, Himl raises `SyntaxError` while parsing these templates.
|
170
|
+
|
171
|
+
Mismatched closing tag
|
172
|
+
```erb
|
173
|
+
<div>
|
174
|
+
hello?
|
175
|
+
</div>
|
176
|
+
```
|
177
|
+
|
178
|
+
Mismatched ERB `end` expression
|
179
|
+
```erb
|
180
|
+
<% if @current_user.admin? %>
|
181
|
+
TOP SECRET
|
182
|
+
<% end %>
|
183
|
+
```
|
184
|
+
|
185
|
+
Extra ERB `end` expression
|
186
|
+
```erb
|
187
|
+
<% @books.each do |book| %>
|
188
|
+
<% book.read %>
|
189
|
+
<% end %>
|
190
|
+
<% end %>
|
191
|
+
```
|
192
|
+
|
120
193
|
|
121
194
|
## Example
|
122
195
|
|
123
|
-
Following is a comparison of ERB, Haml, and Himl templates that
|
196
|
+
Following is a comparison of ERB, Haml, and Himl templates that renders similar HTML results (the Haml example is taken from the [Haml documentation](http://haml.info/)).
|
124
197
|
You'll notice that Himl consumes the same LOC with the Haml version for expressing the structure of this document, without introducing any new syntax from the ERB version.
|
125
198
|
|
126
199
|
### ERB Template
|
data/lib/himl/handler.rb
CHANGED
@@ -9,9 +9,7 @@ module Himl
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def call(template, source)
|
12
|
-
|
13
|
-
parser.call(source)
|
14
|
-
erb = parser.to_erb
|
12
|
+
erb = Himl::Parser.new(source).call(source).to_erb
|
15
13
|
|
16
14
|
escape = ERB_HANDLER.respond_to?(:escape_ignore_list) ? ERB_HANDLER.escape_ignore_list.include?(template.type) : ERB_HANDLER.escape_whitelist.include?(template.type)
|
17
15
|
|
data/lib/himl/parser.rb
CHANGED
@@ -82,10 +82,15 @@ module Himl
|
|
82
82
|
return if last_tag.name == ROOT_NODE
|
83
83
|
|
84
84
|
if (name == ERB_TAG) && last_tag.is_a?(ErbEndMarker)
|
85
|
-
raise SyntaxError "end of block indentation mismatch at line: #{current_line}, column: #{current_indentation}" if last_tag.indentation != @tags[-2].indentation
|
85
|
+
raise SyntaxError, "end of block indentation mismatch at line: #{current_line}, column: #{current_indentation}" if last_tag.indentation != @tags[-2].indentation
|
86
86
|
|
87
87
|
@tags.pop
|
88
|
-
|
88
|
+
|
89
|
+
if (ErbBlockStartMarker === @tags.last) && (@tags.last.indentation == last_tag.indentation)
|
90
|
+
@tags.pop
|
91
|
+
else
|
92
|
+
raise SyntaxError, "end of block mismatch at line: #{current_line}, column: #{current_indentation}" unless (ErbBlockStartMarker === @tags.last) && (@tags.last.indentation == last_tag.indentation)
|
93
|
+
end
|
89
94
|
end
|
90
95
|
|
91
96
|
if name == last_tag.name
|
@@ -127,8 +132,9 @@ module Himl
|
|
127
132
|
private
|
128
133
|
|
129
134
|
def current_indentation
|
130
|
-
line =
|
131
|
-
line.slice(0, context.column).rindex('<')
|
135
|
+
line = current_line
|
136
|
+
line -=1 until (ret = @lines[line].slice(0, context.column).rindex('<'))
|
137
|
+
ret
|
132
138
|
end
|
133
139
|
|
134
140
|
def current_line
|
@@ -169,6 +175,8 @@ module Himl
|
|
169
175
|
end
|
170
176
|
|
171
177
|
@document.close_document!
|
178
|
+
|
179
|
+
self
|
172
180
|
end
|
173
181
|
end
|
174
182
|
end
|
data/lib/himl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: himl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|