Capcode 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +128 -48
- data/doc/rdoc/classes/Capcode.html +216 -215
- data/doc/rdoc/classes/Capcode/HTTPError.html +1 -0
- data/doc/rdoc/classes/Capcode/Helpers.html +41 -29
- data/doc/rdoc/classes/Capcode/Views.html +1 -0
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/AUTHORS.html +1 -0
- data/doc/rdoc/files/COPYING.html +1 -0
- data/doc/rdoc/files/README.html +133 -47
- data/doc/rdoc/files/lib/capcode_rb.html +2 -1
- data/examples/erb/m_hello.rhtml +5 -0
- data/examples/haml/m_hello.haml +7 -0
- data/examples/sample.rb +18 -4
- data/lib/capcode.rb +17 -2
- data/lib/capcode/render/erb.rb +21 -0
- data/lib/capcode/render/haml.rb +21 -0
- data/lib/capcode/render/json.rb +10 -0
- data/lib/capcode/render/markaby.rb +15 -0
- data/lib/capcode/version.rb +1 -1
- metadata +9 -3
data/lib/capcode.rb
CHANGED
@@ -14,15 +14,29 @@ module Capcode
|
|
14
14
|
class RouteError < ArgumentError #:nodoc:
|
15
15
|
end
|
16
16
|
|
17
|
+
class RenderError < ArgumentError
|
18
|
+
end
|
19
|
+
|
17
20
|
module Views; end
|
18
21
|
|
19
22
|
# Helpers contains methods available in your controllers
|
20
23
|
module Helpers
|
21
24
|
# Render a view
|
22
|
-
def render(
|
23
|
-
|
25
|
+
def render( h )
|
26
|
+
if h.class == Hash
|
27
|
+
t = (h.keys)[0]
|
28
|
+
v = h[t]
|
29
|
+
begin
|
30
|
+
self.send( "render_#{t.to_s}", v )
|
31
|
+
rescue => e
|
32
|
+
raise Capcode::RenderError, "Error rendering `#{t.to_s}' : #{e.message}", caller
|
33
|
+
end
|
34
|
+
else
|
35
|
+
return self.send(h.to_s)
|
36
|
+
end
|
24
37
|
end
|
25
38
|
|
39
|
+
|
26
40
|
# Help you to return a JSON response
|
27
41
|
#
|
28
42
|
# module Capcode
|
@@ -33,6 +47,7 @@ module Capcode
|
|
33
47
|
# end
|
34
48
|
# end
|
35
49
|
def json( d )
|
50
|
+
warn( "json is deprecated, please use `render( :json => ... )'" )
|
36
51
|
@response['Content-Type'] = 'application/json'
|
37
52
|
d.to_json
|
38
53
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Capcode
|
4
|
+
module Helpers
|
5
|
+
@@__ERB_PATH__ = File.expand_path( "." )
|
6
|
+
def self.erb_path=( p )
|
7
|
+
@@__ERB_PATH__ = File.expand_path( p )
|
8
|
+
end
|
9
|
+
|
10
|
+
def render_erb( f )
|
11
|
+
f = f.to_s
|
12
|
+
if f.include? '..'
|
13
|
+
return [403, {}, '403 - Invalid path']
|
14
|
+
end
|
15
|
+
|
16
|
+
f = f + ".rhtml" if File.extname( f ) != ".rhtml"
|
17
|
+
file = File.join( @@__ERB_PATH__, f )
|
18
|
+
ERB.new(open(file).read).result(binding)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "haml"
|
2
|
+
|
3
|
+
module Capcode
|
4
|
+
module Helpers
|
5
|
+
@@__HAML_PATH__ = File.expand_path( "." )
|
6
|
+
def self.haml_path=( p )
|
7
|
+
@@__HAML_PATH__ = File.expand_path( p )
|
8
|
+
end
|
9
|
+
|
10
|
+
def render_haml( f ) #:nodoc:
|
11
|
+
f = f.to_s
|
12
|
+
if f.include? '..'
|
13
|
+
return [403, {}, '403 - Invalid path']
|
14
|
+
end
|
15
|
+
|
16
|
+
f = f + ".haml" if File.extname( f ) != ".haml"
|
17
|
+
file = File.join( @@__HAML_PATH__, f )
|
18
|
+
Haml::Engine.new( open( file ).read ).to_html( self )
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/capcode/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Capcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Gr\xC3\xA9goire Lejeune"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-07 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -54,12 +54,18 @@ files:
|
|
54
54
|
- lib/capcode/base/couchdb.rb
|
55
55
|
- lib/capcode/base/dm.rb
|
56
56
|
- lib/capcode/core_ext.rb
|
57
|
+
- lib/capcode/render/erb.rb
|
58
|
+
- lib/capcode/render/haml.rb
|
59
|
+
- lib/capcode/render/json.rb
|
60
|
+
- lib/capcode/render/markaby.rb
|
57
61
|
- lib/capcode/version.rb
|
58
62
|
- lib/capcode.rb
|
59
63
|
- examples/blog-couchdb.rb
|
60
64
|
- examples/blog-couchdb.yml
|
61
65
|
- examples/blog-dm.rb
|
62
66
|
- examples/blog-dm.yml
|
67
|
+
- examples/erb/m_hello.rhtml
|
68
|
+
- examples/haml/m_hello.haml
|
63
69
|
- examples/index.html
|
64
70
|
- examples/my_blog.db
|
65
71
|
- examples/sample.rb
|
@@ -100,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
106
|
requirements: []
|
101
107
|
|
102
108
|
rubyforge_project: capcode
|
103
|
-
rubygems_version: 1.3.
|
109
|
+
rubygems_version: 1.3.3
|
104
110
|
signing_key:
|
105
111
|
specification_version: 3
|
106
112
|
summary: Capcode is a web microframework
|