Capcode 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,11 @@ module Capcode
7
7
  @@__ERB_PATH__ = p
8
8
  end
9
9
 
10
- def render_erb( f ) #:nodoc:
10
+ def get_binding
11
+ binding
12
+ end
13
+
14
+ def render_erb( f, opts ) #:nodoc:
11
15
  f = f.to_s
12
16
  if f.include? '..'
13
17
  return [403, {}, '403 - Invalid path']
@@ -22,10 +26,21 @@ module Capcode
22
26
  @@__ERB_PATH__ = File.expand_path( File.join(@@__ROOT_DIRECTORY, @@__ERB_PATH__) )
23
27
  end
24
28
  end
25
-
29
+
30
+ layout = opts.delete(:layout)||:layout
31
+ layout_file = File.join( @@__ERB_PATH__, layout.to_s+".rhtml" )
32
+
26
33
  f = f + ".rhtml" if File.extname( f ) != ".rhtml"
27
34
  file = File.join( @@__ERB_PATH__, f )
28
- ERB.new(open(file).read).result(binding)
35
+
36
+ if( File.exist?( layout_file ) )
37
+ ERB.new(open(layout_file).read).result( get_binding { |*args|
38
+ @@__ARGS__ = args
39
+ ERB.new(open(file).read).result(binding)
40
+ } )
41
+ else
42
+ ERB.new(open(file).read).result(binding)
43
+ end
29
44
  end
30
45
  end
31
46
  end
@@ -7,7 +7,7 @@ module Capcode
7
7
  @@__HAML_PATH__ = p
8
8
  end
9
9
 
10
- def render_haml( f ) #:nodoc:
10
+ def render_haml( f, opts ) #:nodoc:
11
11
  f = f.to_s
12
12
  if f.include? '..'
13
13
  return [403, {}, '403 - Invalid path']
@@ -23,9 +23,20 @@ module Capcode
23
23
  end
24
24
  end
25
25
 
26
+ layout = opts.delete(:layout)||:layout
27
+ layout_file = File.join( @@__HAML_PATH__, layout.to_s+".haml" )
28
+
26
29
  f = f + ".haml" if File.extname( f ) != ".haml"
27
30
  file = File.join( @@__HAML_PATH__, f )
28
- Haml::Engine.new( open( file ).read ).to_html( self )
31
+
32
+ if( File.exist?( layout_file ) )
33
+ Haml::Engine.new( open( layout_file ).read ).to_html(self) { |*args|
34
+ @@__ARGS__ = args
35
+ Haml::Engine.new( open( file ).read ).render(self)
36
+ }
37
+ else
38
+ Haml::Engine.new( open( file ).read ).to_html( self )
39
+ end
29
40
  end
30
41
  end
31
42
  end
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  module Capcode
4
4
  module Helpers
5
- def render_json( f )
5
+ def render_json( f, opts )
6
6
  @response['Content-Type'] = 'application/json'
7
7
  f.to_json
8
8
  end
@@ -1,16 +1,23 @@
1
1
  require "markaby"
2
2
 
3
+ Markaby::Builder.set(:indent, 2)
4
+
3
5
  module Capcode
4
6
  class Markaby::Builder
5
7
  include Views
6
8
  end
7
9
 
8
10
  module Helpers
9
- def render_markaby( f ) #:nodoc:
11
+ def render_markaby( f, opts ) #:nodoc:
10
12
  f = f.to_s
13
+ layout = opts.delete(:layout)||:layout
14
+
11
15
  mab = Markaby::Builder.new({}, self) {
12
- if self.respond_to?(:layout)
13
- layout { self.send(f) }
16
+ if self.respond_to?(layout)
17
+ self.send(layout.to_s) { |*args|
18
+ @@__ARGS__ = args
19
+ self.send(f)
20
+ }
14
21
  else
15
22
  self.send(f)
16
23
  end
@@ -0,0 +1,7 @@
1
+ module Capcode
2
+ module Helpers
3
+ def render_text( f )
4
+ f
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Capcode
2
- CAPCOD_VERION="0.6.1"
2
+ CAPCOD_VERION="0.6.2"
3
3
  end
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.6.1
4
+ version: 0.6.2
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-06-15 00:00:00 +02:00
12
+ date: 2009-06-29 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -69,13 +69,20 @@ files:
69
69
  - lib/capcode/render/haml.rb
70
70
  - lib/capcode/render/json.rb
71
71
  - lib/capcode/render/markaby.rb
72
+ - lib/capcode/render/text.rb
72
73
  - lib/capcode/version.rb
73
74
  - lib/capcode.rb
74
75
  - examples/blog-couchdb.rb
75
76
  - examples/blog-couchdb.yml
76
77
  - examples/blog-dm.rb
77
78
  - examples/blog-dm.yml
79
+ - examples/erb/cf.rhtml
80
+ - examples/erb/cf_layout.rhtml
81
+ - examples/erb/layout.rhtml
78
82
  - examples/erb/m_hello.rhtml
83
+ - examples/haml/cf.haml
84
+ - examples/haml/cf_layout.haml
85
+ - examples/haml/layout.haml
79
86
  - examples/haml/m_hello.haml
80
87
  - examples/index.html
81
88
  - examples/my_blog.db