contour 1.0.0.beta12 → 1.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/CHANGELOG.rdoc +4 -0
  2. data/README.rdoc +83 -14
  3. data/app/assets/images/contour/ajax-loader.gif +0 -0
  4. data/app/assets/javascripts/contour/global.js.coffee +23 -2
  5. data/app/helpers/contour_helper.rb +18 -1
  6. data/app/views/contour/layouts/_per_page.html.erb +7 -0
  7. data/config/initializers/devise.rb +0 -29
  8. data/contour.gemspec +5 -5
  9. data/lib/contour/version.rb +1 -1
  10. data/lib/generators/contour/install/install_generator.rb +30 -0
  11. data/lib/generators/{templates → contour/install/templates}/README +9 -13
  12. data/lib/generators/{templates → contour/install/templates}/contour.rb +0 -0
  13. data/lib/generators/{templates → contour/install/templates}/omniauth.rb +0 -0
  14. data/lib/generators/contour/scaffold/USAGE +15 -0
  15. data/lib/generators/contour/scaffold/scaffold_generator.rb +58 -0
  16. data/lib/generators/contour/scaffold/templates/_form.html.erb +37 -0
  17. data/lib/generators/contour/scaffold/templates/_paginate.html.erb +30 -0
  18. data/lib/generators/contour/scaffold/templates/controller.rb +107 -0
  19. data/lib/generators/contour/scaffold/templates/edit.html.erb +3 -0
  20. data/lib/generators/contour/scaffold/templates/index.html.erb +21 -0
  21. data/lib/generators/contour/scaffold/templates/index.js.erb +1 -0
  22. data/lib/generators/contour/scaffold/templates/new.html.erb +3 -0
  23. data/lib/generators/contour/scaffold/templates/show.html.erb +23 -0
  24. data/test/dummy/config/initializers/devise.rb +14 -13
  25. data/test/dummy/db/test.sqlite3 +0 -0
  26. data/test/dummy/log/test.log +1574 -0
  27. metadata +53 -42
  28. data/lib/generators/contour/install_generator.rb +0 -46
  29. data/lib/generators/templates/devise.rb +0 -142
@@ -9,6 +9,10 @@
9
9
  * Ex: <tt>config.sign_up_fields = [ { attribute: 'first_name', type: 'text_field' }, { attribute: 'last_name', type: 'text_field' } ]</tt>
10
10
  * An empty <tt>links</tt> array is no longer required when specifying a menu item without a submenu
11
11
  * Submenus are properly hidden if none of the submenu link conditions evaluate to true
12
+ * Added Rails scaffold generator
13
+ * <tt>rails generate contour:scaffold ModelName</tt>
14
+ * NOTE: This generator currently assumes you have a scope named current in your model. The conditions can be modified to limit only those records who are not deleted for example.
15
+ * <tt>scope :current, conditions: { }</tt>
12
16
 
13
17
  * Breaking Changes
14
18
  * CSS updated to use Twitter-Bootstrap
@@ -4,11 +4,11 @@ Basic Rails framework files and assets for layout and authentication
4
4
 
5
5
  == Installation
6
6
 
7
- Contour can be installed from rubygems.org using:
7
+ Contour can be installed from rubygems.org using
8
8
 
9
9
  gem install contour
10
10
 
11
- Or update your Gemfile to include:
11
+ Or update your <tt>Gemfile</tt> to include
12
12
 
13
13
  gem 'contour'
14
14
 
@@ -22,7 +22,7 @@ Make sure you have Rails 3.2.3
22
22
 
23
23
  cd blank_rails_project
24
24
 
25
- Modify Gemfile and add
25
+ Modify <tt>Gemfile</tt> and add
26
26
 
27
27
  gem 'contour', '~> 1.0.0'
28
28
 
@@ -48,33 +48,37 @@ Create a sample controller
48
48
 
49
49
  rails generate controller welcome index --skip-stylesheets
50
50
 
51
- Remove the public/index.html
51
+ Remove the <tt>public/index.html</tt>
52
52
 
53
53
  rm public/index.html
54
54
 
55
- Add the following line to your app/controllers/application_controller.rb
55
+ Add the following line to your <tt>app/controllers/application_controller.rb</tt>
56
56
 
57
57
  layout "contour/layouts/application"
58
58
 
59
- Edit your app/assets/javascripts/application.js manifest to use Contour JavaScript (Replace jquery and jquery_ujs)
59
+ Edit your <tt>app/assets/javascripts/application.js</tt> manifest to use Contour JavaScript (Replace jquery and jquery_ujs)
60
60
 
61
61
  //= require contour
62
62
 
63
- Edit your app/assets/stylesheets/application.css manifest to use Contour CSS (after self, before tree)
63
+ Edit your <tt>app/assets/stylesheets/application.css</tt> manifest to use Contour CSS (after self, before tree)
64
64
 
65
65
  *= require contour
66
66
 
67
- Make sure the devise line in config/routes.rb looks as follows
67
+ Make sure the devise line in <tt>config/routes.rb</tt> looks as follows
68
68
 
69
69
  devise_for :users, controllers: { registrations: 'contour/registrations', sessions: 'contour/sessions', passwords: 'contour/passwords', confirmations: 'contour/confirmations', unlocks: 'contour/unlocks' }, path_names: { sign_up: 'register', sign_in: 'login' }
70
70
 
71
- <b>If there is a line that just says 'devise_for :users' or a duplicate, <i>REMOVE IT!</i></b>
71
+ <b>If there is a line that just says <tt>devise_for :users</tt> or a duplicate, <i>REMOVE IT!</i></b>
72
72
 
73
- Create a root in your config/routes.rb
73
+ Create a root in your <tt>config/routes.rb</tt>
74
74
 
75
75
  root to: 'welcome#index'
76
76
 
77
- Add the following to your app/models/user.rb
77
+ Add the following to the top of your <tt>app/controllers/welcome_controller.rb</tt>
78
+
79
+ before_filter :authenticate_user!
80
+
81
+ Add the following to your <tt>app/models/user.rb</tt>
78
82
 
79
83
  # Model Relationships
80
84
  has_many :authentications
@@ -90,7 +94,7 @@ Add the following to your app/models/user.rb
90
94
  (authentications.empty? || !password.blank?) && super
91
95
  end
92
96
 
93
- Add the following to your app/models/authentication.rb
97
+ Add the following to your <tt>app/models/authentication.rb</tt>
94
98
 
95
99
  belongs_to :user
96
100
 
@@ -98,7 +102,7 @@ Add the following to your app/models/authentication.rb
98
102
  OmniAuth.config.camelizations[provider.to_s.downcase] || provider.to_s.titleize
99
103
  end
100
104
 
101
- Edit config/initializers/devise.rb to use :get for devise sign_out_via
105
+ Edit <tt>config/initializers/devise.rb</tt> to use <tt>:get</tt> for devise <tt>sign_out_via</tt>
102
106
 
103
107
  # The default HTTP method used to sign out a resource. Default is :delete.
104
108
  config.sign_out_via = :get
@@ -109,8 +113,73 @@ Start your server and navigate to http://localhost:3000/users/login
109
113
 
110
114
  You can then sign in using your {Google Account}[http://localhost:3000/auth/google_apps?domain=gmail.com] or by registering for an account at http://localhost:3000/users/register
111
115
 
116
+ == Overwrite Default Rails Scaffolding (optional)
117
+
118
+ Add {Kaminari}[https://github.com/amatsuda/kaminari] gem to your <tt>Gemfile</tt>
119
+
120
+ gem 'kaminari', '~> 0.13.0'
121
+
122
+ Update your gems
123
+
124
+ bundle update
125
+
126
+ Create a new model using the Rails scaffold
127
+
128
+ rails g scaffold Item name:string description:text user_id:integer bought_date:date --no-stylesheets
129
+
130
+ Add a current <tt>scope</tt> and <tt>belongs_to</tt> relationship to <tt>app/models/item.rb</tt>
131
+
132
+ scope :current, conditions: { }
133
+
134
+ belongs_to :user
135
+
136
+ Add a current <tt>scope</tt> and <tt>has_many</tt> relationship to <tt>app/models/user.rb</tt> along with name placeholder
137
+
138
+ scope :current, conditions: { }
139
+
140
+ has_many :items
141
+
142
+ def name
143
+ "User ##{self.id}"
144
+ end
145
+
146
+ Add a user resource to your <tt>config/routes.rb</tt> file
147
+
148
+ resources :users
149
+
150
+ NOTE: Adding the User controller is not shown, but could be created using <tt>rails g controller Users index show edit update destroy --no-stylesheets</tt>. Remember that the <tt>new</tt> and <tt>create</tt> actions are already defined and should be left commented out.
151
+
152
+ Migrate your database
153
+
154
+ bundle exec rake db:migrate
155
+
156
+ Update with the Contour scaffold
157
+
158
+ rails g contour:scaffold Item
159
+
160
+ When prompted to overwrite the existing files, type <tt>a</tt> for ALL.
161
+
162
+ NOTE: This will overwrite all the files generated by the rails scaffold command!
163
+
164
+ Go to http://localhost:3000/items to see the changes! Note, that the <tt>user_id</tt> selection now defaults to a drop down box!
165
+
166
+ == Inspiration and Attribution
167
+
168
+ Contour is designed to rapidly prototype Rails applications with nice default styling and a solid authentication system. The Contour code base has been influenced by existing Rails Engines architectures that are listed below. Please check them out if you are interested in seeing how Contour is put together!
169
+
170
+ === Devise
171
+
172
+ {Devise}[https://github.com/plataformatec/devise] is the highly configurable authentication gem that Contour utilizes.
173
+
174
+ Contour has adopted Devise's installation and configuration approach <tt>rails generate devise:install</tt> and <tt>config/intializers/devise.rb</tt>.
175
+
176
+ === Twitter Bootstrap Rails
177
+
178
+ While Contour doesn't have an external dependency on the {Twitter Bootstrap Rails}[https://github.com/seyhunak/twitter-bootstrap-rails] gem, Contour does adopt the templating approach, <tt>rails generate contour:scaffold ModelName</tt>, used to overwrite the default scaffolding provided by Rails.
179
+
180
+ For those interested in having better control on modifying the Twitter Bootstrap Less file and CSS, I highly recommend taking a look at Twitter Bootstrap Rails!
112
181
 
113
- == Contributing to contour
182
+ == Contributing to Contour
114
183
 
115
184
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
116
185
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
@@ -2,6 +2,27 @@
2
2
  @showWaiting = (element_id, text, centered) ->
3
3
  element = $(element_id)
4
4
  if element && centered
5
- element.html('<br /><center><img width=\"13\" height=\"13\" src=\"' + root_url + 'assets/ajax-loader.gif\" align=\"absmiddle\" alt=\"...\" />' + text + '</center><br />')
5
+ element.html('<br /><center><img width=\"13\" height=\"13\" src=\"' + root_url + 'assets/contour/ajax-loader.gif\" align=\"absmiddle\" alt=\"...\" />' + text + '</center><br />')
6
6
  else if element
7
- element.html('<img width=\"13\" height=\"13\" src=\"' + root_url + 'assets/ajax-loader.gif\" align=\"absmiddle\" alt=\"...\" />' + text)
7
+ element.html('<img width=\"13\" height=\"13\" src=\"' + root_url + 'assets/contour/ajax-loader.gif\" align=\"absmiddle\" alt=\"...\" />' + text)
8
+
9
+ jQuery ->
10
+ $(".datepicker").datepicker
11
+ showOtherMonths: true
12
+ selectOtherMonths: true
13
+ changeMonth: true
14
+ changeYear: true
15
+
16
+ $("#ui-datepicker-div").hide()
17
+
18
+ $(document).on('click', ".pagination a, .page a, .next a, .prev a", () ->
19
+ return false if $(this).parent().is('.active, .disabled, .per_page')
20
+ $.get(this.href, null, null, "script")
21
+ false
22
+ )
23
+
24
+ $(document).on("click", ".per_page a", () ->
25
+ object_class = $(this).data('object')
26
+ $.get($("#"+object_class+"_search").attr("action"), $("#"+object_class+"_search").serialize() + "&"+object_class+"_per_page="+ $(this).data('count'), null, "script")
27
+ false
28
+ )
@@ -1,5 +1,20 @@
1
- # From Twitter-Bootstrap-Rails
2
1
  module ContourHelper
2
+
3
+ def cancel
4
+ link_to 'Cancel', URI.parse(request.referer.to_s).path.blank? ? root_path : (URI.parse(request.referer.to_s).path), class: 'btn btn-danger'
5
+ end
6
+
7
+ def sort_field_helper(order, sort_field, display_name, search_form_id = 'search_form')
8
+ result = ''
9
+ if order == sort_field
10
+ result = "<span class='selected'>#{display_name} #{ link_to_function('&raquo;'.html_safe, "$('#order').val('#{sort_field} DESC');$('##{search_form_id}').submit();", style: 'text-decoration:none')}</span>"
11
+ elsif order == sort_field + ' DESC' or order.split(' ').first != sort_field
12
+ result = "<span #{'class="selected"' if order == sort_field + ' DESC'}>#{display_name} #{link_to_function((order == sort_field + ' DESC' ? '&laquo;'.html_safe : '&laquo;&raquo;'.html_safe), "$('#order').val('#{sort_field}');$('##{search_form_id}').submit();", style: 'text-decoration:none')}</span>"
13
+ end
14
+ result
15
+ end
16
+
17
+ # From Twitter-Bootstrap-Rails
3
18
  def flash_block
4
19
  output = ''
5
20
  flash.each do |type, message|
@@ -9,6 +24,7 @@ module ContourHelper
9
24
  raw(output)
10
25
  end
11
26
 
27
+ # From Twitter-Bootstrap-Rails
12
28
  def flash_container(type, message)
13
29
  type = 'success' if type.to_s == 'notice'
14
30
  type = 'error' if type.to_s == 'alert'
@@ -16,4 +32,5 @@ module ContourHelper
16
32
  content_tag(:a, raw("&times;"), href: '#', class: 'close', data: { dismiss: 'alert' }) + message
17
33
  end.html_safe
18
34
  end
35
+
19
36
  end
@@ -0,0 +1,7 @@
1
+ <div class="pagination pagination-right">
2
+ <ul>
3
+ <li class="disabled"><a href="#">Per Page</a></li>
4
+ <li class="active per_page"><%= link_to (defined?(per_page) and per_page ? per_page : 20), "#" %></li>
5
+ <% if defined?(object_count) and object_count %><li class="disabled"><a href="#">out of <%= object_count %></a></li><% end %>
6
+ </ul>
7
+ </div>
@@ -1,32 +1,3 @@
1
1
  Devise.setup do |config|
2
2
  config.router_name = :main_app
3
3
  end
4
-
5
- module Devise
6
- class FailureApp < ActionController::Metal
7
-
8
- protected
9
-
10
- def scope_path
11
- opts = {}
12
- route = :"new_#{scope}_session_path"
13
- opts[:format] = request_format unless skip_format?
14
- # The 2.1.0.rc of Devise has the following line. I've commented it out since it
15
- # breaks subdomain redirects when failing to login.
16
- # Until 2.1.0.rc2 is out, use the following from:
17
- # https://github.com/plataformatec/devise/commit/ad0aed3ba5ab58cbe2f54b1a5bd760642c1c689c
18
- # Thanks @josevalim !
19
- opts[:script_name] = Rails.application.config.relative_url_root
20
-
21
- context = send(Devise.available_router_name)
22
-
23
- if context.respond_to?(route)
24
- context.send(route, opts)
25
- elsif respond_to?(:root_path)
26
- root_path(opts)
27
- else
28
- "/"
29
- end
30
- end
31
- end
32
- end
@@ -25,14 +25,14 @@ Gem::Specification.new do |s|
25
25
 
26
26
  s.add_dependency 'rails', '~> 3.2.3'
27
27
  s.add_dependency 'jquery-rails', '~> 2.0.2'
28
- s.add_dependency 'devise', '~> 2.1.0.rc'
28
+ s.add_dependency 'devise', '~> 2.1.0'
29
29
  s.add_dependency 'omniauth', '~> 1.1.0'
30
- s.add_dependency 'omniauth-openid', '~> 1.0.1'
31
- s.add_dependency 'omniauth-ldap', '~> 1.0.2'
32
- s.add_dependency 'omniauth-twitter', '~> 0.0.11'
30
+ s.add_dependency 'omniauth-cas', '~> 0.0.7'
33
31
  s.add_dependency 'omniauth-facebook', '~> 1.3.0'
32
+ s.add_dependency 'omniauth-ldap', '~> 1.0.2'
34
33
  s.add_dependency 'omniauth-linkedin', '~> 0.0.6'
35
- s.add_dependency 'omniauth-cas', '~> 0.0.7'
34
+ s.add_dependency 'omniauth-openid', '~> 1.0.1'
35
+ s.add_dependency 'omniauth-twitter', '~> 0.0.11'
36
36
 
37
37
  s.add_development_dependency "sqlite3"
38
38
  end
@@ -3,7 +3,7 @@ module Contour
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
5
  TINY = 0
6
- BUILD = "beta12" # nil, "pre", "rc", "rc2"
6
+ BUILD = "rc" # nil, "pre", "rc", "rc2"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
@@ -0,0 +1,30 @@
1
+ class Contour::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ desc "Install default Contour Files"
5
+ # class_option :orm
6
+
7
+ def copy_initializer
8
+ template "contour.rb", "config/initializers/contour.rb"
9
+ end
10
+
11
+ def copy_omniauth
12
+ template "omniauth.rb", "config/initializers/omniauth.rb"
13
+ end
14
+
15
+ def install_devise
16
+ generate("devise:install")
17
+ model_name = ask("What would you like the user model to be called? [user]")
18
+ model_name = "user" if model_name.blank?
19
+ generate("devise", model_name)
20
+ route "devise_for :#{model_name}s, controllers: { registrations: 'contour/registrations', sessions: 'contour/sessions', passwords: 'contour/passwords', confirmations: 'contour/confirmations', unlocks: 'contour/unlocks' }, path_names: { sign_up: 'register', sign_in: 'login' }"
21
+ end
22
+
23
+ def show_readme
24
+ readme "README" if behavior == :invoke
25
+ end
26
+
27
+ # def copy_locale
28
+ # copy_file "../../../config/locales/en.yml", "config/locales/contour.en.yml"
29
+ # end
30
+ end
@@ -4,25 +4,21 @@
4
4
  Contour requires some additional setup:
5
5
 
6
6
  1. Add the following line to your application_controller.rb
7
-
7
+
8
8
  layout "contour/layouts/application"
9
-
9
+
10
10
  2. Edit your application.js manifest to use Contour JavaScript
11
-
11
+
12
12
  //= require contour
13
-
13
+
14
14
  3. Edit your application.css manifest to use Contour CSS
15
-
15
+
16
16
  *= require contour
17
-
17
+
18
18
  4. Remove any scaffold.css files that exist in your application
19
-
19
+
20
20
  5. Make a migration for Authentications
21
-
21
+
22
22
  rails generate model Authentication user_id:integer provider:string uid:string
23
-
24
- 6. Add first_name and last_name to User model
25
-
26
- rails generate migration AddFirstNameAndLastNameToUsers first_name:string last_name:string
27
-
23
+
28
24
  ===============================================================================
@@ -0,0 +1,15 @@
1
+ Description:
2
+ Installs views and controller based on the model name provided
3
+
4
+ Example:
5
+ rails generate contour:bootstrap NAME
6
+
7
+ This will create:
8
+ app/controllers/NAMEs_controller.rb
9
+ app/views/NAMEs/_form.html.erb
10
+ app/views/NAMEs/_NAMEs.html.erb
11
+ app/views/NAMEs/edit.html.erb
12
+ app/views/NAMEs/index.html.erb
13
+ app/views/NAMEs/index.js.erb
14
+ app/views/NAMEs/new.html.erb
15
+ app/views/NAMEs/show.html.erb
@@ -0,0 +1,58 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/generated_attribute'
3
+
4
+ class Contour::ScaffoldGenerator < Rails::Generators::NamedBase
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ argument :name
8
+
9
+ # "project_user"
10
+ def resource_name
11
+ name.underscore
12
+ end
13
+
14
+ # "ProjectUser"
15
+ def resource_class_name
16
+ resource_name.camelize
17
+ end
18
+
19
+ # "ProjectUsers"
20
+ def resource_class_name_plural
21
+ resource_name.camelize.pluralize
22
+ end
23
+
24
+ # "project_users"
25
+ def resource_name_plural
26
+ resource_name.pluralize
27
+ end
28
+
29
+ # "Project User"
30
+ def resource_title
31
+ resource_name.titleize
32
+ end
33
+
34
+ # "Project Users"
35
+ def resource_title_plural
36
+ resource_title.pluralize
37
+ end
38
+
39
+ def columns
40
+ begin
41
+ resource_name.camelize.constantize.columns.reject{|c| ['id', 'created_at', 'updated_at'].include?(c.name)}.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type)}
42
+ rescue NoMethodError
43
+ []
44
+ end
45
+ end
46
+
47
+ def date_columns
48
+ self.columns.select{|c| c.field_type == :date_select}
49
+ end
50
+
51
+ def generate_views
52
+ ['_form.html.erb', 'new.html.erb', 'edit.html.erb', 'show.html.erb', 'index.html.erb', 'index.js.erb'].each do |view|
53
+ template view, "app/views/#{resource_name_plural}/#{view}"
54
+ end
55
+ template '_paginate.html.erb', "app/views/#{resource_name_plural}/_#{resource_name_plural}.html.erb"
56
+ template 'controller.rb', "app/controllers/#{resource_name_plural}_controller.rb"
57
+ end
58
+ end