Hyper: A Framework For Ruby Websites
I could have called this gem Yawf: Yet Another Website Framework. Do we really need one? I think we — or at least I — do, so I built it.
Hyper is a micro-framework that supports small, static HTML sites with some Ruby magic thrown in. Its focus is on building and launching a site fast: there’s zero configuration, no route definitions, and definitely no databases.
Why Build Hyper?
I could have used Sinatra or Rails for my personal projects, but I wanted something lighter. I wanted a framework that could take me from a standing start to a functioning website without any configuration (I’m impatient: even Sinatra’s get '/url' route definitions felt like they were holding me back).
Most importantly, I wanted the experience that comes from building something for myself.
Quick Start
$ gem install hyper
$ hyper new cool_site
$ cd cool_site
$ bundle install
$ bundle exec rackup
Your new site is now live at http://0.0.0.0:9292/.
Magic
I want Hyper to hit the sweet spot between plain HTML (no Ruby) and dynamic frameworks like Rails. Routes are automatic:
/ # maps to templates/views/index.html.erb
/about # maps to templates/views/about.html.erb
/contact # maps to templates/views/contact.html.erb
Because Hyper does this automagically, I can just drop my content into the correct file and move on. Every URL is handled in this way, and there are no exceptions: this behaviour covers 99% of my needs, and if I want something more dynamic I can use a different framework.
Helpers
Because this is a Ruby framework, you get a helper module:
# in lib/helper.rb
module Hyper::Helper
def say_hello
"Hello world"
end
end
# in templates/views/hello.html.erb
<p><%= say_hello -%></p>
And because it makes sense to split HTML into layout and views, Hyper does just that: shared HTML lives in templates/layout.html.erb, and page-specific content lives in templates/views.
Fast Deployment With Heroku
Right now, Ruby developers have an amazing hosting service in Heroku: prices start at free and the platform supports any web app that’s based on Rack. Can you guess what Hyper is based on?
$ cd cool_website
$ heroku create
$ git push heroku master
-----> Heroku receiving push
-----> Rack app detected
Boom: your website is now on the web.
Share And Enjoy
Hyper is available on Github and via Rubygems: right now it’s is working great for me; I hope it works for you too.
Photo by phunk on Flickr
