Skip to content

Instantly share code, notes, and snippets.

@songjiayang
Created August 21, 2013 03:53
Show Gist options
  • Save songjiayang/6290168 to your computer and use it in GitHub Desktop.
Save songjiayang/6290168 to your computer and use it in GitHub Desktop.
rails template..
# 更换源
comment_lines "Gemfile", /source .http.*/
add_source "http://ruby.taobao.org"
# HTML模板
gem 'slim'
# 单点登录
gem 'rubycas-client'
# 权限管理
gem 'cancan'
# 系统设置
gem 'settingslogic'
# 插件系统
gem 'cells'
# 按不同的操作系统提供通知插件
inject_into_file 'Gemfile', after: '"http://ruby.taobao.org"\n' do <<-'RUBY'
require 'rbconfig'
HOST_OS = RbConfig::CONFIG['host_os']
case HOST_OS
when /darwin/i
gem 'rb-fsevent', :group => :development
gem 'growl', :group => :development
when /linux/i
gem 'libnotify', :group => :development
gem 'rb-inotify', :group => :development
when /mswin|windows/i
gem 'rb-fchange', :group => :development
gem 'win32console', :group => :development
gem 'rb-notifu', :group => :development
end
RUBY
end
# 集成测试
gem_group :test do
gem 'turn', :require => false
gem 'rspec-rails'
gem 'spork'
gem 'database_cleaner'
gem 'factory_girl_rails', :require => false
gem "capybara"
gem "launchy"
gem 'guard-spork'
gem 'guard-rspec'
gem 'guard-livereload'
gem 'guard-bundler'
gem 'simplecov', :require => false
end
# 删除默认的主页
remove_file 'public/index.html'
# 采用slim做为解释器,删除默认布局
remove_file 'app/views/layouts/application.html.erb'
# 统一角色管理
if yes?("Are you require 'zhiyi-unirole'(y/n)?")
gem('unirole', git: 'git@task.zhiyisoft.com:bazaar/xiegang/zhiyi-unirole.git')
run('bundle install')
generate('unirole:install')
end
# 工作流
if yes?("Are you require 'ruote' workflow(y/n)?")
gem('ruote')
gem('ruote-mon')
end
# 更新包
run('bundle install')
# 生成数据库配置文件
generate('mongoid:config')
# 生成权限配置文件,默认登录用户具备全部权限
generate('cancan:ability')
inject_into_file "app/models/ability.rb", after: "def initialize(user)\n" do <<-'RUBY'
unless user.new_record?
can :manage, :all
else
cannot :manage, :all
end
RUBY
end
# 配置单点登录
inject_into_file "config/environment.rb", after: "require File.expand_path('../application', __FILE__)\n" do <<-'RUBY'
CASClient::Frameworks::Rails::Filter.configure(
:cas_base_url => "http://sso.zhiyisoft.com/",
:username_session_key => :login,
:extra_attributes_session_key => :login_extra_attributes,
:enable_single_sign_out => true,
:authenticate_on_every_request => false
)
RUBY
end
# 增加Home控制器
create_file "app/controllers/home_controller.rb" do <<-'RUBY'
class HomeController < ApplicationController
def index
end
end
RUBY
end
create_file "app/views/home/index.slim" do <<-'RUBY'
h1 Todo: 请修改这个页面!
RUBY
end
# 增加根路由
route "root :to => 'home#index'"
route "match '/logout' => 'application#logout'"
# 增加控制器方法
inject_into_file "app/controllers/application_controller.rb", after: "protect_from_forgery\n" do <<-'RUBY'
before_filter CASClient::Frameworks::Rails::Filter
def current_user
user ||= Unirole::User.where(login: session[:login]).first if session[:login]
user ||= Unirole::User.new
end
def logout
CASClient::Frameworks::Rails::Filter.logout(self, root_url)
end
rescue_from CanCan::AccessDenied do |exception|
redirect_to main_app.root_path, alert: exception.message
end
RUBY
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment