Skip to content
Browse files

Refactored the new and edit pages to use arb templates

  • Loading branch information...
1 parent a9a3804 commit e97472385fa3fa99b447e01606d49b35169607ad @gregbell gregbell committed May 3, 2011
View
77 features/edit_page.feature
@@ -0,0 +1,77 @@
+Feature: Edit Page
+
+ Customizing the form to edit resources
+
+ Background:
+ Given a category named "Music" exists
+ And a user named "John Doe" exists
+ And a post with the title "Hello World" written by "John Doe" exists
+ And I am logged in
+ Given a configuration of:
+ """
+ ActiveAdmin.register Post
+ """
+ When I am on the index page for posts
+
+ Scenario: Default form with no config
+ Given I follow "Edit"
+ Then the "Title" field should contain "Hello World"
+ And the "Body" field should contain ""
+ And the "Category" field should contain ""
+ And the "Author" field should contain "John Doe"
+ When I fill in "Title" with "Hello World from update"
+ When I press "Update Post"
+ Then I should see "Post was successfully updated."
+ And I should see the attribute "Title" with "Hello World from update"
+ And I should see the attribute "Author" with "John Doe"
+
+ Scenario: Generating a custom form
+ Given a configuration of:
+ """
+ ActiveAdmin.register Post do
+ form do |f|
+ f.inputs "Your Post" do
+ f.input :title
+ f.input :body
+ end
+ f.inputs "Publishing" do
+ f.input :published_at
+ end
+ f.buttons
+ end
+ end
+ """
+ Given I follow "Edit"
+ Then I should see a fieldset titled "Your Post"
+ And I should see a fieldset titled "Publishing"
+ And the "Title" field should contain "Hello World"
+ And the "Body" field should contain ""
+ When I fill in "Title" with "Hello World from update"
+ When I press "Update Post"
+ Then I should see "Post was successfully updated."
+ And I should see the attribute "Title" with "Hello World from update"
+ And I should see the attribute "Author" with "John Doe"
+
+ Scenario: Generating a form from a partial
+ Given "app/views/admin/posts/_form.html.erb" contains:
+ """
+ <% url = @post.new_record? ? admin_posts_path : admin_post_path(@post) %>
+ <%= active_admin_form_for @post, :url => url do |f|
+ f.inputs :title, :body
+ f.buttons
+ end %>
+ """
+ Given a configuration of:
+ """
+ ActiveAdmin.register Post do
+ form :partial => "form"
+ end
+ """
+ Given I follow "Edit"
+ Then the "Title" field should contain "Hello World"
+ And the "Body" field should contain ""
+ When I fill in "Title" with "Hello World from update"
+ When I press "Update Post"
+ Then I should see "Post was successfully updated."
+ And I should see the attribute "Title" with "Hello World from update"
+ And I should see the attribute "Author" with "John Doe"
View
3 features/new_page.feature
@@ -54,7 +54,8 @@ Feature: New Page
Scenario: Generating a form from a partial
Given "app/views/admin/posts/_form.html.erb" contains:
"""
- <%= active_admin_form_for @post, :url => admin_posts_path do |f|
+ <% url = @post.new_record? ? admin_posts_path : admin_post_path(@post) %>
+ <%= active_admin_form_for @post, :url => url do |f|
f.inputs :title, :body
f.buttons
end %>
View
2 lib/active_admin/arbre.rb
@@ -19,5 +19,5 @@ module Arbre
require 'action_view'
ActionView::Template.register_template_handler :arb, lambda { |template|
- "self.class.send :include, Arbre::HTML; #{template.source}; current_dom_context"
+ "self.class.send :include, Arbre::HTML; @_helpers = self; #{template.source}; current_dom_context"
}
View
1 lib/active_admin/view_helpers.rb
@@ -16,7 +16,6 @@ module ViewHelpers
include StatusTagHelper
include FilterFormHelper
include TitleHelper
- include FlashMessageHelper
include ViewFactoryHelper
end
View
17 lib/active_admin/view_helpers/flash_message_helper.rb
@@ -1,17 +0,0 @@
-module ActiveAdmin
- module ViewHelpers
- module FlashMessageHelper
-
- def flash_messages
- if flash.keys.any?
- content_tag :div, :class => 'flashes' do
- flash.collect do |type, message|
- content_tag :div, message, :class => "flash flash_#{type}"
- end.join.html_safe
- end
- end
- end
-
- end
- end
-end
View
11 lib/active_admin/views/base_page.rb
@@ -54,11 +54,22 @@ def build_page_content
# TODO: Skip sidebar
div :id => "content", :class => "with_sidebar" do
# TODO: FLash Messages
+ build_flash_messages
build_main_content_wrapper
build_sidebar
end
end
+ def build_flash_messages
+ if flash.keys.any?
+ div :class => 'flashes' do
+ flash.each do |type, message|
+ div message, :class => "flash flash_#{type}"
+ end
+ end
+ end
+ end
+
def build_main_content_wrapper
div :id => "main_content_wrapper" do
div :id => "main_content" do
View
7 lib/active_admin/views/new_page.rb
@@ -7,19 +7,20 @@ def title
end
def main_content
+ p "Building main content"
config = self.form_config.dup
config.delete(:block)
config.reverse_merge!({
:url => collection_path
})
if form_config[:partial]
- render form_config[:partial]
+ text_node render(form_config[:partial])
else
- active_admin_form_for resource, config, &form_config[:block]
+ text_node active_admin_form_for(resource, config, &form_config[:block])
end
end
- end
+ end
end
end
View
1 lib/active_admin/views/show_page.rb
@@ -24,7 +24,6 @@ def main_content
else
default_main_content
end
- current_dom_context.document.content
end
def attributes_table(*args, &block)
View
1 lib/active_admin/views/templates/active_admin_default/edit.html.arb
@@ -0,0 +1 @@
+render renderer_for(:edit)
View
1 lib/active_admin/views/templates/active_admin_default/edit.html.erb
@@ -1 +0,0 @@
-<%= renderer_for(:edit).new(self).to_html %>
View
1 lib/active_admin/views/templates/active_admin_default/index.html.arb
@@ -1,2 +1 @@
-@_helpers = self
render renderer_for(:index)
View
1 lib/active_admin/views/templates/active_admin_default/new.html.arb
@@ -0,0 +1 @@
+render renderer_for(:new)
View
1 lib/active_admin/views/templates/active_admin_default/new.html.erb
@@ -1 +0,0 @@
-<%= renderer_for(:new).new(self).to_html %>
View
1 lib/active_admin/views/templates/active_admin_default/show.html.arb
@@ -0,0 +1 @@
+render renderer_for(:show)
View
1 lib/active_admin/views/templates/active_admin_default/show.html.erb
@@ -1 +0,0 @@
-<%= renderer_for(:show).new(self).to_html %>
View
2 lib/active_admin/views/templates/layouts/active_admin_logged_out.html.erb
@@ -14,7 +14,7 @@
<div id="wrapper">
<div id="content_wrapper">
- <%= flash_messages %>
+ <% #flash_messages %>
<div id="content">
<%= yield %>
</div>

0 comments on commit e974723

Please sign in to comment.
Something went wrong with that request. Please try again.