fullstack-cms 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/Gemfile +17 -0
  2. data/Gemfile.lock +289 -0
  3. data/README.md +28 -0
  4. data/Rakefile +53 -0
  5. data/VERSION +1 -0
  6. data/app/controllers/links_controller.rb +59 -0
  7. data/app/controllers/menus_controller.rb +40 -0
  8. data/app/controllers/page_parts_controller.rb +16 -0
  9. data/app/controllers/pages_controller.rb +21 -0
  10. data/app/controllers/posts_controller.rb +39 -0
  11. data/app/controllers/settings_controller.rb +39 -0
  12. data/app/controllers/tags_controller.rb +22 -0
  13. data/app/controllers/users_controller.rb +39 -0
  14. data/app/helpers/menus_helper.rb +42 -0
  15. data/app/helpers/pages_helper.rb +14 -0
  16. data/app/helpers/settings_helper.rb +7 -0
  17. data/app/models/.gitkeep +0 -0
  18. data/app/models/link.rb +17 -0
  19. data/app/models/menu.rb +19 -0
  20. data/app/models/page.rb +16 -0
  21. data/app/models/page_part.rb +6 -0
  22. data/app/models/redirect.rb +4 -0
  23. data/app/models/setting.rb +64 -0
  24. data/app/views/admin/links/_filter.html.erb +14 -0
  25. data/app/views/admin/links/_form.html.erb +24 -0
  26. data/app/views/admin/links/_index.html.erb +9 -0
  27. data/app/views/admin/links/_links.html.erb +128 -0
  28. data/app/views/admin/links/_table_row.html.erb +9 -0
  29. data/app/views/admin/links/create.js.erb +12 -0
  30. data/app/views/admin/links/sort.js.coffee +6 -0
  31. data/app/views/admin/links/update.js.coffee +6 -0
  32. data/app/views/admin/menus/_filter.html.erb +12 -0
  33. data/app/views/admin/menus/_form.html.erb +34 -0
  34. data/app/views/admin/menus/_index.html.erb +9 -0
  35. data/app/views/admin/page_parts/_tabs.html.erb +21 -0
  36. data/app/views/admin/page_parts/destroy.js.coffee +12 -0
  37. data/app/views/admin/pages/_collection.html.erb +7 -0
  38. data/app/views/admin/pages/_form.html.erb +54 -0
  39. data/app/views/admin/settings/_filter.html.erb +10 -0
  40. data/app/views/admin/settings/_form.html.erb +25 -0
  41. data/app/views/admin/settings/_index.html.erb +8 -0
  42. data/fullstack-cms.gemspec +189 -0
  43. data/lib/fullstack-cms.rb +1 -0
  44. data/lib/fullstack/cms.rb +41 -0
  45. data/lib/fullstack/cms/engine.rb +9 -0
  46. data/lib/generators/fullstack/cms/install_generator.rb +88 -0
  47. data/lib/generators/fullstack/cms/locale_generator.rb +11 -0
  48. data/lib/generators/fullstack/cms/templates/rails/README.md +40 -0
  49. data/lib/generators/fullstack/cms/templates/rails/app/controllers/site/site_controller.rb +10 -0
  50. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/attachments/_attachments.html.erb +49 -0
  51. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/attachments/create.js.coffee +14 -0
  52. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/base/destroy.js.coffee +7 -0
  53. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/base/edit.html.erb +8 -0
  54. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/base/index.html.erb +54 -0
  55. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/base/new.html.erb +8 -0
  56. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/base/update.js.coffee +5 -0
  57. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/dashboard/show.html.erb +0 -0
  58. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/links/_filter.html.erb +14 -0
  59. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/links/_form.html.erb +24 -0
  60. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/links/_index.html.erb +9 -0
  61. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/links/_links.html.erb +128 -0
  62. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/links/_table_row.html.erb +9 -0
  63. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/links/create.js.erb +12 -0
  64. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/links/sort.js.coffee +6 -0
  65. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/links/update.js.coffee +6 -0
  66. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/menus/_filter.html.erb +12 -0
  67. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/menus/_form.html.erb +34 -0
  68. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/menus/_index.html.erb +9 -0
  69. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/page_parts/_tabs.html.erb +21 -0
  70. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/page_parts/destroy.js.coffee +12 -0
  71. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/pages/_filter.html.erb +12 -0
  72. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/pages/_form.html.erb +50 -0
  73. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/pages/_index.html.erb +14 -0
  74. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/photogalleries/_filter.html.erb +14 -0
  75. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/photogalleries/_form.html.erb +26 -0
  76. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/photogalleries/_index.html.erb +9 -0
  77. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/settings/_filter.html.erb +10 -0
  78. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/settings/_form.html.erb +25 -0
  79. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/settings/_index.html.erb +8 -0
  80. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/shared/_nav.html.erb +38 -0
  81. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/users/_filter.html.erb +12 -0
  82. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/users/_form.html.erb +53 -0
  83. data/lib/generators/fullstack/cms/templates/rails/app/views/admin/users/_index.html.erb +18 -0
  84. data/lib/generators/fullstack/cms/templates/rails/app/views/layouts/admin.html.erb +80 -0
  85. data/lib/generators/fullstack/cms/templates/rails/app/views/layouts/application.html.erb +28 -0
  86. data/lib/generators/fullstack/cms/templates/rails/app/views/layouts/email.html.erb +167 -0
  87. data/lib/generators/fullstack/cms/templates/rails/app/views/site/_footer.html.erb +3 -0
  88. data/lib/generators/fullstack/cms/templates/rails/app/views/site/_google_analytics.html.erb +6 -0
  89. data/lib/generators/fullstack/cms/templates/rails/app/views/site/_head.html.erb +33 -0
  90. data/lib/generators/fullstack/cms/templates/rails/app/views/site/_header.html.erb +15 -0
  91. data/lib/generators/fullstack/cms/templates/rails/app/views/site/_javascripts.html.erb +22 -0
  92. data/lib/generators/fullstack/cms/templates/rails/app/views/site/_map.html.erb +14 -0
  93. data/lib/generators/fullstack/cms/templates/rails/app/views/site/_nav.html.erb +15 -0
  94. data/lib/generators/fullstack/cms/templates/rails/app/views/site/_share_buttons_big.html.erb +15 -0
  95. data/lib/generators/fullstack/cms/templates/rails/app/views/site/site/home.html.erb +12 -0
  96. data/lib/generators/fullstack/cms/templates/rails/config/initializers/devise_controller.rb +29 -0
  97. data/lib/generators/fullstack/cms/templates/rails/config/schedule.rb +5 -0
  98. data/lib/generators/fullstack/cms/templates/rails/config/sitemap.rb.tt +28 -0
  99. data/lib/generators/fullstack/cms/templates/rails/config/styles.yml +47 -0
  100. data/lib/generators/fullstack/cms/templates/rails/db/migrate/20120416071459_acts_as_taggable_on_migration.rb +31 -0
  101. data/lib/generators/fullstack/cms/templates/rails/db/migrate/20120730184641_create_friendly_id_slugs.rb +18 -0
  102. data/lib/generators/fullstack/cms/templates/rails/db/migrate/20120730204729_create_ckeditor_assets.rb +26 -0
  103. data/lib/generators/fullstack/cms/templates/rails/db/seeds.rb.tt +11 -0
  104. data/lib/generators/fullstack/cms/templates/rails/lib/support/ckeditor/asset.rb +4 -0
  105. data/lib/generators/fullstack/cms/templates/rails/lib/support/ckeditor/attachment_file.rb +12 -0
  106. data/lib/generators/fullstack/cms/templates/rails/lib/support/ckeditor/picture.rb +13 -0
  107. data/lib/generators/fullstack/cms/templates/rails/lib/support/content.rb +16 -0
  108. data/lib/generators/fullstack/cms/templates/rails/lib/support/pageable.rb +37 -0
  109. data/lib/generators/fullstack/cms/templates/rails/lib/support/timestamped_content.rb +12 -0
  110. data/lib/generators/fullstack/cms/templates/rails/lib/support/user_subject.rb +40 -0
  111. data/lib/generators/fullstack/cms/templates/rails/lib/tasks/.gitkeep +0 -0
  112. data/lib/generators/fullstack/cms/templates/rails/lib/tasks/assets.rake +53 -0
  113. data/lib/generators/fullstack/cms/templates/rails/lib/tasks/cms.rake +23 -0
  114. data/lib/generators/fullstack/cms/templates/rails/lib/tasks/remote.rake +255 -0
  115. data/lib/generators/fullstack/cms/templates/rails/public/404.html +43 -0
  116. data/lib/generators/fullstack/cms/templates/rails/public/422.html +26 -0
  117. data/lib/generators/fullstack/cms/templates/rails/public/500.html +25 -0
  118. data/lib/generators/fullstack/cms/templates/rails/public/apple-touch-icon.png +0 -0
  119. data/lib/generators/fullstack/cms/templates/rails/public/crossdomain.xml +25 -0
  120. data/lib/generators/fullstack/cms/templates/rails/public/favicon.ico +0 -0
  121. data/lib/generators/fullstack/cms/templates/rails/public/img/.gitignore +0 -0
  122. data/lib/generators/fullstack/cms/templates/rails/public/img/glyphicons-halflings.png +0 -0
  123. data/lib/generators/fullstack/cms/templates/rails/public/js/modernizr-2.5.3.min.js +4 -0
  124. data/lib/generators/fullstack/cms/templates/rails/public/robots.txt +4 -0
  125. metadata +333 -0
@@ -0,0 +1,5 @@
1
+ every 3.hours do
2
+ rake "sitemap:generate"
3
+ rake "sitemap:ping"
4
+ end
5
+
@@ -0,0 +1,28 @@
1
+ Sitemap::Generator.instance.load :host => "www.#{Settings.app.domain}" do
2
+
3
+ path :home
4
+
5
+ # Sample path:
6
+ # path :faq
7
+ # The specified path must exist in your routes file (usually specified through :as).
8
+
9
+ # Sample path with params:
10
+ # path :faq, :params => { :format => "html", :filter => "recent" }
11
+ # Depending on the route, the resolved url could be http://mywebsite.com/frequent-questions.html?filter=recent.
12
+
13
+ # Sample resource:
14
+ # resources :articles
15
+
16
+ # Sample resource with custom objects:
17
+ # resources :articles, :objects => proc { Article.published }
18
+
19
+ # Sample resource with search options:
20
+ # resources :articles, :priority => 0.8, :change_frequency => "monthly"
21
+
22
+ # Sample resource with block options:
23
+ # resources :activities,
24
+ # :skip_index => true,
25
+ # :updated_at => proc { |activity| activity.published_at.strftime("%Y-%m-%d") }
26
+ # :params => { :subdomain => proc { |activity| activity.location } }
27
+
28
+ end
@@ -0,0 +1,47 @@
1
+ styles:
2
+ link:
3
+ image:
4
+ banner:
5
+ - "940x300"
6
+ - :jpeg
7
+ squared:
8
+ - "300x300"
9
+ - :jpeg
10
+ medium:
11
+ - "620x300"
12
+ - :jpeg
13
+ thumb:
14
+ - "140x110"
15
+ - :jpeg
16
+
17
+ icon:
18
+ i16:
19
+ - "16x16"
20
+ - :png
21
+ i24:
22
+ - "24x24"
23
+ - :png
24
+ i32:
25
+ - "32x32"
26
+ - :png
27
+ i48:
28
+ - "48x48"
29
+ - :png
30
+ i72:
31
+ - "72x72"
32
+ - :png
33
+
34
+ photo:
35
+ image:
36
+ banner:
37
+ - "940x300"
38
+ - :jpeg
39
+ squared:
40
+ - "300x300"
41
+ - :jpeg
42
+ medium:
43
+ - "620x300"
44
+ - :jpeg
45
+ thumb:
46
+ - "140x110"
47
+ - :jpeg
@@ -0,0 +1,31 @@
1
+ class ActsAsTaggableOnMigration < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :tags do |t|
4
+ t.string :name
5
+ end
6
+
7
+ create_table :taggings do |t|
8
+ t.references :tag
9
+
10
+ # You should make sure that the column created is
11
+ # long enough to store the required class names.
12
+ t.references :taggable, :polymorphic => true
13
+ t.references :tagger, :polymorphic => true
14
+
15
+ # limit is created to prevent mysql error o add_index lenght for myisam table type.
16
+ # http://bit.ly/vgW2Ql
17
+ t.string :context, :limit => 128
18
+
19
+ t.datetime :created_at
20
+ end
21
+
22
+ add_index :taggings, :tag_id
23
+ add_index :taggings, [:taggable_id, :taggable_type, :context]
24
+ end
25
+
26
+ def self.down
27
+ drop_table :taggings
28
+ drop_table :tags
29
+ end
30
+ end
31
+
@@ -0,0 +1,18 @@
1
+ class CreateFriendlyIdSlugs < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :friendly_id_slugs do |t|
5
+ t.string :slug, :null => false
6
+ t.integer :sluggable_id, :null => false
7
+ t.string :sluggable_type, :limit => 40
8
+ t.datetime :created_at
9
+ end
10
+ add_index :friendly_id_slugs, :sluggable_id
11
+ add_index :friendly_id_slugs, [:slug, :sluggable_type], :unique => true
12
+ add_index :friendly_id_slugs, :sluggable_type
13
+ end
14
+
15
+ def self.down
16
+ drop_table :friendly_id_slugs
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ class CreateCkeditorAssets < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :ckeditor_assets do |t|
4
+ t.string :data_file_name, :null => false
5
+ t.string :data_content_type
6
+ t.integer :data_file_size
7
+
8
+ t.integer :assetable_id
9
+ t.string :assetable_type, :limit => 30
10
+ t.string :type, :limit => 30
11
+
12
+ # Uncomment it to save images dimensions, if your need it
13
+ t.integer :width
14
+ t.integer :height
15
+
16
+ t.timestamps
17
+ end
18
+
19
+ add_index "ckeditor_assets", ["assetable_type", "type", "assetable_id"], :name => "idx_ckeditor_assetable_type"
20
+ add_index "ckeditor_assets", ["assetable_type", "assetable_id"], :name => "idx_ckeditor_assetable"
21
+ end
22
+
23
+ def self.down
24
+ drop_table :ckeditor_assets
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ puts "Seeding database ..."
2
+
3
+ if Rails.env.development?
4
+ user = User.new( :email => "admin@example.com",
5
+ :password => "password" )
6
+
7
+ user.skip_confirmation! if user.respond_to?(:skip_confirmation!)
8
+ user.save!
9
+ user.confirm! if user.respond_to?(:confirm)
10
+ user.has_role!(:administrator) if user.respond_to?(:has_role!)
11
+ end
@@ -0,0 +1,4 @@
1
+ class Ckeditor::Asset < ActiveRecord::Base
2
+ include Ckeditor::Orm::ActiveRecord::AssetBase
3
+ include Ckeditor::Backend::Paperclip
4
+ end
@@ -0,0 +1,12 @@
1
+ class Ckeditor::AttachmentFile < Ckeditor::Asset
2
+ has_attached_file :data,
3
+ :url => "/ckeditor_assets/attachments/:id/:filename",
4
+ :path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename"
5
+
6
+ validates_attachment_size :data, :less_than => 100.megabytes
7
+ validates_attachment_presence :data
8
+
9
+ def url_thumb
10
+ @url_thumb ||= Ckeditor::Utils.filethumb(filename)
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ class Ckeditor::Picture < Ckeditor::Asset
2
+ has_attached_file :data,
3
+ :url => "/ckeditor_assets/pictures/:id/:style_:basename.:extension",
4
+ :path => ":rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension",
5
+ :styles => { :content => '800>', :thumb => '118x100#' }
6
+
7
+ validates_attachment_size :data, :less_than => 2.megabytes
8
+ validates_attachment_presence :data
9
+
10
+ def url_content
11
+ url(:content)
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module Content
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ validates_presence_of :title
6
+
7
+ acts_as_taggable
8
+ alias :keywords :tags
9
+ permalink :title, :history => true
10
+
11
+ field :title
12
+ field :excerpt, :as => :text
13
+ alias_attribute :description, :excerpt
14
+ end
15
+
16
+ end
@@ -0,0 +1,37 @@
1
+ module Pageable
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_filter :load_current_page
6
+ end
7
+
8
+ module ClassMethods
9
+ def page(name, path, options = {}, &block)
10
+
11
+ this_controller_name = "#{self.name.underscore}".gsub("_controller", "")
12
+ uid = "#{this_controller_name}##{name}"
13
+ i18n_scope = "pages.#{self.name.underscore.split('/').last}##{name}"
14
+ parent =
15
+ title = options.delete(:title) || I18n.t("#{i18n_scope}.title", :default => "#{name}".humanize)
16
+ if Page.table_exists?
17
+ Page.find_or_create_by_uid(uid, :title => title)
18
+ end
19
+
20
+ map(name, path, options = {}, &block)
21
+ @pages ||= []
22
+ @pages << "#{name}"
23
+ end
24
+
25
+ def pages
26
+ @pages || []
27
+ end
28
+ end
29
+
30
+ def load_current_page
31
+ if self.class.pages.include?(action_name)
32
+ this_controller_name = "#{self.class.name.underscore}".gsub("_controller", "")
33
+ @current_page = Page.find_by_uid("#{this_controller_name}##{action_name}")
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,12 @@
1
+ module TimestampedContent
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ include Content
6
+
7
+ index :created_at
8
+ default_scope :order => 'created_at DESC'
9
+ timestamps
10
+ end
11
+
12
+ end
@@ -0,0 +1,40 @@
1
+ class UserSubject < Checkin::Subject
2
+
3
+ role :guest, :alias => :anonymous do
4
+ !subject_model
5
+ end
6
+
7
+ role :logged_in, :alias => [:connected] do
8
+ !!subject_model
9
+ end
10
+
11
+ role :owner, :require => [:logged_in], :method => :own do |object|
12
+ object && ( object.respond_to?(:author) && ( subject_model == object.author ) ) || ( object.respond_to?(:owner) && ( subject_model == object.owner ) )
13
+ end
14
+
15
+ role :administrator, :require => :logged_in, :alias => :admin do
16
+ subject_model.has_role?(:administrator)
17
+ end
18
+
19
+ #
20
+ # Permissions
21
+ #
22
+
23
+ # Admin
24
+
25
+ scope :admin do
26
+ permissions do
27
+ allow :administrators
28
+ deny
29
+ end
30
+ end
31
+
32
+ scope :support do
33
+ permissions do
34
+ allow :administrators
35
+ deny
36
+ end
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,53 @@
1
+ namespace :assets do
2
+ task :compile => :environment do
3
+ require 'sprockets'
4
+
5
+ # workaround used also by native assets:precompile:all to load sprockets hooks
6
+ _ = ActionView::Base
7
+
8
+ # ==============================================
9
+ # = Read configuration from Rails / assets.yml =
10
+ # ==============================================
11
+
12
+ env = Rails.application.assets
13
+ target = File.join(::Rails.public_path, Rails.application.config.assets.prefix)
14
+ assets = YAML.load_file(Rails.root.join('config', 'assets.yml'))
15
+ manifest_path = Rails.root.join(target, 'manifest.yml')
16
+ digest = !!Rails.application.config.assets.digest
17
+ manifest = digest
18
+
19
+
20
+ # =======================
21
+ # = Old manifest backup =
22
+ # =======================
23
+
24
+ manifest_old = File.exists?(manifest_path) ? YAML.load_file(manifest_path) : {}
25
+
26
+ # ==================
27
+ # = Compile assets =
28
+ # ==================
29
+
30
+ compiler = Sprockets::StaticCompiler.new(env,
31
+ target,
32
+ assets,
33
+ :digest => digest,
34
+ :manifest => manifest)
35
+ compiler.compile
36
+
37
+ # ===================================
38
+ # = Merge new manifest into old one =
39
+ # ===================================
40
+
41
+ manifest_new = File.exists?(manifest_path) ? YAML.load_file(manifest_path) : {}
42
+
43
+ File.open(manifest_path, 'w') do |out|
44
+ YAML.dump(manifest_old.merge(manifest_new), out)
45
+ end
46
+
47
+
48
+ # ===============================
49
+ # = Compress assets if required =
50
+ # ===============================
51
+
52
+ end
53
+ end
@@ -0,0 +1,23 @@
1
+ namespace :cms do
2
+ task :bootstrap do
3
+ models = Dir.glob(Rails.root.join("app","models", "*.rb")).map {|f| File.basename(f, ".rb")}.join(" ")
4
+ exec("cd #{Rails.root} && bundle exec rails g migration:from #{models} && bundle exec rake db:create && bundle exec rake db:migrate && bundle exec rake db:seed")
5
+ end
6
+
7
+ namespace :settings do
8
+ task :collect do
9
+ require "YAML"
10
+ grepd = `grep -R "get_setting" #{Rails.root.join('app', 'views')}`
11
+ lines = grepd.split("\n")
12
+ entries = lines.map do |line|
13
+ m = line.match(/ get_setting\( \s+ [\:\"\'] [A-z\-\_]+ /x )
14
+ m[1]
15
+ end.compact
16
+ puts entries.to_yaml
17
+
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+
@@ -0,0 +1,255 @@
1
+ namespace :remote do
2
+
3
+ task :info do
4
+ require 'remoting/task'
5
+ remote('info', config.login) do
6
+
7
+ source "/usr/local/rvm/scripts/rvm"
8
+ which :ruby
9
+ echo "RUBY VERSION: `ruby --version`"
10
+ echo "RUBYGEM VERSION: `gem --version`"
11
+ command "RVM_VER=`rvm --version`"
12
+ echo "RVM VERSION: $RVM_VER"
13
+ end
14
+ end
15
+
16
+ desc "Setup git origin"
17
+ task :init do
18
+ require 'remoting/task'
19
+
20
+ local('init') do
21
+ git :init
22
+ git :remote, :add, :origin, config.repo
23
+ end
24
+ end
25
+
26
+ desc "Initialize remote"
27
+ task :setup do
28
+ require 'remoting/task'
29
+ repo_location = config.repo.gsub(/^ssh:\/\/[^\/]+/, "")
30
+ remote('setup', config.login) do
31
+ mkdir "-p", repo_location
32
+ cd repo_location
33
+ git :init, "--bare"
34
+ git "--bare", "update-server-info"
35
+ mkdir "-p", config.dest
36
+ git :config, "core.bare", :false
37
+ git :config, "core.worktree", config.dest
38
+ git :config, "receive.denycurrentbranch", :ignore
39
+ touch "hooks/post-receive"
40
+ command("echo '#!/bin/sh' >> hooks/post-receive")
41
+ command("echo git checkout -f >> hooks/post-receive ")
42
+ chmod "+x", "hooks/post-receive"
43
+ end
44
+ end
45
+
46
+ desc "Commit everything to remote git repository"
47
+ task :push do
48
+ require 'remoting/task'
49
+
50
+ message = ENV["MESSAGE"] || "commit #{Time.now}"
51
+
52
+ local('push') do
53
+ git :add, "."
54
+ git :commit, "-a", "-m", "\"#{message}\""
55
+ git :push, "origin", "+master:refs/heads/master"
56
+ end
57
+ end
58
+
59
+ desc "Commit everything to remote git repository"
60
+ task :pull do
61
+ require 'remoting/task'
62
+
63
+ local('pull') do
64
+ git :pull, :origin, :master
65
+ end
66
+ end
67
+
68
+
69
+ desc "Restart the server"
70
+ task :restart do
71
+ require 'remoting/task'
72
+
73
+ remote('restart', config.login) do
74
+ mkdir '-p', config.dest.join('tmp')
75
+ touch config.dest.join('tmp', 'restart.txt')
76
+ end
77
+
78
+ end
79
+
80
+ desc "Run bundle install on the server"
81
+ task :bundle do
82
+ require 'remoting/task'
83
+
84
+ remote('bundle', config.login) do
85
+ source "/usr/local/rvm/scripts/rvm"
86
+ rvm :use, config.ruby
87
+
88
+ cd config.dest
89
+ export "LANG=en_US.UTF-8"
90
+ command "RAILS_ENV=production", "bundle install", "--without development test", "--deployment"
91
+ end
92
+ end
93
+
94
+ desc "Deploy application on server"
95
+ task :deploy => [:push, :bundle, :"assets:compile", :restart] do
96
+ end
97
+
98
+ desc "Run rake tasks on server"
99
+ task :rake, [:invocation] do |t, args|
100
+ require 'remoting/task'
101
+
102
+ invocation = args[:invocation]
103
+
104
+ remote('rake', config.login, :interactive => true) do
105
+ source "/usr/local/rvm/scripts/rvm"
106
+ rvm :use, config.ruby
107
+ cd config.dest
108
+ command("RAILS_ENV=production bundle exec rake #{invocation}")
109
+ end
110
+
111
+ end
112
+
113
+ desc "Open a remote shell session on server"
114
+ task :ssh do
115
+ require 'remoting/task'
116
+ remote('ssh', config.login, :interactive => true) do
117
+ end
118
+ end
119
+
120
+ desc "Dump a remote logfile"
121
+ task :log, [:lines, :filename] do |t, args|
122
+ require 'remoting/task'
123
+
124
+ filename, lines = args.values_at(:lines, :filename)
125
+ filename ||= "production"
126
+ filename = "#{filename}.log" unless filename =~ /\.[a-z]+$/
127
+
128
+ lines ||= 100
129
+
130
+ remote('log', config.login) do
131
+ cd config.dest
132
+ tail "-#{lines} log/#{filename}"
133
+ end
134
+ end
135
+
136
+ task :logs => [:log] do
137
+ end
138
+
139
+
140
+ desc "Run tail -f on logfile"
141
+ task :logtail, [:filename] do |t, args|
142
+ require 'remoting/task'
143
+
144
+ filename= args[:filename]
145
+ filename ||= "production"
146
+ filename = "#{filename}.log" unless filename =~ /\.[a-z]+$/
147
+
148
+ remote('logtail', config.login) do
149
+ cd config.dest
150
+ tail "-f log/#{filename}"
151
+ end
152
+ end
153
+
154
+ desc "Open a remote console"
155
+ task :console do
156
+ require 'remoting/task'
157
+
158
+ remote('console', config.login, :interactive => true) do
159
+ cd config.dest
160
+ source "/usr/local/rvm/scripts/rvm"
161
+ bundle :exec, "rails c production"
162
+ end
163
+ end
164
+
165
+ desc "Update crontab with whenever schedule"
166
+ task :whenever do
167
+ require 'remoting/task'
168
+
169
+ remote('whenever', config.login) do
170
+ cd config.dest
171
+ whenever "-w"
172
+ end
173
+ end
174
+
175
+
176
+ namespace :apache do
177
+ task :ensite do
178
+ require 'remoting/task'
179
+ remote('ensite', config.login, :interactive => true) do
180
+ cd "/etc/apache2/sites-enabled"
181
+ sudo "ln -s #{config.dest.join('config', 'apache.conf')} #{config.app}"
182
+ end
183
+ end
184
+
185
+ task :reload do
186
+ require 'remoting/task'
187
+
188
+ remote('reload', config.login, :interactive => true) do
189
+ sudo "/etc/init.d/apache2 reload"
190
+ end
191
+ end
192
+ end
193
+
194
+ namespace :assets do
195
+
196
+ desc 'Precompile assets'
197
+ task :precompile do
198
+ require 'remoting/task'
199
+
200
+ remote('rake assets:precompile', config.login) do
201
+ source "/usr/local/rvm/scripts/rvm"
202
+ rvm :use, config.ruby
203
+ cd config.dest
204
+ command("RAILS_ENV=production bundle exec rake assets:precompile")
205
+ echo 'restarting ...'
206
+ mkdir '-p', config.dest.join('tmp')
207
+ touch config.dest.join('tmp', 'restart.txt')
208
+
209
+ end
210
+ end
211
+
212
+ desc 'compile application related static assets'
213
+ task :compile do
214
+ require 'remoting/task'
215
+
216
+ remote('rake assets:compile', config.login) do
217
+ source "/usr/local/rvm/scripts/rvm"
218
+ rvm :use, config.ruby
219
+ cd config.dest
220
+ command("RAILS_ENV=production bundle exec rake assets:compile")
221
+ end
222
+ end
223
+
224
+ end
225
+
226
+ namespace :db do
227
+
228
+ desc "Migrate remote database"
229
+ task :migrate do |t, args|
230
+ require 'remoting/task'
231
+
232
+ remote('rake db:migrate', config.login) do
233
+ source "/usr/local/rvm/scripts/rvm"
234
+ rvm :use, config.ruby
235
+ cd config.dest
236
+ command("RAILS_ENV=production bundle exec rake db:migrate")
237
+ end
238
+ end
239
+
240
+ desc "Seed remote database"
241
+ task :seed do |t, args|
242
+ require 'remoting/task'
243
+
244
+ remote('rake db:seed', config.login) do
245
+ source "/usr/local/rvm/scripts/rvm"
246
+ rvm :use, config.ruby
247
+ cd config.dest
248
+ command("RAILS_ENV=production bundle exec rake db:seed")
249
+ end
250
+ end
251
+
252
+
253
+ end
254
+
255
+ end