rack-app-front_end 0.14.0 → 0.15.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.rb +3 -2
- data/lib/rack/app/front_end/endpoint_methods.rb +16 -0
- data/lib/rack/app/front_end/helpers.rb +9 -0
- data/lib/rack/app/front_end/singleton_methods.rb +8 -8
- data/lib/rack/app/front_end/template.rb +28 -31
- data/lib/rack/app/front_end/template/scope.rb +24 -0
- data/rack-app-front_end.gemspec +0 -1
- metadata +5 -3
- data/lib/rack/app/front_end/instance_methods.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 426e13bd34c9a41ac2e81eacc66a0a9d0ac07fc7
|
4
|
+
data.tar.gz: f4ca5b23f2db738e4894aa6e2ed371682a40a55b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db70eebf6181f66e04c5411c1823dc7cdfce045b043edc1d8739d89907b92af620f73d86b9bc854a3727ff797e3a44c6a2e75b077a6ba72080d1fd7b2a87b601
|
7
|
+
data.tar.gz: c93a71ddc8188d2d1e01231de1c779fb42c1e98a9e303d7f49bda983ce68d1f7f57826bd7c37625e45ff994ac85270b668ef520637ff3d55268695aeb5173fa7
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.15.0
|
data/lib/rack/app/front_end.rb
CHANGED
@@ -5,9 +5,10 @@ module Rack::App::FrontEnd
|
|
5
5
|
require 'tilt/plain'
|
6
6
|
|
7
7
|
require 'rack/app/front_end/version'
|
8
|
+
require 'rack/app/front_end/helpers'
|
8
9
|
require 'rack/app/front_end/template'
|
9
10
|
require 'rack/app/front_end/folder_mounter'
|
10
|
-
require 'rack/app/front_end/
|
11
|
+
require 'rack/app/front_end/endpoint_methods'
|
11
12
|
require 'rack/app/front_end/singleton_methods'
|
12
13
|
|
13
14
|
class << self
|
@@ -15,7 +16,7 @@ module Rack::App::FrontEnd
|
|
15
16
|
[:extended, :included].each do |method|
|
16
17
|
define_method(method) do |klass|
|
17
18
|
|
18
|
-
klass.__send__(:include, self::
|
19
|
+
klass.__send__(:include, self::EndpointMethods)
|
19
20
|
klass.__send__(:extend, self::SingletonMethods)
|
20
21
|
|
21
22
|
klass.on_inheritance do |parent, child|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Rack::App::FrontEnd::EndpointMethods
|
2
|
+
|
3
|
+
def render(template_path, variables={}, options={}, &block)
|
4
|
+
options = {:layout_path => self.class.layout}.merge(options)
|
5
|
+
|
6
|
+
scope = Rack::App::FrontEnd::Template::Scope.new
|
7
|
+
scope.extend(self.class.helpers)
|
8
|
+
scope.inherit_instance_variables!(self)
|
9
|
+
|
10
|
+
full_path = Rack::App::Utils.expand_path(template_path)
|
11
|
+
template = Rack::App::FrontEnd::Template.new(full_path, options)
|
12
|
+
|
13
|
+
return template.render(scope, variables, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Rack::App::FrontEnd::Helpers
|
2
|
+
|
3
|
+
def render(template_path, variables={}, options={}, &block)
|
4
|
+
full_path = Rack::App::Utils.expand_path(template_path)
|
5
|
+
template = Rack::App::FrontEnd::Template.new(full_path,options)
|
6
|
+
return template.render(self, variables, &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
@@ -11,16 +11,16 @@ module Rack::App::FrontEnd::SingletonMethods
|
|
11
11
|
@layout
|
12
12
|
end
|
13
13
|
|
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
|
18
|
-
end
|
19
|
-
|
20
14
|
def helpers(&block)
|
21
|
-
|
15
|
+
|
16
|
+
@helpers ||= lambda {
|
17
|
+
helpers_module = Module.new
|
18
|
+
helpers_module.__send__(:include, Rack::App::FrontEnd::Helpers)
|
19
|
+
}.call
|
20
|
+
|
22
21
|
@helpers.class_eval(&block) unless block.nil?
|
23
|
-
|
22
|
+
|
23
|
+
return @helpers
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'tilt'
|
2
2
|
class Rack::App::FrontEnd::Template
|
3
|
-
NO_LAYOUT_KEYWORD = :none
|
4
3
|
|
4
|
+
require 'rack/app/front_end/template/scope'
|
5
5
|
require 'rack/app/front_end/template/default_layout'
|
6
6
|
require 'rack/app/front_end/template/default_template'
|
7
7
|
|
@@ -9,58 +9,55 @@ class Rack::App::FrontEnd::Template
|
|
9
9
|
@cache ||= Tilt::Cache.new
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def self.template?(file_path)
|
13
|
+
not Tilt.templates_for(file_path).empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
def render(current_scope, variables={}, &block)
|
17
|
+
scope = create_scope(current_scope)
|
14
18
|
|
15
|
-
layout
|
19
|
+
layout.render(scope, variables) { template.render(scope, variables, &block) }
|
16
20
|
end
|
17
21
|
|
18
22
|
protected
|
19
23
|
|
20
|
-
|
21
|
-
@file_path = template_path
|
22
|
-
@class = klass
|
23
|
-
end
|
24
|
+
DEFAULT_TEMPLATE_OPTIONS = {:default_encoding => "utf-8"}
|
24
25
|
|
25
|
-
def
|
26
|
-
|
26
|
+
def initialize(template_path, options={})
|
27
|
+
@file_path = template_path
|
28
|
+
@layout_path = options.delete(:layout_path)
|
29
|
+
@template_options = DEFAULT_TEMPLATE_OPTIONS.merge(options)
|
27
30
|
end
|
28
31
|
|
29
32
|
def template
|
30
|
-
if
|
33
|
+
if self.class.template?(@file_path)
|
31
34
|
get_template(@file_path)
|
32
35
|
else
|
33
36
|
DefaultTemplate.new(@file_path)
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
37
|
-
def layout
|
38
|
-
return DefaultLayout if use_default_layout?
|
39
|
-
block_layouts_for(scope)
|
40
|
-
get_template(@class.layout)
|
41
|
-
end
|
40
|
+
def layout
|
41
|
+
return DefaultLayout if use_default_layout?
|
42
42
|
|
43
|
-
|
44
|
-
def use_default_layout?(scope)
|
45
|
-
(scope.instance_variable_get(:@layout) == NO_LAYOUT_KEYWORD) or
|
46
|
-
(@class.respond_to?(:layout) and @class.layout.nil?) or
|
47
|
-
(@file_path =~ /^#{Regexp.escape(Rack::App::Utils.namespace_folder(@class.layout))}/)
|
43
|
+
get_template(@layout_path)
|
48
44
|
end
|
49
45
|
|
50
|
-
def
|
51
|
-
|
46
|
+
def use_default_layout?
|
47
|
+
@layout_path.nil? or
|
48
|
+
not File.exist?(@layout_path) or
|
49
|
+
(@file_path =~ /^#{Regexp.escape(Rack::App::Utils.namespace_folder(@layout_path))}/)
|
52
50
|
end
|
53
51
|
|
54
|
-
def
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def extend_with_helpers(scope)
|
59
|
-
scope.extend(@class.helpers) if @class.respond_to?(:helpers)
|
52
|
+
def get_template(file_path)
|
53
|
+
self.class.cache.fetch(file_path) { Tilt.new(file_path, @template_options) }
|
60
54
|
end
|
61
55
|
|
62
|
-
def
|
63
|
-
|
56
|
+
def create_scope(current_scope)
|
57
|
+
new_scope = Scope.new
|
58
|
+
new_scope.inherit_instance_variables!(current_scope)
|
59
|
+
new_scope.inherit_modules!(current_scope)
|
60
|
+
new_scope
|
64
61
|
end
|
65
62
|
|
66
63
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Rack::App::FrontEnd::Template::Scope
|
2
|
+
|
3
|
+
def extended_modules
|
4
|
+
class << self
|
5
|
+
self
|
6
|
+
end.included_modules
|
7
|
+
end
|
8
|
+
|
9
|
+
def inherit_modules!(object)
|
10
|
+
class << object
|
11
|
+
self
|
12
|
+
end.included_modules.each do |module_constant|
|
13
|
+
extend(module_constant)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def inherit_instance_variables!(object)
|
18
|
+
object.__send__(:instance_variables).each do |instance_variable|
|
19
|
+
value = object.__send__(:instance_variable_get, instance_variable)
|
20
|
+
instance_variable_set(instance_variable, value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
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.15.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-03-
|
11
|
+
date: 2016-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,12 +99,14 @@ files:
|
|
99
99
|
- bin/console
|
100
100
|
- bin/setup
|
101
101
|
- lib/rack/app/front_end.rb
|
102
|
+
- lib/rack/app/front_end/endpoint_methods.rb
|
102
103
|
- lib/rack/app/front_end/folder_mounter.rb
|
103
|
-
- lib/rack/app/front_end/
|
104
|
+
- lib/rack/app/front_end/helpers.rb
|
104
105
|
- lib/rack/app/front_end/singleton_methods.rb
|
105
106
|
- lib/rack/app/front_end/template.rb
|
106
107
|
- lib/rack/app/front_end/template/default_layout.rb
|
107
108
|
- lib/rack/app/front_end/template/default_template.rb
|
109
|
+
- lib/rack/app/front_end/template/scope.rb
|
108
110
|
- lib/rack/app/front_end/version.rb
|
109
111
|
- rack-app-front_end.gemspec
|
110
112
|
homepage: http://www.rack-app.com/
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Rack::App::FrontEnd::InstanceMethods
|
2
|
-
|
3
|
-
def render(template_path, *args, &block)
|
4
|
-
|
5
|
-
full_path = Rack::App::Utils.expand_path(template_path)
|
6
|
-
template = Rack::App::FrontEnd::Template.new(full_path, self.class)
|
7
|
-
return template.render(self, *args, &block)
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|