blossom 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/blossom +1 -1
  2. data/lib/blossom.rb +33 -27
  3. metadata +3 -3
data/bin/blossom CHANGED
@@ -38,7 +38,7 @@ require "rubygems"
38
38
  require "bundler/setup"
39
39
  require "blossom"
40
40
 
41
- run Blossom(__FILE__, #{name_symbol}, :cache => [1, :year])
41
+ run Blossom(__FILE__, #{name_symbol}, :cache => [1, :day])
42
42
  end_file
43
43
 
44
44
  make_file "Gemfile", <<-"end_file"
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.7"
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
- use Rack::StripWWW
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::Base(root_file, index = :index, blossom_options = {})
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' => "public, max-age=#{seconds}" }
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
- - 7
9
- version: 0.0.7
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-05 00:00:00 +01:00
17
+ date: 2010-11-12 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency