Skip to content

Commit

Permalink
Add show view and update markups
Browse files Browse the repository at this point in the history
  • Loading branch information
holysugar committed Apr 16, 2012
1 parent 1398778 commit 16aa1b8
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 33 deletions.
10 changes: 7 additions & 3 deletions app/decorators/item_decorator.rb
Expand Up @@ -3,15 +3,19 @@
module ItemDecorator
include AutocrudAttrs

autocrud_attrs_for :form, [:name, :price]
#autocrud_attrs_for :form, [:name, :price]
autocrud_attrs_for :index, [:id, :enabled, :name, :price, :description_length]
#autocrud_attrs_for :index, proc{ attribute_names.map(&:to_sym) }
autocrud_attrs_for :show, proc{ attribute_names.map(&:to_sym) }

autocrud_attrs_for :show, [:id, :enabled, :name, :price, :description_pre, :created_at, :updated_at]
#autocrud_attrs_for :show, proc{ attribute_names.map(&:to_sym) + [:description_length] }

def description_length
description.length
end

def description_pre
content_tag(:pre, description)
end

end

11 changes: 10 additions & 1 deletion app/helpers/resource_templates_helper.rb
Expand Up @@ -8,7 +8,6 @@ def resources_index(resources, options = {}, &block)
resource = resources.first
attrs = calculate_attrs(resource, options, :index)
if resources.present?
resource_class = resource.class
render 'resources_index', options.reverse_merge(
:resources => resources, :resource_class => resource.class,
:attrs => attrs
Expand All @@ -18,6 +17,16 @@ def resources_index(resources, options = {}, &block)
end
end

def resource_show(resource, options = {}, &block)
attrs = calculate_attrs(resource, options, :show)
resource_class = resource.class
render 'autocrud_show', options.reverse_merge(
:resource => resource, :resource_class => resource.class,
:attrs => attrs
)
end


private
def calculate_attrs(resource, options, default_autocrud)
attrs = options[:attrs]
Expand Down
8 changes: 8 additions & 0 deletions app/views/application/_autocrud_show.html.haml
@@ -0,0 +1,8 @@

%table.table.table-bordered.table-striped
%tbody
- attrs.each do |key|
%tr
%th= resource_class.human_attribute_name(key)
%td= resource.send(key)

2 changes: 1 addition & 1 deletion app/views/application/_resource_form.html.haml
@@ -1,3 +1,3 @@
= semantic_form_for resource, :url => url, :builder => builder do |f|
= semantic_form_for resource, :url => url, :html => {:class => "form-horizontal"}, :builder => builder do |f|
= f.inputs(*attrs)
= f.actions
11 changes: 5 additions & 6 deletions app/views/items/edit.html.haml
@@ -1,7 +1,6 @@
%h1 Editing item
= resource_form @item

= render 'form'

= link_to 'Show', @item
\|
= link_to 'Back', items_path
%footer.footer
= link_to 'Show', @item
\|
= link_to 'Back', items_path
2 changes: 0 additions & 2 deletions app/views/items/index.html.haml
@@ -1,5 +1,3 @@
%h1 Listing items

= resources_index @items

= link_to 'New Item', new_item_path
2 changes: 0 additions & 2 deletions app/views/items/new.html.haml
@@ -1,5 +1,3 @@
%h1 New item

= resource_form @item

= link_to 'Back', items_path
17 changes: 1 addition & 16 deletions app/views/items/show.html.haml
@@ -1,20 +1,5 @@
%p#notice= notice

%p
%b Name:
= @item.name
%p
%b Price:
= @item.price
%p
%b Description:
= @item.description
%p
%b Kind:
= @item.kind
%p
%b Enabled:
= @item.enabled
= resource_show @item

= link_to 'Edit', edit_item_path(@item)
\|
Expand Down
6 changes: 4 additions & 2 deletions app/views/layouts/application.html.haml
Expand Up @@ -28,7 +28,9 @@
.well.sidebar-nav
= render 'sidebar'
.span9
.page-header
%h1= page_title :format => false
= yield
%footer
%p © COPY-NAME-FIXME, 2012
%footer.footer
%p.pull-right © COPY-NAME-FIXME, 2012
= javascript_include_tag "application"

0 comments on commit 16aa1b8

Please sign in to comment.