tag_helper 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -2
  3. data/lib/tag_helper.rb +8 -39
  4. metadata +14 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06dc8efa3ade2413595a185e35a07094c1679e3f
4
- data.tar.gz: 890a0fa82bd291243f759816fa1ed2e254a963e8
3
+ metadata.gz: 2eabb8b249d6c44b44f92b70f466833eeb165565
4
+ data.tar.gz: a1bbaa8fbbc8e7c074c9cbc9c665f34a642a8f63
5
5
  SHA512:
6
- metadata.gz: 0d5e08a8fff8746842eb8a57df70145b18a5cca63ec062e877e3a29fb58cd165ef825df5470542d44d08b883be8400834261182720906a7e2cd87821ccc1f2cb
7
- data.tar.gz: 63cb587c2b66b13b003ebda95459216763c36c65f76166a32113629855c4bf5fbff35486112508992a6d91ba1c17e63fd7ba6478e2d8634e4cf791d9f65d703e
6
+ metadata.gz: 48c4004d2647dde1d73a0d67b18c7ae8daef6d000783a3dfd49f32aefc72691a4eb556e3a890cc6afbf99acc2cc62313412b160b18ed9f906bb5518e405e92b1
7
+ data.tar.gz: 70c3db7ce70aa6cc34775eb823e429f930d166c31319e86ac149c4ff7df529b52d2f4c9c5398791d366b677b47a656a9c8828450e3ea7ad9d961281e5d1ab07c
data/README.md CHANGED
@@ -28,8 +28,17 @@ $ gem install tag_helper
28
28
  ```ruby
29
29
  require 'tag_helper'
30
30
 
31
- TagHelper.image_tag('1.png', :alt => 'number one!')
32
- # => "<img alt="number one!" src="1.png" />"
31
+ TagHelper.unary(:img, src: '1.png', alt: 'number one!'))
32
+ # => '<img src="1.png" alt="number one!" />'
33
+
34
+ TagHelper.unary(:br)
35
+ # => '<br />'
36
+
37
+ TagHelper.content(:label, 'Name', for: 'name'))
38
+ # => '<label for="name">Name</label>'
39
+
40
+ TagHelper.content(:p, '<script>alert(0)</script>')
41
+ # => '<p>&lt;script&gt;alert(0)&lt;/script&gt;</p>'
33
42
  ```
34
43
 
35
44
  ## LICENSE
data/lib/tag_helper.rb CHANGED
@@ -1,44 +1,9 @@
1
+ require 'cgi'
2
+
1
3
  # XHTML tags builder
2
4
  module TagHelper
3
5
  module_function
4
6
 
5
- def image(src, html_options = {})
6
- unary(
7
- :img,
8
- html_options.merge(src: src))
9
- end
10
-
11
- def label(label_for, label = nil, html_options = {})
12
- content(
13
- :label,
14
- label || label_for,
15
- html_options.merge(for: label_for))
16
- end
17
-
18
- def text_field(name, value, html_options = {})
19
- unary(
20
- :input,
21
- html_options.merge(
22
- id: name,
23
- value: value,
24
- type: 'text',
25
- name: name))
26
- end
27
-
28
- def hidden_field(name, value, html_options = {})
29
- unary(
30
- :input,
31
- html_options.merge(
32
- id: name,
33
- value: value,
34
- type: 'hidden',
35
- name: name))
36
- end
37
-
38
- def iframe(html_options = {})
39
- unary(:iframe, html_options)
40
- end
41
-
42
7
  def unary(tag, attrs = {})
43
8
  "<#{tag_and_attributes(tag, attributes(attrs))} />"
44
9
  end
@@ -46,7 +11,7 @@ module TagHelper
46
11
  def content(tag, value, attrs = {})
47
12
  start_tag = "<#{tag_and_attributes(tag, attributes(attrs))}>"
48
13
  end_tag = "</#{tag}>"
49
- [start_tag, value, end_tag].join
14
+ [start_tag, escape_html(value), end_tag].join
50
15
  end
51
16
 
52
17
  def tag_and_attributes(tag, attributes)
@@ -56,6 +21,10 @@ module TagHelper
56
21
  def attributes(hash)
57
22
  hash.to_a
58
23
  .reject { |_k, v| v.nil? }
59
- .map { |k, v| %(#{k}="#{v}") }.join(' ')
24
+ .map { |k, v| %(#{escape_html(k)}="#{escape_html(v)}") }.join(' ')
25
+ end
26
+
27
+ def escape_html(str)
28
+ CGI.escapeHTML(str.to_s)
60
29
  end
61
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tag_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dejan Simic
@@ -15,6 +15,9 @@ dependencies:
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.4'
20
+ - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: 10.4.2
20
23
  type: :development
@@ -22,6 +25,9 @@ dependencies:
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '10.4'
30
+ - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 10.4.2
27
33
  - !ruby/object:Gem::Dependency
@@ -29,6 +35,9 @@ dependencies:
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.1'
40
+ - - ">="
32
41
  - !ruby/object:Gem::Version
33
42
  version: 3.1.5
34
43
  type: :development
@@ -36,6 +45,9 @@ dependencies:
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
47
  - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.1'
50
+ - - ">="
39
51
  - !ruby/object:Gem::Version
40
52
  version: 3.1.5
41
53
  - !ruby/object:Gem::Dependency
@@ -83,6 +95,6 @@ rubyforge_project:
83
95
  rubygems_version: 2.4.5
84
96
  signing_key:
85
97
  specification_version: 4
86
- summary: Lightweight Ruby lib for building XHTML tags
98
+ summary: Build XHTML tags with minimal API
87
99
  test_files: []
88
100
  has_rdoc: