show_for 0.2.2 → 0.2.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/README.rdoc +11 -5
- data/lib/generators/{show_for_install → show_for}/USAGE +1 -1
- data/lib/generators/show_for/install_generator.rb +20 -0
- data/lib/generators/{show_for_install → show_for}/templates/en.yml +0 -0
- data/lib/generators/{show_for_install → show_for}/templates/show.html.erb +2 -2
- data/lib/generators/{show_for_install → show_for}/templates/show_for.rb +1 -2
- data/lib/show_for/attribute.rb +7 -1
- data/lib/show_for/content.rb +2 -2
- data/lib/show_for/version.rb +1 -1
- data/test/builder_test.rb +19 -4
- data/test/test_helper.rb +6 -8
- metadata +19 -9
- data/lib/generators/show_for_install/show_for_install_generator.rb +0 -19
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
ShowFor allows you to quickly show a model information with I18n features.
|
4
4
|
|
5
|
-
|
5
|
+
<%= show_for @user do |u| %>
|
6
6
|
<%= u.attribute :name %>
|
7
7
|
<%= u.attribute :nickname, :in => :profile %>
|
8
8
|
<%= u.attribute :confirmed? %>
|
@@ -37,7 +37,7 @@ if you want to use it with Rails 2.3 you should check this branch:
|
|
37
37
|
|
38
38
|
ShowFor allows you to quickly show a model information with I18n features.
|
39
39
|
|
40
|
-
|
40
|
+
<%= show_for @admin do |a| %>
|
41
41
|
<%= a.attribute :name %>
|
42
42
|
<%= a.attribute :confirmed? %>
|
43
43
|
<%= a.attribute :created_at, :format => :short %>
|
@@ -74,6 +74,12 @@ Will generate something like:
|
|
74
74
|
</p>
|
75
75
|
</div>
|
76
76
|
|
77
|
+
You also have the possibility to show a list of attributes, useful if you don't need to change any configuration:
|
78
|
+
|
79
|
+
<%= show_for @admin do |a| %>
|
80
|
+
<%= a.attributes :name, :confirmed?, :created_at %>
|
81
|
+
<% end %>
|
82
|
+
|
77
83
|
== Value lookup
|
78
84
|
|
79
85
|
To show the proper value, before retrieving the attribute value, show_for first looks if a
|
@@ -102,11 +108,11 @@ human_attribute_name lookup and the default wrapping:
|
|
102
108
|
|
103
109
|
a.label :name #=> <strong class="label">Name</strong>
|
104
110
|
a.label "Name", :id => "my_name" #=> <strong class="label" id="my_name">Name</strong>
|
105
|
-
|
111
|
+
|
106
112
|
Optionally, if you want to wrap the inner part of the label with some text
|
107
113
|
(e.g. adding a semicolon), you can do so by specifying a proc for ShowFor.label_proc
|
108
114
|
that will be called with any label text. E.g.:
|
109
|
-
|
115
|
+
|
110
116
|
ShowFor.label_proc = lambda { |l| l + ":" }
|
111
117
|
|
112
118
|
When taking this route, you can also skip on a per label basis by passing the
|
@@ -116,7 +122,7 @@ When taking this route, you can also skip on a per label basis by passing the
|
|
116
122
|
|
117
123
|
show_for also supports associations.
|
118
124
|
|
119
|
-
|
125
|
+
<%= show_for @artwork do |a| %>
|
120
126
|
<%= a.association :artist %>
|
121
127
|
<%= a.association :artist, :using => :name_with_title %>
|
122
128
|
<%= a.attribute :name_with_title, :in => :artist %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ShowFor
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
desc "Copy ShowFor installation files"
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def copy_initializers
|
8
|
+
copy_file 'show_for.rb', 'config/initializers/show_for.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
def copy_locale_file
|
12
|
+
copy_file 'en.yml', 'config/locales/show_for.en.yml'
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy_generator_template
|
16
|
+
copy_file 'show.html.erb', 'lib/templates/erb/scaffold/show.html.erb'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
<%%= show_for @<%= singular_name %> do |s| %>
|
2
2
|
<% attributes.each do |attribute| -%>
|
3
|
-
<%%=
|
3
|
+
<%%= s.<%= attribute.reference? ? :association : :attribute %> :<%= attribute.name %> %>
|
4
4
|
<% end -%>
|
5
5
|
<%% end %>
|
6
6
|
|
@@ -30,9 +30,8 @@ ShowFor.setup do |config|
|
|
30
30
|
# Whenever a association is given, the first method in association_methods
|
31
31
|
# in which the association responds to is used to retrieve the association labels.
|
32
32
|
# config.association_methods = [ :name, :title, :to_s ]
|
33
|
-
|
33
|
+
|
34
34
|
# If you want to wrap the text inside a label (e.g. to append a semicolon),
|
35
35
|
# specify label_proc - it will be automatically called, passing in the label text.
|
36
36
|
# config.label_proc = lambda { |l| c + ":" }
|
37
|
-
|
38
37
|
end
|
data/lib/show_for/attribute.rb
CHANGED
@@ -13,6 +13,12 @@ module ShowFor
|
|
13
13
|
end
|
14
14
|
|
15
15
|
wrap_label_and_content(attribute_name, value, options, &collection_block)
|
16
|
-
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def attributes(*attribute_names)
|
19
|
+
attribute_names.map do |attribute_name|
|
20
|
+
attribute(attribute_name)
|
21
|
+
end.join.html_safe
|
22
|
+
end
|
17
23
|
end
|
18
24
|
end
|
data/lib/show_for/content.rb
CHANGED
data/lib/show_for/version.rb
CHANGED
data/test/builder_test.rb
CHANGED
@@ -26,7 +26,13 @@ class BuilderTest < ActionView::TestCase
|
|
26
26
|
end)
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
def with_attributes_for(object, *attributes)
|
30
|
+
concat(show_for(object) do |o|
|
31
|
+
concat o.attributes(*attributes)
|
32
|
+
end)
|
33
|
+
end
|
34
|
+
|
35
|
+
# WRAPPER
|
30
36
|
test "show_for attribute wraps each attribute with a label and content" do
|
31
37
|
with_attribute_for @user, :name
|
32
38
|
assert_select "div.show_for p.user_name.wrapper"
|
@@ -154,14 +160,14 @@ class BuilderTest < ActionView::TestCase
|
|
154
160
|
assert_select "div.show_for p.wrapper", /Hell yeah!/
|
155
161
|
end
|
156
162
|
end
|
157
|
-
|
163
|
+
|
158
164
|
test "should let you override the label wrapper" do
|
159
165
|
swap ShowFor, :label_proc => proc { |l| l + ":" } do
|
160
166
|
with_label_for @user, "Special Label"
|
161
167
|
assert_select "div.show_for strong.label", "Special Label:"
|
162
168
|
end
|
163
169
|
end
|
164
|
-
|
170
|
+
|
165
171
|
test "should you skip wrapping the label on a per item basis" do
|
166
172
|
swap ShowFor, :label_proc => proc { |l| l + ":" } do
|
167
173
|
with_label_for @user, "Special Label", :wrap_label => false
|
@@ -232,7 +238,7 @@ class BuilderTest < ActionView::TestCase
|
|
232
238
|
with_content_for @user, "Special content", :content_tag => :b, :id => "thecontent", :class => "special"
|
233
239
|
assert_select "div.show_for b#thecontent.special.content", "Special content"
|
234
240
|
end
|
235
|
-
|
241
|
+
|
236
242
|
test "show_for#content with blank value has a 'no value'-class" do
|
237
243
|
swap ShowFor, :blank_content_class => "nothing" do
|
238
244
|
with_content_for @user, nil, :content_tag => :b
|
@@ -341,4 +347,13 @@ class BuilderTest < ActionView::TestCase
|
|
341
347
|
assert_select "div.show_for p.wrapper p.collection span", "Tag 2"
|
342
348
|
assert_select "div.show_for p.wrapper p.collection span", "Tag 3"
|
343
349
|
end
|
350
|
+
|
351
|
+
# ATTRIBUTES
|
352
|
+
test "show_for attributes wraps each attribute with a label and content" do
|
353
|
+
with_attributes_for @user, :name, :email
|
354
|
+
assert_select "div.show_for p.user_name.wrapper", /ShowFor/
|
355
|
+
assert_select "p.user_name strong.label", "Super User Name!"
|
356
|
+
assert_select "div.show_for p.user_email.wrapper", /Not specified/
|
357
|
+
assert_select "p.user_email strong.label", "Email"
|
358
|
+
end
|
344
359
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
Bundler.setup
|
5
|
+
|
2
6
|
require 'test/unit'
|
3
7
|
|
4
8
|
require 'active_model'
|
@@ -7,12 +11,7 @@ require 'action_view'
|
|
7
11
|
require 'action_view/template'
|
8
12
|
require 'action_view/test_case'
|
9
13
|
|
10
|
-
|
11
|
-
require 'ruby-debug'
|
12
|
-
rescue LoadError
|
13
|
-
end
|
14
|
-
|
15
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib', 'show_for')
|
14
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
16
15
|
require 'show_for'
|
17
16
|
|
18
17
|
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
|
@@ -20,8 +19,7 @@ I18n.default_locale = :en
|
|
20
19
|
|
21
20
|
class ActionView::TestCase
|
22
21
|
include MiscHelpers
|
23
|
-
|
24
|
-
tests ShowFor::Helper
|
22
|
+
include ShowFor::Helper
|
25
23
|
|
26
24
|
setup :setup_new_user
|
27
25
|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: show_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- "Jos\xC3\xA9 Valim"
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-07-25 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -28,11 +29,11 @@ extra_rdoc_files:
|
|
28
29
|
- README.rdoc
|
29
30
|
files:
|
30
31
|
- init.rb
|
31
|
-
- lib/generators/
|
32
|
-
- lib/generators/
|
33
|
-
- lib/generators/
|
34
|
-
- lib/generators/
|
35
|
-
- lib/generators/
|
32
|
+
- lib/generators/show_for/USAGE
|
33
|
+
- lib/generators/show_for/install_generator.rb
|
34
|
+
- lib/generators/show_for/templates/en.yml
|
35
|
+
- lib/generators/show_for/templates/show.html.erb
|
36
|
+
- lib/generators/show_for/templates/show_for.rb
|
36
37
|
- lib/show_for.rb
|
37
38
|
- lib/show_for/association.rb
|
38
39
|
- lib/show_for/attribute.rb
|
@@ -42,6 +43,11 @@ files:
|
|
42
43
|
- lib/show_for/label.rb
|
43
44
|
- lib/show_for/version.rb
|
44
45
|
- README.rdoc
|
46
|
+
- test/builder_test.rb
|
47
|
+
- test/helper_test.rb
|
48
|
+
- test/support/misc_helpers.rb
|
49
|
+
- test/support/models.rb
|
50
|
+
- test/test_helper.rb
|
45
51
|
has_rdoc: true
|
46
52
|
homepage: http://github.com/plataformatec/show_for
|
47
53
|
licenses: []
|
@@ -52,23 +58,27 @@ rdoc_options:
|
|
52
58
|
require_paths:
|
53
59
|
- lib
|
54
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
55
62
|
requirements:
|
56
63
|
- - ">="
|
57
64
|
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
58
66
|
segments:
|
59
67
|
- 0
|
60
68
|
version: "0"
|
61
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
62
71
|
requirements:
|
63
72
|
- - ">="
|
64
73
|
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
65
75
|
segments:
|
66
76
|
- 0
|
67
77
|
version: "0"
|
68
78
|
requirements: []
|
69
79
|
|
70
80
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.3.
|
81
|
+
rubygems_version: 1.3.7
|
72
82
|
signing_key:
|
73
83
|
specification_version: 3
|
74
84
|
summary: Wrap your objects with a helper to easily show them
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class ShowForInstallGenerator < Rails::Generators::Base
|
2
|
-
desc "Copy ShowFor installation files"
|
3
|
-
|
4
|
-
def self.source_root
|
5
|
-
@_source_root = File.expand_path('../templates', __FILE__)
|
6
|
-
end
|
7
|
-
|
8
|
-
def copy_initializers
|
9
|
-
copy_file 'show_for.rb', 'config/initializers/show_for.rb'
|
10
|
-
end
|
11
|
-
|
12
|
-
def copy_locale_file
|
13
|
-
copy_file 'en.yml', 'config/locales/show_for.en.yml'
|
14
|
-
end
|
15
|
-
|
16
|
-
def copy_generator_template
|
17
|
-
copy_file 'show.html.erb', 'lib/templates/erb/scaffold/show.html.erb'
|
18
|
-
end
|
19
|
-
end
|