Capcode is a project mainly written in RUBY and JAVASCRIPT, based on the GPL-2.0 license.
Capcode is a tiny MVC framework
= Capcode
Copyright (C) 2009, 2010 Gregoire Lejeune
== DESCRIPTION:
Capcode is a web microframework
== FEATURES/PROBLEMS:
=== 1.0.1
=== 1.0.0
=== 0.9.9
=== 0.9.8
=== 0.9.7
=== 0.9.6
=== 0.9.5
=== 0.9.4
=== 0.9.3
=== 0.9.2
=== 0.9.1
=== 0.9.0
=== 0.8.9
=== 0.8.8
=== 0.8.7
set :erb, ...',
set :sass, ...' and `set :haml, ...' (see render-erb.rb and render-haml_sass.rb)=== 0.8.6
=== 0.8.5
=== 0.8.4
=== 0.8.3
=== 0.8.2
=== 0.8.1
=== 0.8.0
=== 0.7.1
=== 0.7.0
=== 0.6.2
=== 0.6.1
=== 0.6.0
=== 0.5.0
=== 0.4.0
=== 0.3.0
=== 0.2.0
=== 0.1.0
== SYNOPSIS:
require 'rubygems' require 'capcode'
module Capcode class Hello < Route '/hello' def get "Hello World #{Time.now} !" end end end
Capcode.run( )
=== Running Capcode Apps
=== Create model
require 'rubygems' require 'capcode' require 'capcode/base/dm' # or require 'capcode/base/couchdb'
class Story < Capcode::Base include Capcode::Resource
property :id, Integer, :serial => true # only with DataMapper !
property :title, String
property :body, String
property :date, String
end
See examples/blog-dm.rb and/or examples/blog-couchdb.rb for complete examples.
=== Create View
require 'rubygems' require 'capcode'
module Capcode class Hello < Route '/hello' def get @t = Time.now render :time end end end
module Capcode::Views def time "Hello world #{@t}" end end
Capcode.run( )
=== Create Helper
require 'rubygems' require 'capcode'
module Capcode class Hello < Route '/hello' def get @t = Time.now render :time end end end
module Capcode::Helpers def bold( &b ) ""+yield+"" end end
module Capcode::Views def time "Hello world " + bold { @t } end end
Capcode.run( )
=== Render with Markaby
require 'rubygems' require 'capcode'
module Capcode class Hello < Route '/hello' def get @t = Time.now
# This implies that capcode-render-markaby is installed !
render :markaby => :time
end
end
end
module Capcode::Views def time
html do
body do
p {
text "Hello World "
b @t
}
end
end
end
end
Capcode.run( )
=== Render with Haml
require 'rubygems' require 'capcode'
module Capcode set :haml, "./my_haml_views"
class Hello < Route '/hello'
def get
@t = Time.now
# This implies that capcode-render-haml is installed !
render :haml => :time
end
end
end
Capcode.run( )
%html %body %p Hello World = @t
=== Render with JSON
require 'rubygems' require 'capcode'
module Capcode class Hello < Route '/hello' def get @t = Time.now
# This implies that capcode-render-json is installed !
render :json => { :time => @t }
end
end
end
Capcode.run( )
=== Render with WebDAV
require 'rubygems' require 'capcode'
module Capcode
# !!! Render file from /Users/greg/temp !!!
class WebDav < Route '/temp'
def get
# This implies that capcode-render-webdav is installed !
render :webdav => "/Users/greg/temp"
end
def method_missing(id, *a, &b)
get
end
end
class Index < Route '/'
def get
render "WebDav server acces : <a href='#{URL(Capcode::WebDav)}'>#{URL(Capcode::WebDav)}</a>"
end
end
end
Capcode.run( )
=== HTTP Authentication
require 'rubygems' require 'capcode'
module Capcode class Public < Route '/public' def get render "This page is not protected" end end
class Private < Route '/private'
def get
http_authentication( :type => :digest, :realm => "Private part" ) {
{ "greg" => "p4ssw0rd" }
}
render "This page is private - Hello #{request.env['REMOTE_USER']}"
end
end
end
Capcode.run( )
Second example :
require 'rubygems' require 'capcode'
module Capcode
http_authentication( :type => :digest, :realm => "Private part", :routes => ['/admin', '/private'] ) {
{ "greg" => "p4ssw0rd" }
}
class Public < Route '/public'
def get
render "This page is not protected"
end
end
class Private < Route '/private'
def get
render "This page is private - Hello #{request.env['REMOTE_USER']}"
end
end
class PrivateAgain < Route '/private/again'
def get
render "This page is also private - Hello #{request.env['REMOTE_USER']}"
end
end
class Admin < Route '/admin'
def get
render "This page is private - Hello #{request.env['REMOTE_USER']}"
end
end
end
Capcode.run( )
== DEPLOYMENT
=== With Passenger
First create the directory structure :
my_app/ my_app/tmp my_app/public
Then put your app in my_app/ and comment or remove the line with Capcode.run
Create a rack configuration file (config.ru) in my_app/
require 'app' run Capcode.application()
Capcode.application take the same parameters as Capcode.run (and block too). Be carefull, if you use static files (with the static renderer) you must set the :root option (:root => File.expand_path(File.dirname(FILE)) is probably good)
You can now deploy your application like a {"Rack-based Ruby application"}[http://www.modrails.com/documentation/Users%20guide.html#_deploying_a_rack_based_ruby_application]
== REQUIREMENTS:
== INSTALL:
sudo gem install capcode
== LICENSE:
Capcode is freely distributable according to the terms of the GNU General Public License.
This program is distributed without any warranty. See the file 'COPYING' for details.