brochure 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/brochure.rb +8 -7
- data/lib/brochure/context.rb +28 -12
- data/lib/brochure/errors.rb +3 -1
- data/lib/brochure/template.rb +17 -8
- metadata +21 -7
data/lib/brochure.rb
CHANGED
@@ -3,14 +3,15 @@ require "rack"
|
|
3
3
|
require "tilt"
|
4
4
|
|
5
5
|
module Brochure
|
6
|
-
VERSION = "0.5.
|
6
|
+
VERSION = "0.5.1"
|
7
7
|
|
8
|
-
autoload :Application,
|
9
|
-
autoload :
|
10
|
-
autoload :
|
11
|
-
autoload :
|
12
|
-
autoload :
|
13
|
-
autoload :
|
8
|
+
autoload :Application, "brochure/application"
|
9
|
+
autoload :CaptureNotSupported, "brochure/errors"
|
10
|
+
autoload :Context, "brochure/context"
|
11
|
+
autoload :Failsafe, "brochure/failsafe"
|
12
|
+
autoload :Static, "brochure/static"
|
13
|
+
autoload :Template, "brochure/template"
|
14
|
+
autoload :TemplateNotFound, "brochure/errors"
|
14
15
|
|
15
16
|
def self.app(root, options = {})
|
16
17
|
app = Application.new(root, options)
|
data/lib/brochure/context.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module Brochure
|
2
2
|
class Context
|
3
|
-
include Tilt::CompileSite
|
4
|
-
|
5
3
|
def self.for(helpers)
|
6
4
|
context = Class.new(self)
|
7
5
|
context.send(:include, *helpers) if helpers.any?
|
@@ -35,7 +33,7 @@ module Brochure
|
|
35
33
|
def render(logical_path, locals = {}, &block)
|
36
34
|
if partial = application.find_partial(logical_path, template.format_extension)
|
37
35
|
if block_given?
|
38
|
-
|
36
|
+
concat partial.render(env, locals) { capture(&block) }
|
39
37
|
else
|
40
38
|
partial.render(env, locals)
|
41
39
|
end
|
@@ -44,17 +42,35 @@ module Brochure
|
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
|
-
def
|
48
|
-
|
45
|
+
def engine_name
|
46
|
+
template.engine_extension[1..-1]
|
47
|
+
end
|
48
|
+
|
49
|
+
def concat(str)
|
50
|
+
if respond_to?(method = "#{engine_name}_concat")
|
51
|
+
send(method, str)
|
52
|
+
elsif @_out_buf
|
53
|
+
@_out_buf << str
|
54
|
+
else
|
55
|
+
raise CaptureNotSupported, "no capture support for #{engine_name} templates"
|
56
|
+
end
|
49
57
|
end
|
50
58
|
|
51
|
-
def capture
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
59
|
+
def capture(&block)
|
60
|
+
if respond_to?(method = "capture_#{engine_name}")
|
61
|
+
send(method, &block)
|
62
|
+
elsif @_out_buf
|
63
|
+
begin
|
64
|
+
buf = ""
|
65
|
+
old_buf, @_out_buf = @_out_buf, buf
|
66
|
+
yield
|
67
|
+
buf
|
68
|
+
ensure
|
69
|
+
@_out_buf = old_buf
|
70
|
+
end
|
71
|
+
else
|
72
|
+
raise CaptureNotSupported, "no capture support for #{engine_name} templates"
|
73
|
+
end
|
58
74
|
end
|
59
75
|
end
|
60
76
|
end
|
data/lib/brochure/errors.rb
CHANGED
data/lib/brochure/template.rb
CHANGED
@@ -8,18 +8,23 @@ module Brochure
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def template
|
11
|
-
@template ||= Tilt.new(path, nil, :outvar => '@_out_buf')
|
11
|
+
@template ||= Tilt.new(path, nil, :outvar => '@_out_buf') if engine_extension
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
@
|
14
|
+
def basename
|
15
|
+
@basename ||= File.basename(path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def extensions
|
19
|
+
@extensions ||= basename.scan(/\.[^.]+/)
|
16
20
|
end
|
17
21
|
|
18
22
|
def format_extension
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
extensions.first
|
24
|
+
end
|
25
|
+
|
26
|
+
def engine_extension
|
27
|
+
extensions[1]
|
23
28
|
end
|
24
29
|
|
25
30
|
def content_type
|
@@ -30,7 +35,11 @@ module Brochure
|
|
30
35
|
end
|
31
36
|
|
32
37
|
def render(env, locals = {}, &block)
|
33
|
-
template
|
38
|
+
if template
|
39
|
+
template.render(app.context_for(self, env), locals, &block)
|
40
|
+
else
|
41
|
+
File.read(path)
|
42
|
+
end
|
34
43
|
end
|
35
44
|
end
|
36
45
|
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: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 1
|
10
|
+
version: 0.5.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-11-
|
19
|
+
date: 2010-11-20 00:00:00 -06:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -27,12 +27,12 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 19
|
31
31
|
segments:
|
32
32
|
- 0
|
33
33
|
- 1
|
34
|
-
-
|
35
|
-
version: 0.1.
|
34
|
+
- 4
|
35
|
+
version: 0.1.4
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id001
|
38
38
|
- !ruby/object:Gem::Dependency
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
version: "0"
|
82
82
|
type: :development
|
83
83
|
version_requirements: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: haml
|
86
|
+
prerelease: false
|
87
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
type: :development
|
97
|
+
version_requirements: *id005
|
84
98
|
description: A Rack application for serving static sites with ERB templates.
|
85
99
|
email:
|
86
100
|
- sstephenson@gmail.com
|