actionview-data 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,36 @@
1
+ = ActionView Data
2
+
3
+ HTML5 data attribute helpers for ActionView.
4
+
5
+ tag 'a', nil, :data => { :string => "hi", :number => 1, array => [1, 2, 3], :hash => { :k => 'v' } }
6
+ # <a data-array="[1,2,3]" data-hash="{&quot;k&quot;:&quot;v&quot;}" data-number="1" data-string="hi"/>
7
+
8
+ == Install
9
+
10
+ # Gemfile
11
+ gem "actionview-data"
12
+
13
+
14
+ == License
15
+
16
+ (The MIT License)
17
+
18
+ (c) 2010 Stephen Celis, stephen@stephencelis.com.
19
+
20
+ Permission is hereby granted, free of charge, to any person obtaining a copy
21
+ of this software and associated documentation files (the "Software"), to deal
22
+ in the Software without restriction, including without limitation the rights
23
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24
+ copies of the Software, and to permit persons to whom the Software is
25
+ furnished to do so, subject to the following conditions:
26
+
27
+ The above copyright notice and this permission notice shall be included in all
28
+ copies or substantial portions of the Software.
29
+
30
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ ActionView::Helpers::TagHelper.module_eval do
2
+ private
3
+
4
+ def tag_options(options, escape = true)
5
+ unless options.blank?
6
+ attrs = []
7
+ options.each_pair do |key, value|
8
+ if key.to_s == 'data' && value.is_a?(Hash)
9
+ value.each { |k, v| attrs << %(data-#{k}="#{ERB::Util.h(v.is_a?(String) ? v : v.to_json)}") }
10
+ elsif BOOLEAN_ATTRIBUTES.include?(key)
11
+ attrs << %(#{key}="#{key}") if value
12
+ elsif !value.nil?
13
+ final_value = value.is_a?(Array) ? value.join(" ") : value
14
+ final_value = html_escape(final_value) if escape
15
+ attrs << %(#{key}="#{final_value}")
16
+ end
17
+ end
18
+ " #{attrs.sort * ' '}".html_safe unless attrs.empty?
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ require 'test/unit'
2
+ require 'action_view'
3
+ require './actionview-data'
4
+
5
+ class ActionViewDataTest < ActionView::TestCase
6
+ tests ActionView::Helpers::TagHelper
7
+
8
+ def test_data_attributes
9
+ assert_equal '<a data-array="[1,2,3]" data-hash="{&quot;key&quot;:&quot;value&quot;}" data-number="1" data-string="hello" />',
10
+ tag('a', { :data => { :number => 1, :string => 'hello', :array => [1, 2, 3], :hash => { :key => 'value'} } })
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: actionview-data
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 3
7
+ - 0
8
+ - 0
9
+ version: 3.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Stephen Celis
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-16 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 0
32
+ version: 3.0.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: HTML5 data attribute helpers for ActionView.
36
+ email: stephen@stephencelis.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ files:
44
+ - actionview-data.rb
45
+ - README.rdoc
46
+ - actionview-data_test.rb
47
+ has_rdoc: true
48
+ homepage: http://github.com/stephencelis/actionview-data
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --main
54
+ - README.rdoc
55
+ require_paths:
56
+ - .
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.7
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: HTML5 data attribute helpers for ActionView.
80
+ test_files:
81
+ - actionview-data_test.rb