blossom 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/blossom +1 -1
- data/lib/blossom.rb +33 -27
- metadata +3 -3
data/bin/blossom
CHANGED
data/lib/blossom.rb
CHANGED
@@ -7,18 +7,46 @@ require "rack/strip-www"
|
|
7
7
|
require "hassle"
|
8
8
|
|
9
9
|
module Blossom
|
10
|
-
VERSION = "0.0.
|
10
|
+
VERSION = "0.0.8"
|
11
|
+
end
|
12
|
+
|
13
|
+
def Blossom.get_seconds(value, unit)
|
14
|
+
days = 60 * 60 * 24
|
15
|
+
case unit
|
16
|
+
when :seconds, :second
|
17
|
+
value
|
18
|
+
when :minutes, :minute
|
19
|
+
value * 60
|
20
|
+
when :hours, :hour
|
21
|
+
value * 60 * 60
|
22
|
+
when :days, :day
|
23
|
+
value * days
|
24
|
+
when :weeks, :week
|
25
|
+
value * days * 7
|
26
|
+
when :months, :month
|
27
|
+
value * days * 30
|
28
|
+
when :years, :year
|
29
|
+
value * days * 365
|
30
|
+
else
|
31
|
+
raise ArgumentError, "Unrecognized unit: #{unit}"
|
32
|
+
end
|
11
33
|
end
|
12
34
|
|
13
35
|
def Blossom(root_file, index = :index, options = {})
|
14
36
|
Rack::Builder.app do
|
15
|
-
|
37
|
+
cache = options[:cache]
|
16
38
|
use Hassle
|
39
|
+
use Rack::StripWWW
|
40
|
+
defined? Rack::Coffee and use Rack::Coffee,
|
41
|
+
:static => false,
|
42
|
+
:urls => "/",
|
43
|
+
:cache => !!cache,
|
44
|
+
:ttl => cache && Blossom.get_seconds(*cache)
|
17
45
|
run Blossom::Base(root_file, index, options)
|
18
46
|
end
|
19
47
|
end
|
20
48
|
|
21
|
-
def Blossom
|
49
|
+
def Blossom.Base(root_file, index = :index, blossom_options = {})
|
22
50
|
root = File.dirname(root_file)
|
23
51
|
Class.new(Sinatra::Base).tap do |app|
|
24
52
|
app.class_eval do
|
@@ -62,34 +90,12 @@ def Blossom::Base(root_file, index = :index, blossom_options = {})
|
|
62
90
|
|
63
91
|
define_method :blossom_headers do
|
64
92
|
if blossom_options.include? :cache
|
65
|
-
seconds = get_seconds(*blossom_options[:cache])
|
66
|
-
{ 'Cache-Control' => "
|
93
|
+
seconds = Blossom.get_seconds(*blossom_options[:cache])
|
94
|
+
{ 'Cache-Control' => "max-age=#{seconds}" }
|
67
95
|
else
|
68
96
|
{}
|
69
97
|
end
|
70
98
|
end
|
71
|
-
|
72
|
-
def get_seconds(value, unit)
|
73
|
-
days = 60 * 60 * 24
|
74
|
-
case unit
|
75
|
-
when :seconds, :second
|
76
|
-
value
|
77
|
-
when :minutes, :minute
|
78
|
-
value * 60
|
79
|
-
when :hours, :hour
|
80
|
-
value * 60 * 60
|
81
|
-
when :days, :day
|
82
|
-
value * days
|
83
|
-
when :weeks, :week
|
84
|
-
value * days * 7
|
85
|
-
when :months, :month
|
86
|
-
value * days * 30
|
87
|
-
when :years, :year
|
88
|
-
value * days * 365
|
89
|
-
else
|
90
|
-
raise ArgumentError, "Unrecognized unit: #{unit}"
|
91
|
-
end
|
92
|
-
end
|
93
99
|
end
|
94
100
|
end
|
95
101
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 8
|
9
|
+
version: 0.0.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Brockman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-12 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|