attributes_for 0.4.4 → 0.5.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/Gemfile.lock +41 -6
- data/README.md +10 -3
- data/app/helpers/attributes_for/rails/attributes_for_helper.rb +32 -22
- data/attributes_for.gemspec +2 -3
- data/lib/attributes_for.rb +0 -2
- data/lib/attributes_for/version.rb +1 -1
- metadata +17 -43
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 21f33333a9b99cbf9570de9a631293eed058d910
|
|
4
|
+
data.tar.gz: 221fa4a21ec0f980e1b6b20237e555868ca1fdc3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b6a6bd76ba365bbd95278722adb7fcfd3eb89e34a7b1236609275c803f7d62cfea97f35ff03a655bc2901aac931cbb7f9fb0e2254be1faffa5c66147398d9f51
|
|
7
|
+
data.tar.gz: 9d5868db7a235f928d47ba5a2d7750bc59120f14b5c60abb851003a6eb195cbb3c421824aa7cd5a33aa764bb166a0ea87c5f67cd9fd674016e4fa29f425a1a9b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [0.
|
|
3
|
+
## [0.5.0] - 2015-21-09
|
|
4
|
+
### Fixed
|
|
5
|
+
- Use font-awesome-rails `fa_icon` helper to handle icons. Icons are now
|
|
6
|
+
positioned in front of content instead of wrapping it.
|
|
7
|
+
- Fixed tests.
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- Use options[:icon] to handle Font Awesome icons.
|
|
11
|
+
- Wrap key-val pairs with <span> tags.
|
|
12
|
+
|
|
13
|
+
## [0.4.4] - 2015-09-09
|
|
4
14
|
### Fixed
|
|
5
15
|
- Explicitly require dependencies.
|
|
6
16
|
|
data/Gemfile.lock
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
attributes_for (0.
|
|
5
|
-
actionview (>= 3.2, < 5.0)
|
|
6
|
-
activemodel (>= 3.2, < 5.0)
|
|
4
|
+
attributes_for (0.5.0)
|
|
7
5
|
chronic_duration (~> 0.10)
|
|
8
6
|
font-awesome-rails (~> 4.0)
|
|
9
7
|
phony (~> 2.0)
|
|
10
|
-
|
|
8
|
+
rails (>= 3.2, < 5.0)
|
|
11
9
|
|
|
12
10
|
GEM
|
|
13
11
|
remote: https://rubygems.org/
|
|
14
12
|
specs:
|
|
13
|
+
actionmailer (4.2.4)
|
|
14
|
+
actionpack (= 4.2.4)
|
|
15
|
+
actionview (= 4.2.4)
|
|
16
|
+
activejob (= 4.2.4)
|
|
17
|
+
mail (~> 2.5, >= 2.5.4)
|
|
18
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
15
19
|
actionpack (4.2.4)
|
|
16
20
|
actionview (= 4.2.4)
|
|
17
21
|
activesupport (= 4.2.4)
|
|
@@ -25,15 +29,23 @@ GEM
|
|
|
25
29
|
erubis (~> 2.7.0)
|
|
26
30
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
27
31
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
32
|
+
activejob (4.2.4)
|
|
33
|
+
activesupport (= 4.2.4)
|
|
34
|
+
globalid (>= 0.3.0)
|
|
28
35
|
activemodel (4.2.4)
|
|
29
36
|
activesupport (= 4.2.4)
|
|
30
37
|
builder (~> 3.1)
|
|
38
|
+
activerecord (4.2.4)
|
|
39
|
+
activemodel (= 4.2.4)
|
|
40
|
+
activesupport (= 4.2.4)
|
|
41
|
+
arel (~> 6.0)
|
|
31
42
|
activesupport (4.2.4)
|
|
32
43
|
i18n (~> 0.7)
|
|
33
44
|
json (~> 1.7, >= 1.7.7)
|
|
34
45
|
minitest (~> 5.1)
|
|
35
46
|
thread_safe (~> 0.3, >= 0.3.4)
|
|
36
47
|
tzinfo (~> 1.1)
|
|
48
|
+
arel (6.0.3)
|
|
37
49
|
builder (3.2.2)
|
|
38
50
|
chronic_duration (0.10.6)
|
|
39
51
|
numerizer (~> 0.1.1)
|
|
@@ -49,12 +61,16 @@ GEM
|
|
|
49
61
|
erubis (2.7.0)
|
|
50
62
|
font-awesome-rails (4.4.0.0)
|
|
51
63
|
railties (>= 3.2, < 5.0)
|
|
64
|
+
globalid (0.3.6)
|
|
65
|
+
activesupport (>= 4.1.0)
|
|
52
66
|
http-cookie (1.0.2)
|
|
53
67
|
domain_name (~> 0.5)
|
|
54
68
|
i18n (0.7.0)
|
|
55
69
|
json (1.8.3)
|
|
56
70
|
loofah (2.0.3)
|
|
57
71
|
nokogiri (>= 1.5.9)
|
|
72
|
+
mail (2.6.3)
|
|
73
|
+
mime-types (>= 1.16, < 3)
|
|
58
74
|
mime-types (2.6.1)
|
|
59
75
|
mini_portile (0.6.2)
|
|
60
76
|
minitest (5.8.0)
|
|
@@ -62,10 +78,21 @@ GEM
|
|
|
62
78
|
nokogiri (1.6.6.2)
|
|
63
79
|
mini_portile (~> 0.6.0)
|
|
64
80
|
numerizer (0.1.1)
|
|
65
|
-
phony (2.15.
|
|
81
|
+
phony (2.15.1)
|
|
66
82
|
rack (1.6.4)
|
|
67
83
|
rack-test (0.6.3)
|
|
68
84
|
rack (>= 1.0)
|
|
85
|
+
rails (4.2.4)
|
|
86
|
+
actionmailer (= 4.2.4)
|
|
87
|
+
actionpack (= 4.2.4)
|
|
88
|
+
actionview (= 4.2.4)
|
|
89
|
+
activejob (= 4.2.4)
|
|
90
|
+
activemodel (= 4.2.4)
|
|
91
|
+
activerecord (= 4.2.4)
|
|
92
|
+
activesupport (= 4.2.4)
|
|
93
|
+
bundler (>= 1.3.0, < 2.0)
|
|
94
|
+
railties (= 4.2.4)
|
|
95
|
+
sprockets-rails
|
|
69
96
|
rails-deprecated_sanitizer (1.0.3)
|
|
70
97
|
activesupport (>= 4.2.0.alpha)
|
|
71
98
|
rails-dom-testing (1.0.7)
|
|
@@ -89,6 +116,13 @@ GEM
|
|
|
89
116
|
json (~> 1.8)
|
|
90
117
|
simplecov-html (~> 0.10.0)
|
|
91
118
|
simplecov-html (0.10.0)
|
|
119
|
+
sprockets (3.3.4)
|
|
120
|
+
rack (~> 1.0)
|
|
121
|
+
sprockets-rails (2.3.3)
|
|
122
|
+
actionpack (>= 3.0)
|
|
123
|
+
activesupport (>= 3.0)
|
|
124
|
+
sprockets (>= 2.8, < 4.0)
|
|
125
|
+
sqlite3 (1.3.10)
|
|
92
126
|
term-ansicolor (1.3.2)
|
|
93
127
|
tins (~> 1.0)
|
|
94
128
|
thor (0.19.1)
|
|
@@ -106,6 +140,7 @@ PLATFORMS
|
|
|
106
140
|
DEPENDENCIES
|
|
107
141
|
attributes_for!
|
|
108
142
|
coveralls
|
|
143
|
+
sqlite3
|
|
109
144
|
|
|
110
145
|
BUNDLED WITH
|
|
111
|
-
1.10.
|
|
146
|
+
1.10.6
|
data/README.md
CHANGED
|
@@ -43,6 +43,11 @@ Preferred icon and CSS framework is [Font Awesome][fontawesome] Bring
|
|
|
43
43
|
## Screenshot
|
|
44
44
|

|
|
45
45
|
|
|
46
|
+
## Sample Application
|
|
47
|
+
|
|
48
|
+
Sample application using `attributes_for` can be found
|
|
49
|
+
[here](https://github.com/blacktangent/attributes_for-demo).
|
|
50
|
+
|
|
46
51
|
## Usage
|
|
47
52
|
|
|
48
53
|
Present attributes using the API in the example below. It can also generate a
|
|
@@ -52,14 +57,14 @@ strings can also be presented using the `string` method.
|
|
|
52
57
|
```erb
|
|
53
58
|
<ul class="list-unstyled">
|
|
54
59
|
<%= attributes_for @company do |b| %>
|
|
55
|
-
<li><%= b.attribute :name,
|
|
60
|
+
<li><%= b.attribute :name, icon: 'building-o' %></li>
|
|
56
61
|
<li><%= b.phone :phone %></li>
|
|
57
|
-
<li><%= b.phone :fax,
|
|
62
|
+
<li><%= b.phone :fax, icon: 'fax' %></li>
|
|
58
63
|
<li><%= b.email :email %></li>
|
|
59
64
|
<li><%= b.email :support_email %></li>
|
|
60
65
|
<li><%= b.url :website, id: :site %></li>
|
|
61
66
|
<li>
|
|
62
|
-
<%= b.attribute(:user,
|
|
67
|
+
<%= b.attribute(:user, icon: 'user') do %>
|
|
63
68
|
<%= link_to @company.user_name, url_for(@company.user) %>
|
|
64
69
|
<% end %>
|
|
65
70
|
</li>
|
|
@@ -82,6 +87,8 @@ Available options:
|
|
|
82
87
|
* __:label__ - Disables label if set to false
|
|
83
88
|
* __:css__ - Override element's CSS
|
|
84
89
|
* __:id__ - Set element's ID
|
|
90
|
+
* __:format__ - Used with `date` helper to format dates.
|
|
91
|
+
* __:icon__ - Name of Font Awesome icon to use.
|
|
85
92
|
|
|
86
93
|
## Development
|
|
87
94
|
|
|
@@ -8,6 +8,7 @@ module AttributesFor
|
|
|
8
8
|
|
|
9
9
|
class AttributeBuilder
|
|
10
10
|
include ActionView::Helpers
|
|
11
|
+
include FontAwesome::Rails::IconHelper
|
|
11
12
|
|
|
12
13
|
attr_accessor :object, :template
|
|
13
14
|
|
|
@@ -15,20 +16,28 @@ module AttributesFor
|
|
|
15
16
|
@object, @template = object, template
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
def
|
|
19
|
-
|
|
19
|
+
def method_missing(method, *args, &block)
|
|
20
|
+
build_content(method, *args, &block)
|
|
20
21
|
end
|
|
21
22
|
|
|
22
|
-
def
|
|
23
|
-
|
|
23
|
+
def string(label, options = {}, &block)
|
|
24
|
+
wrap_content(label, template.capture(&block), options)
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
private
|
|
27
28
|
|
|
28
29
|
def build_content(method, attribute_name, options = {}, &block)
|
|
30
|
+
content = format_attribute(method, attribute_name, options, &block)
|
|
31
|
+
|
|
32
|
+
options[:icon] ||= icon_map(method)
|
|
33
|
+
|
|
34
|
+
wrap_content(human_name(attribute_name), content, options)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def format_attribute(method, attribute_name, options = {}, &block)
|
|
29
38
|
value = object.public_send(attribute_name)
|
|
30
39
|
|
|
31
|
-
|
|
40
|
+
if block_given?
|
|
32
41
|
template.capture(&block)
|
|
33
42
|
elsif value.to_s.empty?
|
|
34
43
|
I18n.t "attributes_for.not_set"
|
|
@@ -51,34 +60,35 @@ module AttributesFor
|
|
|
51
60
|
value
|
|
52
61
|
end
|
|
53
62
|
end
|
|
63
|
+
end
|
|
54
64
|
|
|
55
|
-
|
|
56
|
-
options[:
|
|
65
|
+
def wrap_content(label, content, options)
|
|
66
|
+
html_options = options[:html] || {}
|
|
67
|
+
html_options[:id] = options.delete(:id) if options.key?(:id)
|
|
68
|
+
html_options[:class] = options.delete(:class) if options.key?(:class)
|
|
57
69
|
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
content = "#{label}: " + content unless options[:label] === false
|
|
71
|
+
content = content_tag(:span, content.html_safe, html_options)
|
|
60
72
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
73
|
+
if options[:icon]
|
|
74
|
+
content = fa_icon(options[:icon], text: content)
|
|
75
|
+
end
|
|
64
76
|
|
|
65
|
-
|
|
66
|
-
return " ".html_safe if options[:label] === false
|
|
67
|
-
" #{human_name(attribute)}: ".html_safe
|
|
77
|
+
content
|
|
68
78
|
end
|
|
69
79
|
|
|
70
80
|
def human_name(attribute)
|
|
71
|
-
object.class.human_attribute_name(attribute)
|
|
81
|
+
object.class.human_attribute_name(attribute, default: attribute.to_s.titleize)
|
|
72
82
|
end
|
|
73
83
|
|
|
74
84
|
def icon_map(method)
|
|
75
85
|
{
|
|
76
|
-
boolean: '
|
|
77
|
-
date: '
|
|
78
|
-
duration: '
|
|
79
|
-
email: '
|
|
80
|
-
phone: '
|
|
81
|
-
url: '
|
|
86
|
+
boolean: 'check',
|
|
87
|
+
date: 'calendar',
|
|
88
|
+
duration: 'clock-o',
|
|
89
|
+
email: 'envelope',
|
|
90
|
+
phone: 'phone',
|
|
91
|
+
url: 'globe',
|
|
82
92
|
}[method]
|
|
83
93
|
end
|
|
84
94
|
|
data/attributes_for.gemspec
CHANGED
|
@@ -20,12 +20,11 @@ Gem::Specification.new do |spec|
|
|
|
20
20
|
|
|
21
21
|
spec.required_ruby_version = '>= 1.9.3'
|
|
22
22
|
|
|
23
|
-
spec.add_dependency '
|
|
24
|
-
spec.add_dependency 'actionview', '>= 3.2', '< 5.0'
|
|
25
|
-
spec.add_dependency 'activemodel', '>= 3.2', '< 5.0'
|
|
23
|
+
spec.add_dependency 'rails', '>= 3.2', '< 5.0'
|
|
26
24
|
spec.add_dependency 'font-awesome-rails', '~> 4.0'
|
|
27
25
|
spec.add_dependency 'chronic_duration', '~> 0.10'
|
|
28
26
|
spec.add_dependency 'phony', '~> 2.0'
|
|
29
27
|
|
|
30
28
|
spec.add_development_dependency 'coveralls'
|
|
29
|
+
spec.add_development_dependency 'sqlite3'
|
|
31
30
|
end
|
data/lib/attributes_for.rb
CHANGED
metadata
CHANGED
|
@@ -1,57 +1,17 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: attributes_for
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ole J. Rosendahl
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-09-
|
|
11
|
+
date: 2015-09-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - ">="
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '3.2'
|
|
20
|
-
- - "<"
|
|
21
|
-
- !ruby/object:Gem::Version
|
|
22
|
-
version: '5.0'
|
|
23
|
-
type: :runtime
|
|
24
|
-
prerelease: false
|
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
-
requirements:
|
|
27
|
-
- - ">="
|
|
28
|
-
- !ruby/object:Gem::Version
|
|
29
|
-
version: '3.2'
|
|
30
|
-
- - "<"
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '5.0'
|
|
33
|
-
- !ruby/object:Gem::Dependency
|
|
34
|
-
name: actionview
|
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
|
36
|
-
requirements:
|
|
37
|
-
- - ">="
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: '3.2'
|
|
40
|
-
- - "<"
|
|
41
|
-
- !ruby/object:Gem::Version
|
|
42
|
-
version: '5.0'
|
|
43
|
-
type: :runtime
|
|
44
|
-
prerelease: false
|
|
45
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
46
|
-
requirements:
|
|
47
|
-
- - ">="
|
|
48
|
-
- !ruby/object:Gem::Version
|
|
49
|
-
version: '3.2'
|
|
50
|
-
- - "<"
|
|
51
|
-
- !ruby/object:Gem::Version
|
|
52
|
-
version: '5.0'
|
|
53
|
-
- !ruby/object:Gem::Dependency
|
|
54
|
-
name: activemodel
|
|
14
|
+
name: rails
|
|
55
15
|
requirement: !ruby/object:Gem::Requirement
|
|
56
16
|
requirements:
|
|
57
17
|
- - ">="
|
|
@@ -126,6 +86,20 @@ dependencies:
|
|
|
126
86
|
- - ">="
|
|
127
87
|
- !ruby/object:Gem::Version
|
|
128
88
|
version: '0'
|
|
89
|
+
- !ruby/object:Gem::Dependency
|
|
90
|
+
name: sqlite3
|
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
type: :development
|
|
97
|
+
prerelease: false
|
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
129
103
|
description: ActiveView Helper to present formatted ActiveModel attributes with icons.
|
|
130
104
|
email:
|
|
131
105
|
- ole.johnny.rosendahl@gmail.com
|