htmless 0.4 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +36 -2
- data/README_FULL.md +51 -49
- data/lib/htmless.rb +7 -1
- metadata +18 -2
data/README.md
CHANGED
|
@@ -1,7 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
# Htmless
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://travis-ci.org/pitr-ch/htmless)
|
|
4
|
+
|
|
5
|
+
**Fast** and **extensible** HTML5 builder in pure **Ruby**
|
|
4
6
|
|
|
5
7
|
- Documentation: <http://blog.pitr.ch/htmless>
|
|
6
8
|
- Source: <https://github.com/pitr-ch/htmless>
|
|
7
9
|
- Blog: <http://blog.pitr.ch/blog/categories/htmless/>
|
|
10
|
+
|
|
11
|
+
## Quick syntax example
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
Htmless::Formatted.new.go_in do
|
|
15
|
+
html5
|
|
16
|
+
html do
|
|
17
|
+
head { title 'my_page' }
|
|
18
|
+
body do
|
|
19
|
+
div.content! do
|
|
20
|
+
p.centered "my page's content"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end.to_html
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
returns
|
|
28
|
+
|
|
29
|
+
```html
|
|
30
|
+
<!DOCTYPE html>
|
|
31
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
32
|
+
<head>
|
|
33
|
+
<title>my_page</title>
|
|
34
|
+
</head>
|
|
35
|
+
<body>
|
|
36
|
+
<div id="content">
|
|
37
|
+
<p class="centered">my page's content</p>
|
|
38
|
+
</div>
|
|
39
|
+
</body>
|
|
40
|
+
</html>
|
|
41
|
+
```
|
data/README_FULL.md
CHANGED
|
@@ -1,11 +1,43 @@
|
|
|
1
1
|
# Htmless
|
|
2
2
|
|
|
3
|
-
Fast extensible
|
|
3
|
+
**Fast** and **extensible** HTML5 builder in pure **Ruby**
|
|
4
4
|
|
|
5
5
|
- Documentation: <http://blog.pitr.ch/htmless>
|
|
6
6
|
- Source: <https://github.com/pitr-ch/htmless>
|
|
7
7
|
- Blog: <http://blog.pitr.ch/blog/categories/htmless/>
|
|
8
8
|
|
|
9
|
+
## Quick syntax example
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
Htmless::Formatted.new.go_in do
|
|
13
|
+
html5
|
|
14
|
+
html do
|
|
15
|
+
head { title 'my_page' }
|
|
16
|
+
body do
|
|
17
|
+
div.content! do
|
|
18
|
+
p.centered "my page's content"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end.to_html
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
returns
|
|
26
|
+
|
|
27
|
+
```html5
|
|
28
|
+
<!DOCTYPE html>
|
|
29
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
30
|
+
<head>
|
|
31
|
+
<title>my_page</title>
|
|
32
|
+
</head>
|
|
33
|
+
<body>
|
|
34
|
+
<div id="content">
|
|
35
|
+
<p class="centered">my page's content</p>
|
|
36
|
+
</div>
|
|
37
|
+
</body>
|
|
38
|
+
</html>
|
|
39
|
+
```
|
|
40
|
+
|
|
9
41
|
## Why?
|
|
10
42
|
|
|
11
43
|
I needed html builder with these characteristics:
|
|
@@ -20,38 +52,8 @@ Disadvanteges of other options:
|
|
|
20
52
|
* Markaby - slow
|
|
21
53
|
* Wee::Brush - extensible but not a standalone gem
|
|
22
54
|
* Tagz - very slow
|
|
23
|
-
* Erubis - fast but
|
|
24
|
-
* Tenjin - faster but
|
|
25
|
-
|
|
26
|
-
## Quick syntax example
|
|
27
|
-
|
|
28
|
-
!!!ruby
|
|
29
|
-
Htmless::Formatted.new.go_in do
|
|
30
|
-
html5
|
|
31
|
-
html do
|
|
32
|
-
head { title 'my_page' }
|
|
33
|
-
body do
|
|
34
|
-
div.content! do
|
|
35
|
-
p.centered "my page's content"
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end.to_html
|
|
40
|
-
|
|
41
|
-
returns
|
|
42
|
-
|
|
43
|
-
!!!html
|
|
44
|
-
<!DOCTYPE html>
|
|
45
|
-
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
46
|
-
<head>
|
|
47
|
-
<title>my_page</title>
|
|
48
|
-
</head>
|
|
49
|
-
<body>
|
|
50
|
-
<div id="content">
|
|
51
|
-
<p class="centered">my page's content</p>
|
|
52
|
-
</div>
|
|
53
|
-
</body>
|
|
54
|
-
</html>
|
|
55
|
+
* Erubis - fast but template engine and no tag extensibility
|
|
56
|
+
* Tenjin - faster but template engine and no tag extensibility
|
|
55
57
|
|
|
56
58
|
## Chaining
|
|
57
59
|
|
|
@@ -88,7 +90,7 @@ until tag is closed.
|
|
|
88
90
|
div(:class => 'left').class('center') # <div class='left center'></div>
|
|
89
91
|
div(:id => 1).id(2) # <div id="1" id="2"></div>
|
|
90
92
|
|
|
91
|
-
|
|
93
|
+
Undefined attribute can be rendered with.
|
|
92
94
|
|
|
93
95
|
!!!ruby
|
|
94
96
|
html.attribute :xmlns, 'http://www.w3.org/1999/xhtml'
|
|
@@ -198,7 +200,7 @@ Ids generated by Arrays are joined with '-'
|
|
|
198
200
|
div.id('an', 'id') # => <div id="an-id"></div>
|
|
199
201
|
|
|
200
202
|
|
|
201
|
-
## Tag's
|
|
203
|
+
## Tag's representation
|
|
202
204
|
|
|
203
205
|
Each tag has its own class.
|
|
204
206
|
|
|
@@ -440,13 +442,13 @@ How to define `AMutant::RihtEye` to return `"next to laser left eye"` ?
|
|
|
440
442
|
end
|
|
441
443
|
end
|
|
442
444
|
|
|
443
|
-
Each class is a
|
|
445
|
+
Each class is a different object.
|
|
444
446
|
|
|
445
447
|
!!!ruby
|
|
446
448
|
Parent.dynamic_classes[:LeftEye] # => #<Class:0x00000001d449b8(A.dc[:LeftEye])>
|
|
447
449
|
AChild.dynamic_classes[:LeftEye] # => #<Class:0x00000001d42398(A.dc[:LeftEye])>
|
|
448
450
|
|
|
449
|
-
`AMutant.dc[:RightEye]`
|
|
451
|
+
`AMutant.dc[:RightEye]` automatically inherits from extended `AMutant.dc[:LeftEye]`
|
|
450
452
|
|
|
451
453
|
!!!ruby
|
|
452
454
|
Parent.dc[:LeftEye].new.to_s # => 'left eye'
|
|
@@ -514,7 +516,7 @@ returns
|
|
|
514
516
|
|
|
515
517
|
### Synthetic
|
|
516
518
|
|
|
517
|
-
|
|
519
|
+
Benchmark can be found on Github. It renders simple page with two collections. 'reuse' means
|
|
518
520
|
that template is precompiled and reused during benchmark.
|
|
519
521
|
|
|
520
522
|
user system total real
|
|
@@ -532,8 +534,8 @@ that template is precompiled and reused during benchmark.
|
|
|
532
534
|
|
|
533
535
|
### Rails 3
|
|
534
536
|
|
|
535
|
-
|
|
536
|
-
Single page with or without a partial which is rendered 200 times. Partials make no
|
|
537
|
+
Benchmark can be found on Github.
|
|
538
|
+
Single page with or without a partial which is rendered 200 times. Partials make no difference for Htmless.
|
|
537
539
|
|
|
538
540
|
BenchTest#test_erubis_partials (3.34 sec warmup)
|
|
539
541
|
wall_time: 3.56 sec
|
|
@@ -558,14 +560,14 @@ Single page with or without a partial which is rendered 200 times. Partials make
|
|
|
558
560
|
|
|
559
561
|
## Why is it fast?
|
|
560
562
|
|
|
561
|
-
*
|
|
562
|
-
* 10-15%
|
|
563
|
-
*
|
|
563
|
+
* Optimization of garbage collecting.
|
|
564
|
+
* 10-15% improvement.
|
|
565
|
+
* Pre-initialization (tag's instances, even strings).
|
|
564
566
|
* No string's `#+`, `#{}`. Just `#<<` to buffer.
|
|
565
567
|
* Precomputed spaces for indentation.
|
|
566
|
-
* Doing as less as
|
|
567
|
-
* Magic by
|
|
568
|
-
* Number of micro
|
|
568
|
+
* Doing as less as possible when rendering.
|
|
569
|
+
* Magic by meta-programing not by `method_missing`. Magic is run on initialization not when rendering.
|
|
570
|
+
* Number of micro optimization.
|
|
569
571
|
* Data in constants or instance variables.
|
|
570
572
|
* Buffer.
|
|
571
573
|
* No `#define_method`.
|
|
@@ -580,6 +582,6 @@ Single page with or without a partial which is rendered 200 times. Partials make
|
|
|
580
582
|
|
|
581
583
|
## Why use it?
|
|
582
584
|
|
|
583
|
-
* Its fast
|
|
584
|
-
* You can use inheritance (
|
|
585
|
-
* You can
|
|
585
|
+
* Its as fast as template-engines (erb) and much faster then other Ruby HTML builders.
|
|
586
|
+
* You can use inheritance (impossible with templates) and other goodness of Ruby.
|
|
587
|
+
* You can write html in pure Ruby.
|
data/lib/htmless.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: htmless
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -44,7 +44,23 @@ dependencies:
|
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
45
|
version: '0'
|
|
46
46
|
- !ruby/object:Gem::Dependency
|
|
47
|
-
name:
|
|
47
|
+
name: redcarpet
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: github-markup
|
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
|
49
65
|
none: false
|
|
50
66
|
requirements:
|