Here's how to use this template:
$ git clone --depth 1 git://github.com/rstacruz/sinatra-template.git myproject
$ rm -r myproject/.git
# Set up
$ bundle install # Install gems
$ rake vendor # Vendor JS files
# Eventually get rid of this README file
$ mv README.example.md README.md
Hack away! Remove this screen by editing app/routes/site.rb
and app/views/home.haml
.
Some views were set up for you that use Haml (for HTML) and SASS / SCSS (for CSS).
The skeleton comes with no ORM by default.
However, there are sample initializers in app/init/
and config files in
config/
for Ohm and Sequel. See those files for instructions.
The bootstrapper loads all of config/*.rb
, starting with the default
files (like haml.default.rb
).
- To set settings:
Main.set :name, "Hello"
- To retrieve settings:
settings.name
Built-in support for http://compass-style.org.
Uses JsFiles (to compress JS files). This supports CoffeeScript support by the way.
- Edit
config/jsfiles.defaults.rb
to see which JS files are to be processed.
Some things from the HTML5 boilerplate were roughly followed:
- JQuery is in there
- Modernizr built in
- Load JQuery/Modernizr/etc via CDN (Google's and Cachedcommon's public CDNs)
- DD_belatedPNG
- ...among other things (which should be fairly trivial to remove)
Dump your CoffeeScripts to /app/js
. The file yourfile.coffee
will be
available in http://localhost:4567/js/yourfile.js
.
(Edit your gemfile to add the coffeescript
gem if needed.)
Dump your Less, SCSS, or Sass files onto /app/css
. Watch hello.sass
show
up on http://localhost:4567/css/hello.css
.
(Edit your gemfile to add the less
gem if needed.)
Type rake
to see a list of commands with an extended help screen.
The jQuery helpers ensure that jQuery is loaded from Google servers first before falling back to the app-provided jQuery file.
./
|- app/
| |- init/ - Initializers (akin to Rails config/initializers)
| |- models/ - Models
| |- routes/ - Sinatra routes (akin to Rails controllers)
| |- helpers/ - Helper modules
| |- views/ - Views and layouts (haml, erb, etc)
| |- css/ - Stylesheets served under /css
| `- js/ - JS files served under /js
|
|- lib/ - General purpose libraries
| `- tasks/ - Rake tasks (*.rake)
|
|- config/ - Configuration files (*.rb)
|- public/ - Static assets
|- test/
`- init.rb
The main file is init.rb
-- just run it to start the server.
When init.rb is loaded, it:
- loads
*.rb
inconfig/defaults/
to load default settings - loads
*.rb
inconfig/
to load user settings -- these files are gitignore'd - loads
*.rb
inapp/init/
to initialize stuff - loads
*.rb
inapp/
(recursive) to load routes and models - starts the server