hydeweb 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,10 @@
1
+ v0.1.11
2
+ -------
3
+
4
+ - Deprecate in-app caching for rack-cache.
5
+ - The Hyde server now sends the Last-Modified HTTP header.
6
+ - New Hyde sites will now use rack-cache (optionally) when used as a Rack site.
7
+
1
8
  v0.1.10
2
9
  -------
3
10
 
@@ -4,6 +4,11 @@
4
4
  require 'hyde'
5
5
  require 'hyde/server'
6
6
 
7
+ begin
8
+ # Add the 'rack-cache' gem if you want to enable caching.
9
+ require 'rack/cache'
10
+ use Rack::Cache
11
+ end
12
+
7
13
  Hyde::Project.new File.dirname(__FILE__)
8
- Hyde::Server.options[:cache] = true
9
14
  run Hyde::Server
@@ -9,7 +9,7 @@ output_path: _output
9
9
  # Other paths:
10
10
  layouts_path: _layouts
11
11
  extensions_path: _extensions
12
- partials_path: _layouts
12
+ partials_path: .
13
13
 
14
14
  # Files to be excluded from processing
15
15
  ignore:
@@ -17,7 +17,7 @@ ignore:
17
17
  - README*
18
18
  - config.ru
19
19
  - **/.*
20
- - **/_*.scss
20
+ - **/_*
21
21
 
22
22
  # Optional options for layout engines
23
23
  tilt_options:
data/lib/hyde/cli.rb CHANGED
@@ -68,13 +68,9 @@ class CLI < Shake
68
68
  port = (params.extract('-p') || 4833).to_i
69
69
  host = (params.extract('-o') || '0.0.0.0')
70
70
  daemon = (!! params.delete('-D'))
71
- cache = (!! params.delete('--cache'))
72
71
 
73
72
  require 'hyde/server'
74
73
 
75
- # No caching whatsoever.
76
- Hyde::Server.options[:cache] = cache
77
-
78
74
  if daemon
79
75
  pid = fork { Hyde::Server.run! :Host => host, :Port => port, :quiet => true }
80
76
  sleep 2
@@ -91,16 +87,13 @@ class CLI < Shake
91
87
  task.help = %{
92
88
  Usage:
93
89
 
94
- #{executable} start [-p PORT] [-o HOST] [--cache] [-D]
90
+ #{executable} start [-p PORT] [-o HOST] [-D]
95
91
 
96
92
  Starts an HTTP server so you may rapidly test your project locally.
97
93
 
98
94
  If the -p and/or -o is specified, it will listen on the specified HOST:PORT.
99
95
  Otherwise, the default is 0.0.0.0:4833.
100
96
 
101
- Hyde doesn't send cache instructions, ensuring that every page load is fresh.
102
- You can use --cache to override this behavior.
103
-
104
97
  If -D is specified, it goes into daemon mode.
105
98
  }.gsub(/^ {4}/, '').strip.split("\n")
106
99
 
data/lib/hyde/server.rb CHANGED
@@ -48,16 +48,17 @@ class Hyde
48
48
  begin
49
49
  page = Hyde::Page[env['PATH_INFO']] or break not_found
50
50
 
51
- if server.options[:cache]
52
- # Fairly aggressive caching. Best for Rack apps.
53
- res['Cache-Control'] = 'max-age=86400, public'
54
- else
55
- res['Cache-Control'] = 'no-cache'
56
- end
51
+ # Make the clients use If-Modified-Since
52
+ res['Cache-Control'] = 'max-age=86400, public, must-revalidate'
57
53
 
54
+ mtime = [server.options[:last_modified], File.mtime(page.file)].compact.max
55
+ res['Last-Modified'] = mtime.to_s if mtime
56
+
57
+ # Get the MIME type from Hyde, then fallback to Rack
58
58
  type = mime_type_for(page)
59
59
  res['Content-Type'] = type if type
60
60
 
61
+ # Okay, we're done
61
62
  res.write page.to_html
62
63
  show_status page
63
64
  rescue => e
@@ -71,13 +72,9 @@ end
71
72
 
72
73
  module Hyde::Server
73
74
  # Available options:
74
- # - cache - (bool) sets if we do caching or not. Defaults to false.
75
+ # :last_modified -- timestamp for all files
75
76
  def self.options
76
77
  @options ||= Hash.new
77
- if @options.empty?
78
- @options[:cache] = true
79
- end
80
- @options
81
78
  end
82
79
 
83
80
  # :Host, :Port
data/lib/hyde.rb CHANGED
@@ -15,7 +15,7 @@ require 'shake'
15
15
  Tilt.mappings['html'] = Tilt.mappings['erb']
16
16
 
17
17
  class Hyde
18
- VERSION = "0.1.10"
18
+ VERSION = "0.1.11"
19
19
  PREFIX = File.expand_path('../', __FILE__)
20
20
 
21
21
  Error = Class.new(StandardError)
@@ -41,15 +41,8 @@ class PageTest < TestCase
41
41
  assert_equal 'text/html', Page['/about/us.html'].mime_type
42
42
  assert_equal 'html', Page['/about/us.html'].default_ext
43
43
  assert_equal 'css', Page['/css/style.css'].default_ext
44
-
45
- assert_equal 'image/jpeg', Page['/images/foo.jpg'].mime_type
46
44
  end
47
45
 
48
- test "ext" do
49
- assert_equal '.html', Page['/'].ext
50
- assert_equal '.jpg', Page['/images/foo.jpg'].ext
51
- end
52
-
53
46
  test "no layout" do
54
47
  page = Page['/hi.html']
55
48
  assert_equal false, page.meta.layout
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hydeweb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.10
5
+ version: 0.1.11
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rico Sta. Cruz