Skip to content

Commit 54f49d7

Browse files
committed
Added docs for index as blog and updated the docs/ folder
1 parent ae40449 commit 54f49d7

File tree

4 files changed

+151
-29
lines changed

4 files changed

+151
-29
lines changed
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<!-- Please don't edit this file. It will be clobbered. -->
22

3-
Simplest rendering possible. Calls the block for each element in the collection.
3+
# Index as a Block
44

5-
Example:
5+
If you want to fully customize the display of your resources on the index
6+
screen, Index as a Block allows you to render a block of content for each
7+
resource.
68

7-
ActiveAdmin.register Post do
8-
index :as => :block do |post|
9-
# render the post partial (app/views/admin/posts/_post)
10-
render 'post', :post => post
11-
end
12-
end
9+
index :as => :block do |product|
10+
div :for => product do
11+
h2 auto_link(product.title)
12+
div do
13+
simple_format product.description
14+
end
15+
end
16+
end
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
11
<!-- Please don't edit this file. It will be clobbered. -->
22

3+
# Index as Blog
4+
5+
Render your index page as a set of posts. The post has two main options:
6+
title and body.
7+
8+
index :as => :blog do
9+
title :my_title # Calls #my_title on each resource
10+
body :my_body # Calls #my_body on each resource
11+
end
12+
13+
## Post Title
14+
15+
The title is the content that will be rendered within a link to the
16+
resource. There are two main ways to set the content for the title
17+
18+
First, you can pass in a method to be called on your
19+
resource. For example:
20+
21+
index :as => :blog do
22+
title :a_method_to_call
23+
end
24+
25+
This will result in the title of the post being the return value of
26+
#a_method_to_call
27+
28+
Second, you can pass a block to the tile option which will then be
29+
used as the contents fo the title. The resource being rendered
30+
is passed in to the block. For Example:
31+
32+
index :as => :blog do
33+
title do |post|
34+
span post.title, :class => 'title'
35+
span post.created_at, :class => 'created_at'
36+
end
37+
end
38+
39+
## Post Body
40+
41+
The body is rendered underneath the title of each post. The same two
42+
style of options work as the Post Title above.
43+
44+
Call a method on the resource as the body:
45+
46+
index :as => :blog do
47+
title :my_title
48+
body :my_body # Return value of #my_body will be the body
49+
end
50+
51+
Or, render a block as the body:
52+
53+
index :as => :blog do
54+
title :my_title
55+
body do |post|
56+
div truncate(post.title)
57+
div :class => 'meta' do
58+
span "Post in #{post.categories.join(', ')}"
59+
end
60+
end
61+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
11
<!-- Please don't edit this file. It will be clobbered. -->
22

3+
# Index as a Grid
4+
5+
Sometimes you want to display the index screen for a set of resources as a grid
6+
(possibly a grid of thumbnail images). To do so, use the :grid option for the
7+
index block.
8+
9+
index :as => :grid do |product|
10+
link_to(image_tag(product.image_path), admin_products_path(product))
11+
end
12+
13+
The block is rendered within a cell in the grid once for each resource in the
14+
collection. The resource is passed into the block for you to use in the view.
15+
16+
You can customize the number of colums that are rendered using the columns
17+
option:
18+
19+
index :as => :grid, :columns => 5 do |product|
20+
link_to(image_tag(product.image_path), admin_products_path(product))
21+
end

lib/active_admin/views/index_as_blog.rb

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
module ActiveAdmin
22
module Views
3+
4+
# = Index as Blog
5+
#
6+
# Render your index page as a set of posts. The post has two main options:
7+
# title and body.
8+
#
9+
# index :as => :blog do
10+
# title :my_title # Calls #my_title on each resource
11+
# body :my_body # Calls #my_body on each resource
12+
# end
13+
#
14+
# == Post Title
15+
#
16+
# The title is the content that will be rendered within a link to the
17+
# resource. There are two main ways to set the content for the title
18+
#
19+
# First, you can pass in a method to be called on your
20+
# resource. For example:
21+
#
22+
# index :as => :blog do
23+
# title :a_method_to_call
24+
# end
25+
#
26+
# This will result in the title of the post being the return value of
27+
# #a_method_to_call
28+
#
29+
# Second, you can pass a block to the tile option which will then be
30+
# used as the contents fo the title. The resource being rendered
31+
# is passed in to the block. For Example:
32+
#
33+
# index :as => :blog do
34+
# title do |post|
35+
# span post.title, :class => 'title'
36+
# span post.created_at, :class => 'created_at'
37+
# end
38+
# end
39+
#
40+
# == Post Body
41+
#
42+
# The body is rendered underneath the title of each post. The same two
43+
# style of options work as the Post Title above.
44+
#
45+
# Call a method on the resource as the body:
46+
#
47+
# index :as => :blog do
48+
# title :my_title
49+
# body :my_body # Return value of #my_body will be the body
50+
# end
51+
#
52+
# Or, render a block as the body:
53+
#
54+
# index :as => :blog do
55+
# title :my_title
56+
# body do |post|
57+
# div truncate(post.title)
58+
# div :class => 'meta' do
59+
# span "Post in #{post.categories.join(', ')}"
60+
# end
61+
# end
62+
# end
63+
#
364
class IndexAsBlog < ActiveAdmin::Component
465

566
def build(page_config, collection)
@@ -14,16 +75,6 @@ def build(page_config, collection)
1475
end
1576

1677
# Setter method for the configuration of the title
17-
#
18-
# index :as => :blog do
19-
# title :a_method_to_call #=> Calls #a_method_to_call on the resource
20-
#
21-
# # OR
22-
#
23-
# title do |post|
24-
# post.a_method_to_call
25-
# end
26-
# end
2778
def title(method = nil, &block)
2879
if block_given? || method
2980
@title = block_given? ? block : method
@@ -33,17 +84,6 @@ def title(method = nil, &block)
3384

3485
# Setter method for the configuration of the body
3586
#
36-
# index :as => :blog do
37-
# title :my_title
38-
#
39-
# body :a_method_to_call #=> Calls #a_method_to_call on the resource
40-
#
41-
# # OR
42-
#
43-
# title do |post|
44-
# post.a_method_to_call
45-
# end
46-
# end
4787
def body(method = nil, &block)
4888
if block_given? || method
4989
@body = block_given? ? block : method

0 commit comments

Comments
 (0)