rails-maker 0.1.1

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.
@@ -0,0 +1,79 @@
1
+ remove_file 'app/views/admin/dashboard/index.html.haml'
2
+ create_file 'app/views/admin/dashboard/index.html.haml' do
3
+ <<-FILE
4
+ %h1 #{app_name.humanize} Admin
5
+ FILE
6
+ end
7
+
8
+ run 'mkdir app/views/admin/shared'
9
+
10
+ create_file 'app/views/admin/shared/_header.html.haml' do
11
+ <<-FILE
12
+ %header#main_admin_header
13
+ %h1= link_to '#{app_name.humanize}', root_path
14
+ = render 'admin/shared/messages'
15
+ %nav#main_admin_nav
16
+ %ul
17
+ %li= link_to 'Home', root_path
18
+ %ul#user_admin_nav
19
+ = render 'devise/menu/login_items'
20
+ FILE
21
+ end
22
+
23
+ create_file 'app/views/admin/shared/_messages.html.haml' do
24
+ <<-FILE
25
+ - if flash[:notice]
26
+ %div#messenger{:class => "flasher"}= flash[:notice]
27
+ - if flash[:error]
28
+ %div#error{:class => "flasher"}= flash[:error]
29
+ - if flash[:alert]
30
+ %div#alert{:class => "flasher"}= flash[:alert]
31
+ FILE
32
+ end
33
+
34
+ create_file 'app/views/admin/shared/_footer.html.haml' do
35
+ <<-FILE
36
+ %footer#main_admin_footer
37
+ FILE
38
+ end
39
+
40
+ create_file 'app/views/admin/shared/_end_scripts.html.haml' do
41
+ <<-FILE
42
+ = include_javascripts :common
43
+ FILE
44
+ end
45
+
46
+ create_file 'app/views/layouts/admin.html.haml' do
47
+ <<-FILE
48
+ !!! 5
49
+ -# paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
50
+ <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
51
+ <!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
52
+ <!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
53
+ <!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
54
+ <!--[if (gte IE 9)|!(IE)]><!-->
55
+ %html.no-js{ :lang => "en" }
56
+ <!--<![endif]-->
57
+ %head
58
+ %meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}
59
+ %meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}
60
+ %title<
61
+ #{app_name.humanize}
62
+ = yield(:title)
63
+ %meta{:name => 'viewport', :content => 'width=device-width initial-scale=1.0 maximum-scale=1.0'}
64
+ %meta{:name => 'apple-mobile-web-app-capable', :content => 'yes'}
65
+ = csrf_meta_tag
66
+ %link{:rel => "shortcut icon", :href => "/favicon.ico", :type => "image/x-icon"}
67
+ /[if lt IE 9]
68
+ %script{:type => "text/javascript", :src => "/javascripts/shiv.js"}
69
+ = include_stylesheets :admin, :media => 'all'
70
+ = yield(:head)
71
+ %body
72
+ #container
73
+ = render :partial => "admin/shared/header"
74
+ %section#content
75
+ = yield
76
+ = render :partial => "admin/shared/footer"
77
+ = render :partial => "admin/shared/end_scripts"
78
+ FILE
79
+ end
@@ -0,0 +1,43 @@
1
+ create_file 'public/stylesheets/sass/admin.scss' do
2
+ <<-FILE
3
+ @import "partials/admin_variables";
4
+ @import "partials/fonts";
5
+ @import "partials/defaults";
6
+ @import "partials/media";
7
+
8
+ @mixin admin {
9
+ @include fonts;
10
+ @include defaults;
11
+ @include media;
12
+ }
13
+ @include admin;
14
+ FILE
15
+ end
16
+
17
+ create_file 'public/stylesheets/sass/partials/_admin_variables.scss' do
18
+ <<-FILE
19
+ $base-font-family: unquote('sans-serif'); // default font-family
20
+
21
+ $base-font-size: 13px; // default font-size for YUI fonts
22
+
23
+ $base-line-height: 1.231; // default line-height for YUI fonts
24
+
25
+ $font-color: #444;
26
+
27
+ $link-color: #607890;
28
+
29
+ $link-hover-color: #036;
30
+
31
+ $link-active-color: #607890;
32
+
33
+ $link-visited-color: #607890;
34
+
35
+ $selected-font-color: #fff; // color for selected text
36
+
37
+ $selected-background-color: #ff5E99; // bg-color for selected text
38
+
39
+ $list-left-margin: 1.8em; // left margin for ul an ol
40
+ FILE
41
+ end
42
+
43
+ run 'sass public/stylesheets/sass/admin.scss public/stylesheets/admin.css'
@@ -0,0 +1,134 @@
1
+ generate(:controller, "admin/users index new create edit update destroy")
2
+
3
+ inject_into_file 'config/routes.rb', :after => "devise_for :users\n" do
4
+ <<-'FILE'
5
+ namespace "admin" do
6
+ resources :users
7
+ end
8
+ FILE
9
+ end
10
+
11
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def index\n" do
12
+ <<-'FILE'
13
+ @users = User.paginate :page => params[:page], :per_page => 50
14
+ FILE
15
+ end
16
+
17
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def new\n" do
18
+ <<-'FILE'
19
+ @user = User.new
20
+ FILE
21
+ end
22
+
23
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def create\n" do
24
+ <<-'FILE'
25
+ @user = User.new
26
+ # attr_accessor logic here
27
+ @user.attributes = params[:user]
28
+ if @user.save
29
+ flash[:notice] = "User created!"
30
+ redirect_to admin_users_url
31
+ else
32
+ render :action => 'new'
33
+ end
34
+ FILE
35
+ end
36
+
37
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def update\n" do
38
+ <<-'FILE'
39
+ params[:user].delete(:password) if params[:user][:password].blank?
40
+ params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
41
+ # attr_accessor logic here
42
+ if @user.update_attributes(params[:user])
43
+ flash[:notice] = "Successfully updated #{@user.name}."
44
+ redirect_to admin_users_url
45
+ else
46
+ render :action => 'edit'
47
+ end
48
+ FILE
49
+ end
50
+
51
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def destroy\n" do
52
+ <<-'FILE'
53
+ @user.destroy
54
+ flash[:notice] = "User deleted."
55
+ redirect_to admin_users_url
56
+ FILE
57
+ end
58
+
59
+ gsub_file 'app/controllers/admin/users_controller.rb', /ApplicationController/, 'Admin::BaseController'
60
+
61
+ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "class Admin::UsersController < Admin::BaseController\n" do
62
+ <<-'FILE'
63
+ before_filter :find_user, :only => [:edit, :update, :destroy]
64
+
65
+ def find_user
66
+ @user = User.find(params[:id])
67
+ end
68
+
69
+ FILE
70
+ end
71
+
72
+ create_file 'app/views/admin/users/_form.html.haml' do
73
+ <<-'FILE'
74
+ = form_for([:admin, @user]) do |f|
75
+ .form_errors
76
+ = f.error_messages
77
+ %fieldset#user_form
78
+ .form_row
79
+ = f.label :name
80
+ = f.text_field :name
81
+ .form_row
82
+ = f.label :email
83
+ = f.text_field :email
84
+ .form_row
85
+ = f.label :password
86
+ = f.password_field :password
87
+ .form_row
88
+ = f.label :password_confirmation
89
+ = f.password_field :password_confirmation
90
+ .form_row.form_row_button
91
+ = f.submit "Save"
92
+ FILE
93
+ end
94
+
95
+ remove_file 'app/views/admin/users/edit.html.haml'
96
+ create_file 'app/views/admin/users/edit.html.haml' do
97
+ <<-'FILE'
98
+ = render :partial => "form"
99
+ FILE
100
+ end
101
+
102
+ remove_file 'app/views/admin/users/new.html.haml'
103
+ create_file 'app/views/admin/users/new.html.haml' do
104
+ <<-'FILE'
105
+ = render :partial => "form"
106
+ FILE
107
+ end
108
+
109
+ remove_file 'app/views/admin/users/index.html.haml'
110
+ create_file 'app/views/admin/users/index.html.haml' do
111
+ <<-FILE
112
+ - if !@users.blank?
113
+ %table
114
+ %thead
115
+ %tr
116
+ %th Name
117
+ %th Email
118
+ %th
119
+ %tbody
120
+ - @users.each do |user|
121
+ %tr
122
+ %td= link_to user.name, edit_admin_user_path(user), :class => 'edit_link'
123
+ %td= user.email
124
+ %td
125
+ - if user.id != current_user.id
126
+ = link_to "Delete", admin_user_path(user), :confirm => 'Are you sure?', :method => :delete, :class => 'delete_link'
127
+ - else
128
+ That's you!
129
+ = will_paginate @users
130
+ - else
131
+ %p No users
132
+ FILE
133
+ end
134
+
@@ -0,0 +1,31 @@
1
+ run 'rm spec/controllers/admin/users_controller_spec.rb'
2
+
3
+ create_file 'spec/controllers/admin/users_controller_spec.rb' do
4
+ <<-'FILE'
5
+ require 'spec_helper'
6
+ include Devise::TestHelpers
7
+
8
+ describe Admin::UsersController do
9
+
10
+ before(:each) do
11
+ @user = @user ||=Factory.create(:admin)
12
+ sign_in @user
13
+ end
14
+
15
+ describe "GET 'index'" do
16
+ it "should be successful" do
17
+ get 'index'
18
+ response.should be_success
19
+ end
20
+ end
21
+
22
+ describe "GET 'new'" do
23
+ it "should be successful" do
24
+ get 'new'
25
+ response.should be_success
26
+ end
27
+ end
28
+ end
29
+
30
+ FILE
31
+ end
@@ -0,0 +1,118 @@
1
+ run 'mkdir app/views/shared'
2
+
3
+ create_file 'app/views/shared/_header.html.haml' do
4
+ <<-FILE
5
+ %header#main_header
6
+ %h1= link_to '#{app_name.humanize}', root_path
7
+ = render 'shared/messages'
8
+ %nav#main_nav
9
+ %ul
10
+ %li= link_to 'Home', root_path
11
+ FILE
12
+ end
13
+
14
+ create_file 'app/views/shared/_messages.html.haml' do
15
+ <<-FILE
16
+ - if flash[:notice]
17
+ %div#messenger{:class => "flasher"}= flash[:notice]
18
+ - if flash[:error]
19
+ %div#error{:class => "flasher"}= flash[:error]
20
+ - if flash[:alert]
21
+ %div#alert{:class => "flasher"}= flash[:alert]
22
+ FILE
23
+ end
24
+
25
+ create_file 'app/views/shared/_footer.html.haml' do
26
+ <<-FILE
27
+ %footer#main_footer
28
+ FILE
29
+ end
30
+
31
+ create_file 'app/views/shared/_end_scripts.html.haml' do
32
+ <<-FILE
33
+ = include_javascripts :common
34
+ = yield(:end_scripts)
35
+ - if Rails.env == 'production'
36
+ :javascript
37
+ var _gaq = [['_setAccount', 'UA-XXXXX-X'], ['_trackPageview']];
38
+ (function(d, t) {
39
+ var g = d.createElement(t),
40
+ s = d.getElementsByTagName(t)[0];
41
+ g.async = true;
42
+ g.src = ('https:' == location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
43
+ s.parentNode.insertBefore(g, s);
44
+ })(document, 'script');
45
+ FILE
46
+ end
47
+
48
+ run 'rm app/views/layouts/application.html.erb'
49
+ create_file 'app/views/layouts/application.html.haml' do
50
+ <<-FILE
51
+ !!! 5
52
+ -# paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
53
+ <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
54
+ <!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
55
+ <!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
56
+ <!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
57
+ <!--[if (gte IE 9)|!(IE)]><!-->
58
+ %html.no-js{ :lang => "en" }
59
+ <!--<![endif]-->
60
+ %head
61
+ %meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}
62
+ %meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}
63
+ %title<
64
+ #{app_name.humanize}
65
+ = yield(:title)
66
+ %meta{:name => 'description', :content => ''}
67
+ %meta{:name => 'author', :content => ''}
68
+ %meta{:name => 'viewport', :content => 'width=device-width initial-scale=1.0 maximum-scale=1.0'}
69
+ %meta{:name => 'apple-mobile-web-app-capable', :content => 'yes'}
70
+ = csrf_meta_tag
71
+ %link{:rel => "shortcut icon", :href => "/favicon.ico", :type => "image/x-icon"}
72
+ %link{:rel => "apple-touch-icon", :href => "/images/ati.png"}
73
+ /[if lt IE 9]
74
+ %script{:type => "text/javascript", :src => "/javascripts/shiv.js"}
75
+ = include_stylesheets :main, :media => 'all'
76
+ = yield(:head)
77
+ %body
78
+ #container
79
+ = render :partial => "shared/header"
80
+ %section#content
81
+ = yield
82
+ = render :partial => "shared/footer"
83
+ = render :partial => "shared/end_scripts"
84
+ FILE
85
+ end
86
+
87
+ create_file 'public/maintenance.html' do
88
+ <<-FILE
89
+ <!DOCTYPE html>
90
+ <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
91
+ <!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
92
+ <!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
93
+ <!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
94
+ <!--[if (gte IE 9)|!(IE)]><!-->
95
+ <html class='no-js' lang='en'>
96
+ <!--<![endif]-->
97
+ <head>
98
+ <meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
99
+ <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>
100
+ <title>#{app_name.humanize} is down for maintenance</title>
101
+ <meta content='width=device-width initial-scale=1.0 maximum-scale=1.0' name='viewport'>
102
+ <link href='/favicon.ico' rel='shortcut icon' type='image/x-icon'>
103
+ <!--[if lt IE 9]>
104
+ <script src='/javascripts/shiv.js' type='text/javascript'></script>
105
+ <![endif]-->
106
+ <link href="/stylesheets/reset.css" media="all" rel="stylesheet" type="text/css" />
107
+ <link href="/stylesheets/main.css" media="all" rel="stylesheet" type="text/css" />
108
+ </head>
109
+ <body>
110
+ <div id='container'>
111
+ <section id='content'>
112
+ <h1>#{app_name.humanize} is down for maintenance</h1>
113
+ </section>
114
+ </div>
115
+ </body>
116
+ </html>
117
+ FILE
118
+ end
@@ -0,0 +1,165 @@
1
+ require 'hpricot'
2
+ require 'ruby_parser'
3
+
4
+ say "Building authentication"
5
+
6
+ # Configure sensitive parameters which will be filtered from the log file.
7
+ gsub_file 'config/application.rb', /:password/, ':password, :password_confirmation'
8
+
9
+ run 'rails generate devise:install'
10
+ # Generate devise views
11
+ run 'rails generate devise:views -e erb'
12
+ # Convert devise views to haml
13
+ run "for i in `find app/views/devise -name '*.erb'` ; do html2haml -e $i ${i%erb}haml ; rm $i ; done"
14
+
15
+ gsub_file 'config/environments/development.rb', /# Don't care if the mailer can't send/, '### ActionMailer Config'
16
+
17
+ gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/ do
18
+ <<-RUBY
19
+ config.action_mailer.default_url_options = { :host => '0.0.0.0:3000' }
20
+ config.action_mailer.delivery_method = :letter_opener
21
+ config.action_mailer.raise_delivery_errors = false
22
+ config.action_mailer.default :charset => "utf-8"
23
+ RUBY
24
+ end
25
+
26
+ inject_into_file 'config/environments/test.rb', :after => "config.action_controller.allow_forgery_protection = false\n" do
27
+ <<-RUBY
28
+ config.action_mailer.default_url_options = { :host => '0.0.0.0:3000' }
29
+ RUBY
30
+ end
31
+
32
+ gsub_file 'config/environments/production.rb', /config.i18n.fallbacks = true/ do
33
+ <<-RUBY
34
+ config.i18n.fallbacks = true
35
+ config.action_mailer.default_url_options = { :host => 'yourhost.com' }
36
+ ### ActionMailer Config
37
+ # Setup for production - deliveries, no errors raised
38
+ config.action_mailer.delivery_method = :smtp
39
+ config.action_mailer.perform_deliveries = true
40
+ config.action_mailer.raise_delivery_errors = false
41
+ config.action_mailer.default :charset => "utf-8"
42
+ RUBY
43
+ end
44
+
45
+ run 'rails generate devise User'
46
+ run 'rm app/models/user.rb'
47
+
48
+ create_file 'app/models/user.rb' do
49
+ <<-RUBY
50
+ class User < ActiveRecord::Base
51
+ devise :database_authenticatable, :token_authenticatable, :recoverable, :rememberable, :trackable, :confirmable
52
+ default_scope :conditions => { :deleted_at => nil }
53
+ validates_presence_of :name, :email
54
+ validates_presence_of :password, :on => :create
55
+ validates_confirmation_of :password, :on => :create
56
+ validates_length_of :password, :within => 6..30, :allow_blank => true
57
+ validates_uniqueness_of :email, :case_sensitive => false, :scope => :deleted_at
58
+ validates_format_of :email, :with => Devise::email_regexp
59
+
60
+ attr_accessible :name, :email, :password, :password_confirmation, :remember_me
61
+
62
+ def destroy
63
+ self.update_attribute(:deleted_at, Time.now.utc)
64
+ end
65
+
66
+ def self.find_with_destroyed *args
67
+ self.with_exclusive_scope { find(*args) }
68
+ end
69
+
70
+ def self.find_only_destroyed
71
+ self.with_exclusive_scope :find => { :conditions => "deleted_at IS NOT NULL" } do
72
+ all
73
+ end
74
+ end
75
+
76
+ end
77
+ RUBY
78
+ end
79
+
80
+ generate(:migration, "AddNameToUsers name:string")
81
+ generate(:migration, "AddCachedSlugToUsers cached_slug:string")
82
+ generate(:migration, "AddDeletedAtToUsers deleted_at:datetime")
83
+
84
+ create_file 'app/views/devise/menu/_login_items.html.haml' do
85
+ <<-'FILE'
86
+ - if user_signed_in?
87
+ %li
88
+ = link_to('Logout', destroy_user_session_path)
89
+ - else
90
+ %li
91
+ = link_to('Login', new_user_session_path)
92
+ %li
93
+ User:
94
+ - if current_user
95
+ = current_user.name
96
+ - else
97
+ (not logged in)
98
+ FILE
99
+ end
100
+
101
+ append_file 'app/views/shared/_header.html.haml' do
102
+ <<-'FILE'
103
+ %ul#user_nav
104
+ = render 'devise/menu/login_items'
105
+ FILE
106
+ end
107
+
108
+ devise_migration = Dir['db/migrate/*_devise_create_users.rb'].first
109
+
110
+ gsub_file devise_migration, /./, <<-FILE
111
+ class DeviseCreateUsers < ActiveRecord::Migration
112
+ def change
113
+ create_table(:users) do |t|
114
+ ## Database authenticatable
115
+ t.string :email, :null => false, :default => ""
116
+ t.string :encrypted_password, :null => false, :default => ""
117
+
118
+ ## Recoverable
119
+ t.string :reset_password_token
120
+ t.datetime :reset_password_sent_at
121
+
122
+ ## Rememberable
123
+ t.datetime :remember_created_at
124
+
125
+ ## Trackable
126
+ t.integer :sign_in_count, :default => 0
127
+ t.datetime :current_sign_in_at
128
+ t.datetime :last_sign_in_at
129
+ t.string :current_sign_in_ip
130
+ t.string :last_sign_in_ip
131
+
132
+ ## Confirmable
133
+ t.string :confirmation_token
134
+ t.datetime :confirmed_at
135
+ t.datetime :confirmation_sent_at
136
+ t.string :unconfirmed_email
137
+
138
+ ## Lockable
139
+ t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
140
+ t.string :unlock_token # Only if unlock strategy is :email or :both
141
+ t.datetime :locked_at
142
+
143
+ ## Token authenticatable
144
+ t.string :authentication_token
145
+
146
+ t.timestamps
147
+ end
148
+
149
+ add_index :users, :email, :unique => true
150
+ add_index :users, :reset_password_token, :unique => true
151
+ add_index :users, :confirmation_token, :unique => true
152
+ add_index :users, :unlock_token, :unique => true
153
+ add_index :users, :authentication_token, :unique => true
154
+ end
155
+ end
156
+ FILE
157
+
158
+ append_file 'db/seeds.rb' do
159
+ <<-FILE
160
+ # Setup initial user so we can get in
161
+ user = User.create! :name => "#{ENV['RAILSMAKER_USER_NAME']}", :email => "#{ENV['RAILSMAKER_USER_EMAIL']}", :password => "#{ENV['RAILSMAKER_USER_PASSWORD']}", :password_confirmation => "#{ENV['RAILSMAKER_USER_PASSWORD']}"
162
+ user.confirmed_at = user.confirmation_sent_at
163
+ user.save
164
+ FILE
165
+ end