Project

spire

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Light rack-based framework with controllers, HAML/ERB views, router & error handler
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.0.0
>= 1.6.4

Runtime

>= 2.7.0
>= 3.1.0
>= 1.3.0
 Project Readme

spire¶ ↑

Light controller-only rack framework with a dash of views.

Installation¶ ↑

gem install spire
spire -c project_name
cd !$ && rackup

This will install spire, create a project called ‘project_name’ in the same directory it’s run in, and then start the site.

Usage ¶ ↑

Creating a project¶ ↑

To create a new project you simply use the spire executable like so:

spire -c my_project

and it will make a template app in ./my_project in the folder it was executed.

Routes¶ ↑

Routes are used in the config.ru, and are handled using the Map object.

map.route :url => "/index", :to => {:controller => "index", :action => "index"}

The “default” route is what is opened when someone goes to ‘/’ on your address. Routes happily along to the IndexController and executes the ‘index’ method

map.route :url => "/", :to => {:controller => "index", :action => "index"}

Controllers¶ ↑

Controllers are named to tie with the routes (read above). They are stored in:

project_name/app/controllers/

With the naming scheme like so:

FooController.rb

Where Foo is the name of the controller. The name must be camel-cased. All classes must be defined like so:

class Foo < Spire::MainController

end

as a skeleton controller for the framework to use. An example response would look like this:

class Index < Spire::MainController
  def index
    "This is just a response"
  end
end

This would display a html page with that text. The Response.new initiator could be used like so:

def index
  @status = 200
  @content_type = "text/html;"
  return "Hi, I'm a test page!"
end

Where the first instance variable @status is the HTTP status to show, the second being the content type, and the last being the returned value as a string.

Controller generator¶ ↑

You can generate controllers using the spire executable. To do this you can simply run:

spire -g foo

Which will generate the FooController in the app/controllers directory with all the necessary code for you.

Views¶ ↑

RHTML¶ ↑

RHTML templates are executed using erubis due to its speed. To create a erb view, you must create a view in:

/app/views/

With the naming scheme of:

template.rhtml

The .rhtml is important so Spire knows what file it is. To pass data to a view, you simply define an instance variable before you render the template and it will automatically be accessible in your view template. To render a template, you simply use:

render :view => "index.rhtml"

HAML¶ ↑

HAML templates can be rendered like so:

render :view => "index.haml"

This would load the index.haml view in:

/app/views/index.haml

To pass data to the view, define and fill an instance variable with content or an object, and you can use it inside your HAML view.

HTML¶ ↑

HTML are static templates to be used in your project/app. they can’t use variables, nor can they execute ruby code. They can be rendered using:

render :view => "index.html"

Which would load the ‘index.html’ file from:

project_name/app/views/index.html

Request data¶ ↑

To access request data (the whole bleedin’ rack ENV!) you just tap into the @request object made available to you.

@request.POST

will return a lovely hash of the post paramaters. You can read up on all the methods and properties of this object here: rack.rubyforge.org/doc/classes/Rack/Request.html

Buffer¶ ↑

Okay, this is stuff you shouldn’t touch (really). Spire uses a buffer that can be written to or cleared if need be. The buffer is populated by renders, but returns don’t touch the buffer. You can access the buffer using:

@buffer += "extra stuff for buffer"

Yup, pretty basic but just around for convenience.

Dependencies ¶ ↑

You will need ‘git’, ‘wget’ and ‘ruby’ and ‘rubygems’ to get started.