dobro 0.1.0alpha3 → 0.1.0alpha4

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,7 +28,9 @@ Before you get too carried away though, you'll almost certainly want to edit the
28
28
 
29
29
  h2. Usage
30
30
 
31
- If you'd like to customise the views, just put your versions in @app/views/dobro@, broken down by resources. For example, a custom edit view for users would end up in @app/views/dobro/users/edit.html.erb@.
31
+ Customising the @_form.html.erb@ and @_show.html.erb@ partials for each of your resources is highly recommended. You can also add a @_dashboard.html.erb@, which will show up on resource indices.
32
+
33
+ It's not recommended, but you're also welcome to customise the views. Just put your versions in @app/views/dobro@, broken down by resources. For example, a custom edit view for users would end up in @app/views/dobro/users/edit.html.erb@.
32
34
 
33
35
  The standard set of views for Dobro includes:
34
36
 
@@ -38,11 +40,6 @@ The standard set of views for Dobro includes:
38
40
  * edit
39
41
  * delete
40
42
 
41
- Generally it's not recommended you edit those though - best to stick to the partials:
42
-
43
- * _form (used by both new and edit views)
44
- * _show (used by the show view)
45
-
46
43
  And perhaps you want to add custom controllers into the mix? That's easy too. For the relevant resources, just give them their own @dobro_for@ call, and specify the custom controller:
47
44
 
48
45
  <pre><code>dobro_for :pages, :controller => 'pages'</code></pre>
@@ -1,10 +1,11 @@
1
1
  class Dobro::ApplicationController < Dobro.controller_base
2
2
  layout 'dobro'
3
+ helper :dobro
3
4
 
4
- expose(:resource) { default_resource.to_sym }
5
+ expose(:resource) { Dobro.resources[default_resource.to_sym] }
5
6
  expose(:singular_class) { singular_reference.capitalize.constantize }
6
- expose(:plural_class) { resource.to_s.capitalize }
7
- expose(:singular_reference) { resource.to_s.singularize }
7
+ expose(:plural_class) { resource.reference.to_s.capitalize }
8
+ expose(:singular_reference) { resource.reference.to_s.singularize }
8
9
  expose(:records) { singular_class.all }
9
10
  expose(:current_record) {
10
11
  if params[:id]
@@ -18,7 +19,7 @@ class Dobro::ApplicationController < Dobro.controller_base
18
19
 
19
20
  def create
20
21
  if current_record.save
21
- redirect_to current_record
22
+ redirect_to resource.route_for(current_record)
22
23
  else
23
24
  render 'new'
24
25
  end
@@ -26,7 +27,7 @@ class Dobro::ApplicationController < Dobro.controller_base
26
27
 
27
28
  def update
28
29
  if current_record.update_attributes(params[singular_reference])
29
- redirect_to current_record
30
+ redirect_to resource.route_for(current_record)
30
31
  else
31
32
  render 'edit'
32
33
  end
@@ -34,13 +35,13 @@ class Dobro::ApplicationController < Dobro.controller_base
34
35
 
35
36
  def destroy
36
37
  current_record.destroy
37
- redirect_to resource
38
+ redirect_to resource.index_route
38
39
  end
39
40
 
40
41
  private
41
42
 
42
43
  def default_resource
43
- params[:resource] || Dobro.resources.first
44
+ params[:resource] || Dobro.resources.keys.first
44
45
  end
45
46
 
46
47
  def prepend_view_paths
@@ -0,0 +1,29 @@
1
+ module DobroHelper
2
+ def standard_dobro_columns
3
+ singular_class.columns.select { |column|
4
+ !hidden_dobro_column_names.include?(column.name.to_s)
5
+ }
6
+ end
7
+
8
+ def dobro_field_for(form, column)
9
+ column_name = column.name.to_sym
10
+ case column.type.to_sym
11
+ when :integer
12
+ form.text_field column_name, :class => 'integer'
13
+ when :date
14
+ form.text_field column_name, :placeholder => 'yyyy-mm-dd'
15
+ when :text
16
+ form.text_area column_name
17
+ when :boolean
18
+ form.check_box column_name
19
+ else
20
+ form.text_field column_name
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def hidden_dobro_column_names
27
+ %w( id created_at updated_at )
28
+ end
29
+ end
@@ -1,14 +1,12 @@
1
- <%= form_for current_record do |f| %>
1
+ <%= form_for resource.route_for(current_record) do |f| %>
2
2
  <fieldset>
3
- <% singular_class.column_names.each do |column| %>
4
- <p>
5
- <%= f.label column.to_sym %>
6
- <%= f.text_field column.to_sym %>
7
- </p>
3
+ <% standard_dobro_columns.each do |column| %>
4
+ <%= f.label column.name.to_sym %>
5
+ <%= dobro_field_for f, column %>
8
6
  <% end %>
9
7
  </fieldset>
10
8
 
11
- <fieldset>
9
+ <fieldset class="buttons">
12
10
  <%= f.submit "Save #{singular_class}" %>
13
11
  </fieldset>
14
12
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= form_for current_record, :html => {:method => :delete} do |f| %>
1
+ <%= form_for resource.route_for(current_record), :html => {:method => :delete} do |f| %>
2
2
  <p>Are you sure you want to delete this record? This cannot be undone.</p>
3
3
 
4
4
  <%= f.submit 'Confirm' %>
@@ -0,0 +1 @@
1
+ <%= render :partial => 'dashboard' %>
@@ -4,10 +4,10 @@
4
4
  <nav>
5
5
  <ul>
6
6
  <li>
7
- <%= link_to 'Edit', [:edit, current_record], :class => 'edit' %>
7
+ <%= link_to 'Edit', resource.route_for(:edit, current_record), :class => 'edit' %>
8
8
  </li>
9
9
  <li>
10
- <%= link_to 'Delete', [:delete, current_record], :class => 'cancel' %>
10
+ <%= link_to 'Delete', resource.route_for(:delete, current_record), :class => 'cancel' %>
11
11
  </li>
12
12
  </ul>
13
13
  </nav>
@@ -18,10 +18,10 @@
18
18
  </header>
19
19
 
20
20
  <ul class="records">
21
- <% Dobro.resources.each do |res| %>
21
+ <% Dobro.resources.each do |reference, res| %>
22
22
  <li class="record">
23
- <%= link_to res, :class => (resource == res && 'selected') do %>
24
- <h4><%= res.to_s.titleize %></h4>
23
+ <%= link_to res.index_route, :class => (resource.reference == reference && 'selected') do %>
24
+ <h4><%= reference.to_s.titleize %></h4>
25
25
  <% end %>
26
26
  </li>
27
27
  <% end %>
@@ -33,14 +33,14 @@
33
33
  <h3><%= plural_class.titleize %></h3>
34
34
  <nav>
35
35
  <ul>
36
- <li><%= link_to "New #{singular_class}", [:new, singular_reference.to_sym], :class => 'new' %></li>
36
+ <li><%= link_to "New #{singular_class}", resource.route_for(:new, singular_reference.to_sym), :class => 'new' %></li>
37
37
  </ul>
38
38
  </nav>
39
39
  </header>
40
40
 
41
41
  <ul class="records">
42
42
  <% records.each do |record| %>
43
- <li class="record"><h5><%= link_to record.identifier, record %></h5></li>
43
+ <li class="record"><h5><%= link_to record.identifier, resource.route_for(record), :class => (current_record.present? && current_record == record && 'selected')%></h5></li>
44
44
  <% end %>
45
45
  </ul>
46
46
  </section>
@@ -3,7 +3,7 @@ require 'action_controller'
3
3
  require 'decent_exposure'
4
4
 
5
5
  module Dobro
6
- @resources = []
6
+ @resources = {}
7
7
  def self.resources
8
8
  @resources
9
9
  end
@@ -20,5 +20,6 @@ end
20
20
 
21
21
  require 'dobro/engine'
22
22
  require 'dobro/file_system_resolver'
23
+ require 'dobro/resource'
23
24
  require 'dobro/routes'
24
25
  require 'dobro/version'
@@ -8,7 +8,7 @@ class Dobro::FileSystemResolver < ActionView::FileSystemResolver
8
8
  end
9
9
 
10
10
  def find_templates(name, prefix, partial, details)
11
- prefix = "dobro/#{resource}" if prefix == 'dobro/application'
11
+ prefix = "dobro/#{resource.reference}" if prefix == 'dobro/application'
12
12
  super name, prefix, partial, details
13
13
  end
14
14
  end
@@ -0,0 +1,22 @@
1
+ class Dobro::Resource
2
+ attr_accessor :reference, :options
3
+
4
+ def initialize(reference, options = {})
5
+ @reference, @options = reference, options
6
+ end
7
+
8
+ def index_route
9
+ [namespace, reference].compact
10
+ end
11
+
12
+ def route_for(action, object = nil)
13
+ action, object = nil, action if object.nil?
14
+ [action, namespace, object].compact
15
+ end
16
+
17
+ private
18
+
19
+ def namespace
20
+ options[:namespace]
21
+ end
22
+ end
@@ -1,15 +1,19 @@
1
1
  class ActionDispatch::Routing::Mapper
2
2
  def dobro_for(*resources)
3
3
  options = resources.extract_options!
4
+ outer_module, @scope[:module] = @scope[:module], nil
4
5
 
5
6
  resources.each do |res|
6
- Dobro.resources << res
7
+
8
+ Dobro.resources[res] = Dobro::Resource.new res, :namespace => @scope[:as]
7
9
 
8
10
  self.resources res, dobro_options_for(res).merge(options) do
9
11
  member { get :delete }
10
12
  yield if block_given?
11
13
  end
12
14
  end
15
+
16
+ @scope[:module] = outer_module
13
17
  end
14
18
 
15
19
  private
@@ -1,3 +1,3 @@
1
1
  module Dobro
2
- VERSION = '0.1.0alpha3'
2
+ VERSION = '0.1.0alpha4'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'custom views', :driver => :rack_test do
3
+ describe 'custom views' do
4
4
  before :each do
5
5
  Widget.create! :name => 'Thing'
6
6
  end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'namespaced views' do
4
+ before :each do
5
+ Author.create :name => 'Neil Gaiman'
6
+ Author.create :name => 'Terry Pratchett'
7
+ end
8
+
9
+ it "lists the pages" do
10
+ visit admin_authors_path
11
+
12
+ page.should have_content('Authors')
13
+ page.should have_content('Neil Gaiman')
14
+ page.should have_content('Terry Pratchett')
15
+ end
16
+
17
+ it "creates a new page" do
18
+ visit admin_authors_path
19
+
20
+ click_link 'New Author'
21
+
22
+ fill_in 'Name', :with => 'Haruki Murakami'
23
+ click_button 'Save Author'
24
+
25
+ page.should have_content('Haruki Murakami')
26
+ end
27
+
28
+ it "edits an existing page" do
29
+ visit admin_authors_path
30
+
31
+ click_link 'Neil Gaiman'
32
+ click_link 'Edit'
33
+
34
+ fill_in 'Name', :with => 'China Mieville'
35
+ click_button 'Save Author'
36
+
37
+ page.should have_content('China Mieville')
38
+ page.should have_no_content('Neil Gaiman')
39
+ end
40
+
41
+ it "deletes pages" do
42
+ visit admin_authors_path
43
+
44
+ click_link 'Neil Gaiman'
45
+ click_link 'Delete'
46
+ click_button 'Confirm'
47
+
48
+ page.should have_content('Terry Pratchett')
49
+ page.should have_no_content('Neil Gaiman')
50
+ end
51
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'scoped views' do
4
+ before :each do
5
+ Link.create :title => 'XKCD', :url => 'http://xkcd.com'
6
+ Link.create :title => 'Big Picture', :url => 'http://boston.com/bigpicture/'
7
+ end
8
+
9
+ it "lists the pages" do
10
+ visit my_links_path
11
+
12
+ page.should have_content('Links')
13
+ page.should have_content('XKCD')
14
+ page.should have_content('Big Picture')
15
+ end
16
+
17
+ it "creates a new page" do
18
+ visit my_links_path
19
+
20
+ click_link 'New Link'
21
+
22
+ fill_in 'Title', :with => 'Github'
23
+ fill_in 'Url', :with => 'http://github.com'
24
+ click_button 'Save Link'
25
+
26
+ page.should have_content('Github')
27
+ end
28
+
29
+ it "edits an existing page" do
30
+ visit my_links_path
31
+
32
+ click_link 'Big Picture'
33
+ click_link 'Edit'
34
+
35
+ fill_in 'Title', :with => 'Boston Herald'
36
+ click_button 'Save Link'
37
+
38
+ page.should have_content('Boston Herald')
39
+ page.should have_no_content('Big Picture')
40
+ end
41
+
42
+ it "deletes pages" do
43
+ visit my_links_path
44
+
45
+ click_link 'Big Picture'
46
+ click_link 'Delete'
47
+ click_button 'Confirm'
48
+
49
+ page.should have_content('XKCD')
50
+ page.should have_no_content('Big Picture')
51
+ end
52
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'standard setup', :driver => :rack_test do
3
+ describe 'standard setup' do
4
4
  before :each do
5
5
  Page.create :name => 'About Us', :content => 'All you need to know'
6
6
  Page.create :name => 'FAQ', :content => 'All you need to ask'
@@ -0,0 +1,5 @@
1
+ class Author < ActiveRecord::Base
2
+ def identifier
3
+ name
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Link < ActiveRecord::Base
2
+ def identifier
3
+ title
4
+ end
5
+ end
@@ -6,7 +6,7 @@
6
6
  </p>
7
7
  </fieldset>
8
8
 
9
- <fieldset>
9
+ <fieldset class="buttons">
10
10
  <%= f.submit "Save This Widget" %>
11
11
  </fieldset>
12
12
  <% end %>
@@ -8,4 +8,12 @@ Rails.application.routes.draw do
8
8
  put :approve
9
9
  end
10
10
  end
11
+
12
+ namespace :admin do
13
+ dobro_for :authors
14
+ end
15
+
16
+ scope 'my', :as => 'my' do
17
+ dobro_for :links
18
+ end
11
19
  end
@@ -1,4 +1,15 @@
1
1
  ActiveRecord::Schema.define do
2
+ create_table(:authors, :force => true) do |t|
3
+ t.string :name
4
+ t.timestamps
5
+ end
6
+
7
+ create_table(:links, :force => true) do |t|
8
+ t.string :title
9
+ t.string :url
10
+ t.timestamps
11
+ end
12
+
2
13
  create_table(:pages, :force => true) do |t|
3
14
  t.string :name
4
15
  t.text :content
@@ -8,6 +19,7 @@ ActiveRecord::Schema.define do
8
19
  create_table(:tasks, :force => true) do |t|
9
20
  t.string :description
10
21
  t.boolean :approved
22
+ t.timestamps
11
23
  end
12
24
 
13
25
  create_table(:widgets, :force => true) do |t|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dobro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0alpha3
4
+ version: 0.1.0alpha4
5
5
  prerelease: 5
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-08-25 00:00:00.000000000Z
14
+ date: 2011-08-28 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
18
- requirement: &70338764799960 !ruby/object:Gem::Requirement
18
+ requirement: &70268690516720 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 3.1.0rc1
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70338764799960
26
+ version_requirements: *70268690516720
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: decent_exposure
29
- requirement: &70338764799460 !ruby/object:Gem::Requirement
29
+ requirement: &70268690513540 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '1.0'
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70338764799460
37
+ version_requirements: *70268690513540
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: sass-rails
40
- requirement: &70338764798960 !ruby/object:Gem::Requirement
40
+ requirement: &70268690511680 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: 3.1.0.rc
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *70338764798960
48
+ version_requirements: *70268690511680
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rspec-rails
51
- requirement: &70338764798460 !ruby/object:Gem::Requirement
51
+ requirement: &70268690510640 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ~>
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: 2.6.1
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *70338764798460
59
+ version_requirements: *70268690510640
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: capybara
62
- requirement: &70338764797960 !ruby/object:Gem::Requirement
62
+ requirement: &70268690509420 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ~>
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: 1.0.0
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *70338764797960
70
+ version_requirements: *70268690509420
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: combustion
73
- requirement: &70338764797500 !ruby/object:Gem::Requirement
73
+ requirement: &70268690507540 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ~>
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: 0.1.1
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *70338764797500
81
+ version_requirements: *70268690507540
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: sqlite3
84
- requirement: &70338764797020 !ruby/object:Gem::Requirement
84
+ requirement: &70268690505100 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ~>
@@ -89,7 +89,7 @@ dependencies:
89
89
  version: 1.3.4
90
90
  type: :development
91
91
  prerelease: false
92
- version_requirements: *70338764797020
92
+ version_requirements: *70268690505100
93
93
  description: A Rails Engine that provides a simple yet effective interface, perfect
94
94
  for admin management.
95
95
  email:
@@ -115,6 +115,8 @@ files:
115
115
  - app/assets/stylesheets/dobro/_fonts.css.scss
116
116
  - app/assets/stylesheets/dobro/_reset.css.scss
117
117
  - app/controllers/dobro/application_controller.rb
118
+ - app/helpers/dobro_helper.rb
119
+ - app/views/dobro/application/_dashboard.html.erb
118
120
  - app/views/dobro/application/_form.html.erb
119
121
  - app/views/dobro/application/_show.html.erb
120
122
  - app/views/dobro/application/delete.html.erb
@@ -128,12 +130,17 @@ files:
128
130
  - lib/dobro.rb
129
131
  - lib/dobro/engine.rb
130
132
  - lib/dobro/file_system_resolver.rb
133
+ - lib/dobro/resource.rb
131
134
  - lib/dobro/routes.rb
132
135
  - lib/dobro/version.rb
133
136
  - spec/acceptance/custom_actions_spec.rb
134
137
  - spec/acceptance/custom_views_spec.rb
138
+ - spec/acceptance/namespaced_resource_spec.rb
139
+ - spec/acceptance/scoped_resource_spec.rb
135
140
  - spec/acceptance/standard_namespace_spec.rb
136
141
  - spec/internal/app/controllers/tasks_controller.rb
142
+ - spec/internal/app/models/author.rb
143
+ - spec/internal/app/models/link.rb
137
144
  - spec/internal/app/models/page.rb
138
145
  - spec/internal/app/models/task.rb
139
146
  - spec/internal/app/models/widget.rb
@@ -161,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
161
168
  version: '0'
162
169
  segments:
163
170
  - 0
164
- hash: 2005177753622462932
171
+ hash: 2852548357804714324
165
172
  required_rubygems_version: !ruby/object:Gem::Requirement
166
173
  none: false
167
174
  requirements:
@@ -177,8 +184,12 @@ summary: Simple, clean Rails admin interface
177
184
  test_files:
178
185
  - spec/acceptance/custom_actions_spec.rb
179
186
  - spec/acceptance/custom_views_spec.rb
187
+ - spec/acceptance/namespaced_resource_spec.rb
188
+ - spec/acceptance/scoped_resource_spec.rb
180
189
  - spec/acceptance/standard_namespace_spec.rb
181
190
  - spec/internal/app/controllers/tasks_controller.rb
191
+ - spec/internal/app/models/author.rb
192
+ - spec/internal/app/models/link.rb
182
193
  - spec/internal/app/models/page.rb
183
194
  - spec/internal/app/models/task.rb
184
195
  - spec/internal/app/models/widget.rb