-
-
Save alvin2ye/2908045 to your computer and use it in GitHub Desktop.
A custom Rails template for Mongoid.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# This is a Rails init template with MongoDB projects | |
# | |
# Mongoid, Devise, Bootstrap, jQuery, Redis, Cells, will_paginate, Carrierwave, simple_form, Settingslogic, Thin | |
# | |
# Usage | |
# | |
# $ rails new app_name -m https://raw.github.com/gist/2168014 | |
# | |
initializer 'generators.rb', <<-RUBY | |
Rails.application.config.generators do |g| | |
end | |
RUBY | |
# Remove unnecessary files | |
run "rm README.rdoc" | |
run "touch README.md" | |
run "rm public/index.html" | |
run "rm public/favicon.ico" | |
run "rm app/assets/images/rails.png" | |
run "rm Gemfile" | |
# Setup Git | |
# git :init | |
run "rm .gitignore" | |
get 'https://raw.github.com/gist/2167387', '.gitignore' | |
@current_recipe = nil | |
@configs = {} | |
@after_blocks = [] | |
def after_bundler(&block); @after_blocks << [@current_recipe, block]; end | |
@after_everything_blocks = [] | |
def after_everything(&block); @after_everything_blocks << [@current_recipe, block]; end | |
@before_configs = {} | |
def before_config(&block); @before_configs[@current_recipe] = block; end | |
# Gemfile | |
get "https://raw.github.com/gist/2167336", "Gemfile" | |
# config/environments/development.rb | |
gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/, "config.action_mailer.default_url_options = { :host => 'localhost:3000' }" | |
gsub_file 'config/environments/development.rb', /^([\s]{0,})config\.active_record\./," # config.active_record." | |
# config/application/rb | |
gsub_file 'config/application.rb', "require 'rails/all'", | |
<<-STR | |
require "action_controller/railtie" | |
require "action_mailer/railtie" | |
require "active_resource/railtie" | |
require "rails/test_unit/railtie" | |
require "sprockets/railtie" | |
STR | |
gsub_file 'config/application.rb', 'Bundler.require(*Rails.groups(:assets => %w(development test)))', 'Bundler.require *Rails.groups(:assets => %w(production development test))' | |
gsub_file 'config/application.rb', '# config.autoload_paths += %W(#{config.root}/extras)', | |
<<-STR | |
config.autoload_paths += %W(\#{config.root}/cells) | |
config.autoload_paths += %W(\#{config.root}/uploaders) | |
STR | |
gsub_file 'config/application.rb', "# config.time_zone = 'Central Time (US & Canada)'","config.time_zone = 'Beijing'" | |
gsub_file 'config/application.rb', "# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]", "config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]" | |
gsub_file 'config/application.rb', "# config.i18n.default_locale = :de", 'config.i18n.default_locale = "zh-CN"' | |
gsub_file 'config/application.rb', 'config.filter_parameters += [:password]', 'config.filter_parameters += [:password,:password_confirmation]' | |
gsub_file 'config/application.rb', '# config.active_record.schema_format = :sql', 'config.mongoid.include_root_in_json = false' | |
gsub_file 'config/application.rb', /^[\s]{0,}#.+/, "" | |
gsub_file 'config/application.rb', /\n+/,"\n" | |
# Generate configs | |
after_bundler do | |
run "rm config/database.yml" | |
# Mongoid | |
get "https://raw.github.com/gist/2167751", "config/mongoid.yml" | |
gsub_file "config/mongoid.yml", "app_name", "#{app_name}" | |
run "cp config/mongoid.yml config/mongoid.yml.default" | |
# Mongoid BaseModel | |
run "mkdir app/models/mongoid" | |
run "touch app/models/mongoid/base_model.rb" | |
append_file "app/models/mongoid/base_model.rb", <<-STR | |
# coding: utf-8 | |
module Mongoid | |
module BaseModel | |
extend ActiveSupport::Concern | |
included do | |
scope :recent, desc(:_id) | |
scope :exclude_ids, Proc.new { |ids| where(:_id.nin => ids.map(&:to_i)) } | |
end | |
end | |
end | |
STR | |
# Redis | |
get "https://raw.github.com/gist/2167666", "config/redis.yml" | |
gsub_file "config/redis.yml", "app_name", "#{app_name}" | |
run "cp config/redis.yml config/redis.yml.default" | |
get "https://raw.github.com/gist/2167671", "config/initializers/redis.rb" | |
# Devise | |
generate("devise:install") | |
generate("devise User") | |
gsub_file "app/models/user.rb", "include Mongoid::Document", 'include Mongoid::Document | |
include Mongoid::Timestamps | |
include Mongoid::BaseModel' | |
# Simple Form | |
generate("simple_form:install") | |
get "https://raw.github.com/gist/2167880", "config/initializers/simple_form.rb" | |
# SettingsLogic | |
run "touch config/setting.yml" | |
append_file 'config/setting.yml', <<-STR | |
defaults: &defaults | |
app_name: "#{app_name.humanize.titleize}" | |
footer_html: "© #{app_name.humanize.titleize}." | |
domain: "127.0.0.1:3000" | |
upload_url: "http://127.0.0.1:3000/uplaods" | |
development: | |
<<: *defaults | |
test: | |
<<: *defaults | |
production: | |
<<: *defaults | |
STR | |
run "cp config/setting.yml config/setting.yml.default" | |
run "touch app/models/setting.rb" | |
append_file "app/models/setting.rb", <<-STR | |
# coding: utf-8 | |
class Setting < Settingslogic | |
source "\#{Rails.root}/config/setting.yml" | |
namespace Rails.env | |
end | |
STR | |
# Uploaders | |
run "mkdir app/uploaders" | |
get "https://raw.github.com/gist/2167981", "app/uploaders/base_uploader.rb" | |
# Routes | |
gsub_file 'config/routes.rb', ".+?", "" | |
route "devise_for :users, :path => 'account', :controllers => { :registrations => :account }\n root :to => 'home#index'" | |
# HomeController | |
generate("controller home index") | |
end | |
# Assets files | |
get "https://raw.github.com/gist/2168046", "vendor/assets/javascripts/will_paginate.js" | |
run "rm app/assets/javascripts/application.js" | |
run "touch app/assets/javascripts/application.coffee" | |
append_file "app/assets/javascripts/application.coffee", <<-STR | |
#= require jquery | |
#= require jquery_ujs | |
#= require will_paginate | |
#= require bootstrap | |
#= require_tree | |
#= require_self | |
$(document).ready -> | |
$('.dropdown-toggle').dropdown() | |
STR | |
run "rm app/assets/stylesheets/application.css" | |
run "touch app/assets/stylesheets/application.scss" | |
append_file "app/assets/stylesheets/application.scss", <<-STR | |
/* | |
*= require bootstrap | |
*= require responsive | |
*= require_self | |
*= require_tree | |
*/ | |
body { position: relative; background-color: #fff; background-repeat: repeat-x; background-position: 0 40px; } | |
a,a:visited { | |
color: #0069D6; text-decoration: none; line-height: inherit; font-weight: inherit; | |
&:hover { color:#000; } | |
} | |
.navbar-fixed-top { | |
position: static; right: 0; left: 0; margin-bottom:20px; | |
.brand { | |
padding-right: 0; padding-left: 0; margin-left: 0px; float: left; font-weight: bold; color: #000; text-shadow: 0 1px 0 rgba(255,255,255,.1), 0 0 30px rgba(255,255,255,.125); -webkit-transition: all .2s linear; -moz-transition: all .2s linear; transition: all .2s linear; | |
&:hover { text-decoration: none; background:none; } | |
} | |
} | |
.container-fluid { padding-left: 0px; padding-right: 0px; } | |
.box { | |
margin-bottom:20px; | |
h2 { font-size:14px; border-bottom:1px solid #ddd; margin-bottom:10px; } | |
} | |
STR | |
# I18n files | |
get "https://raw.github.com/gist/2167594", "config/locales/zh-CN.yml" | |
get "https://raw.github.com/gist/2167614", "config/locales/devise.zh-CN.yml" | |
get "https://raw.github.com/gist/2167630", "config/locales/carrierwave.zh-CN.yml" | |
# Run callback | |
@current_recipe = nil | |
run "bundle install" | |
@after_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call} | |
@current_recipe = nil | |
@after_everything_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment