caboose-cms 0.1.7 → 0.1.34

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rails/all'
4
+ require 'caboose'
5
+ require 'caboose/engine'
6
+ require 'caboose/version'
7
+ require 'caboose/caboose_helper'
8
+
9
+ action = false
10
+ action = ARGV[0] if ARGV.count > 0
11
+
12
+ path = Dir.pwd
13
+ path = ARGV[1] if ARGV.count > 1
14
+ helper = CabooseHelper.new(path)
15
+
16
+ case action
17
+
18
+ when 'v', 'version'
19
+ puts "Caboose CMS Version #{Caboose::VERSION}\n\n"
20
+ exit
21
+
22
+ when 'help'
23
+ puts "Usage:"
24
+ puts "Create a new caboose app:"
25
+ puts " caboose new <app_path>"
26
+ puts "Initialize an existing rails app as a new caboose app:"
27
+ puts " caboose init [<app_path>]\n\n"
28
+ exit
29
+
30
+ when 'new'
31
+
32
+ if (ARGV.count != 2)
33
+ puts "Usage: caboose new <app_path>\n\n"
34
+ exit
35
+ end
36
+ puts "Creating the new rails app..."
37
+ `rails new #{path} -d=mysql`
38
+ helper.init_all
39
+
40
+ when 'init'
41
+
42
+ is_rails_app = File.exists(File.join(path, 'config', 'environment.rb'))
43
+ if (!is_rails_app)
44
+ if (ARGV.count == 1)
45
+ puts "Error: You don't seem to be in a rails app.\n\n"
46
+ else
47
+ puts "Error: The supplied path (#{path}) doesn't seem to be a rails app.\n\n"
48
+ end
49
+ exit
50
+ end
51
+ helper.init_all
52
+
53
+ else
54
+ end
@@ -0,0 +1,319 @@
1
+
2
+ class CabooseHelper
3
+
4
+ def initialize(app_path)
5
+ @app_path = app_path
6
+ end
7
+
8
+ def init_all
9
+ init_gem
10
+ init_app_config
11
+ init_initializer
12
+ init_routes
13
+ init_assets
14
+ init_tinymce
15
+ init_session
16
+ remove_public_index
17
+ end
18
+
19
+ def init_file(filename)
20
+ gem_root = Gem::Specification.find_by_name('caboose-cms').gem_dir
21
+ filename = File.join(@app_path, filename)
22
+ copy_from = File.join(gem_root,'lib','sample_files', Pathname.new(filename).basename)
23
+
24
+ if (!File.exists?(filename))
25
+ FileUtils.cp(copy_from, filename)
26
+ end
27
+ end
28
+
29
+ # Add the gem to the Gemfile
30
+ def init_gem
31
+ puts "Adding the caboose gem to the Gemfile... "
32
+ filename = File.join(@app_path,'Gemfile')
33
+ return if !File.exists?(filename)
34
+
35
+ file = File.open(filename, 'rb')
36
+ str = file.read
37
+ file.close
38
+ str2 = ""
39
+ str.each_line do |line|
40
+ if (!line.strip.start_with?('#') && (!line.index("gem 'caboose'").nil? || !line.index('gem "caboose"').nil?))
41
+ str2 << "##{line}"
42
+ else
43
+ str2 << line
44
+ end
45
+ end
46
+ str2 << "gem 'caboose', '= #{Caboose::VERSION}'\n"
47
+ File.open(filename, 'w') {|file| file.write(str2) }
48
+ end
49
+
50
+ # Require caboose in the application config
51
+ def init_app_config
52
+ puts "Requiring caboose in the application config..."
53
+
54
+ filename = File.join(@app_path,'config','application.rb')
55
+ return if !File.exists?(filename)
56
+
57
+ file = File.open(filename, 'rb')
58
+ contents = file.read
59
+ file.close
60
+ if (contents.index("require 'caboose'").nil?)
61
+ arr = contents.split("require 'rails/all'", -1)
62
+ str = arr[0] + "\nrequire 'rails/all'\nrequire 'caboose'\n" + arr[1]
63
+ File.open(filename, 'w') { |file| file.write(str) }
64
+ end
65
+ end
66
+
67
+ # Removes the public/index.html file from the rails app
68
+ def remove_public_index
69
+ puts "Removing the public/index.html file... "
70
+
71
+ filename = File.join(@app_path,'public','index.html')
72
+ return if !File.exists?(filename)
73
+ File.delete(filename)
74
+ end
75
+
76
+ # Adds the caboose initializer file
77
+ def init_initializer
78
+ puts "Adding the caboose initializer file..."
79
+
80
+ filename = File.join(@app_path,'config','initializers','caboose.rb')
81
+ return if File.exists?(filename)
82
+
83
+ Caboose::salt = Digest::SHA1.hexdigest(DateTime.now.to_s)
84
+ str = ""
85
+ str << "# Salt to ensure passwords are encrypted securely\n"
86
+ str << "Caboose::salt = '#{Caboose::salt}'\n\n"
87
+ str << "# Where page asset files will be uploaded\n"
88
+ str << "Caboose::assets_path = File.join(@app_path,'app', 'assets', 'caboose')\n\n"
89
+ str << "# Register any caboose plugins\n"
90
+ str << "#Caboose::plugins + ['MyCaboosePlugin']\n\n"
91
+
92
+ File.open(filename, 'w') {|file| file.write(str) }
93
+ end
94
+
95
+ # Adds the routes to the host app to point everything to caboose
96
+ def init_routes
97
+ puts "Adding the caboose routes..."
98
+
99
+ filename = File.join(@app_path,'config','routes.rb')
100
+ return if !File.exists?(filename)
101
+
102
+ str = ""
103
+ str << "\t# Catch everything with caboose\n"
104
+ str << "\tmount Caboose::Engine => '/'\n"
105
+ str << "\tmatch '*path' => 'caboose/pages#show'\n"
106
+ str << "\troot :to => 'caboose/pages#show'\n"
107
+ file = File.open(filename, 'rb')
108
+ contents = file.read
109
+ file.close
110
+ if (contents.index(str).nil?)
111
+ arr = contents.split('end', -1)
112
+ str2 = arr[0] + "\n" + str + "\nend" + arr[1]
113
+ File.open(filename, 'w') {|file| file.write(str2) }
114
+ end
115
+ end
116
+
117
+ def init_assets
118
+ puts "Adding the javascript files..."
119
+ init_file('app/assets/javascripts/caboose_before.js')
120
+ init_file('app/assets/javascripts/caboose_after.js')
121
+
122
+ puts "Adding the stylesheet files..."
123
+ init_file('app/assets/stylesheets/caboose_before.css')
124
+ init_file('app/assets/stylesheets/caboose_after.css')
125
+
126
+ puts "Adding the layout files..."
127
+ init_file('app/views/layouts/layout_default.html.erb')
128
+ end
129
+
130
+ def init_tinymce
131
+ puts "Adding the tinymce config file..."
132
+ init_file('config/tinymce.yml')
133
+ end
134
+
135
+ def init_session
136
+ puts "Setting the session config..."
137
+
138
+ lines = []
139
+ str = File.open(File.join(@app_path,'config','initializers','session_store.rb')).read
140
+ str.gsub!(/\r\n?/, "\n")
141
+ str.each_line do |line|
142
+ line = '#' + line if !line.index(':cookie_store').nil? && !line.start_with?('#')
143
+ line[0] = '' if !line.index(':active_record_store').nil? && line.start_with?('#')
144
+ lines << line.strip
145
+ end
146
+ str = lines.join("\n")
147
+ File.open(File.join(@app_path,'config','initializers','session_store.rb'), 'w') {|file| file.write(str) }
148
+ end
149
+
150
+ def init_schema
151
+ drop_tables
152
+ create_tables
153
+ end
154
+
155
+ def drop_tables
156
+ puts "Dropping any existing caboose tables..."
157
+ c = ActiveRecord::Base.connection
158
+ c.drop_table :users if c.table_exists?('users')
159
+ c.drop_table :roles if c.table_exists?('roles')
160
+ c.drop_table :permissions if c.table_exists?('permissions')
161
+ c.drop_table :roles_users if c.table_exists?('roles_users')
162
+ c.drop_table :permissions_roles if c.table_exists?('permissions_roles')
163
+ c.drop_table :assets if c.table_exists?('assets')
164
+ c.drop_table :pages if c.table_exists?('pages')
165
+ c.drop_table :page_permissions if c.table_exists?('page_permissions')
166
+ c.drop_table :sessions if c.table_exists?('sessions')
167
+ c.drop_table :settings if c.table_exists?('settings')
168
+ end
169
+
170
+ def create_tables
171
+ puts "Creating required caboose tables..."
172
+
173
+ c = ActiveRecord::Base.connection
174
+
175
+ # User/Role/Permissions
176
+ c.create_table :users do |t|
177
+ t.string :first_name
178
+ t.string :last_name
179
+ t.string :username
180
+ t.string :email
181
+ t.string :password
182
+ t.string :password_reset_id
183
+ t.datetime :password_reset_sent
184
+ t.string :token
185
+ end
186
+ c.create_table :roles do |t|
187
+ t.integer :parent_id
188
+ t.string :name
189
+ t.string :description
190
+ end
191
+ c.create_table :permissions do |t|
192
+ t.string :resource
193
+ t.string :action
194
+ end
195
+
196
+ # Role membership
197
+ c.create_table :roles_users do |t|
198
+ t.references :role
199
+ t.references :user
200
+ end
201
+ c.add_index :roles_users, :role_id
202
+ c.add_index :roles_users, :user_id
203
+
204
+ # Role permissions
205
+ c.create_table :permissions_roles do |t|
206
+ t.references :role
207
+ t.references :permission
208
+ end
209
+ c.add_index :permissions_roles, :role_id
210
+ c.add_index :permissions_roles, :permission_id
211
+
212
+ # Pages and Assets
213
+ c.create_table :assets do |t|
214
+ t.references :page
215
+ t.references :user
216
+ t.datetime :date_uploaded
217
+ t.string :name
218
+ t.string :filename
219
+ t.string :description
220
+ t.string :extension
221
+ end
222
+ c.create_table :pages do |t|
223
+ t.integer :parent_id
224
+ t.string :title
225
+ t.string :menu_title
226
+ t.text :content
227
+ t.string :slug
228
+ t.string :alias
229
+ t.string :uri
230
+ t.string :redirect_url
231
+ t.boolean :hide, :default => false
232
+ t.integer :content_format, :default => Caboose::Page::CONTENT_FORMAT_HTML
233
+ t.text :custom_css
234
+ t.text :custom_js
235
+ t.string :layout
236
+ t.integer :sort_order, :default => 0
237
+ t.boolean :custom_sort_children, :default => false
238
+ t.string :seo_title, :limit => 70
239
+ t.string :meta_description, :limit => 156
240
+ t.string :meta_robots, :default => 'index, follow' # Multi-select options: none, noindex, nofollow, nosnippet, noodp, noarchive
241
+ t.string :canonical_url
242
+ t.string :fb_description, :limit => 156
243
+ t.string :gp_description, :limit => 156
244
+ end
245
+ c.create_table :page_permissions do |t|
246
+ t.references :role
247
+ t.references :page
248
+ t.string :action
249
+ end
250
+ c.create_table :sessions do |t|
251
+ t.string :session_id, :null => false
252
+ t.text :data
253
+ t.timestamps
254
+ end
255
+ c.add_index :sessions, :session_id
256
+ c.add_index :sessions, :updated_at
257
+ c.change_column :sessions, :created_at, :datetime, :null => true
258
+ c.change_column :sessions, :updated_at, :datetime, :null => true
259
+ c.create_table :settings do |t|
260
+ t.string :name
261
+ t.text :value
262
+ end
263
+
264
+ end
265
+
266
+ def init_data
267
+ puts "Loading data into caboose tables..."
268
+
269
+ admin_user = Caboose::User.create(first_name: 'Admin', last_name: 'User', username: 'admin', email: 'william@nine.is')
270
+ admin_user.password = Digest::SHA1.hexdigest(Caboose::salt + 'caboose')
271
+ admin_user.save
272
+
273
+ admin_role = Caboose::Role.create(parent_id: -1, name: 'Admin')
274
+ elo_role = Caboose::Role.create(parent_id: -1, name: 'Everyone Logged Out')
275
+ eli_role = Caboose::Role.create(parent_id: elo_role.id, name: 'Everyone Logged In')
276
+
277
+ elo_user = Caboose::User.create(first_name: 'John', last_name: 'Doe', username: 'elo', email: 'william@nine.is')
278
+
279
+ admin_perm = Caboose::Permission.create(resource: 'all', action: 'all')
280
+ Caboose::Permission.create(resource: 'users' , action: 'view')
281
+ Caboose::Permission.create(resource: 'users' , action: 'edit')
282
+ Caboose::Permission.create(resource: 'users' , action: 'delete')
283
+ Caboose::Permission.create(resource: 'users' , action: 'add')
284
+ Caboose::Permission.create(resource: 'roles' , action: 'view')
285
+ Caboose::Permission.create(resource: 'roles' , action: 'edit')
286
+ Caboose::Permission.create(resource: 'roles' , action: 'delete')
287
+ Caboose::Permission.create(resource: 'roles' , action: 'add')
288
+ Caboose::Permission.create(resource: 'permissions' , action: 'view')
289
+ Caboose::Permission.create(resource: 'permissions' , action: 'edit')
290
+ Caboose::Permission.create(resource: 'permissions' , action: 'delete')
291
+ Caboose::Permission.create(resource: 'permissions' , action: 'add')
292
+
293
+ # Add the admin user to the admin role
294
+ admin_user.roles.push(admin_role)
295
+ admin_user.save
296
+
297
+ # Add the elo to the elo role
298
+ elo_user.roles.push(elo_role)
299
+ elo_user.save
300
+
301
+ # Add the all/all permission to the admin role
302
+ admin_role.permissions.push(admin_perm)
303
+ admin_role.save
304
+
305
+ # Create the home page
306
+ home_page = Caboose::Page.create(title: 'Home' , parent_id: -1, hide: 0, layout: 'home' , uri: '')
307
+ admin_page = Caboose::Page.create(title: 'Admin' , parent_id: home_page.id, hide: 0, layout: 'admin', alias: 'admin', slug: 'admin', uri: 'admin')
308
+ login_page = Caboose::Page.create(title: 'Login' , parent_id: home_page.id, hide: 0, layout: 'login', alias: 'login', slug: 'login', uri: 'login')
309
+ Caboose::PagePermission.create(role_id: elo_role.id, page_id: home_page.id, action: 'view')
310
+ Caboose::PagePermission.create(role_id: elo_role.id, page_id: login_page.id, action: 'view')
311
+
312
+ # Create the required settings
313
+ Caboose::Setting.create(name: 'version' , value: Caboose::VERSION)
314
+ Caboose::Setting.create(name: 'site_name' , value: 'New Caboose Site')
315
+ Caboose::Setting.create(name: 'site_url' , value: 'www.mycaboosesite.com')
316
+ Caboose::Setting.create(name: 'admin_email' , value: 'william@nine.is')
317
+
318
+ end
319
+ end
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = "0.1.7"
2
+ VERSION = '0.1.34'
3
3
  end
@@ -2,121 +2,21 @@ require "caboose/version"
2
2
 
3
3
  namespace :caboose do
4
4
 
5
- desc "Initialize a caboose installation"
6
- task :setup => :environment do
7
- init_config
8
- init_routes
9
- init_assets
10
- init_tinymce
11
- init_session
12
- init_schema
13
- init_data
5
+ desc "Initializes the database for a caboose installation"
6
+ task :db => :environment do
7
+ drop_tables
8
+ create_tables
9
+ load_data
14
10
  end
15
- desc "Initializes the caboose config file"
16
- task :init_config => :environment do init_config end
17
- desc "Configures the host application to use caboose for routing"
18
- task :init_routes => :environment do init_routes end
19
- desc "Initializes all the required caboose js, css and layout files in the host application"
20
- task :init_assets => :environment do init_assets end
21
- desc "Initializes the tinymce config file in the host application"
22
- task :init_tinymce => :environment do init_tinymce end
23
- desc "Configures the host application to use active record session storing"
24
- task :init_session => :environment do init_session end
25
- desc "Initializes the caboose database schema"
26
- task :init_schema => :environment do init_schema end
27
- desc "Loads data into caboose tables"
28
- task :init_data => :environment do init_data end
29
11
  desc "Drops all caboose tables"
30
12
  task :drop_tables => :environment do drop_tables end
31
13
  desc "Creates all caboose tables"
32
14
  task :create_tables => :environment do create_tables end
15
+ desc "Loads data into caboose tables"
16
+ task :load_data => :environment do load_data end
33
17
 
34
18
  #=============================================================================
35
19
 
36
- def init_file(filename)
37
- gem_root = Gem::Specification.find_by_name('caboose-cms').gem_dir
38
- filename = Rails.root.join(filename)
39
- copy_from = File.join(gem_root,'lib','sample_files', Pathname.new(filename).basename)
40
-
41
- if (!File.exists?(filename))
42
- FileUtils.cp(copy_from, filename)
43
- end
44
- end
45
-
46
- def init_config
47
- puts "Adding the caboose initializer file..."
48
-
49
- Caboose::salt = Digest::SHA1.hexdigest(DateTime.now.to_s)
50
-
51
- str = ""
52
- str << "# Salt to ensure passwords are encrypted securely\n"
53
- str << "Caboose::salt = '#{Caboose::salt}'\n\n"
54
- str << "# Where page asset files will be uploaded\n"
55
- str << "Caboose::assets_path = Rails.root.join('app', 'assets', 'caboose')\n\n"
56
- str << "# Register any caboose plugins\n"
57
- str << "#Caboose::plugins + ['MyCaboosePlugin']\n\n"
58
-
59
- filename = Rails.root.join('config','initializers','caboose.rb')
60
- if (!File.exists?(filename))
61
- File.open(filename, 'w') {|file| file.write(str) }
62
- end
63
- end
64
-
65
- def init_routes
66
- puts "Adding the caboose routes..."
67
- str = ""
68
- str << "\t# Catch everything with caboose\n"
69
- str << "\tmount Caboose::Engine => '/'\n"
70
- str << "\tmatch '*path' => 'caboose/pages#show'\n"
71
- str << "\troot :to => 'caboose/pages#show'\n"
72
- file = File.open(Rails.root.join('config','routes.rb'), 'rb')
73
- contents = file.read
74
- file.close
75
- if (contents.index(str).nil?)
76
- arr = contents.split('end', -1)
77
- str2 = arr[0] + "\n" + str + "\nend" + arr[1]
78
- File.open(Rails.root.join('config','routes.rb'), 'w') {|file| file.write(str2) }
79
- end
80
- end
81
-
82
- def init_assets
83
- puts "Adding the javascript files..."
84
- init_file('app/assets/javascripts/caboose_before.js')
85
- init_file('app/assets/javascripts/caboose_after.js')
86
-
87
- puts "Adding the stylesheet files..."
88
- init_file('app/assets/stylesheets/caboose_before.css')
89
- init_file('app/assets/stylesheets/caboose_after.css')
90
-
91
- puts "Adding the layout files..."
92
- init_file('app/views/layouts/layout_default.html.erb')
93
- end
94
-
95
- def init_tinymce
96
- puts "Adding the tinymce config file..."
97
- init_file('config/tinymce.yml')
98
- end
99
-
100
- def init_session
101
- puts "Setting the session config..."
102
-
103
- lines = []
104
- str = File.open(Rails.root.join('config','initializers','session_store.rb')).read
105
- str.gsub!(/\r\n?/, "\n")
106
- str.each_line do |line|
107
- line = '#' + line if !line.index(':cookie_store').nil? && !line.starts_with?('#')
108
- line[0] = '' if !line.index(':active_record_store').nil? && line.starts_with?('#')
109
- lines << line.strip
110
- end
111
- str = lines.join("\n")
112
- File.open(Rails.root.join('config','initializers','session_store.rb'), 'w') {|file| file.write(str) }
113
- end
114
-
115
- def init_schema
116
- drop_tables
117
- create_tables
118
- end
119
-
120
20
  def drop_tables
121
21
  puts "Dropping any existing caboose tables..."
122
22
  c = ActiveRecord::Base.connection
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.34
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-03 00:00:00.000000000 Z
12
+ date: 2013-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -123,10 +123,11 @@ dependencies:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
- description: CMS built on rails.
126
+ description: CMS built on rails with love.
127
127
  email:
128
128
  - william@nine.is
129
- executables: []
129
+ executables:
130
+ - caboose
130
131
  extensions: []
131
132
  extra_rdoc_files: []
132
133
  files:
@@ -200,7 +201,9 @@ files:
200
201
  - app/views/layouts/caboose/admin.html.erb
201
202
  - app/views/layouts/caboose/application.html.erb
202
203
  - app/views/layouts/caboose/error404.html.erb
204
+ - bin/caboose
203
205
  - config/routes.rb
206
+ - lib/caboose/caboose_helper.rb
204
207
  - lib/caboose/engine.rb
205
208
  - lib/caboose/version.rb
206
209
  - lib/caboose.rb