show_for 0.1.6 → 0.2.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.
- data/README.rdoc +13 -14
- data/init.rb +1 -1
- data/{generators → lib/generators}/show_for_install/USAGE +1 -1
- data/lib/generators/show_for_install/show_for_install_generator.rb +19 -0
- data/lib/{show_for/locale → generators/show_for_install/templates}/en.yml +0 -0
- data/lib/generators/show_for_install/templates/show.html.erb +8 -0
- data/{generators → lib/generators}/show_for_install/templates/show_for.rb +0 -0
- data/lib/show_for/builder.rb +5 -19
- data/lib/show_for/content.rb +1 -3
- data/lib/show_for/label.rb +2 -2
- data/lib/show_for/version.rb +2 -2
- data/lib/show_for.rb +3 -0
- data/test/builder_test.rb +10 -4
- data/test/support/models.rb +6 -0
- data/test/test_helper.rb +1 -2
- metadata +10 -26
- data/generators/show_for_install/show_for_install_generator.rb +0 -19
data/README.rdoc
CHANGED
@@ -7,12 +7,12 @@ ShowFor allows you to quickly show a model information with I18n features.
|
|
7
7
|
<%= u.attribute :nickname, :in => :profile %>
|
8
8
|
<%= u.attribute :confirmed? %>
|
9
9
|
<%= u.attribute :created_at, :format => :short %>
|
10
|
-
<%= u.attribute :last_sign_in_at, :if_blank => "User did not access yet"
|
10
|
+
<%= u.attribute :last_sign_in_at, :if_blank => "User did not access yet",
|
11
11
|
:wrapper_html => { :id => "sign_in_timestamp" } %>
|
12
12
|
|
13
|
-
<% u.attribute :photo do
|
14
|
-
<%=
|
15
|
-
|
13
|
+
<% u.attribute :photo do
|
14
|
+
<%= image_url(@user.photo_url) %>
|
15
|
+
end %>
|
16
16
|
|
17
17
|
<%= u.association :company %>
|
18
18
|
<%= u.association :tags, :to_sentence => true %>
|
@@ -22,17 +22,16 @@ ShowFor allows you to quickly show a model information with I18n features.
|
|
22
22
|
|
23
23
|
Install the gem:
|
24
24
|
|
25
|
-
sudo gem install show_for --version=0.
|
26
|
-
|
27
|
-
Configure simple_form gem inside your app:
|
28
|
-
|
29
|
-
config.gem 'show_for'
|
25
|
+
sudo gem install show_for --version=0.2
|
30
26
|
|
31
27
|
Run the generator:
|
32
28
|
|
33
|
-
|
29
|
+
rails generate show_for_install
|
30
|
+
|
31
|
+
And you are ready to go. Since this branch is aims Rails 3 support,
|
32
|
+
if you want to use it with Rails 2.3 you should check this branch:
|
34
33
|
|
35
|
-
|
34
|
+
http://github.com/plataformatec/show_for/tree/v0.1
|
36
35
|
|
37
36
|
== Usage
|
38
37
|
|
@@ -46,7 +45,7 @@ ShowFor allows you to quickly show a model information with I18n features.
|
|
46
45
|
:wrapper_html => { :id => "sign_in_timestamp" } %>
|
47
46
|
|
48
47
|
<% a.attribute :photo do %>
|
49
|
-
<%=
|
48
|
+
<%= image_url(@admin.photo_url) %>
|
50
49
|
<% end %>
|
51
50
|
<% end %>
|
52
51
|
|
@@ -101,8 +100,8 @@ options. Containers can have their tags configured on demand as well through
|
|
101
100
|
show_for also exposes the label method. In case you want to use the default
|
102
101
|
human_attribute_name lookup and the default wrapping:
|
103
102
|
|
104
|
-
a.label :name #=> <
|
105
|
-
a.label "Name", :id => "my_name" #=> <
|
103
|
+
a.label :name #=> <b class="label">Name</b>
|
104
|
+
a.label "Name", :id => "my_name" #=> <b class="label" id="my_name">Name</b>
|
106
105
|
|
107
106
|
== Associations
|
108
107
|
|
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'show_for'
|
1
|
+
require 'show_for'
|
@@ -0,0 +1,19 @@
|
|
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
|
File without changes
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%% show_for @<%= singular_name %> do |o| %>
|
2
|
+
<% attributes.each do |attribute| -%>
|
3
|
+
<%%= o.<%= attribute.reference? ? :association : :attribute %> :<%= attribute.name %> %>
|
4
|
+
<% end -%>
|
5
|
+
<%% end %>
|
6
|
+
|
7
|
+
<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
|
8
|
+
<%%= link_to 'Back', <%= plural_name %>_path %>
|
File without changes
|
data/lib/show_for/builder.rb
CHANGED
@@ -23,10 +23,8 @@ module ShowFor
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def wrap_label_and_content(name, value, options, &block) #:nodoc:
|
26
|
-
|
27
|
-
|
28
|
-
wrap_with(:wrapper, label + content(value, options, false, &block),
|
29
|
-
options, true, (value.is_a?(Proc) or collection_block?(block)))
|
26
|
+
wrap_with(:wrapper, label(name, options, false) + ShowFor.separator.to_s.html_safe +
|
27
|
+
content(value, options, false, &block), options, value.is_a?(Proc))
|
30
28
|
end
|
31
29
|
|
32
30
|
# Set "#{object_name}_#{attribute_name}" as in the wrapper tag.
|
@@ -39,7 +37,7 @@ module ShowFor
|
|
39
37
|
# Gets the default tag set in ShowFor module and apply (if defined)
|
40
38
|
# around the given content. It also check for html_options in @options
|
41
39
|
# hash related to the current type.
|
42
|
-
def wrap_with(type, content, options,
|
40
|
+
def wrap_with(type, content, options, concat=false) #:nodoc:
|
43
41
|
tag = options.delete(:"#{type}_tag") || ShowFor.send(:"#{type}_tag")
|
44
42
|
|
45
43
|
html = if tag
|
@@ -50,8 +48,7 @@ module ShowFor
|
|
50
48
|
content
|
51
49
|
end
|
52
50
|
|
53
|
-
|
54
|
-
concat ? @template.concat(html) : html
|
51
|
+
concat ? @template.safe_concat(html) : html.html_safe
|
55
52
|
end
|
56
53
|
|
57
54
|
# Returns true if the block is supposed to iterate through a collection,
|
@@ -59,16 +56,5 @@ module ShowFor
|
|
59
56
|
def collection_block?(block) #:nodoc:
|
60
57
|
block && block.arity == 1
|
61
58
|
end
|
62
|
-
|
63
|
-
# Ensure we make html safe only if it responds to it.
|
64
|
-
def html_safe(content)
|
65
|
-
if content.respond_to?(:html_safe)
|
66
|
-
content.html_safe
|
67
|
-
elsif content.respond_to?(:html_safe!)
|
68
|
-
content.html_safe!
|
69
|
-
else
|
70
|
-
content
|
71
|
-
end
|
72
|
-
end
|
73
59
|
end
|
74
|
-
end
|
60
|
+
end
|
data/lib/show_for/content.rb
CHANGED
@@ -5,8 +5,6 @@ module ShowFor
|
|
5
5
|
value = options.delete(:if_blank) || I18n.t(:'show_for.blank', :default => "Not specified")
|
6
6
|
options[:class] = [options[:class], ShowFor.blank_content_class].join(' ')
|
7
7
|
end
|
8
|
-
|
9
|
-
value = value.to_a if value.is_a?(Array)
|
10
8
|
|
11
9
|
content = case value
|
12
10
|
when Date, Time, DateTime
|
@@ -45,4 +43,4 @@ module ShowFor
|
|
45
43
|
wrap_with(:collection, response, options)
|
46
44
|
end
|
47
45
|
end
|
48
|
-
end
|
46
|
+
end
|
data/lib/show_for/label.rb
CHANGED
@@ -9,7 +9,7 @@ module ShowFor
|
|
9
9
|
human_attribute_name(text_or_attribute)
|
10
10
|
end
|
11
11
|
|
12
|
-
return
|
12
|
+
return "" if label == false
|
13
13
|
options[:label_html] = options.dup if apply_options
|
14
14
|
wrap_with :label, label, options
|
15
15
|
end
|
@@ -20,4 +20,4 @@ module ShowFor
|
|
20
20
|
@object.class.human_attribute_name(attribute.to_s)
|
21
21
|
end
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
data/lib/show_for/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module ShowFor
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
2
|
+
VERSION = "0.2.0".freeze
|
3
|
+
end
|
data/lib/show_for.rb
CHANGED
data/test/builder_test.rb
CHANGED
@@ -26,7 +26,7 @@ class BuilderTest < ActionView::TestCase
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
# WRAPPER
|
29
|
+
# WRAPPER
|
30
30
|
test "show_for attribute wraps each attribute with a label and content" do
|
31
31
|
with_attribute_for @user, :name
|
32
32
|
assert_select "div.show_for p.user_name.wrapper"
|
@@ -66,7 +66,6 @@ class BuilderTest < ActionView::TestCase
|
|
66
66
|
test "show_for skips label if requested" do
|
67
67
|
with_attribute_for @user, :name, :label => false
|
68
68
|
assert_no_select "div.show_for p.wrapper strong.label"
|
69
|
-
assert_no_select "div.show_for p.wrapper br"
|
70
69
|
end
|
71
70
|
|
72
71
|
test "show_for allows label to be configured globally" do
|
@@ -219,7 +218,7 @@ class BuilderTest < ActionView::TestCase
|
|
219
218
|
with_content_for @user, "Special content", :content_tag => :b, :id => "thecontent", :class => "special"
|
220
219
|
assert_select "div.show_for b#thecontent.special.content", "Special content"
|
221
220
|
end
|
222
|
-
|
221
|
+
|
223
222
|
test "show_for#content with blank value has a 'no value'-class" do
|
224
223
|
swap ShowFor, :blank_content_class => "nothing" do
|
225
224
|
with_content_for @user, nil, :content_tag => :b
|
@@ -227,6 +226,13 @@ class BuilderTest < ActionView::TestCase
|
|
227
226
|
end
|
228
227
|
end
|
229
228
|
|
229
|
+
test "show_for#content with blank value fallbacks on a default value" do
|
230
|
+
swap ShowFor, :blank_content => "Not specified" do
|
231
|
+
with_content_for @user, nil, :content_tag => :b
|
232
|
+
assert_select "div.show_for b", "Not specified"
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
230
236
|
# COLLECTIONS
|
231
237
|
test "show_for accepts an attribute as a collection" do
|
232
238
|
with_attribute_for @user, :scopes
|
@@ -328,4 +334,4 @@ class BuilderTest < ActionView::TestCase
|
|
328
334
|
assert_select "div.show_for p.wrapper p.collection span", "Tag 2"
|
329
335
|
assert_select "div.show_for p.wrapper p.collection span", "Tag 3"
|
330
336
|
end
|
331
|
-
end
|
337
|
+
end
|
data/test/support/models.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
|
3
3
|
class Company < Struct.new(:id, :name)
|
4
|
+
extend ActiveModel::Naming
|
5
|
+
|
4
6
|
def alternate_name
|
5
7
|
"Alternate #{self.name}"
|
6
8
|
end
|
7
9
|
end
|
8
10
|
|
9
11
|
class Tag < Struct.new(:id, :name)
|
12
|
+
extend ActiveModel::Naming
|
13
|
+
|
10
14
|
def self.all(options={})
|
11
15
|
(1..3).map{ |i| Tag.new(i, "Tag #{i}") }
|
12
16
|
end
|
@@ -17,6 +21,8 @@ class Tag < Struct.new(:id, :name)
|
|
17
21
|
end
|
18
22
|
|
19
23
|
class User < OpenStruct
|
24
|
+
extend ActiveModel::Naming
|
25
|
+
|
20
26
|
# Get rid of deprecation warnings
|
21
27
|
undef_method :id
|
22
28
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: show_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 6
|
10
|
-
version: 0.1.6
|
4
|
+
version: 0.2.0
|
11
5
|
platform: ruby
|
12
6
|
authors:
|
13
7
|
- "Jos\xC3\xA9 Valim"
|
@@ -15,7 +9,7 @@ autorequire:
|
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
11
|
|
18
|
-
date: 2010-
|
12
|
+
date: 2010-02-07 00:00:00 +01:00
|
19
13
|
default_executable:
|
20
14
|
dependencies: []
|
21
15
|
|
@@ -28,10 +22,12 @@ extensions: []
|
|
28
22
|
extra_rdoc_files:
|
29
23
|
- README.rdoc
|
30
24
|
files:
|
31
|
-
- generators/show_for_install/USAGE
|
32
|
-
- generators/show_for_install/show_for_install_generator.rb
|
33
|
-
- generators/show_for_install/templates/show_for.rb
|
34
25
|
- init.rb
|
26
|
+
- lib/generators/show_for_install/USAGE
|
27
|
+
- lib/generators/show_for_install/show_for_install_generator.rb
|
28
|
+
- lib/generators/show_for_install/templates/en.yml
|
29
|
+
- lib/generators/show_for_install/templates/show.html.erb
|
30
|
+
- lib/generators/show_for_install/templates/show_for.rb
|
35
31
|
- lib/show_for.rb
|
36
32
|
- lib/show_for/association.rb
|
37
33
|
- lib/show_for/attribute.rb
|
@@ -39,14 +35,8 @@ files:
|
|
39
35
|
- lib/show_for/content.rb
|
40
36
|
- lib/show_for/helper.rb
|
41
37
|
- lib/show_for/label.rb
|
42
|
-
- lib/show_for/locale/en.yml
|
43
38
|
- lib/show_for/version.rb
|
44
39
|
- README.rdoc
|
45
|
-
- test/builder_test.rb
|
46
|
-
- test/helper_test.rb
|
47
|
-
- test/support/misc_helpers.rb
|
48
|
-
- test/support/models.rb
|
49
|
-
- test/test_helper.rb
|
50
40
|
has_rdoc: true
|
51
41
|
homepage: http://github.com/plataformatec/show_for
|
52
42
|
licenses: []
|
@@ -57,27 +47,21 @@ rdoc_options:
|
|
57
47
|
require_paths:
|
58
48
|
- lib
|
59
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
-
none: false
|
61
50
|
requirements:
|
62
51
|
- - ">="
|
63
52
|
- !ruby/object:Gem::Version
|
64
|
-
hash: 3
|
65
|
-
segments:
|
66
|
-
- 0
|
67
53
|
version: "0"
|
54
|
+
version:
|
68
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
56
|
requirements:
|
71
57
|
- - ">="
|
72
58
|
- !ruby/object:Gem::Version
|
73
|
-
hash: 3
|
74
|
-
segments:
|
75
|
-
- 0
|
76
59
|
version: "0"
|
60
|
+
version:
|
77
61
|
requirements: []
|
78
62
|
|
79
63
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.3.
|
64
|
+
rubygems_version: 1.3.5
|
81
65
|
signing_key:
|
82
66
|
specification_version: 3
|
83
67
|
summary: Wrap your objects with a helper to easily show them
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class ShowForInstallGenerator < Rails::Generator::Base
|
2
|
-
|
3
|
-
def manifest
|
4
|
-
record do |m|
|
5
|
-
m.directory 'config/initializers'
|
6
|
-
m.template 'show_for.rb', 'config/initializers/show_for.rb'
|
7
|
-
|
8
|
-
m.directory 'config/locales'
|
9
|
-
m.template locale_file, 'config/locales/show_for.en.yml'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def locale_file
|
16
|
-
@locale_file ||= '../../../lib/show_for/locale/en.yml'
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|