tag_helper 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f7f6872d2d8442b16fd8d82f23fb88a70157c85b
4
+ data.tar.gz: 236c708c31e978e4b924b2dd29e08cb8d2cdda25
5
+ SHA512:
6
+ metadata.gz: 15fe6fe63357d881f1f5fa2fcc93b5c9c469d858f682c4db0a57d631fba7616b06eb3690750e9b92779b72aec9c9a9743dc9fca3cf0747e0e4eb735d4dea8a28
7
+ data.tar.gz: 3ce20e2c35af6c6b81b139583347a50737d9c615b741532bea390d617dfd6c0a3075d507f64760a65480d485eae5ee926c9e59adfcec8649584391b3e694ad90
data/README.md CHANGED
@@ -3,26 +3,52 @@ tag_helper
3
3
 
4
4
  TagHelper is a zero dependency, lightweight Ruby lib for building XHTML tags similar to the API provided by Rails' *TagHelper modules.
5
5
 
6
- ## Install
6
+ ## Installation
7
7
 
8
- gem install tag_helper
8
+ Add this line to your application's Gemfile:
9
9
 
10
+ ```ruby
11
+ gem 'tag_helper'
12
+ ```
10
13
 
11
- ## Example usage
14
+ And then execute:
12
15
 
13
- >> require 'tag_helper'
14
- => true
16
+ ```sh
17
+ $ bundle
18
+ ```
15
19
 
16
- >> TagHelper.image_tag('1.png', :alt => 'number one!')
17
- => "<img alt="number one!" src="1.png" />"
20
+ Or install it yourself as:
18
21
 
19
- >> include TagHelper
20
- => Object
22
+ ```sh
23
+ $ gem install tag_helper
24
+ ```
21
25
 
22
- >> image_tag('1.png', :alt => 'number one!')
23
- => "<img alt="number one!" src="1.png" />"
26
+ ## Usage
24
27
 
28
+ ```ruby
29
+ >> require 'tag_helper'
30
+ => true
25
31
 
26
- ## Credits
32
+ >> TagHelper.image_tag('1.png', :alt => 'number one!')
33
+ => "<img alt="number one!" src="1.png" />"
27
34
 
28
- Author: [Dejan Simic](http://github.com/dejan)
35
+ >> include TagHelper
36
+ => Object
37
+
38
+ >> image_tag('1.png', :alt => 'number one!')
39
+ => "<img alt="number one!" src="1.png" />"
40
+ ```
41
+
42
+ ## LICENCE
43
+
44
+ Licence
45
+
46
+ Copyright (c) 2015 Dejan Simic
47
+
48
+ MIT License
49
+
50
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/tag_helper.rb CHANGED
@@ -19,18 +19,24 @@ module TagHelper
19
19
  end
20
20
 
21
21
  def unary_tag(tag, attrs = {})
22
- "<#{tag} #{attributes(attrs)} />"
22
+ "<#{tag_and_attributes(tag, attributes(attrs))} />"
23
23
  end
24
24
 
25
25
  def content_tag(tag, value, attrs = {})
26
- b = "<#{tag} #{attributes(attrs)}>"
26
+ b = "<#{tag_and_attributes(tag, attributes(attrs))}>"
27
27
  v = normalize(value)
28
28
  e = "</#{tag}>"
29
29
  [b, v, e].join
30
30
  end
31
31
 
32
+ def tag_and_attributes(tag, attributes)
33
+ attributes.empty?? tag : "#{tag} #{attributes}"
34
+ end
35
+
32
36
  def attributes(hash)
33
- hash.to_a.reject { |k,v| v.nil? }.map { |k, v| %{#{k}="#{normalize v}"} }.join(' ')
37
+ hash.to_a.
38
+ reject { |k,v| v.nil? }.
39
+ map { |k, v| %{#{k}="#{normalize v}"} }.join(' ')
34
40
  end
35
41
 
36
42
  def normalize(s)
metadata CHANGED
@@ -1,71 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: tag_helper
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Dejan Simic
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-07-05 00:00:00 +02:00
19
- default_executable:
11
+ date: 2015-02-14 00:00:00.000000000 Z
20
12
  dependencies: []
21
-
22
- description: TagHelper is a zero dependency, lightweight Ruby lib for building XHTML tags similar to the API provided by Rails' *TagHelper modules.
13
+ description: Zero dependency, lightweight Ruby lib for building XHTML tags similar
14
+ to the API provided by Rails` *TagHelper modules
23
15
  email: desimic@gmail.com
24
16
  executables: []
25
-
26
17
  extensions: []
27
-
28
18
  extra_rdoc_files: []
29
-
30
- files:
31
- - Rakefile
32
- - lib/tag_helper.rb
33
- - test/test_helper.rb
34
- - test/unit/tag_helper_test.rb
19
+ files:
35
20
  - README.md
36
- has_rdoc: true
37
- homepage: http://github.com/dejan/tag_helper
38
- licenses: []
39
-
21
+ - lib/tag_helper.rb
22
+ homepage: https://github.com/dejan/tag_helper
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
40
26
  post_install_message:
41
27
  rdoc_options: []
42
-
43
- require_paths:
28
+ require_paths:
44
29
  - lib
45
- required_ruby_version: !ruby/object:Gem::Requirement
46
- none: false
47
- requirements:
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
48
32
  - - ">="
49
- - !ruby/object:Gem::Version
50
- hash: 3
51
- segments:
52
- - 0
53
- version: "0"
54
- required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
57
37
  - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
63
40
  requirements: []
64
-
65
41
  rubyforge_project:
66
- rubygems_version: 1.3.7
42
+ rubygems_version: 2.4.5
67
43
  signing_key:
68
- specification_version: 3
69
- summary: Build XHTML tags off the Rails
44
+ specification_version: 4
45
+ summary: Lightweight Ruby lib for building XHTML tags
70
46
  test_files: []
71
-
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- require 'rake/testtask'
2
-
3
- desc 'Default: run tests'
4
- task :default => :test
5
-
6
- desc 'Test TagHelper'
7
- Rake::TestTask.new(:test) do |t|
8
- t.pattern = 'test/**/*_test.rb'
9
- end
data/test/test_helper.rb DELETED
@@ -1,5 +0,0 @@
1
- raise "Tests require Ruby 1.9 for ordered hash feature" if RUBY_VERSION.to_f < 1.9
2
- require 'rubygems'
3
- require 'test/unit'
4
-
5
- require File.dirname(__FILE__) + '/../lib/tag_helper'
@@ -1,25 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../test_helper"
2
-
3
- class ConfigTest < Test::Unit::TestCase
4
-
5
- def test_image_tag
6
- assert_equal '<img src="1.png" />', TagHelper.image_tag('1.png')
7
- end
8
-
9
- def test_image_tag2
10
- assert_equal '<img alt="number one!" src="1.png" />', TagHelper.image_tag('1.png', :alt => 'number one!')
11
- end
12
-
13
- def test_label_tag2
14
- assert_equal '<label for="name">name</label>', TagHelper.label_tag('name')
15
- end
16
-
17
- def test_hidden_field_tag
18
- assert_equal '<input id="token" value="abc" type="hidden" name="token" />', TagHelper.hidden_field_tag('token', 'abc')
19
- end
20
-
21
- def test_hidden_field_tag2
22
- assert_equal '<input id="u" value="dejan" type="text" name="u" />', TagHelper.text_field_tag('u', 'dejan')
23
- end
24
-
25
- end