tag_helper 0.2.0 → 0.3.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 +4 -11
  3. data/lib/tag_helper.rb +37 -16
  4. metadata +47 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b420333feaa707ac8a407a5f42a13465cb5cdf4
4
- data.tar.gz: cd3a1fed83c4bbb9d9a3407583e1f07e089764d4
3
+ metadata.gz: 06dc8efa3ade2413595a185e35a07094c1679e3f
4
+ data.tar.gz: 890a0fa82bd291243f759816fa1ed2e254a963e8
5
5
  SHA512:
6
- metadata.gz: a93025b7b005d96d7be35b3e762f838755cebe473afd9c1992068be2c84256d4054aa717fd3e8e3abcc228a8c42eddd35e9adbc8c5fcd45f73b2b8b6f16e78bc
7
- data.tar.gz: bd4120056cef2251d99271d2cc5a12b866dbf112634cd689709583b78f9a2bbfaf32ec5dda84ba984c592c2f5b190efb32c18a814bdb696f15e0802bde542eb0
6
+ metadata.gz: 0d5e08a8fff8746842eb8a57df70145b18a5cca63ec062e877e3a29fb58cd165ef825df5470542d44d08b883be8400834261182720906a7e2cd87821ccc1f2cb
7
+ data.tar.gz: 63cb587c2b66b13b003ebda95459216763c36c65f76166a32113629855c4bf5fbff35486112508992a6d91ba1c17e63fd7ba6478e2d8634e4cf791d9f65d703e
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  tag_helper
2
2
  ==========
3
3
 
4
- TagHelper is a zero dependency, lightweight Ruby lib for building XHTML tags similar to the API provided by Rails' *TagHelper modules.
4
+ Lightweight Ruby lib for building XHTML tags.
5
5
 
6
6
  ## Installation
7
7
 
@@ -26,17 +26,10 @@ $ gem install tag_helper
26
26
  ## Usage
27
27
 
28
28
  ```ruby
29
- >> require 'tag_helper'
30
- => true
29
+ require 'tag_helper'
31
30
 
32
- >> TagHelper.image_tag('1.png', :alt => 'number one!')
33
- => "<img alt="number one!" src="1.png" />"
34
-
35
- >> include TagHelper
36
- => Object
37
-
38
- >> image_tag('1.png', :alt => 'number one!')
39
- => "<img alt="number one!" src="1.png" />"
31
+ TagHelper.image_tag('1.png', :alt => 'number one!')
32
+ # => "<img alt="number one!" src="1.png" />"
40
33
  ```
41
34
 
42
35
  ## LICENSE
data/lib/tag_helper.rb CHANGED
@@ -1,40 +1,61 @@
1
+ # XHTML tags builder
1
2
  module TagHelper
3
+ module_function
2
4
 
3
- def image_tag(src, html_options = {})
4
- unary_tag(:img, html_options.merge(:src => src))
5
+ def image(src, html_options = {})
6
+ unary(
7
+ :img,
8
+ html_options.merge(src: src))
5
9
  end
6
10
 
7
- def label_tag(label_for, label=nil, html_options = {})
8
- content_tag(:label, label || label_for, html_options.merge(:for => label_for))
11
+ def label(label_for, label = nil, html_options = {})
12
+ content(
13
+ :label,
14
+ label || label_for,
15
+ html_options.merge(for: label_for))
9
16
  end
10
17
 
11
- def text_field_tag(name, value, html_options = {})
12
- unary_tag(:input, html_options.merge(:id => name, :value => value, :type => 'text', :name => name))
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))
13
26
  end
14
27
 
15
- def hidden_field_tag(name, value, html_options = {})
16
- unary_tag(:input, html_options.merge(:id => name, :value => value, :type => 'hidden', :name => name))
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))
17
36
  end
18
37
 
19
- def unary_tag(tag, attrs = {})
38
+ def iframe(html_options = {})
39
+ unary(:iframe, html_options)
40
+ end
41
+
42
+ def unary(tag, attrs = {})
20
43
  "<#{tag_and_attributes(tag, attributes(attrs))} />"
21
44
  end
22
45
 
23
- def content_tag(tag, value, attrs = {})
46
+ def content(tag, value, attrs = {})
24
47
  start_tag = "<#{tag_and_attributes(tag, attributes(attrs))}>"
25
48
  end_tag = "</#{tag}>"
26
49
  [start_tag, value, end_tag].join
27
50
  end
28
51
 
29
52
  def tag_and_attributes(tag, attributes)
30
- attributes.empty?? tag : "#{tag} #{attributes}"
53
+ attributes.empty? ? tag : "#{tag} #{attributes}"
31
54
  end
32
55
 
33
56
  def attributes(hash)
34
- hash.to_a.
35
- reject { |k,v| v.nil? }.
36
- map { |k, v| %{#{k}="#{v}"} }.join(' ')
57
+ hash.to_a
58
+ .reject { |_k, v| v.nil? }
59
+ .map { |k, v| %(#{k}="#{v}") }.join(' ')
37
60
  end
38
-
39
- extend self
40
61
  end
metadata CHANGED
@@ -1,17 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tag_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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-02-14 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Zero dependency, lightweight Ruby lib for building XHTML tags similar
14
- to the API provided by Rails` *TagHelper modules
11
+ date: 2015-12-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 10.4.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 10.4.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.5
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.35.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.35.1
55
+ description: Zero dependency, lightweight API for building XHTML tags
15
56
  email: desimic@gmail.com
16
57
  executables: []
17
58
  extensions: []
@@ -44,3 +85,4 @@ signing_key:
44
85
  specification_version: 4
45
86
  summary: Lightweight Ruby lib for building XHTML tags
46
87
  test_files: []
88
+ has_rdoc: