Skip to content

Instantly share code, notes, and snippets.

@patrickdavey
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickdavey/ee9fb851e8b324742894 to your computer and use it in GitHub Desktop.
Save patrickdavey/ee9fb851e8b324742894 to your computer and use it in GitHub Desktop.
Applies bootstrap3 and some sensible defaults for heroku
# forked from http://refinerycms.com/t/edge
require 'rbconfig'
# We want to ensure that you have an ExecJS runtime available!
begin
require 'execjs'
rescue LoadError
abort "ExecJS is not installed. Please re-start the installer after running:\ngem install execjs"
end
if File.read("#{destination_root}/Gemfile") !~ /assets.+coffee-rails/m
gem "coffee-rails", :group => :assets
end
prepend_file 'Gemfile' do
"ruby '2.1.2'
"
end
gsub_file 'Gemfile', /gem 'rails', '4/ do |match|
"gem 'rails', '~> 4"
end
append_file 'Gemfile' do
"
# add bootstrap-sass
gem 'autoprefixer-rails'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'refinerycms', github: 'refinery/refinerycms', branch: 'master'
gem 'refinerycms-i18n', github: 'refinery/refinerycms-i18n', branch: 'master'
gem 'quiet_assets'
# Add support for refinerycms-acts-as-indexed
gem 'refinerycms-acts-as-indexed', ['~> 2.0', '>= 2.0.0']
# Add support for refinerycms-wymeditor
gem 'refinerycms-wymeditor', ['~> 1.0', '>= 1.0.0']
gem 'seo_meta', github: 'parndt/seo_meta', branch: 'master'
gem 'paper_trail', github: 'airblade/paper_trail', branch: 'master'
"
end
gem_group :development, :test do
gem 'rspec-rails'
gem 'pry-rails'
end
gem_group :test do
gem 'factory_girl_rails'
end
gem_group :production do
gem 'rails_12factor'
gem 'unicorn'
gem 'fog'
# serve deflated zipped assets were possible
gem 'heroku_rails_deflate'
end
begin
require 'execjs'
::ExecJS::Runtimes.autodetect
rescue
gsub_file 'Gemfile', "# gem 'therubyracer'", "gem 'therubyracer'"
end
run 'bundle install'
rake 'db:create'
generate "refinery:cms --fresh-installation #{ARGV.join(' ')}"
# add the mail config for heroku.
initializer 'mail.rb', <<-CODE
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
CODE
# add the procfile and unicorn.rb
file 'Procfile', <<-CODE
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
CODE
file 'config/unicorn.rb', <<-CODE
# config/unicorn.rb
worker_processes 3
timeout 30
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
CODE
# start the bootstrapping process
# remove the old application.css
run 'rm app/assets/stylesheets/application.css'
run 'rm app/assets/stylesheets/application.css.scss'
file 'app/assets/stylesheets/application.css.scss', <<-CODE
@import "bootstrap";
@import "header";
/* add padding for the basic menu */
body {
padding-top: 50px;
}
#page, footer {
@extend .container;
}
#body_content {
@extend .row;
h1#body_content_title {
@extend .col-md-12
}
}
#body {
@extend .col-md-8;
}
#side_body {
@extend .col-md-4;
}
CODE
run 'rm app/assets/stylesheets/header.css.scss'
file 'app/assets/stylesheets/header.scss', <<-CODE
.navbar {
@extend .container;
border-right: none;
border-left: none;
.navbar-nav li {
padding-right: 22px;
&:hover {
.dropdown-menu {
display: block;
> li {
> a {
padding: 3px 13px;
}
}
}
}
}
}
@media (max-width: $screen-sm-min){
.navbar-nav > li > a {
padding-top: 3px;
padding-bottom: 3px;
}
.navbar .navbar-nav li {
padding-right: 0px;
.dropdown-menu {
display: block;
position: static;
float: none;
border: none;
box-shadow: none;
li a {
padding: 3px 30px !important;
}
}
}
}
CODE
# remove the application.js and replace with new one
run 'rm app/assets/javascripts/application.js'
file 'app/assets/javascripts/application.js', <<-CODE
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
CODE
run 'rm app/helpers/application_helper.rb'
file 'app/helpers/application_helper.rb', <<-CODE
module ApplicationHelper
def bootstrap_menu
menu = Refinery::Pages::Bootstrap::BootstrapMenu.new(refinery_menu_pages, self)
menu.max_depth = 1
menu.list_tag_css = 'nav navbar-nav'
menu.selected_css = 'active'
menu.to_html
end
end
CODE
run 'rm app/views/refinery/_header.html.erb'
file 'app/views/refinery/_header.html.erb', <<-CODE
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<%= link_to Refinery::Core.site_name, refinery.root_path, class: 'navbar-brand' %>
</div>
<%= bootstrap_menu %>
</div>
</div>
CODE
run 'rm app/presenters/refinery/pages/bootstrap/bootstrap_menu.rb'
file 'app/presenters/refinery/pages/bootstrap/bootstrap_menu.rb', <<-CODE
module Refinery
module Pages
module Bootstrap
class BootstrapMenu < Refinery::Pages::MenuPresenter
def render_menu(items)
content_tag(:div, :id => "nav", :class => 'collapse navbar-collapse') do
render_menu_items(items)
end
end
def render_menu_items(menu_items)
if menu_items.present?
list_class = menu_items.first.depth > 0 ? 'dropdown-menu' : 'nav navbar-nav'
content_tag(list_tag, :class => list_class) do
menu_items.each_with_index.inject(ActiveSupport::SafeBuffer.new) do |buffer, (item, index)|
buffer << render_menu_item(item, index)
end
end
end
end
def menu_item_css(menu_item, index)
css = []
selected_or_descendent = selected_item_or_descendant_item_selected?(menu_item)
css << selected_css if selected_or_descendent
css << "not-exact-select" if selected_or_descendent && !selected_item?(menu_item)
css << first_css if index == 0
css << last_css if index == menu_item.shown_siblings.length
css.reject(&:blank?).presence
end
end
end
end
end
CODE
gsub_file 'config/initializers/refinery/images.rb', /# config.dragonfly_secret/ do |match|
"config.dragonfly_secret"
end
say <<-SAY
============================================================================
Your new Refinery CMS application is now running on edge and mounted to /.
============================================================================
SAY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment