A light framework for front-end development inspired by Rails. The sole purpose of Rail is to compile assets, and it includes the following components:
- CoffeeScript for JavaScript,
- Haml for HTML, and
- Sass for CSS.
Installation
Straightforward
Install the gem:
gem install railCreate a new project:
rail new my_projectRun Bundler:
cd ./my_project
bundleRun the server:
rake serverOpen http://localhost:3000 in your browser, see “My Project,” and enjoy.
Under the hood, the rail new my_project command creates a new folder in the
current directory called my_project and initializes a basic Rail project
inside that folder. In this case, MyProject is used as the class name of the
project. Feel free to replace my_project with the name of your project.
Manual
Create a Gemfile:
source 'https://rubygems.org'
gem 'rail'Run Bundler:
bundleCreate three files: config/application.rb, config.ru, and Rakefile. In
config/application.rb:
require 'bundler'
Bundler.require(:default)
module MyProject
class Application < Rail::Application
end
endIn config.ru:
require_relative 'config/application'
run MyProject::Application.newIn Rakefile:
require_relative 'config/application'
MyProject::Application.load_tasksFeel free to replace MyProject with the name of your project.
Usage
Rail closely follows Rails. If you know Rails, you already know Rail.
Structure
Organize your code according to the following convention:
-
app/assets/javascriptsfor scripts, -
app/assets/stylesheetsfor styles, -
app/viewsfor templates, -
app/helpersfor helper modules, and -
publicfor other static content.
The templates in app/views/layouts have a special purpose. First,
application.html.haml is used for rendering the root of your application (both
/ and /index.html). Second, any template in layouts is used as a layout
for the templates in the subfolder of views that has the same name as the
layout. For example, articles/what-is-the-meaning-of-life.html.haml will be
rendered in the context of layouts/articles.html.haml provided that the latter
has a placeholder for the former via the yield keyword.
Configuration
As with Rails, Rail is configured inside config/application.rb:
module MyProject
class Application < Rail::Application
# Gems to look for additional assets
config.gems << 'googleplus-reader'
# Assets to precompile when running `rake assets`
config.precompile << 'application.css'
config.precompile << 'application.js'
config.precompile << 'index.html'
# Compress assets when serving and precompiling
config.compress = true
end
endIf config.compress is not specified, it is implicitly set to ENV['RAIL_ENV'] == 'production'.
Commands
Run Rake to see the available tasks:
rake -T
rake assets # Precompile assets
rake server # Start serverrake server starts up a Web server; if none is specified in Gemfile,
WEBrick will be fired up.
rake assets compiles your assets and stores them in public. You should
explicitly tell Rail what to compile as it was shown in the previous section.
Note that the server will try to serve from public first, so make sure you
delete the precompiled files when you change your code in app.
Examples
Additional usage examples can be found here, here, and here.
Contribution
- Fork the project.
- Implement your idea.
- Open a pull request.