sinatra-cache 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -11
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/lib/sinatra/cache.rb +3 -2
- data/lib/sinatra/cache/helpers.rb +5 -1
- data/sinatra-cache.gemspec +5 -3
- data/spec/sinatra/cache_spec.rb +2 -1
- metadata +21 -8
- data/lib/sinatra/output.rb +0 -147
data/README.rdoc
CHANGED
@@ -17,11 +17,11 @@ With that said, on to the real stuff.
|
|
17
17
|
|
18
18
|
|
19
19
|
== Installation
|
20
|
-
|
20
|
+
|
21
21
|
# Add RubyGems.org (former Gemcutter) to your RubyGems sources
|
22
22
|
$ gem sources -a http://rubygems.org
|
23
23
|
|
24
|
-
$ (sudo)? gem install sinatra-cache
|
24
|
+
$ (sudo)? gem install sinatra-cache
|
25
25
|
|
26
26
|
== Dependencies
|
27
27
|
|
@@ -30,14 +30,18 @@ This Gem depends upon the following:
|
|
30
30
|
=== Runtime:
|
31
31
|
|
32
32
|
* sinatra ( >= 1.0.a )
|
33
|
+
* sinatra-outputbuffer[http://github.com/kematzy/sinatra-outputbuffer] (>= 0.1.0)
|
34
|
+
|
35
|
+
Optionals:
|
33
36
|
|
37
|
+
* sinatra-settings[http://github.com/kematzy/sinatra-settings] (>= 0.1.1) # to view default settings in a browser display.
|
34
38
|
|
35
39
|
=== Development & Tests:
|
36
40
|
|
41
|
+
* sinatra-tests (>= 0.1.6)
|
37
42
|
* rspec (>= 1.3.0 )
|
38
43
|
* rack-test (>= 0.5.3)
|
39
44
|
* rspec_hpricot_matchers (>= 0.1.0)
|
40
|
-
* sinatra-tests (>= 0.1.6)
|
41
45
|
* fileutils
|
42
46
|
* sass
|
43
47
|
* ostruct
|
@@ -376,14 +380,6 @@ See LICENSE for details.
|
|
376
380
|
|
377
381
|
=== Credits
|
378
382
|
|
379
|
-
Included in this gem is code from <tt>SinatraMore::OutputHelpers</tt>, taken from the
|
380
|
-
<tt>sinatra_more</tt> gem [ http://github.com/nesquena/sinatra_more/ ] by Nathan Esquenazi.
|
381
|
-
|
382
|
-
The code was renamed to Sinatra::Output to prevent any extension clashes.
|
383
|
-
|
384
|
-
Copyright (c) 2009 Nathan Esquenazi. Released under the MIT License.
|
385
|
-
|
386
|
-
|
387
383
|
A big <b>Thank You!</b> goes to rtomayko[http://github/rtomayko], blakemizerany[http://github.com/blakemizerany/]
|
388
384
|
and others working on the Sinatra framework.
|
389
385
|
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/kematzy/sinatra-cache"
|
12
12
|
gem.authors = ["kematzy"]
|
13
13
|
gem.add_dependency('sinatra', '>=1.0.a')
|
14
|
-
|
14
|
+
gem.add_dependency('sinatra-outputbuffer', '>=0.1.0')
|
15
15
|
gem.add_development_dependency "sinatra-tests", ">= 0.1.6"
|
16
16
|
gem.add_development_dependency "rspec", ">= 1.3.0"
|
17
17
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
@@ -36,10 +36,10 @@ end
|
|
36
36
|
|
37
37
|
namespace :spec do
|
38
38
|
|
39
|
-
desc "Run all specifications
|
40
|
-
Spec::Rake::SpecTask.new(:
|
39
|
+
desc "Run all specifications quietly"
|
40
|
+
Spec::Rake::SpecTask.new(:quiet) do |t|
|
41
41
|
t.libs << "lib"
|
42
|
-
t.spec_opts = ["--color", "--
|
42
|
+
t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
|
43
43
|
end
|
44
44
|
|
45
45
|
desc "Run specific spec verbosely (SPEC=/path/2/file)"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/sinatra/cache.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
|
2
2
|
require 'sinatra/base'
|
3
|
+
require 'sinatra/outputbuffer'
|
3
4
|
|
4
5
|
module Sinatra
|
5
6
|
module Cache
|
6
|
-
VERSION = '0.3.
|
7
|
+
VERSION = '0.3.1' unless const_defined?(:VERSION)
|
7
8
|
def self.version; "Sinatra::Cache v#{VERSION}"; end
|
8
9
|
end #/ Cache
|
9
10
|
end #/ Sinatra
|
10
11
|
|
11
|
-
%w(templates
|
12
|
+
%w(templates cache/helpers).each do |lib|
|
12
13
|
require "sinatra/#{lib}"
|
13
14
|
end
|
@@ -19,7 +19,11 @@ module Sinatra
|
|
19
19
|
# === Runtime:
|
20
20
|
#
|
21
21
|
# * sinatra ( >= 1.0.a )
|
22
|
+
# * sinatra-outputbuffer[http://github.com/kematzy/sinatra-outputbuffer] (>= 0.1.0)
|
22
23
|
#
|
24
|
+
# Optionals:
|
25
|
+
#
|
26
|
+
# * sinatra-settings[http://github.com/kematzy/sinatra-settings] (>= 0.1.1) # to view default settings in a browser display.
|
23
27
|
#
|
24
28
|
# === Development & Tests:
|
25
29
|
#
|
@@ -629,7 +633,7 @@ module Sinatra
|
|
629
633
|
#
|
630
634
|
#
|
631
635
|
def self.registered(app)
|
632
|
-
app.
|
636
|
+
app.register(Sinatra::OutputBuffer)
|
633
637
|
app.helpers Cache::Helpers
|
634
638
|
|
635
639
|
## CONFIGURATIONS::
|
data/sinatra-cache.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra-cache}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["kematzy"]
|
12
|
-
s.date = %q{2010-02
|
12
|
+
s.date = %q{2010-03-02}
|
13
13
|
s.description = %q{A Sinatra Extension that makes Page and Fragment Caching easy.}
|
14
14
|
s.email = %q{kematzy@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,7 +24,6 @@ Gem::Specification.new do |s|
|
|
24
24
|
"VERSION",
|
25
25
|
"lib/sinatra/cache.rb",
|
26
26
|
"lib/sinatra/cache/helpers.rb",
|
27
|
-
"lib/sinatra/output.rb",
|
28
27
|
"lib/sinatra/templates.rb",
|
29
28
|
"sinatra-cache.gemspec",
|
30
29
|
"spec/fixtures/apps/base/views/css.sass",
|
@@ -52,15 +51,18 @@ Gem::Specification.new do |s|
|
|
52
51
|
|
53
52
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
54
53
|
s.add_runtime_dependency(%q<sinatra>, [">= 1.0.a"])
|
54
|
+
s.add_runtime_dependency(%q<sinatra-outputbuffer>, [">= 0.1.0"])
|
55
55
|
s.add_development_dependency(%q<sinatra-tests>, [">= 0.1.6"])
|
56
56
|
s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
|
57
57
|
else
|
58
58
|
s.add_dependency(%q<sinatra>, [">= 1.0.a"])
|
59
|
+
s.add_dependency(%q<sinatra-outputbuffer>, [">= 0.1.0"])
|
59
60
|
s.add_dependency(%q<sinatra-tests>, [">= 0.1.6"])
|
60
61
|
s.add_dependency(%q<rspec>, [">= 1.3.0"])
|
61
62
|
end
|
62
63
|
else
|
63
64
|
s.add_dependency(%q<sinatra>, [">= 1.0.a"])
|
65
|
+
s.add_dependency(%q<sinatra-outputbuffer>, [">= 0.1.0"])
|
64
66
|
s.add_dependency(%q<sinatra-tests>, [">= 0.1.6"])
|
65
67
|
s.add_dependency(%q<rspec>, [">= 1.3.0"])
|
66
68
|
end
|
data/spec/sinatra/cache_spec.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- kematzy
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-02
|
17
|
+
date: 2010-03-02 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -32,9 +32,23 @@ dependencies:
|
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
|
-
name: sinatra-
|
35
|
+
name: sinatra-outputbuffer
|
36
36
|
prerelease: false
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
version: 0.1.0
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: sinatra-tests
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
38
52
|
requirements:
|
39
53
|
- - ">="
|
40
54
|
- !ruby/object:Gem::Version
|
@@ -44,11 +58,11 @@ dependencies:
|
|
44
58
|
- 6
|
45
59
|
version: 0.1.6
|
46
60
|
type: :development
|
47
|
-
version_requirements: *
|
61
|
+
version_requirements: *id003
|
48
62
|
- !ruby/object:Gem::Dependency
|
49
63
|
name: rspec
|
50
64
|
prerelease: false
|
51
|
-
requirement: &
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
66
|
requirements:
|
53
67
|
- - ">="
|
54
68
|
- !ruby/object:Gem::Version
|
@@ -58,7 +72,7 @@ dependencies:
|
|
58
72
|
- 0
|
59
73
|
version: 1.3.0
|
60
74
|
type: :development
|
61
|
-
version_requirements: *
|
75
|
+
version_requirements: *id004
|
62
76
|
description: A Sinatra Extension that makes Page and Fragment Caching easy.
|
63
77
|
email: kematzy@gmail.com
|
64
78
|
executables: []
|
@@ -76,7 +90,6 @@ files:
|
|
76
90
|
- VERSION
|
77
91
|
- lib/sinatra/cache.rb
|
78
92
|
- lib/sinatra/cache/helpers.rb
|
79
|
-
- lib/sinatra/output.rb
|
80
93
|
- lib/sinatra/templates.rb
|
81
94
|
- sinatra-cache.gemspec
|
82
95
|
- spec/fixtures/apps/base/views/css.sass
|
data/lib/sinatra/output.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
|
2
|
-
# :stopdoc:
|
3
|
-
unless Object.new.respond_to?(:blank?)
|
4
|
-
|
5
|
-
class Object
|
6
|
-
def blank?
|
7
|
-
respond_to?(:empty?) ? empty? : !self
|
8
|
-
end
|
9
|
-
def present?
|
10
|
-
!blank?
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
# :startdoc:
|
15
|
-
|
16
|
-
|
17
|
-
module Sinatra
|
18
|
-
|
19
|
-
# Sinatra::Output Extension
|
20
|
-
#
|
21
|
-
# Provides support for the :cache_fragment() functionality.
|
22
|
-
#
|
23
|
-
# Thank You very much Nathan. Much appreciated!
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# The code within this extension is almost in its interity copied from:
|
27
|
-
#
|
28
|
-
# sinatra_more gem [ http://github.com/nesquena/sinatra_more/ ] by Nathan Esquenazi.
|
29
|
-
#
|
30
|
-
#
|
31
|
-
# Copyright (c) 2009 Nathan Esquenazi
|
32
|
-
#
|
33
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
34
|
-
# a copy of this software and associated documentation files (the
|
35
|
-
# "Software"), to deal in the Software without restriction, including
|
36
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
37
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
38
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
39
|
-
# the following conditions:
|
40
|
-
#
|
41
|
-
# The above copyright notice and this permission notice shall be
|
42
|
-
# included in all copies or substantial portions of the Software.
|
43
|
-
#
|
44
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
45
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
46
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
47
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
48
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
49
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
50
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
51
|
-
#
|
52
|
-
#
|
53
|
-
module Output
|
54
|
-
|
55
|
-
VERSION = Sinatra::Cache::VERSION
|
56
|
-
##
|
57
|
-
# Returns the version string for this extension
|
58
|
-
#
|
59
|
-
# ==== Examples
|
60
|
-
#
|
61
|
-
# Sinatra::Output.version => 'Sinatra::Output v0.9.9'
|
62
|
-
#
|
63
|
-
def self.version; "Sinatra::Output v#{VERSION}"; end
|
64
|
-
|
65
|
-
|
66
|
-
module Helpers
|
67
|
-
|
68
|
-
# Captures the html from a block of template code for erb or haml
|
69
|
-
# capture_html(&block) => "...html..."
|
70
|
-
def capture_html(*args, &block)
|
71
|
-
if self.respond_to?(:is_haml?) && is_haml?
|
72
|
-
block_is_haml?(block) ? capture_haml(*args, &block) : block.call
|
73
|
-
elsif has_erb_buffer?
|
74
|
-
result_text = capture_erb(*args, &block)
|
75
|
-
result_text.present? ? result_text : (block_given? && block.call(*args))
|
76
|
-
else # theres no template to capture, invoke the block directly
|
77
|
-
block.call(*args)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# Outputs the given text to the templates buffer directly
|
82
|
-
# concat_content("This will be output to the template buffer in erb or haml")
|
83
|
-
def concat_content(text="")
|
84
|
-
if self.respond_to?(:is_haml?) && is_haml?
|
85
|
-
haml_concat(text)
|
86
|
-
elsif has_erb_buffer?
|
87
|
-
erb_concat(text)
|
88
|
-
else # theres no template to concat, return the text directly
|
89
|
-
text
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# Returns true if the block is from an ERB or HAML template; false otherwise.
|
94
|
-
# Used to determine if html should be returned or concatted to view
|
95
|
-
# block_is_template?(block)
|
96
|
-
def block_is_template?(block)
|
97
|
-
block && (block_is_erb?(block) || (self.respond_to?(:block_is_haml?) && block_is_haml?(block)))
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
protected
|
102
|
-
|
103
|
-
# Used to capture the html from a block of erb code
|
104
|
-
# capture_erb(&block) => '...html...'
|
105
|
-
def capture_erb(*args, &block)
|
106
|
-
erb_with_output_buffer { block_given? && block.call(*args) }
|
107
|
-
end
|
108
|
-
|
109
|
-
# Concats directly to an erb template
|
110
|
-
# erb_concat("Direct to buffer")
|
111
|
-
def erb_concat(text)
|
112
|
-
@_out_buf << text if has_erb_buffer?
|
113
|
-
end
|
114
|
-
|
115
|
-
# Returns true if an erb buffer is detected
|
116
|
-
# has_erb_buffer? => true
|
117
|
-
def has_erb_buffer?
|
118
|
-
!@_out_buf.nil?
|
119
|
-
end
|
120
|
-
|
121
|
-
# Used to determine if a block is called from ERB.
|
122
|
-
# NOTE: This doesn't actually work yet because the variable __in_erb_template
|
123
|
-
# hasn't been defined in ERB. We need to find a way to fix this.
|
124
|
-
def block_is_erb?(block)
|
125
|
-
has_erb_buffer? || block && eval('defined? __in_erb_template', block)
|
126
|
-
end
|
127
|
-
|
128
|
-
# Used to direct the buffer for the erb capture
|
129
|
-
def erb_with_output_buffer(buf = '') #:nodoc:
|
130
|
-
@_out_buf, old_buffer = buf, @_out_buf
|
131
|
-
yield
|
132
|
-
@_out_buf
|
133
|
-
ensure
|
134
|
-
@_out_buf = old_buffer
|
135
|
-
end
|
136
|
-
|
137
|
-
end #/ Helpers
|
138
|
-
|
139
|
-
# def self.registered(app)
|
140
|
-
# app.helpers Sinatra::Output::Helpers
|
141
|
-
# end #/ self.registered
|
142
|
-
|
143
|
-
end #/ Output
|
144
|
-
|
145
|
-
helpers Sinatra::Output::Helpers
|
146
|
-
|
147
|
-
end #/ Sinatra
|