rack-app-front_end 0.13.0 → 0.14.0

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: a5983723b1ed5893aa432c049e76c58734f9113b
4
- data.tar.gz: 3ddce6ab78b7939cf2e5fe9c55b99887926918ec
3
+ metadata.gz: 137ded4eba081d289c0b302d4355381e82bc3bf8
4
+ data.tar.gz: 3068644d9ca4fce3ff1ed155a04db4c353724bff
5
5
  SHA512:
6
- metadata.gz: 69ee00d52045b883dbea6d5cb38af91b2ce1c6134b97da4d2d526c73cfd63af75f15662a3949b89cc839a8789ed21a0a80668c5fe37e6a11623b193ae32c7f9b
7
- data.tar.gz: 0b868ba5876ef8c515b2f5d1525d4225b1b274e1599e9a58f0ad3b9a7a2ceec5fcfa46927946780b96641c2c4db0a4a155fa7b4a51dcc750a2b9837dd634e0ee
6
+ metadata.gz: f768c263b5f33445cc22eafe83a90d1c45074442f8afeb852a95235f8dd6a652ee42be31b72da33d2c0deb0248131dbe19dae55d7537feb1c43bd5d01b73d877
7
+ data.tar.gz: 7cfe28419ead7aef1fb9a7c08e6214d98c22dbdc62d3646c66d41427cac6b102801307432871b129a4577537c48cff868fa0c144bced8c0a028cd325e973e232
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.13.0
1
+ 0.14.0
@@ -1,13 +1,11 @@
1
1
  module Rack::App::FrontEnd::InstanceMethods
2
2
 
3
3
  def render(template_path, *args, &block)
4
+
4
5
  full_path = Rack::App::Utils.expand_path(template_path)
5
- template = Rack::App::FrontEnd::Template.new(full_path, __runtime_properties__[:layout], self.class)
6
+ template = Rack::App::FrontEnd::Template.new(full_path, self.class)
6
7
  return template.render(self, *args, &block)
7
- end
8
8
 
9
- def __runtime_properties__
10
- @__runtime_properties__ ||= {}
11
9
  end
12
10
 
13
11
  end
@@ -11,12 +11,10 @@ module Rack::App::FrontEnd::SingletonMethods
11
11
  @layout
12
12
  end
13
13
 
14
- def precache_templates(*template_paths)
15
- full_paths = template_paths.map { |path| Rack::App::Utils.expand_path(path) }
16
- full_paths.each do |full_path|
17
- Rack::App::FrontEnd::Template.cache.fetch(full_path) { Tilt.new(full_path) }
18
- end
19
- nil
14
+ def template_options(hash=nil)
15
+ @template_options ||= {:default_encoding => "utf-8"}
16
+ @template_options.merge!(hash) if hash.is_a?(Hash)
17
+ @template_options
20
18
  end
21
19
 
22
20
  def helpers(&block)
@@ -3,56 +3,56 @@ class Rack::App::FrontEnd::Template
3
3
  NO_LAYOUT_KEYWORD = :none
4
4
 
5
5
  require 'rack/app/front_end/template/default_layout'
6
+ require 'rack/app/front_end/template/default_template'
6
7
 
7
8
  def self.cache
8
9
  @cache ||= Tilt::Cache.new
9
10
  end
10
11
 
11
12
  def render(scope, *args, &block)
12
- return render_result(scope, *args, &block)
13
+ extend_with_helpers(scope)
14
+
15
+ layout(scope).render(scope, *args) { template.render(scope, *args, &block) }
13
16
  end
14
17
 
15
18
  protected
16
19
 
17
- def initialize(template_path, layout, klass)
20
+ def initialize(template_path, klass)
18
21
  @file_path = template_path
19
- @layout = layout
20
22
  @class = klass
21
23
  end
22
24
 
23
- def render_result(scope, *args, &block)
24
- return Rack::App::File::Streamer.new(@file_path) unless it_is_a_template?
25
- extend_with_helpers(scope)
26
- block_layouts_for(scope)
27
- layout.render(scope, *args) { template.render(scope, *args, &block) }
28
- end
29
-
30
- def it_is_a_template?
25
+ def is_a_template?
31
26
  not Tilt.templates_for(@file_path).empty?
32
27
  end
33
28
 
34
29
  def template
35
- get_template(@file_path)
30
+ if is_a_template?
31
+ get_template(@file_path)
32
+ else
33
+ DefaultTemplate.new(@file_path)
34
+ end
36
35
  end
37
36
 
38
- def layout
39
- return DefaultLayout if use_default_layout?
40
-
41
- get_template(layout_path)
37
+ def layout(scope)
38
+ return DefaultLayout if use_default_layout?(scope)
39
+ block_layouts_for(scope)
40
+ get_template(@class.layout)
42
41
  end
43
42
 
44
- def layout_path
45
- return @class.layout
46
- end
47
43
 
48
- def use_default_layout?
49
- (@layout == NO_LAYOUT_KEYWORD) or
44
+ def use_default_layout?(scope)
45
+ (scope.instance_variable_get(:@layout) == NO_LAYOUT_KEYWORD) or
50
46
  (@class.respond_to?(:layout) and @class.layout.nil?) or
51
- (@file_path =~ /^#{Regexp.escape(Rack::App::Utils.namespace_folder(layout_path))}/)
47
+ (@file_path =~ /^#{Regexp.escape(Rack::App::Utils.namespace_folder(@class.layout))}/)
52
48
  end
53
49
 
54
50
  def get_template(file_path)
55
- self.class.cache.fetch(file_path) { Tilt.new(file_path) }
51
+ self.class.cache.fetch(file_path) { Tilt.new(file_path, template_options) }
52
+ end
53
+
54
+ def template_options
55
+ @class.template_options
56
56
  end
57
57
 
58
58
  def extend_with_helpers(scope)
@@ -60,7 +60,7 @@ class Rack::App::FrontEnd::Template
60
60
  end
61
61
 
62
62
  def block_layouts_for(scope)
63
- scope.__runtime_properties__[:layout]= NO_LAYOUT_KEYWORD
63
+ scope.instance_variable_set(:@layout, NO_LAYOUT_KEYWORD)
64
64
  end
65
65
 
66
66
  end
@@ -1,4 +1,5 @@
1
1
  module Rack::App::FrontEnd::Template::DefaultLayout
2
+
2
3
  extend self
3
4
 
4
5
  def render(*args, &block)
@@ -0,0 +1,11 @@
1
+ class Rack::App::FrontEnd::Template::DefaultTemplate
2
+
3
+ def initialize(file_path)
4
+ @file_path = file_path
5
+ end
6
+
7
+ def render(*args)
8
+ File.read(@file_path)
9
+ end
10
+
11
+ end
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec"
26
26
 
27
- spec.add_dependency 'rack-app','>= 1.2.2'
27
+ spec.add_dependency 'rack-app','>= 2.0.0'
28
28
  spec.add_dependency 'tilt'
29
29
 
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app-front_end
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-29 00:00:00.000000000 Z
11
+ date: 2016-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 1.2.2
61
+ version: 2.0.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 1.2.2
68
+ version: 2.0.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: tilt
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -104,6 +104,7 @@ files:
104
104
  - lib/rack/app/front_end/singleton_methods.rb
105
105
  - lib/rack/app/front_end/template.rb
106
106
  - lib/rack/app/front_end/template/default_layout.rb
107
+ - lib/rack/app/front_end/template/default_template.rb
107
108
  - lib/rack/app/front_end/version.rb
108
109
  - rack-app-front_end.gemspec
109
110
  homepage: http://www.rack-app.com/