brochure 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.md CHANGED
@@ -1,7 +1,9 @@
1
1
  Brochure
2
2
  ========
3
3
 
4
- A Rack application for serving static sites with ERB templates.
4
+ A Rack application for serving static sites with ERB templates (or any
5
+ of the many [template languages supported by
6
+ Tilt](http://github.com/rtomayko/tilt/blob/master/TEMPLATES.md#readme)).
5
7
 
6
8
  Sample application structure:
7
9
 
@@ -20,17 +22,52 @@ Sample application structure:
20
22
  Sample `config.ru`:
21
23
 
22
24
  require "brochure"
23
- run Brochure.app(File.dirname(__FILE__))
25
+ ROOT = File.dirname(__FILE__)
26
+ run Brochure.app(ROOT)
24
27
 
25
- URLs are automatically mapped to template names. So `/` will render
26
- `templates/index.html.erb`, `/signup` will render
27
- `templates/signup.html.erb`, `/help/` will render
28
- `templates/help/index.html.erb`, and so on.
29
28
 
30
- Templates can render partials. Partials are denoted by a leading
31
- underscore in their filename. So `<%= render "shared/header" %>` will
29
+ ## Templates and URL mapping
30
+
31
+ URLs are automatically mapped to template names:
32
+
33
+ * `/` &rarr; `templates/index.html.erb`
34
+ * `/signup` &rarr; `templates/signup.html.erb`
35
+ * `/help/` &rarr; `templates/help/index.html.erb`
36
+
37
+ Templates can render partials. A partial is denoted by a leading
38
+ underscore in its filename. So `<%= render "shared/header" %>` will
32
39
  render `templates/shared/_header.html.erb` inline.
33
40
 
41
+ Templates have access to the Rack environment via the `env` method and
42
+ to the Brochure application via the `application` method.
43
+
44
+
45
+ ## Helper methods and instance variables
46
+
47
+ You can make additional helper methods and instance variables
48
+ available to your templates. Helper methods live in Ruby modules and
49
+ can be included with the `:helpers` option to `Brochure.app`:
50
+
51
+ module AssetHelper
52
+ def asset_path(filename)
53
+ local_path = File.join(application.asset_root, filename)
54
+ if File.file?(local_path)
55
+ cache_buster = "?#{Digest::MD5.hexdigest(IO.read(local_path))}"
56
+ else
57
+ cache_buster = ""
58
+ end
59
+ "#{filename}#{cache_buster}"
60
+ end
61
+ end
62
+
63
+ run Brochure.app(ROOT, :helpers => [AssetHelper])
64
+
65
+ Similarly, instance variables can be defined with the `:assigns`
66
+ option:
67
+
68
+ run Brochure.app(ROOT, :assigns => { :domain => "37signals.com" })
69
+
70
+
34
71
  # Installation
35
72
 
36
73
  $ gem install brochure
@@ -39,6 +76,7 @@ Requires [Hike](http://github.com/sstephenson/hike),
39
76
  [Rack](http://rack.rubyforge.org/), and
40
77
  [Tilt](http://github.com/rtomayko/tilt).
41
78
 
79
+
42
80
  # License
43
81
 
44
82
  Copyright (c) 2010 Sam Stephenson and Josh Peek.
@@ -3,7 +3,7 @@ require "rack"
3
3
  require "tilt"
4
4
 
5
5
  module Brochure
6
- VERSION = "0.3.0"
6
+ VERSION = "0.3.1"
7
7
 
8
8
  autoload :Application, "brochure/application"
9
9
  autoload :Context, "brochure/context"
@@ -94,10 +94,10 @@ module Brochure
94
94
  template.render(context, locals)
95
95
  end
96
96
 
97
- def respond_with(status, body, content_type = "text/html, charset=utf-8")
97
+ def respond_with(status, body, content_type = "text/html; charset=utf-8")
98
98
  headers = {
99
99
  "Content-Type" => content_type,
100
- "Content-Length" => body.length.to_s
100
+ "Content-Length" => Rack::Utils.bytesize(body).to_s
101
101
  }
102
102
  [status, headers, [body]]
103
103
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brochure
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Stephenson
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-10-21 00:00:00 -05:00
19
+ date: 2010-10-22 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency