rack-app-front_end 0.13.0 → 0.14.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 +4 -4
- data/VERSION +1 -1
- data/lib/rack/app/front_end/instance_methods.rb +2 -4
- data/lib/rack/app/front_end/singleton_methods.rb +4 -6
- data/lib/rack/app/front_end/template.rb +24 -24
- data/lib/rack/app/front_end/template/default_layout.rb +1 -0
- data/lib/rack/app/front_end/template/default_template.rb +11 -0
- data/rack-app-front_end.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 137ded4eba081d289c0b302d4355381e82bc3bf8
|
4
|
+
data.tar.gz: 3068644d9ca4fce3ff1ed155a04db4c353724bff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f768c263b5f33445cc22eafe83a90d1c45074442f8afeb852a95235f8dd6a652ee42be31b72da33d2c0deb0248131dbe19dae55d7537feb1c43bd5d01b73d877
|
7
|
+
data.tar.gz: 7cfe28419ead7aef1fb9a7c08e6214d98c22dbdc62d3646c66d41427cac6b102801307432871b129a4577537c48cff868fa0c144bced8c0a028cd325e973e232
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
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,
|
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
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
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,
|
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
|
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
|
-
|
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(
|
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
|
-
(
|
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(
|
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.
|
63
|
+
scope.instance_variable_set(:@layout, NO_LAYOUT_KEYWORD)
|
64
64
|
end
|
65
65
|
|
66
66
|
end
|
data/rack-app-front_end.gemspec
CHANGED
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.
|
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
|
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:
|
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:
|
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/
|