serve 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.9.9 (September 19, 2008)
2
+ * Fixed ERB partial support. [jlong]
3
+ * Added support for content_for blocks in ERB. [jlong]
4
+
1
5
  == 0.9.8 (July 18, 2008)
2
6
 
3
7
  * Added experimental support for ERB layouts. [Lawjoskar]
data/Manifest.txt CHANGED
@@ -34,7 +34,11 @@ tasks/undefine.rake
34
34
  tasks/website.rake
35
35
  test_project/_layout.haml
36
36
  test_project/erb/_layout.html.erb
37
+ test_project/erb/_footer.html.erb
37
38
  test_project/erb/index.html.erb
39
+ test_project/haml/_footer.haml
40
+ test_project/haml/_layout.haml
41
+ test_project/haml/index.haml
38
42
  test_project/test.haml
39
43
  test_project/test.html.erb
40
44
  test_project/view_helpers.rb
@@ -33,30 +33,31 @@ module Serve #:nodoc:
33
33
  root = Dir.pwd
34
34
  path = filename[root.size..-1]
35
35
  layout = nil
36
-
37
36
  until layout or path == "/"
38
37
  path = File.dirname(path)
39
-
40
- possible_layouts = ['_layout.haml', '_layout.html.erb'].map do |l|
38
+ possible_layouts = ['_layout.haml', '_layout.html.haml', '_layout.erb', '_layout.html.erb'].map do |l|
41
39
  possible_layout = File.join(root, path, l)
42
40
  File.file?(possible_layout) ? possible_layout : false
43
41
  end
44
-
45
- layout = possible_layouts.detect {|o| o }
46
- end
47
-
42
+ layout = possible_layouts.detect { |o| o }
43
+ end
48
44
  layout
49
45
  end
50
46
 
51
47
  module ERB #:nodoc:
52
48
  class Engine #:nodoc:
53
49
  def initialize(string, options = {})
54
- @erb = ::ERB.new(string, nil, '-')
50
+ @erb = ::ERB.new(string, nil, '-', '@erbout')
55
51
  @erb.filename = options[:filename]
56
52
  end
57
53
 
58
54
  def render(context, &block)
59
- @erb.result(context.instance_eval { binding })
55
+ # we have to keep track of the old erbout variable for nested renders
56
+ # because ERB#result will set it to an empty string before it renders
57
+ old_erbout = context.instance_variable_get('@erbout')
58
+ result = @erb.result(context.instance_eval { binding })
59
+ context.instance_variable_set('@erbout', old_erbout)
60
+ result
60
61
  end
61
62
  end
62
63
  end
@@ -100,10 +101,33 @@ module Serve #:nodoc:
100
101
  @content = ''
101
102
  end
102
103
 
104
+ def _erbout
105
+ @erbout
106
+ end
107
+
108
+ # This is extracted from Rails
109
+ def capture_erb(&block)
110
+ buffer = _erbout
111
+ pos = buffer.length
112
+ block.call
113
+
114
+ # extract the block
115
+ data = buffer[pos..-1]
116
+
117
+ # replace it in the original with empty string
118
+ buffer[pos..-1] = ''
119
+
120
+ data
121
+ end
122
+
103
123
  # Content_for methods
104
124
 
105
125
  def content_for(symbol, &block)
106
- set_content_for(symbol, capture_haml(&block))
126
+ if @haml_buffer
127
+ set_content_for(symbol, capture_haml(&block))
128
+ else
129
+ set_content_for(symbol, capture_erb(&block))
130
+ end
107
131
  end
108
132
 
109
133
  def content_for?(symbol)
@@ -121,9 +145,9 @@ module Serve #:nodoc:
121
145
  def set_content_for(symbol, value)
122
146
  instance_variable_set("@content_for_#{symbol}", value)
123
147
  end
124
-
148
+
125
149
  # Render methods
126
-
150
+
127
151
  def render(options)
128
152
  partial = options.delete(:partial)
129
153
  template = options.delete(:template)
data/lib/serve/version.rb CHANGED
@@ -2,7 +2,7 @@ module Serve #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 9
5
- TINY = 8
5
+ TINY = 9
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,2 @@
1
+ <hr style="clear: both" />
2
+ <p>Copyright &copy; John W. Long. All rights reserved.</p>
@@ -2,9 +2,27 @@
2
2
  <html>
3
3
  <head>
4
4
  <title><%= @title %></title>
5
+ <style type="text/css">
6
+ #content {
7
+ float: left;
8
+ width: 70%;
9
+ }
10
+ #sidebar {
11
+ float: right;
12
+ width: 28%;
13
+ }
14
+ </style>
5
15
  </head>
6
16
  <body>
7
- <h1><%= @title %></h1>
8
- <%= yield %>
17
+ <div id="content">
18
+ <h1><%= @title %></h1>
19
+ <%= yield %>
20
+ </div>
21
+ <% if content_for?(:sidebar) %>
22
+ <div id="sidebar">
23
+ <%= yield :sidebar %>
24
+ </div>
25
+ <% end %>
26
+ <%= render :partial => "footer" %>
9
27
  </body>
10
28
  </html>
@@ -2,4 +2,9 @@
2
2
 
3
3
  <p>Hello World!</p>
4
4
 
5
- <%= custom_method %>
5
+ <%= custom_method %>
6
+
7
+ <% content_for :sidebar do %>
8
+ <h3>Sidebar</h3>
9
+ <p>Just a test</p>
10
+ <% end %>
@@ -0,0 +1,2 @@
1
+ %hr{:style=>"clear: both"}/
2
+ %p Copyright &copy; John W. Long. All rights reserved.
@@ -0,0 +1,20 @@
1
+ !!! Strict
2
+ %html
3
+ %head
4
+ %title= @title
5
+ %style{:type=>"text/css"}
6
+ :sass
7
+ #content
8
+ float: left
9
+ width: 70%
10
+ #sidebar
11
+ float: right
12
+ width: 28%
13
+ %body
14
+ #content
15
+ %h1= @title
16
+ = yield
17
+ - if content_for?(:sidebar)
18
+ #sidebar
19
+ = yield :sidebar
20
+ = render :partial => "footer"
@@ -0,0 +1,9 @@
1
+ - @title = "HAML Template"
2
+
3
+ %p Hello World!
4
+
5
+ = custom_method
6
+
7
+ - content_for :sidebar do
8
+ %h3 Sidebar
9
+ %p Just a test
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serve
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - John W. Long
@@ -30,7 +30,7 @@ cert_chain:
30
30
  qXI=
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2008-07-18 00:00:00 -04:00
33
+ date: 2008-09-19 00:00:00 -04:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
@@ -91,7 +91,11 @@ files:
91
91
  - tasks/website.rake
92
92
  - test_project/_layout.haml
93
93
  - test_project/erb/_layout.html.erb
94
+ - test_project/erb/_footer.html.erb
94
95
  - test_project/erb/index.html.erb
96
+ - test_project/haml/_footer.haml
97
+ - test_project/haml/_layout.haml
98
+ - test_project/haml/index.haml
95
99
  - test_project/test.haml
96
100
  - test_project/test.html.erb
97
101
  - test_project/view_helpers.rb
metadata.gz.sig CHANGED
Binary file