flame 4.2.1 → 4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 143c89bd2f9b509aacac88782cc376339135cbfe
4
- data.tar.gz: f7feaffc253e6ea95233f381f2e8d550929e0af3
3
+ metadata.gz: aa9181ef76573d3f62778f9534e09e0714695993
4
+ data.tar.gz: cdbf13a1103537a6e1de7a1e6f0bd995b6203dcc
5
5
  SHA512:
6
- metadata.gz: d166e036f47a0a738ef4a859ec02a707d03f6740b4f173976f1a4f8114ed510d988e3e88aa992a020ce1e701a969059aff9f48c4c2a04be2057c585d3e0d82b5
7
- data.tar.gz: 938a0b0d6761742b91698f418fd935432fb2c67821379a3475fcb2701155af9a017e2c81df081bfc5ad6956d613b968e39510c9ff66c8375e46088ab55591a78
6
+ metadata.gz: 6b3a2cf7e74d4cf4480c482298c17c512b64a28ad1337ba0fd6b4751b0ccbd788b79fa164c394cb363c00451c096b0edef2b1c5d1e627b9c10500bf2b9d42d42
7
+ data.tar.gz: 17e953a8119939d35579cacd740c0497e420430c9cfb519eba7f0569afa35a1a32330832ed81fb8b74ded1e1c34d223ec6ef95581577e85fde708d8244192558
@@ -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 = cache ? self.class.tilts[@filename] ||= compile : compile
32
+ tilt = compile_file
32
33
  ## Render Tilt from instance hash with new options
33
- layout_render tilt.render(@scope, @locals), cache: cache
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 compile(filename = @filename)
55
- Tilt.new(filename)
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
- def find_file(path, layout: false)
61
- ## Get full filename
62
- dirs = layout ? layout_dirs : controller_dirs
63
- Dir[File.join(
64
- views_dir,
65
- "{#{dirs.join(',')},}",
66
- "#{path}.*"
67
- )].uniq.find do |file|
68
- Tilt[file]
69
- end
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
- ## @param cache [Boolean] cache compiles or not
107
- def layout_render(result, cache: true)
108
- layout_file = find_file(@layout, layout: true)
109
- ## Compile layout to hash
110
- return result unless layout_file
111
- layout =
112
- if cache
113
- self.class.tilts[layout_file] ||= compile(layout_file)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flame
4
- VERSION = '4.2.1'.freeze
4
+ VERSION = '4.3'.freeze
5
5
  end
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.2.1
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-02 00:00:00.000000000 Z
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack