mologue 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ run 'rm spec/controllers/admin/dashboard_controller_spec.rb'
2
+
3
+ create_file 'spec/controllers/admin/dashboard_controller_spec.rb' do
4
+ <<-'FILE'
5
+ require 'spec_helper'
6
+ include Devise::TestHelpers
7
+
8
+ describe Admin::DashboardController do
9
+ before(:each) do
10
+ @user = @user ||=Factory.create(:admin)
11
+ sign_in @user
12
+ end
13
+
14
+ describe "GET 'index'" do
15
+ it "should be successful" do
16
+ get 'index'
17
+ response.should be_success
18
+ end
19
+ end
20
+
21
+ end
22
+ FILE
23
+ end
@@ -0,0 +1,76 @@
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
+ %html
50
+ %head
51
+ %meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}
52
+ %meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}
53
+ %title
54
+ #{app_name.humanize}
55
+ = yield(:title)
56
+ %meta{:name => 'viewport', :content => 'width=device-width; initial-scale=1.0'}
57
+ = csrf_meta_tag
58
+ %link{:rel => "shortcut icon", :href => "/images/favicon.ico", :type => "image/x-icon"}
59
+ /[if lt IE 9]
60
+ %script{:type => "text/javascript", :src => "/javascripts/shiv.js"}
61
+ = include_stylesheets :admin, :media => 'all'
62
+ = yield(:head)
63
+ /[if IE 7]
64
+ = stylesheet_link_tag 'ie7', :media => 'all'
65
+ /[if IE 8]
66
+ = stylesheet_link_tag 'ie8', :media => 'all'
67
+ %body
68
+ #container
69
+ = render :partial => "admin/shared/header"
70
+ %section#content
71
+ = yield
72
+ #pusher
73
+ = render :partial => "admin/shared/footer"
74
+ = render :partial => "admin/shared/end_scripts"
75
+ FILE
76
+ end
@@ -0,0 +1,80 @@
1
+ create_file 'public/stylesheets/sass/admin.scss' do
2
+ <<-FILE
3
+ @import "reset";
4
+ @import "common";
5
+ @mixin layout_base {
6
+ @include reset;
7
+ @include container;
8
+ @include user_admin_nav;
9
+ @include main_admin_nav;
10
+ //uncomment for a handy layout guide
11
+ @include layout_guide;
12
+ }
13
+
14
+ @mixin container($container_size: 950px) {
15
+ #container {
16
+ width: $container_size;
17
+ clear:both;
18
+ padding: 0 20px;
19
+ min-height: 100%;
20
+ height: auto !important;
21
+ height: 100%;
22
+ margin: 0 auto -80px;
23
+ }
24
+ #main_admin_header {
25
+ width: $container_size;
26
+ height: 60px;
27
+ @include clear_left;
28
+ h1 {
29
+ float: left;
30
+ padding: 20px 0 0 0;
31
+ font-size: 24px;
32
+ font-weight: bold;
33
+ }
34
+ }
35
+ #content {
36
+ width: $container_size;
37
+ @include clear_left;
38
+ padding: 10px 0 20px 0;
39
+ }
40
+ #main_admin_footer, #pusher {
41
+ height: 80px;
42
+ clear:both;
43
+ }
44
+ }
45
+
46
+ @mixin user_admin_nav {
47
+ #user_admin_nav {
48
+ float: right;
49
+ padding: 20px 0 0 0;
50
+ }
51
+ }
52
+
53
+ @mixin main_admin_nav {
54
+ #main_admin_nav {
55
+ width: 950px;
56
+ @include clear_left;
57
+ padding: 10px 0;
58
+ ul {
59
+ @include clear_left;
60
+ li {
61
+ float: left;
62
+ padding: 0 15px 0 0;
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ @mixin layout_guide {
69
+ #container { background-color: #e8e6e6; }
70
+ #main_admin_header { background-color: #f7dddd; }
71
+ #main_admin_nav { background-color: #f4ddf7; }
72
+ #content { background-color: #f2f7dd; }
73
+ #main_admin_footer .inner { background-color: #ddf7e7; }
74
+ }
75
+
76
+ @include layout_base;
77
+ FILE
78
+ end
79
+
80
+ run 'sass public/stylesheets/sass/admin.scss public/stylesheets/admin.css'
@@ -0,0 +1,137 @@
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.username}."
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 :username
80
+ = f.text_field :username
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
91
+ = f.label :admin
92
+ = f.check_box :admin
93
+ .form_row.form_row_button
94
+ = f.submit "Save"
95
+ FILE
96
+ end
97
+
98
+ remove_file 'app/views/admin/users/edit.html.haml'
99
+ create_file 'app/views/admin/users/edit.html.haml' do
100
+ <<-'FILE'
101
+ = render :partial => "form"
102
+ FILE
103
+ end
104
+
105
+ remove_file 'app/views/admin/users/new.html.haml'
106
+ create_file 'app/views/admin/users/new.html.haml' do
107
+ <<-'FILE'
108
+ = render :partial => "form"
109
+ FILE
110
+ end
111
+
112
+ remove_file 'app/views/admin/users/index.html.haml'
113
+ create_file 'app/views/admin/users/index.html.haml' do
114
+ <<-FILE
115
+ - if !@users.blank?
116
+ %table
117
+ %thead
118
+ %tr
119
+ %th Username
120
+ %th Email
121
+ %th
122
+ %tbody
123
+ - @users.each do |user|
124
+ %tr
125
+ %td= link_to user.username, edit_admin_user_path(user), :class => 'edit_link'
126
+ %td= user.email
127
+ %td
128
+ - if user.id != current_user.id
129
+ = link_to "Delete", admin_user_path(user), :confirm => 'Are you sure?', :method => :delete, :class => 'delete_link'
130
+ - else
131
+ That's you!
132
+ = will_paginate @users
133
+ - else
134
+ %p No users
135
+ FILE
136
+ end
137
+
@@ -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,71 @@
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
+ FILE
35
+ end
36
+
37
+ run 'rm app/views/layouts/application.html.erb'
38
+ create_file 'app/views/layouts/application.html.haml' do
39
+ <<-FILE
40
+ !!! 5
41
+ %html
42
+ %head
43
+ %meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}
44
+ %meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}
45
+ %title
46
+ #{app_name.humanize}
47
+ = yield(:title)
48
+ %meta{:name => 'description', :content => ''}
49
+ %meta{:name => 'author', :content => ''}
50
+ %meta{:name => 'viewport', :content => 'width=device-width; initial-scale=1.0'}
51
+ = csrf_meta_tag
52
+ %link{:rel => "shortcut icon", :href => "/images/favicon.ico", :type => "image/x-icon"}
53
+ %link{:rel => "apple-touch-icon", :href => "/images/ati.png"}
54
+ /[if lt IE 9]
55
+ %script{:type => "text/javascript", :src => "/javascripts/shiv.js"}
56
+ = include_stylesheets :main, :media => 'all'
57
+ = yield(:head)
58
+ /[if IE 7]
59
+ = stylesheet_link_tag 'ie7', :media => 'all'
60
+ /[if IE 8]
61
+ = stylesheet_link_tag 'ie8', :media => 'all'
62
+ %body
63
+ #container
64
+ = render :partial => "shared/header"
65
+ %section#content
66
+ = yield
67
+ #pusher
68
+ = render :partial => "shared/footer"
69
+ = render :partial => "shared/end_scripts"
70
+ FILE
71
+ end
@@ -0,0 +1,117 @@
1
+ require "net/http"
2
+ require "net/https"
3
+ require "uri"
4
+ require 'rbconfig'
5
+
6
+ say "Building Application with Mologue..."
7
+
8
+ def get_remote_https_file(source, destination)
9
+ uri = URI.parse(source)
10
+ http = Net::HTTP.new(uri.host, uri.port)
11
+ http.use_ssl = true
12
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
13
+ request = Net::HTTP::Get.new(uri.request_uri)
14
+ response = http.request(request)
15
+ path = File.join(destination_root, destination)
16
+ File.open(path, "w") { |file| file.write(response.body) }
17
+ end
18
+
19
+ append_file '.gitignore' do <<-RUBY
20
+ .DS_Store
21
+ log/*.log
22
+ tmp/**/*
23
+ config/database.yml
24
+ db/*.sqlite3
25
+ public/system/**/**/**/*
26
+ .idea/*
27
+ .rspec
28
+ .sass-cache
29
+ DIFF*
30
+ RUBY
31
+ end
32
+
33
+ git :init
34
+
35
+ # Apply Gemfile
36
+ apply File.expand_path("../gemfile.rb", __FILE__)
37
+
38
+ # Apply Mongoid
39
+ apply File.expand_path("../mongoid.rb", __FILE__) if ENV['MOLOGUE_MONGOID']
40
+
41
+ # Apply Jammit
42
+ apply File.expand_path("../jammit.rb", __FILE__)
43
+
44
+ # Apply HAML generator
45
+ apply File.expand_path("../haml_generator.rb", __FILE__)
46
+
47
+ # Apply rails clean up
48
+ apply File.expand_path("../rails_clean.rb", __FILE__)
49
+
50
+ # Apply js
51
+ apply File.expand_path("../js.rb", __FILE__)
52
+
53
+ # Apply HTML5 Layout
54
+ apply File.expand_path("../application_layout.rb", __FILE__)
55
+
56
+ # Apply SASS
57
+ apply File.expand_path("../sass.rb", __FILE__)
58
+
59
+ # Apply Test Suite
60
+ apply File.expand_path("../test_suite.rb", __FILE__)
61
+
62
+ # Apply Friendly Id
63
+ apply File.expand_path("../friendly_id.rb", __FILE__) unless ENV['MOLOGUE_MONGOID'] # FIXME: friendly_id only works with AR, find a Mongoid replacement
64
+
65
+ # Apply Devise?
66
+ apply File.expand_path("../devise.rb", __FILE__) if ENV['MOLOGUE_AUTH']
67
+
68
+ # Apply admin
69
+ apply File.expand_path("../admin.rb", __FILE__) if ENV['MOLOGUE_ADMIN']
70
+
71
+ # Apply db create and migrations
72
+ apply File.expand_path("../db.rb", __FILE__) unless ENV['MOLOGUE_MONGOID']
73
+
74
+ # Apply db seeds
75
+ apply File.expand_path("../db_seed.rb", __FILE__)
76
+
77
+ # Make a home controller
78
+ apply File.expand_path("../home_controller.rb", __FILE__)
79
+
80
+ # Make initializers
81
+ apply File.expand_path("../initializers.rb", __FILE__)
82
+
83
+ # Clean up generated routes
84
+ apply File.expand_path("../clean_routes.rb", __FILE__)
85
+
86
+ # Remove RSpec stuff we are not gonna use right away
87
+ apply File.expand_path("../rspec_clean.rb", __FILE__)
88
+
89
+ # Apply Terminitor Script
90
+ apply File.expand_path("../terminitor.rb", __FILE__)
91
+
92
+ # Apply RVM settings
93
+ apply File.expand_path("../rvm.rb", __FILE__)
94
+
95
+ git :add => "."
96
+ git :commit => "-am 'Initial Commit'"
97
+
98
+ login_msg = (ENV['MOLOGUE_ADMIN']) ? "Login to admin with email #{ENV['MOLOGUE_USER_EMAIL']} and password #{ENV['MOLOGUE_USER_PASSWORD']}" : ""
99
+
100
+ say <<-D
101
+
102
+
103
+
104
+
105
+ ########################################################################
106
+
107
+ Mologue just added like 6 hours to your life.
108
+
109
+ Next run...
110
+ rake spec
111
+ rake cucumber
112
+ rails s
113
+
114
+ #{login_msg}
115
+
116
+ ########################################################################
117
+ D