rack-app-front_end 0.12.0 → 0.13.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8263ef1b0f815302a5f193b612eea031505235d3
4
- data.tar.gz: 44c45827ede78fbfb9e03c5a128b13141e4ba2a0
3
+ metadata.gz: a5983723b1ed5893aa432c049e76c58734f9113b
4
+ data.tar.gz: 3ddce6ab78b7939cf2e5fe9c55b99887926918ec
5
5
  SHA512:
6
- metadata.gz: 010619359363d3cab25b6e9e658ba453d59ed6b0f10fa941d6ca19cbb513e42ad9b94c209de8656c83ebf2a7a20a1108124e1a91b6a92ce3ab7bfb55b8128b9a
7
- data.tar.gz: 3bdcfe2c79bad69d8e0f4d142218436176fae383ed12969ddaf68d0de0f125d45952545207a752a32df5eccf9222938b80133c4d1a489c5b41b0265aa6010640
6
+ metadata.gz: 69ee00d52045b883dbea6d5cb38af91b2ce1c6134b97da4d2d526c73cfd63af75f15662a3949b89cc839a8789ed21a0a80668c5fe37e6a11623b193ae32c7f9b
7
+ data.tar.gz: 0b868ba5876ef8c515b2f5d1525d4225b1b274e1599e9a58f0ad3b9a7a2ceec5fcfa46927946780b96641c2c4db0a4a155fa7b4a51dcc750a2b9837dd634e0ee
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.12.0
1
+ 0.13.0
@@ -1,9 +1,13 @@
1
1
  module Rack::App::FrontEnd::InstanceMethods
2
2
 
3
- def render(template_path)
3
+ def render(template_path, *args, &block)
4
4
  full_path = Rack::App::Utils.expand_path(template_path)
5
- template = Rack::App::FrontEnd::Template.new(full_path, self.class)
6
- return template.render(self)
5
+ template = Rack::App::FrontEnd::Template.new(full_path, __runtime_properties__[:layout], self.class)
6
+ return template.render(self, *args, &block)
7
+ end
8
+
9
+ def __runtime_properties__
10
+ @__runtime_properties__ ||= {}
7
11
  end
8
12
 
9
13
  end
@@ -1,5 +1,6 @@
1
1
  require 'tilt'
2
2
  class Rack::App::FrontEnd::Template
3
+ NO_LAYOUT_KEYWORD = :none
3
4
 
4
5
  require 'rack/app/front_end/template/default_layout'
5
6
 
@@ -13,14 +14,16 @@ class Rack::App::FrontEnd::Template
13
14
 
14
15
  protected
15
16
 
16
- def initialize(file_path, klass)
17
- @file_path = file_path
17
+ def initialize(template_path, layout, klass)
18
+ @file_path = template_path
19
+ @layout = layout
18
20
  @class = klass
19
21
  end
20
22
 
21
23
  def render_result(scope, *args, &block)
22
24
  return Rack::App::File::Streamer.new(@file_path) unless it_is_a_template?
23
- scope.extend(@class.helpers) if @class.respond_to?(:helpers)
25
+ extend_with_helpers(scope)
26
+ block_layouts_for(scope)
24
27
  layout.render(scope, *args) { template.render(scope, *args, &block) }
25
28
  end
26
29
 
@@ -33,13 +36,31 @@ class Rack::App::FrontEnd::Template
33
36
  end
34
37
 
35
38
  def layout
36
- return DefaultLayout if @class.respond_to?(:layout) and @class.layout.nil?
37
- return DefaultLayout if @file_path =~ /^#{Regexp.escape(Rack::App::Utils.namespace_folder(@class.layout))}/
38
- get_template(@class.layout)
39
+ return DefaultLayout if use_default_layout?
40
+
41
+ get_template(layout_path)
42
+ end
43
+
44
+ def layout_path
45
+ return @class.layout
46
+ end
47
+
48
+ def use_default_layout?
49
+ (@layout == NO_LAYOUT_KEYWORD) or
50
+ (@class.respond_to?(:layout) and @class.layout.nil?) or
51
+ (@file_path =~ /^#{Regexp.escape(Rack::App::Utils.namespace_folder(layout_path))}/)
39
52
  end
40
53
 
41
54
  def get_template(file_path)
42
55
  self.class.cache.fetch(file_path) { Tilt.new(file_path) }
43
56
  end
44
57
 
58
+ def extend_with_helpers(scope)
59
+ scope.extend(@class.helpers) if @class.respond_to?(:helpers)
60
+ end
61
+
62
+ def block_layouts_for(scope)
63
+ scope.__runtime_properties__[:layout]= NO_LAYOUT_KEYWORD
64
+ end
65
+
45
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app-front_end
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
@@ -106,7 +106,6 @@ files:
106
106
  - lib/rack/app/front_end/template/default_layout.rb
107
107
  - lib/rack/app/front_end/version.rb
108
108
  - rack-app-front_end.gemspec
109
- - spike/test.html.erb
110
109
  homepage: http://www.rack-app.com/
111
110
  licenses:
112
111
  - Apache License 2.0
data/spike/test.html.erb DELETED
@@ -1,3 +0,0 @@
1
- <p><%= test %></p>
2
- <p><%= asdf %></p>
3
- <p><%= hello_world! %></p>