actionview-data 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
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
+
9
+ This patch
10
+ {is in Rails 3.1}[https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5825-html5-data-attributes].
11
+
12
+
13
+ == Install
14
+
15
+ # Gemfile
16
+ gem "actionview-data"
17
+
18
+
19
+ == License
20
+
21
+ (The MIT License)
22
+
23
+ (c) 2010 Stephen Celis, stephen@stephencelis.com.
24
+
25
+ Permission is hereby granted, free of charge, to any person obtaining a copy
26
+ of this software and associated documentation files (the "Software"), to deal
27
+ in the Software without restriction, including without limitation the rights
28
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29
+ copies of the Software, and to permit persons to whom the Software is
30
+ furnished to do so, subject to the following conditions:
31
+
32
+ The above copyright notice and this permission notice shall be included in all
33
+ copies or substantial portions of the Software.
34
+
35
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41
+ SOFTWARE.
@@ -0,0 +1,27 @@
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_pair do |k, v|
10
+ if !v.is_a?(String) && !v.is_a?(Symbol)
11
+ v = v.to_json
12
+ end
13
+ v = html_escape(v) if escape
14
+ attrs << %(data-#{k.to_s.dasherize}="#{v}")
15
+ end
16
+ elsif BOOLEAN_ATTRIBUTES.include?(key)
17
+ attrs << %(#{key}="#{key}") if value
18
+ elsif !value.nil?
19
+ final_value = value.is_a?(Array) ? value.join(" ") : value
20
+ final_value = html_escape(final_value) if escape
21
+ attrs << %(#{key}="#{final_value}")
22
+ end
23
+ end
24
+ " #{attrs.sort * ' '}".html_safe unless attrs.empty?
25
+ end
26
+ end
27
+ 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
+ - 1
9
+ version: 3.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Stephen Celis
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-29 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: actionpack
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