flame 4.2.1 → 4.3
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/render.rb +31 -27
- data/lib/flame/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa9181ef76573d3f62778f9534e09e0714695993
|
4
|
+
data.tar.gz: cdbf13a1103537a6e1de7a1e6f0bd995b6203dcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b3a2cf7e74d4cf4480c482298c17c512b64a28ad1337ba0fd6b4751b0ccbd788b79fa164c394cb363c00451c096b0edef2b1c5d1e627b9c10500bf2b9d42d42
|
7
|
+
data.tar.gz: 17e953a8119939d35579cacd740c0497e420430c9cfb519eba7f0569afa35a1a32330832ed81fb8b74ded1e1c34d223ec6ef95581577e85fde708d8244192558
|
data/lib/flame/render.rb
CHANGED
@@ -26,11 +26,12 @@ module Flame
|
|
26
26
|
## Render template
|
27
27
|
## @param cache [Boolean] cache compiles or not
|
28
28
|
def render(cache: true)
|
29
|
+
@cache = cache
|
29
30
|
## Compile Tilt to instance hash
|
30
31
|
return unless @filename
|
31
|
-
tilt =
|
32
|
+
tilt = compile_file
|
32
33
|
## Render Tilt from instance hash with new options
|
33
|
-
layout_render tilt.render(@scope, @locals)
|
34
|
+
layout_render tilt.render(@scope, @locals)
|
34
35
|
end
|
35
36
|
|
36
37
|
private
|
@@ -51,22 +52,30 @@ module Flame
|
|
51
52
|
|
52
53
|
## Compile file with Tilt engine
|
53
54
|
## @param filename [String] filename
|
54
|
-
def
|
55
|
-
|
55
|
+
def compile_file(filename = @filename)
|
56
|
+
cached = self.class.tilts[filename]
|
57
|
+
return cached if @cache
|
58
|
+
compiled = Tilt.new(filename)
|
59
|
+
self.class.tilts[filename] ||= compiled if @cache
|
60
|
+
compiled
|
56
61
|
end
|
57
62
|
|
58
63
|
## @todo Add `views_dir` for Application and Controller
|
59
64
|
## @todo Add `layout` method for Controller
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
Dir[File.join(
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
|
66
|
+
## Common method for `find_file` and `find_layouts`
|
67
|
+
def find_files(path, dirs)
|
68
|
+
Dir[File.join(views_dir, "{#{dirs.join(',')},}", "#{path}.*")].uniq
|
69
|
+
end
|
70
|
+
|
71
|
+
## Find template-file by path
|
72
|
+
def find_file(path)
|
73
|
+
find_files(path, controller_dirs).find { |file| Tilt[file] }
|
74
|
+
end
|
75
|
+
|
76
|
+
## Find layout-files by path
|
77
|
+
def find_layouts(path)
|
78
|
+
find_files(path, layout_dirs).select { |file| Tilt[file] }.sort!.reverse!
|
70
79
|
end
|
71
80
|
|
72
81
|
## Find possible directories for the controller
|
@@ -103,19 +112,14 @@ module Flame
|
|
103
112
|
|
104
113
|
## Render the layout with template
|
105
114
|
## @param result [String] result of template rendering
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
else
|
115
|
-
compile(layout_file)
|
116
|
-
end
|
117
|
-
return result unless layout
|
118
|
-
layout.render(@scope, @locals) { result }
|
115
|
+
def layout_render(content)
|
116
|
+
return content unless @layout
|
117
|
+
layout_files = find_layouts(@layout)
|
118
|
+
return content if layout_files.empty?
|
119
|
+
layout_files.each_with_object(content) do |layout_file, result|
|
120
|
+
layout = compile_file(layout_file)
|
121
|
+
result.replace layout.render(@scope, @locals) { result }
|
122
|
+
end
|
119
123
|
end
|
120
124
|
end
|
121
125
|
end
|
data/lib/flame/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: '4.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|