ng-attributes 1.0.3 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -0
- data/lib/ng-attributes.rb +1 -0
- data/lib/ng_attributes/railtie.rb +52 -0
- data/ng-attributes.gemspec +16 -0
- metadata +10 -6
- data/lib/action_view/helpers/tag_helper.rb +0 -45
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#ng-attributes
|
2
|
+
|
3
|
+
This gem provides Angular.js ng attributes for rails view helpers.
|
4
|
+
|
5
|
+
#Installing
|
6
|
+
|
7
|
+
For installing gem write in gemfile
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'ng-attributes'
|
11
|
+
```
|
12
|
+
|
13
|
+
#Usage
|
14
|
+
|
15
|
+
Usage is the same as usage of data attribute.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
link_to 'hello world', hello_world_path, ng: { click: 'doSomething()' }
|
19
|
+
```
|
20
|
+
will generate
|
21
|
+
|
22
|
+
```
|
23
|
+
<a href="/hello_world" ng-click="doSomething()">hello world</a>
|
24
|
+
```
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'ng_attributes/railtie' if defined? Rails
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module NgAttributes
|
2
|
+
class Railtie < ::Rails::Railtie #:nodoc:
|
3
|
+
config.after_initialize do
|
4
|
+
|
5
|
+
module ActionView::Helpers::TagHelper
|
6
|
+
private
|
7
|
+
|
8
|
+
def tag_options(options, escape = true)
|
9
|
+
return if options.blank?
|
10
|
+
attrs = []
|
11
|
+
options.each_pair do |key, value|
|
12
|
+
if key.to_s == 'data' && value.is_a?(Hash)
|
13
|
+
value.each_pair do |k, v|
|
14
|
+
attrs << data_tag_option(k, v, escape)
|
15
|
+
end
|
16
|
+
elsif key.to_s == 'ng' && value.is_a?(Hash)
|
17
|
+
value.each_pair do |k, v|
|
18
|
+
attrs << ng_tag_option(k, v, escape)
|
19
|
+
end
|
20
|
+
elsif BOOLEAN_ATTRIBUTES.include?(key)
|
21
|
+
attrs << boolean_tag_option(key) if value
|
22
|
+
elsif !value.nil?
|
23
|
+
attrs << tag_option(key, value, escape)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
" #{attrs.sort! * ' '}".html_safe unless attrs.empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
['ng', 'data'].each do |method_name|
|
30
|
+
define_method("#{method_name}_tag_option") do |key, value, escape|
|
31
|
+
key = "#{method_name}-#{key.to_s.dasherize}"
|
32
|
+
unless value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(BigDecimal)
|
33
|
+
value = value.to_json
|
34
|
+
end
|
35
|
+
tag_option(key, value, escape)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def boolean_tag_option(key)
|
40
|
+
%(#{key}="#{key}")
|
41
|
+
end
|
42
|
+
|
43
|
+
def tag_option(key, value, escape)
|
44
|
+
value = value.join(" ") if value.is_a?(Array)
|
45
|
+
value = ERB::Util.h(value) if escape
|
46
|
+
%(#{key}="#{value}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'ng-attributes'
|
3
|
+
s.platform = Gem::Platform::RUBY
|
4
|
+
s.version = '1.0.5'
|
5
|
+
s.license = 'MIT'
|
6
|
+
s.author = 'Pavel Astraukh'
|
7
|
+
s.email = 'paladin111333@gmail.com'
|
8
|
+
s.description = "Gem for using angular.js ng-attributes in rails view helpers"
|
9
|
+
s.homepage = 'http://github.com/enotpoloskun/ng-attributes'
|
10
|
+
s.summary = "Angular.js ng attributes"
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.require_path = 'lib'
|
14
|
+
|
15
|
+
s.rubyforge_project = s.name
|
16
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ng-attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-03 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Gem for using angular.js ng-attributes in rails view helpers
|
15
15
|
email: paladin111333@gmail.com
|
@@ -17,9 +17,13 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
-
|
21
|
-
|
22
|
-
|
20
|
+
- README.md
|
21
|
+
- lib/ng-attributes.rb
|
22
|
+
- lib/ng_attributes/railtie.rb
|
23
|
+
- ng-attributes.gemspec
|
24
|
+
homepage: http://github.com/enotpoloskun/ng-attributes
|
25
|
+
licenses:
|
26
|
+
- MIT
|
23
27
|
post_install_message:
|
24
28
|
rdoc_options: []
|
25
29
|
require_paths:
|
@@ -37,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
41
|
- !ruby/object:Gem::Version
|
38
42
|
version: '0'
|
39
43
|
requirements: []
|
40
|
-
rubyforge_project:
|
44
|
+
rubyforge_project: ng-attributes
|
41
45
|
rubygems_version: 1.8.25
|
42
46
|
signing_key:
|
43
47
|
specification_version: 3
|
@@ -1,45 +0,0 @@
|
|
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
|