control_center 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.markdown +188 -0
  3. data/generators/control_center/control_center_generator.rb +26 -0
  4. data/generators/control_center/templates/control_center.rb +14 -0
  5. data/lib/control_center.rb +20 -0
  6. data/lib/control_center/engine.rb +18 -0
  7. data/lib/control_center/helpers/layout_helper.rb +65 -0
  8. data/lib/control_center/helpers/tab_builder.rb +14 -0
  9. data/lib/tasks/control_center_tasks.rake +4 -0
  10. data/rails/init.rb +7 -0
  11. data/test/rails/README +2 -0
  12. data/test/rails/Rakefile +10 -0
  13. data/test/rails/app/controllers/application.rb +15 -0
  14. data/test/rails/app/controllers/application_controller.rb +15 -0
  15. data/test/rails/app/controllers/test_controller.rb +3 -0
  16. data/test/rails/app/helpers/application_helper.rb +3 -0
  17. data/test/rails/app/helpers/test_helper.rb +2 -0
  18. data/test/rails/app/views/layouts/_header_links.html.erb +2 -0
  19. data/test/rails/app/views/layouts/_tabs.html.erb +3 -0
  20. data/test/rails/app/views/layouts/control_center.html.erb +64 -0
  21. data/test/rails/app/views/test/forms.html.erb +106 -0
  22. data/test/rails/app/views/test/index.html.erb +28 -0
  23. data/test/rails/app/views/test/no_sidebar.html.erb +17 -0
  24. data/test/rails/app/views/test/pagination.html.erb +4 -0
  25. data/test/rails/app/views/test/tab_override.html.erb +12 -0
  26. data/test/rails/app/views/test/table.html.erb +27 -0
  27. data/test/rails/config/boot.rb +110 -0
  28. data/test/rails/config/database.yml +22 -0
  29. data/test/rails/config/environment.rb +76 -0
  30. data/test/rails/config/environments/development.rb +17 -0
  31. data/test/rails/config/environments/production.rb +24 -0
  32. data/test/rails/config/environments/test.rb +22 -0
  33. data/test/rails/config/initializers/control_center.rb +14 -0
  34. data/test/rails/config/initializers/inflections.rb +10 -0
  35. data/test/rails/config/initializers/mime_types.rb +5 -0
  36. data/test/rails/config/initializers/new_rails_defaults.rb +17 -0
  37. data/test/rails/config/locales/en.yml +5 -0
  38. data/test/rails/config/routes.rb +43 -0
  39. data/test/rails/db/development.sqlite3 +0 -0
  40. data/test/rails/db/test.sqlite3 +0 -0
  41. data/test/rails/doc/README_FOR_APP +5 -0
  42. data/test/rails/lib/tasks/databaseless.rake +3 -0
  43. data/test/rails/log/development.log +251 -0
  44. data/test/rails/log/test.log +280 -0
  45. data/test/rails/public/404.html +30 -0
  46. data/test/rails/public/422.html +30 -0
  47. data/test/rails/public/500.html +33 -0
  48. data/test/rails/public/dispatch.cgi +10 -0
  49. data/test/rails/public/dispatch.fcgi +24 -0
  50. data/test/rails/public/dispatch.rb +10 -0
  51. data/test/rails/public/favicon.ico +0 -0
  52. data/test/rails/public/images/rails.png +0 -0
  53. data/test/rails/public/javascripts/application.js +2 -0
  54. data/test/rails/public/javascripts/controls.js +963 -0
  55. data/test/rails/public/javascripts/dragdrop.js +973 -0
  56. data/test/rails/public/javascripts/effects.js +1128 -0
  57. data/test/rails/public/javascripts/prototype.js +4320 -0
  58. data/test/rails/public/robots.txt +5 -0
  59. data/test/rails/public/stylesheets/control_center.css +289 -0
  60. data/test/rails/public/stylesheets/custom_css_1.css +0 -0
  61. data/test/rails/public/stylesheets/custom_css_2.css +0 -0
  62. data/test/rails/script/about +4 -0
  63. data/test/rails/script/console +3 -0
  64. data/test/rails/script/dbconsole +3 -0
  65. data/test/rails/script/destroy +3 -0
  66. data/test/rails/script/generate +3 -0
  67. data/test/rails/script/performance/benchmarker +3 -0
  68. data/test/rails/script/performance/profiler +3 -0
  69. data/test/rails/script/performance/request +3 -0
  70. data/test/rails/script/plugin +3 -0
  71. data/test/rails/script/process/inspector +3 -0
  72. data/test/rails/script/process/reaper +3 -0
  73. data/test/rails/script/process/spawner +3 -0
  74. data/test/rails/script/runner +3 -0
  75. data/test/rails/script/server +3 -0
  76. data/test/rails/test/functional/test_controller_test.rb +49 -0
  77. data/test/rails/test/performance/browsing_test.rb +9 -0
  78. data/test/rails/test/test_helper.rb +13 -0
  79. data/test/rails/update +6 -0
  80. metadata +145 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2009 Alan Johnson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,188 @@
1
+ Control Center
2
+ ==============
3
+
4
+ Control Center is a Rails plugin for bootstrapping the interface side of an application very quickly. It provides an interface with tabs and subtabs, and with a few nice default styles. Control Center is can be installed through the rails script/plugin script, or as a RubyGem.
5
+
6
+ Installation As A Rails Plugin
7
+ ------------------------------
8
+ While we recommend installing as a RubyGem, installing as a Rails plugin is dead simple. From within the root of your Rails project do:
9
+
10
+ script/plugin install git://github.com/commondream/control_center.git
11
+ script/generate control_center
12
+
13
+ Installation As A RubyGem
14
+ -------------------------
15
+ Installation as a RubyGem ensures that you don't get any weirdness due to installing directly from the repository. Make sure you have GitHub in your gem sources before you try to do the install.
16
+
17
+ gem install commondream-control_center
18
+
19
+ Now that you've got the gem installed, you'll need to configure your application to use control center. Add a line like the following to your environment.rb:
20
+
21
+ config.gem "commondream-control_center", :lib => "control_center"
22
+
23
+ Now, from the root of your rails project, run the following command:
24
+
25
+ script/generate control_center
26
+
27
+ Post-Installation Configuration
28
+ -------------------------------
29
+ Using Control Center is as easy as setting it as a layout in one of your controllers (or in your ApplicationController if you want it to be the layout across your entire app) with:
30
+
31
+ layout 'control_center'
32
+
33
+ You'll want to look at environment/initializers/control_center.rb to customize the Control Center title, the color of the header and several other options. Also, you'll want to set your tabs up in app/views/layouts/_tabs.html.erb.
34
+
35
+ Tabs
36
+ ----
37
+ Tabs are defined by default in the app/views/layouts/_tabs.html.erb partial. You can override the tabs in any page with the tabs helper.
38
+
39
+ Tabs are defined as follows:
40
+
41
+ <%= tab "Title", "url" %>
42
+
43
+ You can create as many tabs as you would like, but be aware that at present the tabs will simply wrap to the next line if you include too many. We'll hopefully fix that in a future release, although you probably shouldn't use so many tabs that it would wrap anyway.
44
+
45
+ The tab method passes the url on to the Rails link_to helper, so the url can be a has or anything else that link_to accepts for its url parameter.
46
+
47
+ To select a tab, simply use the select_tab method in your view. select_tab chooses a tab based on the title given to the tab, so for example, with a tab definition like:
48
+
49
+ <%= tab "Tab 1", "/some_url" %>
50
+ <%= tab "Tab 2", "/some_other_url" %>
51
+
52
+ if you called:
53
+
54
+ <% select_tab "Tab 1" %>
55
+
56
+ in your view, the tab titled *Tab 1* would be selected.
57
+
58
+ Subtabs
59
+ -------
60
+ Subtabs will typically be defined in a partial that you create and included in the views that use that particular set of subtabs. Although that's typical,
61
+ it's not mandatory. The app/views/layouts/_tabs.html.erb partial is another
62
+ great spot to put subtabs if you want to do more of a per-app tab configuration,
63
+ but that's tricker to implement in many cases. Anyway, a set of subtabs will
64
+ look something like this in your view:
65
+
66
+ <% sub_tabs do %>
67
+ <%= sub_tab "Sub Tab", "/subtab" %>
68
+ <%= sub_tab "Sub Tab 2", "/subtab2" %>
69
+ <% end %>
70
+
71
+ You can select what tab to mark as the current one with the select_sub_tab helper:
72
+
73
+ <% select_sub_tab "Sub Tab" %>
74
+
75
+ The sub_tabs helper does not output the tabs, because the Control Center
76
+ layout has a specific place where it needs to put them. So, don't worry about
77
+ where you put the sub tab definition in your view... as long as its in your
78
+ view, they'll show up correctly.
79
+
80
+ Please note that sub_tabs at present don't work with versions of Rails < 2.2.
81
+
82
+ Header Navigation
83
+ -----------------
84
+ The content at the very top right of Control Center is great for login/logout links, help links, etc. You can modify that content by editing the app/views/layouts/_header_links.html.erb partial.
85
+
86
+ Sidebars
87
+ --------
88
+ Control Center has two primary layouts at present, a single column display and a two column display. The two column display shows a sidebar to the right side of the screen. To generate content for the sidebar, simply put normal content, like p, div, ul tags into the sidebar helper in your view:
89
+
90
+ <% sidebar do %>
91
+ <h3>This is a sidebar!</h3>
92
+
93
+ <p>
94
+ Aw, yeah! This is a sidebar. Didn't think you'd be creating sidebars
95
+ today, did you? Well, you are!
96
+ </p>
97
+ <% end %>
98
+
99
+ Forms
100
+ -----
101
+ Forms in Control Center are fairly simple to implement. Control Center puts labels above fields and allows you to do either a single column of fields in your form or to do two columns.
102
+
103
+ The markup for a field should look something like the following:
104
+
105
+ <div>
106
+ <label for="username">Username</label>
107
+ <input type="text" name="username" id="username" />
108
+ </div>
109
+
110
+ Of course, if you used the Rails helpers, it might look more like:
111
+
112
+ <div>
113
+ <%= f.label :username %>
114
+ <%= f.text_field :username %>
115
+ </div>
116
+
117
+ If you would like a two column layout, use markup similar to the following:
118
+
119
+ <div>
120
+ <div class="col2">
121
+ [FIELD GOES HERE]
122
+ </div>
123
+ <div class="col2">
124
+ [FIELD GOES HERE]
125
+ </div>
126
+ </div>
127
+
128
+ Control Center includes styles for the error states of the Rails helpers, and for the error_messages helper, so that you won't have to create style rules yourself.
129
+
130
+ You can learn more about how to lay out your forms in Control Center by looking at the sample/app/views/test/forms.html.erb file in Control Center's source repository.
131
+
132
+ Custom CSS
133
+ ----------
134
+ To add custom CSS to Control Center, simply use the custom_css config property in the initializer. It expects a hash with keys for each of the stylesheets to pass to the Rails stylesheet_link_tag helper, and with values for the options to pass to the helper. For example:
135
+
136
+ ControlCenter::Config.custom_css = {
137
+ "custom_css_1" => { :media => :all },
138
+ "custom_css_2" => { :media => :print }
139
+ }
140
+
141
+ Would create two links in Control Center, one to a stylesheet named custom_css_1 with a media attribute of all, and one to custom_css_2 with a media attribute of print.
142
+
143
+ Custom JavaScript
144
+ -----------------
145
+ Add custom JavaScript to the Control Center interface by using the include_javascript property in the initializer. The value you set to include_javascript gets passed to the Rails javascript_include_tag helper.
146
+
147
+ ControlCenter::Config.include_javascript = [ :defaults ]
148
+
149
+ This would cause the Rails default javascripts (Prototype, Scriptaculous, and application.js) to be inluded with Control Center. The scripts are included at the bottom of the body of your page, as per the YSlow guidelines.
150
+
151
+ Where are the tests?
152
+ --------------------
153
+ I'm usually very good about testing my code, but I wasn't sure of the best way to test something that was so interface intensive, so tests simply aren't present for the 1.0 release. Tests are one of my biggest goals for the 1.1 release.
154
+
155
+ What about IE?
156
+ --------------
157
+ I think most of Control Center should work fine in IE, but I haven't been as thorough as I would with, say, a production website design in testing IE compatibility, so don't be surprised if there are a few issues here and there.
158
+
159
+ Reporting Issues
160
+ ----------------
161
+ If something's not working like you expect it to, submit an issue through the GitHub issues tool for Control Center, and I'll take a look at your problem. You can find the issues tool [here](http://github.com/commondream/control_center/issues).
162
+
163
+ Screenshot
164
+ ----------
165
+ ![Control Center Screenshot](http://cloud.github.com/downloads/commondream/control_center/Control_Center_-_Forms_Sample-1.png)
166
+
167
+ License
168
+ -------
169
+ Copyright (c) 2008-2009 Alan Johnson
170
+
171
+ Permission is hereby granted, free of charge, to any person obtaining
172
+ a copy of this software and associated documentation files (the
173
+ "Software"), to deal in the Software without restriction, including
174
+ without limitation the rights to use, copy, modify, merge, publish,
175
+ distribute, sublicense, and/or sell copies of the Software, and to
176
+ permit persons to whom the Software is furnished to do so, subject to
177
+ the following conditions:
178
+
179
+ The above copyright notice and this permission notice shall be
180
+ included in all copies or substantial portions of the Software.
181
+
182
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
183
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
184
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
185
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
186
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
187
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
188
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ class ControlCenterGenerator < Rails::Generator::Base
2
+ def banner
3
+ "Usage #{$0} #{spec.name}"
4
+ end
5
+
6
+ def manifest
7
+ record do |m|
8
+ # set up the stylesheet
9
+ m.directory('public/stylesheets')
10
+ m.file('control_center.css',
11
+ 'public/stylesheets/control_center.css')
12
+
13
+ # copy the layouts over
14
+ layouts_path = 'app/views/layouts'
15
+ m.directory(layouts_path)
16
+ m.file('_tabs.html.erb',
17
+ File.join(layouts_path, "_tabs.html.erb"))
18
+ m.file('_header_links.html.erb',
19
+ File.join(layouts_path, "_header_links.html.erb"))
20
+
21
+ # copy the initializer over
22
+ m.file 'control_center.rb',
23
+ File.join("config", "initializers", "control_center.rb")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ # This is an initializer script for Control Center. Customize it to your
2
+ # preferences
3
+
4
+ ControlCenter::Config.app_title = "Control Center"
5
+ ControlCenter::Config.theme_color = "#0033CC"
6
+
7
+ # Custom Stylesheets
8
+ # ControlCenter::Config.custom_css = {
9
+ # "custom_css_1" => { :media => :all },
10
+ # "custom_css_2" => { :media => :print }
11
+ # }
12
+
13
+ # Custom JavaScript Includes
14
+ #ControlCenter::Config.include_javascript = [:defaults]
@@ -0,0 +1,20 @@
1
+ module ControlCenter
2
+ require_relative 'control_center/helpers/layout_helper'
3
+ require_relative 'control_center/helpers/tab_builder'
4
+ require 'control_center/engine' if defined?(Rails)
5
+
6
+ class Config
7
+ cattr_accessor :app_title
8
+ cattr_accessor :theme_color
9
+ cattr_accessor :custom_css
10
+ cattr_accessor :include_javascript
11
+
12
+ def self.custom_css
13
+ @@custom_css ||= {}
14
+ end
15
+
16
+ def self.include_javascript
17
+ @@include_javascript || []
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module ControlCenter
2
+ class Engine < Rails::Engine
3
+ engine_name :control_center
4
+
5
+ if Rails.version >= '3.1'
6
+ initializer :assets do |config|
7
+ Rails.application.config.assets.precompile += Dir.glob(File.join("#{self.root}", 'app', 'assets', '**', '*'))
8
+ end
9
+ end
10
+
11
+ initializer 'action_view.helper_mehtods' do |app|
12
+ ActiveSupport.on_load(:action_view) do
13
+ ::ActionView::Base.send :include, ControlCenter::Helpers::LayoutHelper
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,65 @@
1
+ require_relative 'tab_builder'
2
+
3
+ # Helpers that control center uses
4
+ module ControlCenter
5
+ module Helpers
6
+ module LayoutHelper
7
+
8
+ def title(title)
9
+ @control_center_title = title
10
+ end
11
+
12
+ def select_tab(tab)
13
+ @cc_current_tab = tab
14
+ end
15
+ def current_tab
16
+ @cc_current_tab
17
+ end
18
+
19
+ def sub_tabs
20
+ if block_given?
21
+ content_for :sub_tabs do
22
+ yield
23
+ end
24
+ end
25
+ end
26
+
27
+ def select_sub_tab(tab)
28
+ @cc_current_sub_tab = tab
29
+ end
30
+ def current_sub_tab
31
+ @cc_current_sub_tab
32
+ end
33
+
34
+ # Sets up a sidebar in control center.
35
+ def sidebar
36
+ if block_given?
37
+ @sidebar_set = true
38
+ content_for :sidebar do
39
+ yield
40
+ end
41
+ end
42
+ end
43
+
44
+ def sidebar?
45
+ @sidebar_set ||= false
46
+ end
47
+
48
+ def tab(tab_name, tab_url)
49
+ options = {}
50
+ options[:class] = "active" if current_tab == tab_name
51
+ content_tag "li", options, true do
52
+ link_to tab_name, tab_url
53
+ end
54
+ end
55
+
56
+ def sub_tab(tab_name, tab_url)
57
+ options = {}
58
+ options[:class] = "active" if current_sub_tab == tab_name
59
+ content_tag "li", options, true do
60
+ link_to tab_name, tab_url
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,14 @@
1
+ module ControlCenter
2
+ module Helpers
3
+ class TabBuilder
4
+
5
+ def initialize(&block)
6
+ @block = block
7
+ end
8
+
9
+ def tab(tab_name, url)
10
+ @block.call(tab_name, url)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :control_center do
3
+ # # Task goes here
4
+ # end
data/rails/init.rb ADDED
@@ -0,0 +1,7 @@
1
+ # Include hook code here
2
+ require File.join(File.dirname(__FILE__), "..", "lib", "control_center.rb")
3
+
4
+ # Include the helpers we've written
5
+ ActionView::Base.send :include, ControlCenter::Helpers
6
+
7
+ config.middleware.use ::ActionDispatch::Static, "#{root}/public"
data/test/rails/README ADDED
@@ -0,0 +1,2 @@
1
+ == Control Center
2
+
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
@@ -0,0 +1,15 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+
7
+ # See ActionController::RequestForgeryProtection for details
8
+ # Uncomment the :secret if you're not using the cookie session store
9
+ protect_from_forgery # :secret => '50fafc1e38ed429580dd1235acd03744'
10
+
11
+ # See ActionController::Base for details
12
+ # Uncomment this to filter the contents of submitted sensitive data parameters
13
+ # from your application log (in this case, all fields with names like "password").
14
+ # filter_parameter_logging :password
15
+ end
@@ -0,0 +1,15 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+
7
+ # See ActionController::RequestForgeryProtection for details
8
+ # Uncomment the :secret if you're not using the cookie session store
9
+ protect_from_forgery # :secret => '50fafc1e38ed429580dd1235acd03744'
10
+
11
+ # See ActionController::Base for details
12
+ # Uncomment this to filter the contents of submitted sensitive data parameters
13
+ # from your application log (in this case, all fields with names like "password").
14
+ # filter_parameter_logging :password
15
+ end
@@ -0,0 +1,3 @@
1
+ class TestController < ApplicationController
2
+ layout "control_center"
3
+ end