Capcode 0.8.7 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -1
- data/doc/rdoc/classes/Capcode.html +410 -390
- data/doc/rdoc/classes/Capcode/Helpers.html +146 -126
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README_rdoc.html +26 -2
- data/doc/rdoc/files/lib/capcode/render/haml_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/json_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/markaby_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/sass_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/webdav_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode_rb.html +1 -1
- data/doc/rdoc/fr_file_index.html +5 -0
- data/examples/blog-ar.rb +81 -0
- data/examples/blog-ar.yml +3 -0
- data/examples/blog-sq.rb +82 -0
- data/examples/blog-sq.yml +3 -0
- data/examples/mail/mail_html.rhtml +1 -0
- data/examples/mail/mail_text.rhtml +1 -0
- data/examples/mail/ok.rhtml +1 -0
- data/examples/mail/rubyfr.png +0 -0
- data/examples/mustache/with_class.mustache +8 -0
- data/examples/mustache/without_class.mustache +1 -0
- data/examples/render-binary.rb +46 -0
- data/examples/render-email.rb +68 -0
- data/examples/render-erb.rb +2 -0
- data/examples/render-mustache.rb +30 -0
- data/examples/render-redirect.rb +19 -0
- data/lib/capcode.rb +3 -0
- data/lib/capcode/base/ar.rb +54 -0
- data/lib/capcode/base/couchdb.rb +5 -1
- data/lib/capcode/base/dm.rb +5 -1
- data/lib/capcode/base/sq.rb +58 -0
- data/lib/capcode/core_ext.rb +1 -1
- data/lib/capcode/render/binary.rb +8 -0
- data/lib/capcode/render/email.rb +73 -0
- data/lib/capcode/render/haml.rb +5 -1
- data/lib/capcode/render/json.rb +5 -1
- data/lib/capcode/render/markaby.rb +5 -1
- data/lib/capcode/render/mustache.rb +37 -0
- data/lib/capcode/render/none.rb +7 -0
- data/lib/capcode/render/redirect.rb +7 -0
- data/lib/capcode/render/sass.rb +5 -1
- data/lib/capcode/render/webdav.rb +11 -7
- data/lib/capcode/version.rb +1 -1
- metadata +30 -3
- data/examples/my_blog.db +0 -0
data/doc/rdoc/fr_file_index.html
CHANGED
@@ -27,10 +27,15 @@
|
|
27
27
|
<a href="files/lib/capcode/base/db_rb.html">lib/capcode/base/db.rb</a><br />
|
28
28
|
<a href="files/lib/capcode/configuration_rb.html">lib/capcode/configuration.rb</a><br />
|
29
29
|
<a href="files/lib/capcode/helpers/auth_rb.html">lib/capcode/helpers/auth.rb</a><br />
|
30
|
+
<a href="files/lib/capcode/render/binary_rb.html">lib/capcode/render/binary.rb</a><br />
|
31
|
+
<a href="files/lib/capcode/render/email_rb.html">lib/capcode/render/email.rb</a><br />
|
30
32
|
<a href="files/lib/capcode/render/erb_rb.html">lib/capcode/render/erb.rb</a><br />
|
31
33
|
<a href="files/lib/capcode/render/haml_rb.html">lib/capcode/render/haml.rb</a><br />
|
32
34
|
<a href="files/lib/capcode/render/json_rb.html">lib/capcode/render/json.rb</a><br />
|
33
35
|
<a href="files/lib/capcode/render/markaby_rb.html">lib/capcode/render/markaby.rb</a><br />
|
36
|
+
<a href="files/lib/capcode/render/mustache_rb.html">lib/capcode/render/mustache.rb</a><br />
|
37
|
+
<a href="files/lib/capcode/render/none_rb.html">lib/capcode/render/none.rb</a><br />
|
38
|
+
<a href="files/lib/capcode/render/redirect_rb.html">lib/capcode/render/redirect.rb</a><br />
|
34
39
|
<a href="files/lib/capcode/render/sass_rb.html">lib/capcode/render/sass.rb</a><br />
|
35
40
|
<a href="files/lib/capcode/render/static_rb.html">lib/capcode/render/static.rb</a><br />
|
36
41
|
<a href="files/lib/capcode/render/text_rb.html">lib/capcode/render/text.rb</a><br />
|
data/examples/blog-ar.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'rubygems'
|
3
|
+
require 'capcode'
|
4
|
+
require 'capcode/base/ar'
|
5
|
+
|
6
|
+
class Basic < Capcode::Model 1.0
|
7
|
+
def self.up
|
8
|
+
create_table :stories do |t|
|
9
|
+
t.string :title
|
10
|
+
t.string :body
|
11
|
+
t.string :date
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class UpdateBasic < Capcode::Model 1.1
|
17
|
+
def self.up
|
18
|
+
create_table :users do |t|
|
19
|
+
t.string :name
|
20
|
+
t.string :password
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.down
|
25
|
+
drop_table :users
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Story < Capcode::Base
|
30
|
+
include Capcode::Resource
|
31
|
+
end
|
32
|
+
|
33
|
+
module Capcode
|
34
|
+
class HTTPError
|
35
|
+
def r404(f)
|
36
|
+
"Pas glop !!! #{f} est inconnu !!!"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Index < Route '/'
|
41
|
+
def get
|
42
|
+
r = "<html><body>"
|
43
|
+
|
44
|
+
story = Story.all
|
45
|
+
|
46
|
+
story.each do |s|
|
47
|
+
r += "<h2>#{s.title}</h2><small>#{s.date} - <a href='#{URL( Remove, s.id )}'>Delete this entry</a></small><p>#{s.body}</p>"
|
48
|
+
end
|
49
|
+
|
50
|
+
r+"<hr /><a href='#{URL(Add)}'>Add a new entry</a></body></html>"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Remove < Route '/remove/([^\/]*)'
|
55
|
+
def get( id )
|
56
|
+
Story.delete(id)
|
57
|
+
redirect( Index )
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Add < Route '/add'
|
62
|
+
def get
|
63
|
+
'
|
64
|
+
<html><body>
|
65
|
+
<h1>Add a new entry</h1>
|
66
|
+
<form method="POST">
|
67
|
+
Titre : <input type="text" name="title"><br />
|
68
|
+
<textarea name="body"></textarea><br />
|
69
|
+
<input type="submit">
|
70
|
+
</form>
|
71
|
+
</body></html>
|
72
|
+
'
|
73
|
+
end
|
74
|
+
def post
|
75
|
+
Story.new( :title => params['title'], :body => params['body'], :date => Time.now.to_s ).save
|
76
|
+
redirect( Index )
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-ar.yml" )
|
data/examples/blog-sq.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'rubygems'
|
3
|
+
require 'capcode'
|
4
|
+
require 'capcode/base/sq'
|
5
|
+
|
6
|
+
class Basic < Capcode::Model 1.0
|
7
|
+
def up
|
8
|
+
create_table :stories do
|
9
|
+
primary_key :id
|
10
|
+
String :title
|
11
|
+
String :body
|
12
|
+
String :date
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class UpdateBasic < Capcode::Model 1.1
|
18
|
+
def up
|
19
|
+
create_table :users do
|
20
|
+
String :name
|
21
|
+
String :password
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def down
|
26
|
+
drop_table :users
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Story < Capcode::Base
|
31
|
+
include Capcode::Resource
|
32
|
+
end
|
33
|
+
|
34
|
+
module Capcode
|
35
|
+
class HTTPError
|
36
|
+
def r404(f)
|
37
|
+
"Pas glop !!! #{f} est inconnu !!!"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Index < Route '/'
|
42
|
+
def get
|
43
|
+
r = "<html><body>"
|
44
|
+
|
45
|
+
story = Story.all
|
46
|
+
|
47
|
+
story.each do |s|
|
48
|
+
r += "<h2>#{s[:title]}</h2><small>#{s[:date]} - <a href='#{URL( Remove, s[:id] )}'>Delete this entry</a></small><p>#{s[:body]}</p>"
|
49
|
+
end
|
50
|
+
|
51
|
+
r+"<hr /><a href='#{URL(Add)}'>Add a new entry</a></body></html>"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Remove < Route '/remove/([^\/]*)'
|
56
|
+
def get( id )
|
57
|
+
Story.filter(:id => id).delete
|
58
|
+
redirect( Index )
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Add < Route '/add'
|
63
|
+
def get
|
64
|
+
'
|
65
|
+
<html><body>
|
66
|
+
<h1>Add a new entry</h1>
|
67
|
+
<form method="POST">
|
68
|
+
Titre : <input type="text" name="title"><br />
|
69
|
+
<textarea name="body"></textarea><br />
|
70
|
+
<input type="submit">
|
71
|
+
</form>
|
72
|
+
</body></html>
|
73
|
+
'
|
74
|
+
end
|
75
|
+
def post
|
76
|
+
Story.insert( :title => params['title'], :body => params['body'], :date => Time.now.to_s )
|
77
|
+
redirect( Index )
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-sq.yml" )
|
@@ -0,0 +1 @@
|
|
1
|
+
This mail was send at <b><%= @time %></b>
|
@@ -0,0 +1 @@
|
|
1
|
+
This mail was send at <%= @time %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Mail <b>send !!!</b>
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
Bonjour, il est {{time}}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'capcode'
|
3
|
+
require 'capcode/render/markaby'
|
4
|
+
require 'capcode/render/binary'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'graphviz'
|
7
|
+
|
8
|
+
module Capcode
|
9
|
+
class Index < Route '/'
|
10
|
+
def get
|
11
|
+
render :markaby => :index
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Image < Route '/image'
|
16
|
+
def get
|
17
|
+
render :binary => :image, :content_type => "image/png"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module Capcode::Views
|
23
|
+
def glop
|
24
|
+
html do
|
25
|
+
body do
|
26
|
+
yield
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def index
|
32
|
+
h1 "Hello !"
|
33
|
+
img :src => URL(Capcode::Image)
|
34
|
+
end
|
35
|
+
|
36
|
+
def image
|
37
|
+
GraphViz::new( "G" ) { |g|
|
38
|
+
g.hello << g.world
|
39
|
+
g.bonjour - g.monde
|
40
|
+
g.hola > g.mundo
|
41
|
+
g.holla >> g.welt
|
42
|
+
}.output( :png => String )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Capcode.run( )
|
@@ -0,0 +1,68 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'capcode'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'capcode/render/email'
|
5
|
+
require 'capcode/render/markaby'
|
6
|
+
require 'capcode/render/erb'
|
7
|
+
require 'capcode/render/static'
|
8
|
+
require 'graphviz'
|
9
|
+
|
10
|
+
module Capcode
|
11
|
+
set :smtp, { :server => '127.0.0.1', :port => 25 }
|
12
|
+
set :erb, "mail"
|
13
|
+
set :static, "mail"
|
14
|
+
|
15
|
+
class Index < Route '/'
|
16
|
+
def get
|
17
|
+
render :markaby => :index
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class SendMail < Route '/send'
|
22
|
+
def get
|
23
|
+
@time = Time.now
|
24
|
+
render :email => {
|
25
|
+
:from => 'you@yourdomain.com',
|
26
|
+
:to => 'friend@hisdomain.com',
|
27
|
+
:subject => "Mail renderer example...",
|
28
|
+
|
29
|
+
:body => {
|
30
|
+
:text => { :erb => :mail_text },
|
31
|
+
:html => { :erb => :mail_html, :content_type => 'text/html; charset=UTF-8' }
|
32
|
+
},
|
33
|
+
:file => [
|
34
|
+
{ :data => :image, :filename => "hello.png", :mime_type => "image/png" },
|
35
|
+
"rubyfr.png"
|
36
|
+
],
|
37
|
+
:ok => { :erb => :ok },
|
38
|
+
:error => { :redirect => Index }
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module Capcode::Views
|
45
|
+
def glop
|
46
|
+
html do
|
47
|
+
body do
|
48
|
+
yield
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def index
|
54
|
+
h1 "Send me an email"
|
55
|
+
a "Send mail", :href => URL(Capcode::SendMail)
|
56
|
+
end
|
57
|
+
|
58
|
+
def image
|
59
|
+
GraphViz::new( "G" ) { |g|
|
60
|
+
g.hello << g.world
|
61
|
+
g.bonjour - g.monde
|
62
|
+
g.hola > g.mundo
|
63
|
+
g.holla >> g.welt
|
64
|
+
}.output( :png => String )
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Capcode.run( )
|
data/examples/render-erb.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'capcode'
|
3
|
+
require 'capcode/render/mustache'
|
4
|
+
|
5
|
+
module Capcode
|
6
|
+
set :mustache, "mustache"
|
7
|
+
|
8
|
+
class Index < Route '/'
|
9
|
+
def get
|
10
|
+
@time = Time.now
|
11
|
+
render :mustache => :with_class
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class WithoutClass < Route '/without'
|
16
|
+
def get
|
17
|
+
render :mustache => :without_class, :time => Time.now
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module Capcode::Views
|
23
|
+
class WithClass < Mustache
|
24
|
+
def time
|
25
|
+
@time
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Capcode.run( )
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'capcode'
|
3
|
+
require 'capcode/render/redirect'
|
4
|
+
|
5
|
+
module Capcode
|
6
|
+
class Index < Route '/'
|
7
|
+
def get
|
8
|
+
render :redirect => Hello
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Hello < Route '/hello'
|
13
|
+
def get
|
14
|
+
render :text => "Hello World!"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Capcode.run( )
|
data/lib/capcode.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
begin
|
2
|
+
require 'active_record'
|
3
|
+
rescue LoadError => e
|
4
|
+
raise MissingLibrary, "ActiveRecord could not be loaded (is it installed?): #{e.message}"
|
5
|
+
end
|
6
|
+
|
7
|
+
module Capcode
|
8
|
+
# This module contains the resources needed in a model
|
9
|
+
module Resource
|
10
|
+
end
|
11
|
+
|
12
|
+
# This class allow you to define models
|
13
|
+
Base = ActiveRecord::Base
|
14
|
+
|
15
|
+
# Schema info
|
16
|
+
class SchemaInfo < Base
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
# This class allow you to define models
|
21
|
+
def Model( n )
|
22
|
+
@final = [n, @final.to_f].max
|
23
|
+
m = (@migrations ||= [])
|
24
|
+
Class.new(ActiveRecord::Migration) do
|
25
|
+
meta_def(:version) { n }
|
26
|
+
meta_def(:inherited) { |k| m << k }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def db_connect( dbfile, logfile ) #:nodoc:
|
31
|
+
dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
|
32
|
+
version = dbconfig.delete(:schema_version) { |_| @final }
|
33
|
+
|
34
|
+
ActiveRecord::Base.establish_connection(dbconfig)
|
35
|
+
ActiveRecord::Base.logger = Logger.new(logfile)
|
36
|
+
|
37
|
+
if @migrations
|
38
|
+
unless SchemaInfo.table_exists?
|
39
|
+
ActiveRecord::Schema.define do
|
40
|
+
create_table SchemaInfo.table_name do |t|
|
41
|
+
t.column :version, :float
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
si = SchemaInfo.find(:first) || SchemaInfo.new(:version => 0)
|
46
|
+
@migrations.each do |k|
|
47
|
+
k.migrate(:up) if si.version < k.version and k.version <= version
|
48
|
+
k.migrate(:down) if si.version >= k.version and k.version > version
|
49
|
+
end
|
50
|
+
si.update_attributes(:version => version)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|