admin_assistant 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -57,7 +57,7 @@ begin
57
57
  gem.email = "sera@fhwang.net"
58
58
  gem.homepage = "http://github.com/fhwang/admin_assistant"
59
59
  gem.authors = ["Francis Hwang"]
60
- gem.add_dependency "will_paginate", "3.0.pre2"
60
+ gem.add_dependency "will_paginate", "3.0"
61
61
  gem.add_dependency "dynamic_form"
62
62
  gem.files.exclude "rails_3_0/**/*"
63
63
  gem.files.exclude "rails_3_1/**/*"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.2.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{admin_assistant}
8
- s.version = "2.2.0"
8
+ s.version = "2.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Francis Hwang"]
12
- s.date = %q{2011-08-06}
12
+ s.date = %q{2011-09-17}
13
13
  s.description = %q{admin_assistant is a Rails plugin that automates a lot of features typically needed in admin interfaces.}
14
14
  s.email = %q{sera@fhwang.net}
15
15
  s.extra_rdoc_files = [
@@ -51,23 +51,20 @@ Gem::Specification.new do |s|
51
51
  "lib/admin_assistant/search.rb",
52
52
  "lib/admin_assistant/show_view.rb",
53
53
  "lib/admin_assistant/virtual_column.rb",
54
- "lib/images/sort-asc.png",
55
- "lib/images/sort-desc.png",
56
- "lib/javascripts/admin_assistant.js",
57
- "lib/javascripts/jquery.tokeninput.js",
58
- "lib/stylesheets/activescaffold.css",
59
- "lib/stylesheets/default.css",
60
- "lib/stylesheets/token-input.css",
61
54
  "lib/views/_polymorphic_field_search.html.erb",
62
55
  "lib/views/_token_input.html.erb",
63
56
  "lib/views/form.html.erb",
64
57
  "lib/views/index.html.erb",
65
58
  "lib/views/multi_form.html.erb",
66
59
  "lib/views/show.html.erb",
67
- "rails_3_0/.gitignore",
68
60
  "rails_3_0/lib/tasks/.gitkeep",
69
61
  "rails_3_0/public/stylesheets/.gitkeep",
70
62
  "rails_3_0/vendor/plugins/.gitkeep",
63
+ "rails_3_1/app/mailers/.gitkeep",
64
+ "rails_3_1/lib/assets/.gitkeep",
65
+ "rails_3_1/lib/tasks/.gitkeep",
66
+ "rails_3_1/log/.gitkeep",
67
+ "rails_3_1/vendor/plugins/.gitkeep",
71
68
  "tasks/admin_assistant_tasks.rake",
72
69
  "uninstall.rb",
73
70
  "vendor/ar_query/MIT-LICENSE",
@@ -79,6 +76,13 @@ Gem::Specification.new do |s|
79
76
  "vendor/ar_query/spec/ar_query_spec.rb",
80
77
  "vendor/ar_query/tasks/ar_query_tasks.rake",
81
78
  "vendor/ar_query/uninstall.rb",
79
+ "vendor/assets/images/sort-asc.png",
80
+ "vendor/assets/images/sort-desc.png",
81
+ "vendor/assets/javascripts/admin_assistant.js",
82
+ "vendor/assets/javascripts/jquery.tokeninput.js",
83
+ "vendor/assets/stylesheets/admin_assistant.css",
84
+ "vendor/assets/stylesheets/admin_assistant_activescaffold.css",
85
+ "vendor/assets/stylesheets/token-input.css",
82
86
  "website/_layouts/api.html",
83
87
  "website/_layouts/api1.html",
84
88
  "website/_layouts/default.html",
@@ -158,14 +162,14 @@ Gem::Specification.new do |s|
158
162
  s.specification_version = 3
159
163
 
160
164
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
161
- s.add_runtime_dependency(%q<will_paginate>, ["= 3.0.pre2"])
165
+ s.add_runtime_dependency(%q<will_paginate>, ["= 3.0"])
162
166
  s.add_runtime_dependency(%q<dynamic_form>, [">= 0"])
163
167
  else
164
- s.add_dependency(%q<will_paginate>, ["= 3.0.pre2"])
168
+ s.add_dependency(%q<will_paginate>, ["= 3.0"])
165
169
  s.add_dependency(%q<dynamic_form>, [">= 0"])
166
170
  end
167
171
  else
168
- s.add_dependency(%q<will_paginate>, ["= 3.0.pre2"])
172
+ s.add_dependency(%q<will_paginate>, ["= 3.0"])
169
173
  s.add_dependency(%q<dynamic_form>, [">= 0"])
170
174
  end
171
175
  end
data/config/routes.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # In development mode, we need to ensure that all controllers are loaded,
2
2
  # because that's how AdminAssistant knows what routes to create
3
3
  unless Rails.configuration.cache_classes
4
- Find.find("#{Rails.root}/app/controllers") do |path|
4
+ controllers_path = "#{Rails.root}/app/controllers"
5
+ AdminAssistant.all_files_under(controllers_path).each do |path|
5
6
  if path =~ /\.rb$/
6
7
  require path
7
8
  end
@@ -19,6 +19,22 @@ class AdminAssistant
19
19
  self.default_inputs = {}
20
20
  self.routes = []
21
21
 
22
+ # From http://stackoverflow.com/questions/3974087/how-to-make-rubys-find-find-follow-symlinks
23
+ def self.all_files_under(*paths)
24
+ paths.flatten!
25
+ paths.map! { |p| Pathname.new(p) }
26
+ files = paths.select { |p| p.file? }
27
+ (paths - files).each do |dir|
28
+ files << all_files_under(dir.children)
29
+ end
30
+ files.flatten.map(&:to_s)
31
+ end
32
+
33
+ def self.app_uses_sprockets?
34
+ # For now, we assume you're using Sprockets if app/assets exists.
35
+ File.exist?("#{Rails.root}/app/assets")
36
+ end
37
+
22
38
  def self.profile(msg)
23
39
  if self.request_start_time
24
40
  Rails.logger.info "#{msg}: #{Time.now - self.request_start_time}"
@@ -28,7 +44,7 @@ class AdminAssistant
28
44
  def self.template_file(template_name)
29
45
  "#{File.dirname(__FILE__)}/views/#{template_name}.html.erb"
30
46
  end
31
-
47
+
32
48
  attr_reader :base_settings, :controller_class, :form_settings,
33
49
  :index_settings, :model_class, :show_settings
34
50
  attr_accessor :actions, :custom_destroy, :default_search_matches_on
@@ -1,10 +1,12 @@
1
1
  class AdminAssistant
2
2
  module Helper
3
3
  def admin_assistant_includes(opts = {})
4
- theme = opts[:theme] || 'default'
5
- tags = stylesheet_link_tag("admin_assistant/#{theme}")
4
+ ss_name = "admin_assistant/admin_assistant"
5
+ ss_name << "_#{opts[:theme]}" if opts[:theme]
6
+ tags = stylesheet_link_tag(ss_name)
6
7
  tags << stylesheet_link_tag("admin_assistant/token-input")
7
- js_dir = Pathname.new(Rails.root) + "public/javascripts/admin_assistant"
8
+ js_dir =
9
+ Pathname.new(Rails.root) + "public/javascripts/admin_assistant"
8
10
  Dir.entries(js_dir).each do |entry|
9
11
  if entry =~ /\.js$/
10
12
  tags << javascript_include_tag("admin_assistant/#{entry}")
@@ -148,7 +148,7 @@ class AdminAssistant
148
148
  add_base_condition_sqls
149
149
  search.add_to_query @ar_query
150
150
  @ar_query.total_entries = optimized_total_entries
151
- records = @index.model_class.paginate(:all, @ar_query.to_hash)
151
+ records = @index.model_class.paginate(@ar_query.to_hash)
152
152
  if caching_total_entries? && @ar_query.to_hash[:total_entries].nil?
153
153
  cache_total_entries records.total_entries
154
154
  end
@@ -4,10 +4,16 @@ require 'pathname'
4
4
  class AdminAssistant
5
5
  def self.init
6
6
  gem_root = File.dirname(__FILE__) + "/../.."
7
- %w(stylesheets javascripts images).each do |asset_type|
7
+ copy_into_public = %w(images)
8
+ unless app_uses_sprockets?
9
+ copy_into_public.concat(%w(stylesheets javascripts))
10
+ end
11
+ copy_into_public.each do |asset_type|
8
12
  asset_dir = "#{Rails.root}/public/#{asset_type}/admin_assistant"
9
- FileUtils.mkdir(asset_dir) unless File.exist?(asset_dir)
10
- FileUtils.cp_r(Dir.glob("#{gem_root}/lib/#{asset_type}/*"), asset_dir)
13
+ FileUtils.mkdir_p(asset_dir) unless File.exist?(asset_dir)
14
+ FileUtils.cp_r(
15
+ Dir.glob("#{gem_root}/vendor/assets/#{asset_type}/*"), asset_dir
16
+ )
11
17
  end
12
18
  end
13
19
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -7,11 +7,13 @@ title: Quick start
7
7
  This document assumes you are highly familiar with Ruby and Rails; if you are a beginning Rails user you might want to start with our <a href="/admin_assistant/tutorial.html">tutorial</a>.
8
8
  </div>
9
9
 
10
- 1) Add the gem to your Gemfile, and install it with `bundle install`.
10
+ ### Add the gem to your Gemfile
11
11
 
12
12
  gem 'admin_assistant'
13
13
 
14
- 2) admin\_assistant comes packaged with standard CSS and Javascript that you should include in whatever layout your admin controllers will be using. You'll also need to make sure to include jquery, if you're not including it already.
14
+ ### Include admin\_assistant's CSS and Javascript in your layout
15
+
16
+ admin\_assistant comes packaged with standard CSS and Javascript that you should include in whatever layout your admin controllers will be using. You'll also need to make sure to include jquery, if you're not including it already.
15
17
 
16
18
  <html>
17
19
  <head>
@@ -20,8 +22,23 @@ This document assumes you are highly familiar with Ruby and Rails; if you are a
20
22
  </head>
21
23
  ...
22
24
  </html>
25
+
26
+ If you're using Sprockets, which is the default in Rails 3.1, you should include the CSS and Javascript assets in the manifest files that you use for your admin layout.
23
27
 
24
- 3) Setup an admin controller by attaching it to a model and using the admin layout:
28
+ Javascript:
29
+
30
+ //= require admin_assistant
31
+ //= require jquery.tokeninput.js
32
+
33
+ CSS:
34
+
35
+ //= require admin_assistant
36
+ //= require token-input
37
+
38
+
39
+ ### Setup an admin controller
40
+
41
+ Use the admin layout, and call `admin_assistant_for` with the model class.
25
42
 
26
43
  class Admin::BlogPostsController < ApplicationController
27
44
  layout 'admin'
@@ -7,20 +7,26 @@ title: Tutorial
7
7
  This document assumes you are a beginning Rails user; if you are familiar with Rails you might want to check out our <a href="/admin_assistant/quick_start.html">quick start</a>.
8
8
  </div>
9
9
 
10
- 1) Add the gem to `Gemfile` in the root of your Rails project.
10
+ ### Add the gem to your Gemfile
11
+
12
+ This is found at `Gemfile` in the root of your Rails project.
11
13
 
12
14
  gem 'admin_assistant'
13
15
 
14
- 2) Install the gem locally.
16
+ ### Install the gem locally
15
17
 
16
18
  $ bundle install
17
19
 
18
- 3) admin\_assistant uses jQuery. You may already have jQuery installed for your project, but if not, you can get it like so:
20
+ ### Install jQuery if you need to
21
+
22
+ admin\_assistant uses jQuery. You may already have jQuery installed for your project (it's the standard starting with Rails 3.1), but if not, you can get it like so:
19
23
 
20
24
  $ curl http://code.jquery.com/jquery-1.6.2.min.js > \
21
25
  public/javascripts/jquery-1.6.2.min.js
22
26
 
23
- 4) If you don't have any admin controllers in your Rails project yet, you probably need to create a separate admin layout. Create a file called `app/views/layouts/admin.html.erb` like this:
27
+ ### Create a separate admin layout (without Sprockets)
28
+
29
+ If you don't have any admin controllers in your Rails project yet, you probably need to create a separate admin layout. Create a file called `app/views/layouts/admin.html.erb` like this:
24
30
 
25
31
  <html>
26
32
  <head>
@@ -33,12 +39,42 @@ This document assumes you are a beginning Rails user; if you are familiar with R
33
39
  </html>
34
40
 
35
41
  If you've already created an admin layout, you should add the javascript references, and the call to `admin_assistant_includes`. This includes the standard CSS and Javascript that are packed with admin\_assistant.
36
-
37
- 5) Create your new admin controller for a pre-existing model. We'll be using a BlogPost as an example but you should be able to use any model in your Rails app.
42
+
43
+ ### Create a separate admin layout (with Sprockets)
44
+
45
+ Rails 3.1 recommends Sprockets as the default asset packager. If you're using Sprockets, you'll probably want to create separate `admin.js` and `admin.css` manifest files. `app/views/layouts/admin.html.erb` will look like this:
46
+
47
+ <html>
48
+ <head>
49
+ <%= javascript_include_tag "admin" %>
50
+ <%= stylesheet_link_tag "admin" %>
51
+ </head>
52
+ <body>
53
+ <%= yield %>
54
+ </body>
55
+ </html>
56
+
57
+ And you will add admin\_assistant's assets to the manifest files, which you will most likely put at `app/assets/javascripts/admin.js` and `app/assets/stylesheets/admin.css`.
58
+
59
+ Javascript:
60
+
61
+ //= require admin_assistant
62
+ //= require jquery.tokeninput.js
63
+
64
+ CSS:
65
+
66
+ //= require admin_assistant
67
+ //= require token-input
68
+
69
+ ### Create an admin controller
70
+
71
+ Create your new admin controller for a pre-existing model. We'll be using a BlogPost as an example but you should be able to use any model in your Rails app.
38
72
 
39
73
  ./script/generate controller admin/blog_posts
74
+
75
+ ### Edit your admin controller
40
76
 
41
- 6) Open `app/controllers/admin/blog_posts_controller.rb` and set it up to use the admin layout and to use admin\_assistant for the BlogPost model:
77
+ Open `app/controllers/admin/blog_posts_controller.rb` and set it up to use the admin layout and to use admin\_assistant for the BlogPost model:
42
78
 
43
79
  class Admin::BlogPostsController < ApplicationController
44
80
  layout 'admin'
@@ -46,9 +82,13 @@ If you've already created an admin layout, you should add the javascript referen
46
82
  admin_assistant_for BlogPost
47
83
  end
48
84
 
49
- 7) If you were already running your Rails app with `./script/server` etc, you should restart it.
85
+ ### Restart your Rails app
86
+
87
+ If you were already running your Rails app with `./script/server` etc, you should restart it.
88
+
89
+ ### Check out the controller
50
90
 
51
- 8) Visit `/admin/blog_posts` in your browser and you'll see something like this:
91
+ Visit `/admin/blog_posts` in your browser and you'll see something like this:
52
92
 
53
93
  ![index](/admin_assistant/img/blog_posts-index.png)
54
94
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: admin_assistant
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- - 0
10
- version: 2.2.0
9
+ - 1
10
+ version: 2.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Francis Hwang
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-06 00:00:00 -04:00
18
+ date: 2011-09-17 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,13 +26,11 @@ dependencies:
26
26
  requirements:
27
27
  - - "="
28
28
  - !ruby/object:Gem::Version
29
- hash: 1923831917
29
+ hash: 7
30
30
  segments:
31
31
  - 3
32
32
  - 0
33
- - pre
34
- - 2
35
- version: 3.0.pre2
33
+ version: "3.0"
36
34
  type: :runtime
37
35
  version_requirements: *id001
38
36
  - !ruby/object:Gem::Dependency
@@ -93,23 +91,20 @@ files:
93
91
  - lib/admin_assistant/search.rb
94
92
  - lib/admin_assistant/show_view.rb
95
93
  - lib/admin_assistant/virtual_column.rb
96
- - lib/images/sort-asc.png
97
- - lib/images/sort-desc.png
98
- - lib/javascripts/admin_assistant.js
99
- - lib/javascripts/jquery.tokeninput.js
100
- - lib/stylesheets/activescaffold.css
101
- - lib/stylesheets/default.css
102
- - lib/stylesheets/token-input.css
103
94
  - lib/views/_polymorphic_field_search.html.erb
104
95
  - lib/views/_token_input.html.erb
105
96
  - lib/views/form.html.erb
106
97
  - lib/views/index.html.erb
107
98
  - lib/views/multi_form.html.erb
108
99
  - lib/views/show.html.erb
109
- - rails_3_0/.gitignore
110
100
  - rails_3_0/lib/tasks/.gitkeep
111
101
  - rails_3_0/public/stylesheets/.gitkeep
112
102
  - rails_3_0/vendor/plugins/.gitkeep
103
+ - rails_3_1/app/mailers/.gitkeep
104
+ - rails_3_1/lib/assets/.gitkeep
105
+ - rails_3_1/lib/tasks/.gitkeep
106
+ - rails_3_1/log/.gitkeep
107
+ - rails_3_1/vendor/plugins/.gitkeep
113
108
  - tasks/admin_assistant_tasks.rake
114
109
  - uninstall.rb
115
110
  - vendor/ar_query/MIT-LICENSE
@@ -121,6 +116,13 @@ files:
121
116
  - vendor/ar_query/spec/ar_query_spec.rb
122
117
  - vendor/ar_query/tasks/ar_query_tasks.rake
123
118
  - vendor/ar_query/uninstall.rb
119
+ - vendor/assets/images/sort-asc.png
120
+ - vendor/assets/images/sort-desc.png
121
+ - vendor/assets/javascripts/admin_assistant.js
122
+ - vendor/assets/javascripts/jquery.tokeninput.js
123
+ - vendor/assets/stylesheets/admin_assistant.css
124
+ - vendor/assets/stylesheets/admin_assistant_activescaffold.css
125
+ - vendor/assets/stylesheets/token-input.css
124
126
  - website/_layouts/api.html
125
127
  - website/_layouts/api1.html
126
128
  - website/_layouts/default.html
data/rails_3_0/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- .bundle
2
- db/*.sqlite3
3
- log/*.log
4
- tmp/