hydeweb 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,12 @@
1
+ v0.1.10
2
+ -------
3
+
4
+ - New Hyde sites will now have a gems manifest. This means you can
5
+ push your Hyde sites to Heroku instantly.
6
+ - Add cuba to dependencies.
7
+ - The server now serves the right MIME types.
8
+ - When used as a Rack app, Hyde sends cache headers.
9
+
1
10
  v0.1.9
2
11
  ------
3
12
 
data/TODO.md CHANGED
@@ -1,3 +1,6 @@
1
+ - Caching
2
+ - MIME types
3
+
1
4
  - Post build hooks?
2
5
  - tilt_build_options
3
6
  - deprecate $project, implement Hyde.project
@@ -5,4 +5,5 @@ require 'hyde'
5
5
  require 'hyde/server'
6
6
 
7
7
  Hyde::Project.new File.dirname(__FILE__)
8
+ Hyde::Server.options[:cache] = true
8
9
  run Hyde::Server
data/lib/hyde/cli.rb CHANGED
@@ -68,9 +68,13 @@ 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'))
71
72
 
72
73
  require 'hyde/server'
73
74
 
75
+ # No caching whatsoever.
76
+ Hyde::Server.options[:cache] = cache
77
+
74
78
  if daemon
75
79
  pid = fork { Hyde::Server.run! :Host => host, :Port => port, :quiet => true }
76
80
  sleep 2
@@ -87,13 +91,16 @@ class CLI < Shake
87
91
  task.help = %{
88
92
  Usage:
89
93
 
90
- #{executable} start [-p PORT] [-o HOST] [-D]
94
+ #{executable} start [-p PORT] [-o HOST] [--cache] [-D]
91
95
 
92
96
  Starts an HTTP server so you may rapidly test your project locally.
93
97
 
94
98
  If the -p and/or -o is specified, it will listen on the specified HOST:PORT.
95
99
  Otherwise, the default is 0.0.0.0:4833.
96
100
 
101
+ Hyde doesn't send cache instructions, ensuring that every page load is fresh.
102
+ You can use --cache to override this behavior.
103
+
97
104
  If -D is specified, it goes into daemon mode.
98
105
  }.gsub(/^ {4}/, '').strip.split("\n")
99
106
 
data/lib/hyde/project.rb CHANGED
@@ -11,10 +11,14 @@ class Project
11
11
  def validate_version
12
12
  return unless config_file?
13
13
  req = config.hyde_requirement.to_s
14
+
15
+ v = lambda { |version| Gem::Version.new version }
16
+
14
17
  if req.empty?
15
- elsif req < "0.1"
18
+ # pass
19
+ elsif v[req] < v["0.1"]
16
20
  raise LegacyError, "This is a legacy project"
17
- elsif req > Hyde.version
21
+ elsif v[req] > v[Hyde.version]
18
22
  raise VersionError, "You will need Hyde version >= #{req} for this project."
19
23
  end
20
24
  end
data/lib/hyde/server.rb CHANGED
@@ -28,6 +28,16 @@ class Hyde
28
28
  puts "%s\033[0;m %s %s" % [ status, verb, env['PATH_INFO'] ]
29
29
  puts " src: #{page.filepath} (#{page.tilt_engine_name})" if page && page.tilt?
30
30
  end
31
+
32
+ def mime_type_for(page)
33
+ type = page.mime_type
34
+ type ||= Rack::Mime::MIME_TYPES[File.extname(page.file)]
35
+ type
36
+ end
37
+
38
+ def server
39
+ Hyde::Server
40
+ end
31
41
  end
32
42
 
33
43
  module Hyde::Server
@@ -37,8 +47,17 @@ class Hyde
37
47
  on default do
38
48
  begin
39
49
  page = Hyde::Page[env['PATH_INFO']] or break not_found
40
- type = page.mime_type
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
57
+
58
+ type = mime_type_for(page)
41
59
  res['Content-Type'] = type if type
60
+
42
61
  res.write page.to_html
43
62
  show_status page
44
63
  rescue => e
@@ -51,9 +70,19 @@ class Hyde
51
70
  end
52
71
 
53
72
  module Hyde::Server
73
+ # Available options:
74
+ # - cache - (bool) sets if we do caching or not. Defaults to false.
75
+ def self.options
76
+ @options ||= Hash.new
77
+ if @options.empty?
78
+ @options[:cache] = true
79
+ end
80
+ @options
81
+ end
82
+
54
83
  # :Host, :Port
55
84
  def self.run!(options={})
56
- @options = options
85
+ self.options.merge options
57
86
  handler = rack_handler or return false
58
87
  handler.run self, options
59
88
  end
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.9"
18
+ VERSION = "0.1.10"
19
19
  PREFIX = File.expand_path('../', __FILE__)
20
20
 
21
21
  Error = Class.new(StandardError)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -29,6 +29,10 @@ class HydeTest < TestCase
29
29
  # Build
30
30
  project = build path
31
31
 
32
+ assert \
33
+ Dir[project.root('control/**/*')].length ==
34
+ Dir[project.root('public/**/*')].length
35
+
32
36
  Dir[project.root('control/**/*')].each do |control|
33
37
  next unless File.file?(control)
34
38
  var = control.sub('/control/', '/public/')
@@ -41,6 +41,13 @@ 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
+ end
47
+
48
+ test "ext" do
49
+ assert_equal '.html', Page['/'].ext
50
+ assert_equal '.jpg', Page['/images/foo.jpg'].ext
44
51
  end
45
52
 
46
53
  test "no layout" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hydeweb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.9
5
+ version: 0.1.10
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rico Sta. Cruz
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-25 00:00:00 +08:00
13
+ date: 2011-02-26 00:00:00 +08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -36,18 +36,18 @@ dependencies:
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
39
- name: haml
39
+ name: cuba
40
40
  prerelease: false
41
41
  requirement: &id003 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: "0"
47
- type: :development
46
+ version: 1.0.0
47
+ type: :runtime
48
48
  version_requirements: *id003
49
49
  - !ruby/object:Gem::Dependency
50
- name: less
50
+ name: haml
51
51
  prerelease: false
52
52
  requirement: &id004 !ruby/object:Gem::Requirement
53
53
  none: false
@@ -58,7 +58,7 @@ dependencies:
58
58
  type: :development
59
59
  version_requirements: *id004
60
60
  - !ruby/object:Gem::Dependency
61
- name: maruku
61
+ name: less
62
62
  prerelease: false
63
63
  requirement: &id005 !ruby/object:Gem::Requirement
64
64
  none: false
@@ -68,6 +68,17 @@ dependencies:
68
68
  version: "0"
69
69
  type: :development
70
70
  version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: maruku
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ type: :development
81
+ version_requirements: *id006
71
82
  description: Hyde lets you create static websites from a bunch of files written in HAML, Textile, Sass, or any other.
72
83
  email:
73
84
  - rico@sinefunc.com
@@ -129,6 +140,9 @@ files:
129
140
  - test/fixture/one/control/css/style.css
130
141
  - test/fixture/one/control/hello.html
131
142
  - test/fixture/one/control/hi.html
143
+ - test/fixture/one/control/images/bar.gif
144
+ - test/fixture/one/control/images/baz.png
145
+ - test/fixture/one/control/images/foo.jpg
132
146
  - test/fixture/one/control/index.html
133
147
  - test/fixture/one/hyde.conf
134
148
  - test/fixture/one/layouts/default.haml
@@ -140,6 +154,9 @@ files:
140
154
  - test/fixture/one/site/css/style.scss
141
155
  - test/fixture/one/site/hello.haml
142
156
  - test/fixture/one/site/hi.html
157
+ - test/fixture/one/site/images/bar.gif
158
+ - test/fixture/one/site/images/baz.png
159
+ - test/fixture/one/site/images/foo.jpg
143
160
  - test/fixture/one/site/index.haml
144
161
  - test/fixture/parent/control/about/index.html
145
162
  - test/fixture/parent/control/about/us.html