tag_helper 0.4.0 → 0.5.0
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.
- checksums.yaml +4 -4
- data/README.md +17 -15
- data/lib/tag_helper.rb +20 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b2ddf245d8a964ded991b0b8ffa1b1550bc009c
|
4
|
+
data.tar.gz: 11f3ae737de3edadcce4662756c6f105d70f02f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09a6eb568cd5786b8ce8af6eeac3ee21259e93b4318cc11d4a828c6f8345501a756b486e4dc57dc290512f846aa0c4c334917ab80ecf1aca1172956123efe87e
|
7
|
+
data.tar.gz: bd38809cdb62357d444800e46ff6631d404bb63a675ad0afb00052e7b94c9b828e30dbaa48a281d3c83e817e72c743fb4dd27a074d3653891442f6dff368e5ad
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
TagHelper
|
2
|
+
=========
|
3
3
|
|
4
4
|
Lightweight Ruby lib for building XHTML tags.
|
5
5
|
|
@@ -28,27 +28,29 @@ $ gem install tag_helper
|
|
28
28
|
```ruby
|
29
29
|
require 'tag_helper'
|
30
30
|
|
31
|
-
TagHelper
|
31
|
+
include TagHelper
|
32
|
+
|
33
|
+
tag(:img, src: '1.png', alt: 'number one!')
|
32
34
|
# => '<img src="1.png" alt="number one!" />'
|
33
35
|
|
34
|
-
|
36
|
+
tag(:br)
|
35
37
|
# => '<br />'
|
36
38
|
|
37
|
-
|
39
|
+
tag(:label, for: 'name') { 'Name' }
|
38
40
|
# => '<label for="name">Name</label>'
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
+
tag(:div) do
|
43
|
+
tag(:form) do
|
44
|
+
tag(:input, type: 'text')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
# => '<div><form><input type="text" /></form></div>'
|
42
48
|
```
|
43
49
|
|
44
|
-
##
|
45
|
-
|
46
|
-
Copyright (c) 2015 Dejan Simic
|
47
|
-
|
48
|
-
MIT License
|
50
|
+
## Code Status
|
49
51
|
|
50
|
-
|
52
|
+
[](https://circleci.com/gh/dejan/tag_helper)
|
51
53
|
|
52
|
-
|
54
|
+
## License
|
53
55
|
|
54
|
-
|
56
|
+
TagHelper is released under the [MIT License](https://raw.githubusercontent.com/dejan/tag_helper/master/MIT-LICENCE).
|
data/lib/tag_helper.rb
CHANGED
@@ -2,29 +2,35 @@ require 'cgi'
|
|
2
2
|
|
3
3
|
# XHTML tags builder
|
4
4
|
module TagHelper
|
5
|
-
|
5
|
+
def tag(tag_name, attrs = {})
|
6
|
+
if block_given?
|
7
|
+
content_tag(tag_name, yield, attrs)
|
8
|
+
else
|
9
|
+
unary_tag(tag_name, attrs)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
6
14
|
|
7
|
-
def
|
8
|
-
"<#{tag_and_attributes(
|
15
|
+
def unary_tag(tag_name, attrs = {})
|
16
|
+
"<#{tag_and_attributes(tag_name, tag_attributes(attrs))} />"
|
9
17
|
end
|
10
18
|
|
11
|
-
def
|
12
|
-
start_tag = "<#{tag_and_attributes(
|
13
|
-
end_tag = "</#{
|
14
|
-
[start_tag,
|
19
|
+
def content_tag(tag_name, value, attrs = {})
|
20
|
+
start_tag = "<#{tag_and_attributes(tag_name, tag_attributes(attrs))}>"
|
21
|
+
end_tag = "</#{tag_name}>"
|
22
|
+
[start_tag, value, end_tag].join
|
15
23
|
end
|
16
24
|
|
17
|
-
def tag_and_attributes(
|
18
|
-
attributes.empty? ?
|
25
|
+
def tag_and_attributes(tag_name, attributes)
|
26
|
+
attributes.empty? ? tag_name : "#{tag_name} #{attributes}"
|
19
27
|
end
|
20
28
|
|
21
|
-
def
|
29
|
+
def tag_attributes(hash)
|
22
30
|
hash.to_a
|
23
31
|
.reject { |_k, v| v.nil? }
|
24
|
-
.map { |k, v| %(#{
|
32
|
+
.map { |k, v| %(#{k}="#{v}") }.join(' ')
|
25
33
|
end
|
26
34
|
|
27
|
-
|
28
|
-
CGI.escapeHTML(str.to_s)
|
29
|
-
end
|
35
|
+
extend self
|
30
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tag_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dejan Simic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|