template_streaming 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -6,11 +6,7 @@ Rails plugin which enables progressive rendering for templates.
6
6
 
7
7
  A typical Rails client-side profile looks something like this:
8
8
 
9
- <img
10
- alt="Typical Rails Profile"
11
- src="http://github.com/oggy/template_streaming/raw/master/doc/slow-profile.png"
12
- style="width: 100%"
13
- />
9
+ ![Typical Rails Profile][slow-profile]
14
10
 
15
11
  In almost all cases, this is highly suboptimal, as many resources, such as
16
12
  external stylesheets, are static and could be loaded by the client while it's
@@ -35,17 +31,16 @@ and its content. By using the provided `flush` helper prior to yielding in the
35
31
  prelayout, one can now output content early in the rendering process, giving
36
32
  profiles that look more like:
37
33
 
38
- <img
39
- alt="Progressive Rendering Profile"
40
- src="http://github.com/oggy/template_streaming/raw/master/doc/fast-profile.png"
41
- style="width: 100%"
42
- />
34
+ ![Progressive Rendering Profile][fast-profile]
43
35
 
44
36
  Also provided is a `#push(data)` method which can be used to send extra tags to
45
37
  the client as their need becomes apparent. For instance, you may wish to `push`
46
38
  out a stylesheet link tag only if a particular partial is reached which contains
47
39
  a complex widget.
48
40
 
41
+ [slow-profile]: http://github.com/oggy/template_streaming/raw/master/doc/slow-profile.png
42
+ [fast-profile]: http://github.com/oggy/template_streaming/raw/master/doc/fast-profile.png
43
+
49
44
  ## Example
50
45
 
51
46
  Conventional wisdom says to put your external stylesheets in the HEAD of your
data/doc/fast-profile.png CHANGED
Binary file
data/doc/slow-profile.png CHANGED
Binary file
@@ -1,3 +1,3 @@
1
1
  module TemplateStreaming
2
- VERSION = [0, 0, 1]
2
+ VERSION = [0, 0, 2]
3
3
  end
@@ -12,6 +12,7 @@ module TemplateStreaming
12
12
  begin
13
13
  if @render_stack_height == 1
14
14
  @performed_render = true
15
+ check_thin_support
15
16
  @streaming_body = StreamingBody.new(progressive_rendering_threshold) do
16
17
  @performed_render = false
17
18
  last_piece = render_without_template_streaming(*args, &block)
@@ -44,6 +45,7 @@ module TemplateStreaming
44
45
  #
45
46
  def push(data)
46
47
  @streaming_body.push(data)
48
+ flush_thin
47
49
  end
48
50
 
49
51
  private # --------------------------------------------------------
@@ -68,6 +70,26 @@ module TemplateStreaming
68
70
  0
69
71
  end
70
72
  end
73
+
74
+ def check_thin_support
75
+ return if defined?(@thin_support_found)
76
+ if (@thin_callback = request.env['async.callback'])
77
+ begin
78
+ require 'event_machine_flush'
79
+ @thin_support_found = true
80
+ rescue LoadError
81
+ raise "Template Streaming on Thin requires the event_machine_flush gem."
82
+ end
83
+ end
84
+ end
85
+
86
+ #
87
+ # Force EventMachine to flush its buffer when using Thin.
88
+ #
89
+ def flush_thin
90
+ @thin_callback and
91
+ EventMachineFlush.flush(@thin_callback.receiver)
92
+ end
71
93
  end
72
94
 
73
95
  # Only prepare once.
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - George Ogata
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-13 00:00:00 -04:00
17
+ date: 2010-04-22 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -30,9 +30,8 @@ dependencies:
30
30
  type: :development
31
31
  version_requirements: *id001
32
32
  description: |
33
- Adds a #flush helper to Rails which lets you flush the output
34
- buffer to the client early, allowing the client to begin fetching
35
- external resources while the server is rendering the page.
33
+ Adds a #flush helper to Rails which flushes the output buffer to
34
+ the client early.
36
35
 
37
36
  email:
38
37
  - george.ogata@gmail.com