flame 3.2.2 → 3.3.1
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.
- checksums.yaml +4 -4
- data/lib/flame/application.rb +2 -0
- data/lib/flame/controller.rb +3 -2
- data/lib/flame/dispatcher.rb +2 -2
- data/lib/flame/render.rb +21 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a61779c08e772e1bd54da4364ad652061bfdac29
|
4
|
+
data.tar.gz: 1eac1e3b00890e638ea378ca86cb68b3c76fdca8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36f71c677b77b0bbf1a8ba925a3dea66b4b37b015af2173588c610607506aad4855cfcea07cabccb174d5426860298edfbf86eba8327565aa59c1c5179181acb
|
7
|
+
data.tar.gz: 491e236bd4b08481e913bd27645e01333c698e97234c012cf09cd8adb8053e4cf76a5dd2796b1d3a29f54277236c0e1dd71b82a41fc29a28a2724ca7d40f6e96
|
data/lib/flame/application.rb
CHANGED
data/lib/flame/controller.rb
CHANGED
@@ -22,11 +22,12 @@ module Flame
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def view(path = nil, options = {})
|
25
|
-
Flame::Render.new(
|
25
|
+
template = Flame::Render.new(
|
26
26
|
self,
|
27
27
|
(path || caller_locations(1, 1)[0].label.to_sym),
|
28
28
|
options
|
29
|
-
)
|
29
|
+
)
|
30
|
+
template.render(cache: config[:environment] == 'production')
|
30
31
|
end
|
31
32
|
alias_method :render, :view
|
32
33
|
|
data/lib/flame/dispatcher.rb
CHANGED
@@ -49,11 +49,11 @@ module Flame
|
|
49
49
|
path.empty? ? '/' : path
|
50
50
|
end
|
51
51
|
|
52
|
-
def halt(new_status, body =
|
52
|
+
def halt(new_status, body = nil, new_headers = {})
|
53
53
|
new_status.is_a?(String) ? (body = new_status) : (status new_status)
|
54
54
|
response.headers.merge!(new_headers)
|
55
55
|
# p response.body
|
56
|
-
if body.
|
56
|
+
if body.nil? &&
|
57
57
|
!Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status)
|
58
58
|
body = Rack::Utils::HTTP_STATUS_CODES[status]
|
59
59
|
end
|
data/lib/flame/render.rb
CHANGED
@@ -15,26 +15,26 @@ module Flame
|
|
15
15
|
## Find filename
|
16
16
|
@filename = find_file(path)
|
17
17
|
@layout = nil if File.basename(@filename)[0] == '_'
|
18
|
-
## Compile Tilt to instance hash
|
19
|
-
tilts[@filename] ||= Tilt.new(@filename)
|
20
18
|
end
|
21
19
|
|
22
|
-
def render
|
20
|
+
def render(cache: true)
|
21
|
+
## Compile Tilt to instance hash
|
22
|
+
tilt = cache ? self.class.tilts[@filename] ||= compile : compile
|
23
23
|
## Render Tilt from instance hash with new options
|
24
|
-
layout_render
|
24
|
+
layout_render tilt.render(@scope, @locals), cache: cache
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
|
30
|
-
@tilts ||= {}
|
31
|
-
end
|
29
|
+
using GorillaPatch::StringExt
|
32
30
|
|
33
|
-
def
|
34
|
-
|
31
|
+
def compile(filename = @filename)
|
32
|
+
Tilt.new(filename)
|
35
33
|
end
|
36
34
|
|
37
|
-
|
35
|
+
def self.tilts
|
36
|
+
@tilts ||= {}
|
37
|
+
end
|
38
38
|
|
39
39
|
## TODO: Add `views_dir` for Application and Controller
|
40
40
|
## TODO: Add `layout` method for Controller
|
@@ -61,13 +61,18 @@ module Flame
|
|
61
61
|
controller_dir_parts.last]
|
62
62
|
end
|
63
63
|
|
64
|
-
def layout_render(result)
|
65
|
-
|
64
|
+
def layout_render(result, cache: true)
|
65
|
+
layout_file = find_file(@layout)
|
66
66
|
## Compile layout to hash
|
67
|
-
return result unless
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
return result unless layout_file
|
68
|
+
layout =
|
69
|
+
if cache
|
70
|
+
self.class.tilts[layout_file] ||= compile(layout_file)
|
71
|
+
else
|
72
|
+
compile(layout_file)
|
73
|
+
end
|
74
|
+
return result unless layout
|
75
|
+
layout.render(@scope, @locals) { result }
|
71
76
|
end
|
72
77
|
end
|
73
78
|
end
|