ng-attributes 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/action_view/helpers/tag_helper.rb +45 -0
- metadata +45 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
module ActionView::Helpers::TagHelper
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
def tag_options(options, escape = true)
|
6
|
+
return if options.blank?
|
7
|
+
attrs = []
|
8
|
+
options.each_pair do |key, value|
|
9
|
+
if key.to_s == 'data' && value.is_a?(Hash)
|
10
|
+
value.each_pair do |k, v|
|
11
|
+
attrs << data_tag_option(k, v, escape)
|
12
|
+
end
|
13
|
+
elsif key.to_s == 'ng' && value.is_a?(Hash)
|
14
|
+
value.each_pair do |k, v|
|
15
|
+
attrs << ng_tag_option(k, v, escape)
|
16
|
+
end
|
17
|
+
elsif BOOLEAN_ATTRIBUTES.include?(key)
|
18
|
+
attrs << boolean_tag_option(key) if value
|
19
|
+
elsif !value.nil?
|
20
|
+
attrs << tag_option(key, value, escape)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
" #{attrs.sort! * ' '}".html_safe unless attrs.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
['ng', 'data'].each do |method_name|
|
27
|
+
define_method("#{method_name}_tag_option") do |key, value, escape|
|
28
|
+
key = "#{method_name}-#{key.to_s.dasherize}"
|
29
|
+
unless value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(BigDecimal)
|
30
|
+
value = value.to_json
|
31
|
+
end
|
32
|
+
tag_option(key, value, escape)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def boolean_tag_option(key)
|
37
|
+
%(#{key}="#{key}")
|
38
|
+
end
|
39
|
+
|
40
|
+
def tag_option(key, value, escape)
|
41
|
+
value = value.join(" ") if value.is_a?(Array)
|
42
|
+
value = ERB::Util.h(value) if escape
|
43
|
+
%(#{key}="#{value}")
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ng-attributes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pavel Astraukh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-18 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Gem for using angular.js ng-attributes in rails view helpers
|
15
|
+
email: paladin111333@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/action_view/helpers/tag_helper.rb
|
21
|
+
homepage: http://rubygems.org/gems/ng-attributes
|
22
|
+
licenses: []
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 1.8.25
|
42
|
+
signing_key:
|
43
|
+
specification_version: 3
|
44
|
+
summary: Angular.js ng attributes
|
45
|
+
test_files: []
|