simple_admin 0.4.1 → 0.5.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.
@@ -8,5 +8,6 @@ module SimpleAdmin
8
8
  include SimpleAdmin::SidebarHelper
9
9
  include SimpleAdmin::PathHelper
10
10
  include SimpleAdmin::AssetsHelper
11
+ include SimpleAdmin::FormHelper
11
12
  end
12
13
  end
@@ -0,0 +1,25 @@
1
+ module SimpleAdmin
2
+ module FormHelper
3
+ def form_fields(form, attributes)
4
+ attributes.map do |col|
5
+ case col.kind
6
+ when :attribute
7
+ form.input col.attribute, (col.options || {}).dup
8
+ when :content
9
+ instance_exec(@resource, &col.data)
10
+ when :fieldset
11
+ content_tag :fieldset, col.options do
12
+ content_tag :legend do
13
+ col.options[:legend]
14
+ end unless col.options[:legend].blank
15
+ form_fields(form, col.attributes)
16
+ end
17
+ else
18
+ content_tag :div, col.options do
19
+ form_fields(form, col.attributes)
20
+ end
21
+ end
22
+ end.join.html_safe
23
+ end
24
+ end
25
+ end
@@ -2,9 +2,7 @@
2
2
  :url => resource_path(@resource), :html => {:class => "simple_form formtastic #{@interface.member}"}) do |form| %>
3
3
  <fieldset class="inputs">
4
4
  <ol>
5
- <% @interface.attributes_for(:form).each do |col| %>
6
- <%= form.input col.attribute, col.options.dup %>
7
- <% end %>
5
+ <%= form_fields(form, @interface.attributes_for(:form)) %>
8
6
  </ol>
9
7
  </fieldset>
10
8
  <fieldset class="buttons">
@@ -1,7 +1,9 @@
1
- <% content_for :content do %>
2
- <% render :partial => 'form' %>
3
- <% end %>
1
+ <div class="simple_admin_edit">
2
+ <% content_for :content do %>
3
+ <% render :partial => 'form' %>
4
+ <% end %>
4
5
 
5
- <% content_for :sidebar do %>
6
- <%= sidebars %>
7
- <% end %>
6
+ <% content_for :sidebar do %>
7
+ <%= sidebars %>
8
+ <% end %>
9
+ </div>
@@ -1,3 +1,4 @@
1
+ <div class="simple_admin_index">
1
2
  <% content_for :content do %>
2
3
  <div class="paginated_collection">
3
4
  <div class="pagination_information">
@@ -80,3 +81,4 @@
80
81
 
81
82
  <%= sidebars %>
82
83
  <% end %>
84
+ </div>
@@ -1,7 +1,9 @@
1
- <% content_for :content do %>
2
- <% render :partial => 'form' %>
3
- <% end %>
1
+ <div class="simple_admin_new">
2
+ <% content_for :content do %>
3
+ <% render :partial => 'form' %>
4
+ <% end %>
4
5
 
5
- <% content_for :sidebar do %>
6
- <%= sidebars %>
7
- <% end %>
6
+ <% content_for :sidebar do %>
7
+ <%= sidebars %>
8
+ <% end %>
9
+ </div>
@@ -1,22 +1,24 @@
1
- <% content_for :content do %>
2
- <div class="panel">
3
- <h3><%= @interface.member.titleize %> Details</h3>
4
- <div class="panel_contents">
5
- <div class="<%= @interface.member %> attributes_table"
6
- id="<%= ['attributes_table', @interface.member, @resource.to_param].join("_") %>">
7
- <table border="0" cellspacing="0" cellpadding="0">
8
- <% @interface.attributes_for(:show).each do |attr| %>
9
- <tr>
10
- <th><%= attr.title %></th>
11
- <td><%= data_for(attr) %></td>
12
- </tr>
13
- <% end %>
14
- </table>
1
+ <div class="simple_admin_show">
2
+ <% content_for :content do %>
3
+ <div class="panel">
4
+ <h3><%= @interface.member.titleize %> Details</h3>
5
+ <div class="panel_contents">
6
+ <div class="<%= @interface.member %> attributes_table"
7
+ id="<%= ['attributes_table', @interface.member, @resource.to_param].join("_") %>">
8
+ <table border="0" cellspacing="0" cellpadding="0">
9
+ <% @interface.attributes_for(:show).each do |attr| %>
10
+ <tr>
11
+ <th><%= attr.title %></th>
12
+ <td><%= data_for(attr) %></td>
13
+ </tr>
14
+ <% end %>
15
+ </table>
16
+ </div>
15
17
  </div>
16
18
  </div>
17
- </div>
18
- <% end %>
19
+ <% end %>
19
20
 
20
- <% content_for :sidebar do %>
21
- <%= sidebars %>
22
- <% end %>
21
+ <% content_for :sidebar do %>
22
+ <%= sidebars %>
23
+ <% end %>
24
+ </div>
@@ -32,12 +32,13 @@ module SimpleAdmin
32
32
  # :sortable +true+ or +false+ (defaults to +true+)
33
33
  # :sort_key a column name used when sorting this column (defaults to the column for this attribute)
34
34
  #
35
- def attribute(name, options={}, &block)
35
+ def attribute(name, options={}, &block)
36
36
  attr = @attributes.find {|attr| attr.attribute == name.to_sym }
37
37
  unless attr
38
38
  attr = OpenStruct.new
39
39
  @attributes << attr
40
40
  end
41
+ attr.kind = :attribute
41
42
  attr.attribute = name.to_sym
42
43
  attr.options = options
43
44
  attr.data = block
@@ -47,6 +48,48 @@ module SimpleAdmin
47
48
  attr
48
49
  end
49
50
 
51
+ # Include rendered content inline.
52
+ #
53
+ # This is only used when displaying a form.
54
+ #
55
+ def content(options={}, &block)
56
+ cont = OpenStruct.new
57
+ @attributes << cont
58
+ cont.kind = :content
59
+ cont.options = options
60
+ cont.data = block
61
+ cont
62
+ end
63
+
64
+ # Create a section which may or may not contain sub-sections.
65
+ #
66
+ # Note: this works better if you first clear the attributes. For example:
67
+ #
68
+ # attributes do
69
+ # clear
70
+ # section :kind => :fieldset, :legend => "Primary Address" do
71
+ # attribute :address
72
+ # section :class => 'csz' do
73
+ # attribute :city
74
+ # attribute :state
75
+ # attribute :zip
76
+ # end
77
+ # end
78
+ # end
79
+ def section(options={}, &block)
80
+ sect = OpenStruct.new
81
+ @attributes << sect
82
+ sect.kind = options.delete(:kind) || :section
83
+ sect.options = options
84
+ sect.attributes = []
85
+ save_attributes = @attributes
86
+ @attributes = sect.attributes
87
+ instance_eval(&block) if block_given?
88
+ @attributes = save_attributes
89
+ sect
90
+ end
91
+
92
+
50
93
  # Define the default attributes for this section
51
94
  #
52
95
  # If the current section is a form it will only use content columns and will
@@ -1,3 +1,3 @@
1
1
  module SimpleAdmin
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -102,5 +102,57 @@ describe SimpleAdmin::Attributes do
102
102
  @attributes.attributes.map(&:title).should == ["Your Name Here"]
103
103
  end
104
104
  end
105
+
106
+ describe "section" do
107
+ it "creates a section" do
108
+ @attributes.clear
109
+ @attributes.section :class => 'bang'
110
+ @attributes.attributes.map {|att|
111
+ att.attributes.should == []
112
+ att.kind.should == :section
113
+ att.options.should == {:class => 'bang'}
114
+ }
115
+ end
116
+
117
+ it "contains attributes" do
118
+ @attributes.clear
119
+ @attributes.section :class => 'bang' do
120
+ attribute :name, :title => "Your Name Here"
121
+ end
122
+ @attributes.attributes.map {|att|
123
+ att.attributes.map(&:title).should == ["Your Name Here"]
124
+ }
125
+ end
126
+
127
+ it "contains sections" do
128
+ @attributes.clear
129
+ @attributes.section :class => 'bang' do
130
+ section :class => 'bleep' do
131
+ attribute :name, :title => "Your Name Here"
132
+ end
133
+ end
134
+ @attributes.attributes.map {|att|
135
+ att.attributes.map {|sec|
136
+ sec.attributes.map(&:title).should == ["Your Name Here"]
137
+ }
138
+ }
139
+ end
140
+
141
+ end
142
+
143
+ describe "content" do
144
+ it "creates content" do
145
+ SimpleAdmin::Attributes.expects(:fail).never
146
+ @attributes.clear
147
+ @attributes.content(:class => 'bang') do
148
+ SimpleAdmin::Attributes.fail
149
+ end
150
+ @attributes.attributes.map {|att|
151
+ att.data.should_not be_nil
152
+ att.kind.should == :content
153
+ att.options.should == {:class => 'bang'}
154
+ }
155
+ end
156
+ end
105
157
  end
106
158
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_admin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeff Rafter
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-11 00:00:00 -07:00
18
+ date: 2011-08-13 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -200,6 +200,7 @@ files:
200
200
  - app/helpers/simple_admin/assets_helper.rb
201
201
  - app/helpers/simple_admin/display_helper.rb
202
202
  - app/helpers/simple_admin/filter_helper.rb
203
+ - app/helpers/simple_admin/form_helper.rb
203
204
  - app/helpers/simple_admin/header_helper.rb
204
205
  - app/helpers/simple_admin/path_helper.rb
205
206
  - app/helpers/simple_admin/sidebar_helper.rb