brochure 0.4.0 → 0.5.0
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.
- data/README.md +10 -3
- data/lib/brochure.rb +1 -1
- data/lib/brochure/context.rb +19 -2
- data/lib/brochure/template.rb +3 -3
- metadata +4 -4
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
<img src="https://github.com/downloads/sstephenson/brochure/logo.png"
|
2
|
+
width="250" height="135" alt="Brochure">
|
3
3
|
|
4
4
|
Brochure is a Rack application for serving static sites with ERB
|
5
5
|
templates (or any of the many [template languages supported by
|
@@ -29,7 +29,7 @@ Sample `config.ru`:
|
|
29
29
|
run Brochure.app(root)
|
30
30
|
|
31
31
|
|
32
|
-
## URL mapping
|
32
|
+
## Automatic URL mapping
|
33
33
|
|
34
34
|
URLs are automatically mapped to template names:
|
35
35
|
|
@@ -37,10 +37,17 @@ URLs are automatically mapped to template names:
|
|
37
37
|
* `/signup` → `templates/signup.html.erb`
|
38
38
|
* `/help/` → `templates/help/index.html.erb`
|
39
39
|
|
40
|
+
|
41
|
+
## Partials and helpers
|
42
|
+
|
40
43
|
Templates can render partials. A partial is denoted by a leading
|
41
44
|
underscore in its filename. So `<%= render "shared/header" %>` will
|
42
45
|
render `templates/shared/_header.html.erb` inline.
|
43
46
|
|
47
|
+
Partials can `<%= yield %>` back to the templates that render
|
48
|
+
them. You can use this technique to extract common header and footer
|
49
|
+
markup into a single layout file, for example.
|
50
|
+
|
44
51
|
Templates have access to the Rack environment via the `env` method and
|
45
52
|
to the Brochure application via the `application`
|
46
53
|
method. Additionally, a `Rack::Request` wrapper around the Rack
|
data/lib/brochure.rb
CHANGED
data/lib/brochure/context.rb
CHANGED
@@ -32,12 +32,29 @@ module Brochure
|
|
32
32
|
Rack::Utils.escape_html(html)
|
33
33
|
end
|
34
34
|
|
35
|
-
def render(logical_path, locals = {})
|
35
|
+
def render(logical_path, locals = {}, &block)
|
36
36
|
if partial = application.find_partial(logical_path, template.format_extension)
|
37
|
-
|
37
|
+
if block_given?
|
38
|
+
print partial.render(env, locals) { capture(&block) }
|
39
|
+
else
|
40
|
+
partial.render(env, locals)
|
41
|
+
end
|
38
42
|
else
|
39
43
|
raise TemplateNotFound, "no such template '#{logical_path}'"
|
40
44
|
end
|
41
45
|
end
|
46
|
+
|
47
|
+
def print(str)
|
48
|
+
@_out_buf << str
|
49
|
+
end
|
50
|
+
|
51
|
+
def capture
|
52
|
+
buf = ""
|
53
|
+
old_buf, @_out_buf = @_out_buf, buf
|
54
|
+
yield
|
55
|
+
buf
|
56
|
+
ensure
|
57
|
+
@_out_buf = old_buf
|
58
|
+
end
|
42
59
|
end
|
43
60
|
end
|
data/lib/brochure/template.rb
CHANGED
@@ -8,7 +8,7 @@ module Brochure
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def template
|
11
|
-
@template ||= Tilt.new(path)
|
11
|
+
@template ||= Tilt.new(path, nil, :outvar => '@_out_buf')
|
12
12
|
end
|
13
13
|
|
14
14
|
def engine_extension
|
@@ -29,8 +29,8 @@ module Brochure
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def render(env, locals = {})
|
33
|
-
template.render(app.context_for(self, env), locals)
|
32
|
+
def render(env, locals = {}, &block)
|
33
|
+
template.render(app.context_for(self, env), locals, &block)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
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:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
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-
|
19
|
+
date: 2010-11-04 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|