flame 3.2.2 → 3.3.1

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: 8d56480a76f309437a815068dc46798bff1f3eda
4
- data.tar.gz: 41544a764ed20300aefeceea0522138ba373a8a4
3
+ metadata.gz: a61779c08e772e1bd54da4364ad652061bfdac29
4
+ data.tar.gz: 1eac1e3b00890e638ea378ca86cb68b3c76fdca8
5
5
  SHA512:
6
- metadata.gz: aad138df611e1abbaff6c91eb83f171e932df2e46d592989b39f4eb0d18c1a2e4ebbfc1e5b11d2f23e5d3305c4ea673d251c8908bb525fa2a9f01fc9528c2606
7
- data.tar.gz: 680b01ef29626ff4bca78c7d69a07c8ab0fdc29aeff980f77de10babc551c3183f64c9b8b41cfca2e5885098d83a273e6033493814461bc9ae865e301488f237
6
+ metadata.gz: 36f71c677b77b0bbf1a8ba925a3dea66b4b37b015af2173588c610607506aad4855cfcea07cabccb174d5426860298edfbf86eba8327565aa59c1c5179181acb
7
+ data.tar.gz: 491e236bd4b08481e913bd27645e01333c698e97234c012cf09cd8adb8053e4cf76a5dd2796b1d3a29f54277236c0e1dd71b82a41fc29a28a2724ca7d40f6e96
@@ -19,6 +19,8 @@ module Flame
19
19
  app,
20
20
  default_config_dirs(
21
21
  root_dir: File.dirname(caller[0].split(':')[0])
22
+ ).merge(
23
+ environment: ENV['RACK_ENV'] || 'development'
22
24
  )
23
25
  )
24
26
  # app.use Rack::Session::Pool
@@ -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
- ).render
29
+ )
30
+ template.render(cache: config[:environment] == 'production')
30
31
  end
31
32
  alias_method :render, :view
32
33
 
@@ -49,11 +49,11 @@ module Flame
49
49
  path.empty? ? '/' : path
50
50
  end
51
51
 
52
- def halt(new_status, body = '', new_headers = {})
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.empty? &&
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
@@ -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 tilts[@filename].render(@scope, @locals)
24
+ layout_render tilt.render(@scope, @locals), cache: cache
25
25
  end
26
26
 
27
27
  private
28
28
 
29
- def self.tilts
30
- @tilts ||= {}
31
- end
29
+ using GorillaPatch::StringExt
32
30
 
33
- def tilts
34
- self.class.tilts
31
+ def compile(filename = @filename)
32
+ Tilt.new(filename)
35
33
  end
36
34
 
37
- using GorillaPatch::StringExt
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
- layout_filename = find_file(@layout)
64
+ def layout_render(result, cache: true)
65
+ layout_file = find_file(@layout)
66
66
  ## Compile layout to hash
67
- return result unless layout_filename
68
- tilts[layout_filename] ||= Tilt.new(layout_filename)
69
- return result unless tilts[layout_filename]
70
- tilts[layout_filename].render(@scope, @locals) { result }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flame
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov