Skip to content

Instantly share code, notes, and snippets.

@movesmyers
Last active December 20, 2015 14:59
Show Gist options
  • Select an option

  • Save movesmyers/6151051 to your computer and use it in GitHub Desktop.

Select an option

Save movesmyers/6151051 to your computer and use it in GitHub Desktop.
A short script to create a Sinatra project skeleton to my liking. Assumes you are using erb, sass, and passenger.
#!/usr/bin/env ruby
require 'fileutils'
##
# Creates a Sinatra project skeleton.
# Assumes you are using erb, sass, and passenger.
project_name = ""
if ARGV[0]
project_name = ARGV[0]
else
abort("usage: sinatra_skeleton.rb [project name]")
end
# create directories
FileUtils.mkdir(project_name)
FileUtils.mkdir_p(File.join(project_name, 'public/stylesheets/sass'))
FileUtils.mkdir(File.join(project_name, 'public/images'))
FileUtils.mkdir(File.join(project_name, 'tmp'))
FileUtils.mkdir(File.join(project_name, 'views'))
# create empty files
FileUtils.touch(File.join(project_name, 'public/stylesheets/sass/styles.scss'))
FileUtils.touch(File.join(project_name, 'tmp/always_restart.txt'))
FileUtils.touch(File.join(project_name, 'views/layout.erb'))
FileUtils.touch(File.join(project_name, 'views/index.erb'))
# define the strings to be written to non-empty files
root_rb = <<EOF
require 'sinatra'
require 'sass'
get '/' do
erb :index
end
EOF
config_ru = <<EOF
require 'sass/plugin/rack'
require './#{project_name + '.rb'}'
Sass::Plugin.options[:style] = :compressed
use Sass::Plugin::Rack
run Sinatra::Application
EOF
robots_txt = <<EOF
User-agent: *
EOF
# create and write files with content
File.open(File.join(project_name, project_name + '.rb'), 'w+') do |f|
f.write(root_rb)
end
File.open(File.join(project_name, 'config.ru'), 'w+') do |f|
f.write(config_ru)
end
File.open(File.join(project_name, 'public/robots.txt'), 'w+') do |f|
f.write(robots_txt)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment