attributes_for 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +16 -5
- data/app/assets/stylesheets/attributes_for.css +3 -0
- data/app/helpers/attributes_for/attributes_for_helper.rb +42 -44
- data/lib/attributes_for/engine.rb +3 -1
- data/lib/attributes_for/version.rb +1 -1
- data/lib/generators/attributes_for/install_generator.rb +7 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f23d4cb89d3cc588d8e7581eac7ffd8c5abdf4a4
|
4
|
+
data.tar.gz: dfdfb77f005a66815d07c009ff6f89ccfa460e80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d76570dcf17f8dabfd00aa2eb6ad2317c6c1066b24dfb1ae7afb292e24e5331d1d58a78eb25fcb2faeae8243b75088d2621bbce5dc4097907a962dc69c6e36e
|
7
|
+
data.tar.gz: c9db4d9229d1a389a44a5a60d0e4a78d1a3298ad88a52bf58007082feb3b568f2d7d0627ed7ec46975ae2b1dc78883e76f156e11bbde513b3f06f8b258a9abe8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.3.1] - 2015-08-06
|
4
|
+
### Fixed
|
5
|
+
- Fixed stylesheet loading (insert 'require' during installation).
|
6
|
+
|
7
|
+
## [0.3.0] - 2015-08-05
|
8
|
+
### Added
|
9
|
+
- All formatting methods now takes a block. The contents of the block
|
10
|
+
will be displayed after the label.
|
11
|
+
|
3
12
|
## [0.2.0] - 2015-08-04
|
4
13
|
### Added
|
5
14
|
- `boolean` formatting helper, will show 'Yes' or 'No' depending on
|
data/README.md
CHANGED
@@ -23,22 +23,33 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
$ gem install attributes_for
|
25
25
|
|
26
|
+
Run generator to add I18n locales:
|
27
|
+
|
28
|
+
$ rails generate attributes_for:install
|
29
|
+
|
30
|
+
## Screenshot
|
31
|
+
![Screenshot](https://cloud.githubusercontent.com/assets/1222916/9083171/fac21df2-3b92-11e5-837a-71e70ee24cdd.png)
|
32
|
+
|
26
33
|
## Usage
|
27
34
|
|
28
35
|
Present the attributes using the API in the example below. It can also generate a
|
29
|
-
standard label value pair given an attribute name using the `
|
36
|
+
standard label value pair given an attribute name using the `attribute` method. Arbitrary
|
30
37
|
strings can also be presented using the `string` method.
|
31
38
|
|
32
39
|
```ruby
|
33
|
-
<ul class="unstyled">
|
40
|
+
<ul class="list-unstyled">
|
34
41
|
<%= attributes_for @company do |b| %>
|
42
|
+
<li><%= b.attribute :name, class: 'fa fa-building-o' %></li>
|
35
43
|
<li><%= b.phone :phone %></li>
|
36
44
|
<li><%= b.email :email %></li>
|
37
45
|
<li><%= b.url :website %></li>
|
38
|
-
<li
|
39
|
-
|
46
|
+
<li>
|
47
|
+
<%= b.attribute(:user, class: 'fa fa-user') do %>
|
48
|
+
<%= link_to @company.user_name, url_for(@company.user) %>
|
49
|
+
<% end %>
|
50
|
+
</li>
|
40
51
|
<li><%= b.boolean :active %></li>
|
41
|
-
<li><%= b.
|
52
|
+
<li><%= b.date :created_at, format: :long %> </li>
|
42
53
|
<% end %>
|
43
54
|
</ul>
|
44
55
|
```
|
@@ -2,88 +2,86 @@ module AttributesFor
|
|
2
2
|
module AttributesForHelper
|
3
3
|
|
4
4
|
def attributes_for(object, options = {}, &block)
|
5
|
-
builder = AttributeBuilder.new(object)
|
5
|
+
builder = AttributeBuilder.new(object, self)
|
6
6
|
capture builder, &block
|
7
7
|
end
|
8
8
|
|
9
9
|
class AttributeBuilder
|
10
10
|
include ActionView::Helpers
|
11
11
|
|
12
|
-
attr_accessor :object, :output_buffer
|
12
|
+
attr_accessor :object, :template, :output_buffer
|
13
13
|
|
14
|
-
def initialize(object)
|
15
|
-
@object = object
|
14
|
+
def initialize(object, template)
|
15
|
+
@object, @template = object, template
|
16
16
|
end
|
17
17
|
|
18
|
-
def boolean(attribute_name, options = {})
|
18
|
+
def boolean(attribute_name, options = {}, &block)
|
19
19
|
options[:class] ||= 'fa fa-check'
|
20
|
-
|
21
|
-
content(attribute_name, options) do |value|
|
22
|
-
I18n.t("attributes_for.#{value.to_s}")
|
23
|
-
end
|
20
|
+
content(attribute_name, __method__, options, &block)
|
24
21
|
end
|
25
22
|
|
26
|
-
def phone(attribute_name, options = {})
|
23
|
+
def phone(attribute_name, options = {}, &block)
|
27
24
|
options[:class] ||= 'fa fa-phone'
|
28
|
-
|
29
|
-
content(attribute_name, options) do |value|
|
30
|
-
link_to(" #{number_to_phone(value)}", "tel:#{value}", title: human_name(attribute_name))
|
31
|
-
end
|
25
|
+
content(attribute_name, __method__, options, &block)
|
32
26
|
end
|
33
27
|
|
34
|
-
def email(attribute_name, options = {})
|
28
|
+
def email(attribute_name, options = {}, &block)
|
35
29
|
options[:class] ||= 'fa fa-envelope'
|
36
|
-
|
37
|
-
content(attribute_name, options) do |value|
|
38
|
-
mail_to(" #{value}", value, title: human_name(attribute_name))
|
39
|
-
end
|
30
|
+
content(attribute_name, __method__, options, &block)
|
40
31
|
end
|
41
32
|
|
42
|
-
def url(attribute_name, options = {})
|
33
|
+
def url(attribute_name, options = {}, &block)
|
43
34
|
options[:class] ||= 'fa fa-globe'
|
44
|
-
|
45
|
-
content(attribute_name, options) do |value|
|
46
|
-
link_to(" #{value}", value, title: human_name(attribute_name))
|
47
|
-
end
|
35
|
+
content(attribute_name, __method__, options, &block)
|
48
36
|
end
|
49
37
|
|
50
|
-
def date(attribute_name, options = {})
|
38
|
+
def date(attribute_name, options = {}, &block)
|
51
39
|
options[:class] ||= 'fa fa-clock-o'
|
52
|
-
|
53
|
-
content(attribute_name, options) do |value|
|
54
|
-
I18n.l(value, format: options[:format])
|
55
|
-
end
|
40
|
+
content(attribute_name, __method__, options, &block)
|
56
41
|
end
|
57
42
|
|
58
43
|
def string(content, options = {})
|
59
44
|
wrap_content(" #{content}", options)
|
60
45
|
end
|
61
46
|
|
62
|
-
def attribute(attribute_name, options = {})
|
63
|
-
content(attribute_name, options)
|
47
|
+
def attribute(attribute_name, options = {}, &block)
|
48
|
+
content(attribute_name, __method__, options, &block)
|
64
49
|
end
|
65
50
|
|
66
51
|
private
|
67
52
|
|
68
|
-
def content(attribute_name, options = {}, &block)
|
69
|
-
options
|
70
|
-
|
71
|
-
wrap_content(
|
72
|
-
label(attribute_name, options) + prepare_value(attribute_value(attribute_name), &block),
|
73
|
-
options
|
74
|
-
)
|
53
|
+
def content(attribute_name, method, options = {}, &block)
|
54
|
+
wrap_content(label(attribute_name, options) + build_content(attribute_name, method, options, &block), options)
|
75
55
|
end
|
76
56
|
|
77
|
-
def
|
78
|
-
if
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
57
|
+
def build_content(attribute_name, method, options = {}, &block)
|
58
|
+
return template.capture(&block) if block_given?
|
59
|
+
|
60
|
+
value = attribute_value(attribute_name)
|
61
|
+
|
62
|
+
return I18n.t "attributes_for.not_set" if value.to_s.empty?
|
63
|
+
|
64
|
+
case method.to_sym
|
65
|
+
when :attribute
|
83
66
|
value
|
67
|
+
when :boolean
|
68
|
+
I18n.t("attributes_for.#{value.to_s}")
|
69
|
+
when :date
|
70
|
+
I18n.l(value, format: options[:format])
|
71
|
+
when :email
|
72
|
+
mail_to(" #{value}", value, title: human_name(attribute_name))
|
73
|
+
when :phone
|
74
|
+
link_to(" #{number_to_phone(value)}", "tel:#{value}", title: human_name(attribute_name))
|
75
|
+
when :url
|
76
|
+
link_to(" #{value}", value, title: human_name(attribute_name))
|
84
77
|
end
|
85
78
|
end
|
86
79
|
|
80
|
+
def content(attribute_name, method, options = {}, &block)
|
81
|
+
options[:id] ||= attribute_name.to_s
|
82
|
+
wrap_content(label(attribute_name, options) + build_content(attribute_name, method, options, &block), options)
|
83
|
+
end
|
84
|
+
|
87
85
|
def wrap_content(content, options = {})
|
88
86
|
content_tag(:i, content, id: options[:id], class: options[:class])
|
89
87
|
end
|
@@ -8,6 +8,13 @@ module AttributesFor
|
|
8
8
|
copy_file 'attributes_for.en.yml', 'config/locales/attributes_for.en.yml'
|
9
9
|
end
|
10
10
|
|
11
|
+
def inject_stylesheets
|
12
|
+
file = "app/assets/stylesheets/application.css"
|
13
|
+
|
14
|
+
if File.exists?(Rails.root.join(file))
|
15
|
+
inject_into_file file, " *= require attributes_for\n", {before: %r{.*require_self}}
|
16
|
+
end
|
17
|
+
end
|
11
18
|
end
|
12
19
|
end
|
13
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attributes_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
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-08-
|
11
|
+
date: 2015-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- LICENSE.txt
|
97
97
|
- README.md
|
98
98
|
- Rakefile
|
99
|
+
- app/assets/stylesheets/attributes_for.css
|
99
100
|
- app/helpers/attributes_for/attributes_for_helper.rb
|
100
101
|
- attributes_for.gemspec
|
101
102
|
- bin/console
|