flame 1.1.2 → 1.1.8
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/lib/flame/controller.rb +21 -2
- data/lib/flame/dispatcher.rb +33 -1
- data/lib/flame/render.rb +27 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c3b246233ec03fd89c4c0acaabef54f9a21cfd8
|
4
|
+
data.tar.gz: a9a8ab0206466032532d763cf842a6a3cdbd831b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13ee2d5fa5407d377d8370f445e454acf058108450945df5f79b711d02eea628732627ac2c725f579fcefc4460beddcff1d268c3816a7ce3bf3c179ffc2e388b
|
7
|
+
data.tar.gz: d497b609ddc7635cee5b510fa7f04842371463676c07f5f169e6821d9f27fd23a31e1385d70694046d0b356cfa6c54a0d4ad6839a2ea0324845044d8908c8fff
|
data/lib/flame/controller.rb
CHANGED
@@ -3,8 +3,6 @@ require_relative 'render'
|
|
3
3
|
module Flame
|
4
4
|
## Class for controllers helpers, like Framework::Controller
|
5
5
|
class Controller
|
6
|
-
include Flame::Render
|
7
|
-
|
8
6
|
def initialize(dispatcher)
|
9
7
|
@dispatcher = dispatcher
|
10
8
|
end
|
@@ -17,10 +15,19 @@ module Flame
|
|
17
15
|
@dispatcher.request
|
18
16
|
end
|
19
17
|
|
18
|
+
def response
|
19
|
+
@dispatcher.response
|
20
|
+
end
|
21
|
+
|
20
22
|
def params
|
21
23
|
@dispatcher.params
|
22
24
|
end
|
23
25
|
|
26
|
+
def view(path, options = {})
|
27
|
+
Flame::Render.new(self, path, options).render
|
28
|
+
end
|
29
|
+
alias_method :render, :view
|
30
|
+
|
24
31
|
def halt(*params)
|
25
32
|
@dispatcher.halt(*params)
|
26
33
|
end
|
@@ -29,6 +36,18 @@ module Flame
|
|
29
36
|
@dispatcher.path_to(*params)
|
30
37
|
end
|
31
38
|
|
39
|
+
def redirect(*params)
|
40
|
+
@dispatcher.redirect(*params)
|
41
|
+
end
|
42
|
+
|
43
|
+
def session
|
44
|
+
@dispatcher.session
|
45
|
+
end
|
46
|
+
|
47
|
+
def cookies
|
48
|
+
@dispatcher.cookies
|
49
|
+
end
|
50
|
+
|
32
51
|
## TODO: Add more helpers
|
33
52
|
end
|
34
53
|
end
|
data/lib/flame/dispatcher.rb
CHANGED
@@ -61,7 +61,22 @@ module Flame
|
|
61
61
|
def path_to(ctrl, action, args = {})
|
62
62
|
route = @app.router.find_route(controller: ctrl, action: action)
|
63
63
|
fail RouteNotFoundError.new(ctrl, action) unless route
|
64
|
-
route.assign_arguments(args)
|
64
|
+
path = route.assign_arguments(args)
|
65
|
+
path.empty? ? '/' : path
|
66
|
+
end
|
67
|
+
|
68
|
+
def redirect(*params)
|
69
|
+
throw :halt, response.redirect(
|
70
|
+
params[0].is_a?(String) ? params[0] : path_to(*params)
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
def session
|
75
|
+
request.session
|
76
|
+
end
|
77
|
+
|
78
|
+
def cookies
|
79
|
+
@cookies ||= Cookies.new(request.cookies, response)
|
65
80
|
end
|
66
81
|
|
67
82
|
private
|
@@ -102,5 +117,22 @@ module Flame
|
|
102
117
|
def file_mime_type(file)
|
103
118
|
Rack::Mime.mime_type(File.extname(file))
|
104
119
|
end
|
120
|
+
|
121
|
+
## Helper class for cookies
|
122
|
+
class Cookies
|
123
|
+
def initialize(request_cookies, response)
|
124
|
+
@request_cookies = request_cookies
|
125
|
+
@response = response
|
126
|
+
end
|
127
|
+
|
128
|
+
def [](key)
|
129
|
+
@request_cookies[key] || @request_cookies[key.to_s]
|
130
|
+
end
|
131
|
+
|
132
|
+
def []=(key, new_value)
|
133
|
+
return @response.delete_cookie(key) if new_value.nil?
|
134
|
+
@response.set_cookie(key, new_value)
|
135
|
+
end
|
136
|
+
end
|
105
137
|
end
|
106
138
|
end
|
data/lib/flame/render.rb
CHANGED
@@ -4,26 +4,35 @@ require 'tilt/erb'
|
|
4
4
|
|
5
5
|
module Flame
|
6
6
|
## Helper for render functionality
|
7
|
-
|
8
|
-
def
|
7
|
+
class Render
|
8
|
+
def initialize(ctrl, path, options = {})
|
9
9
|
## Take options for rendering
|
10
|
-
|
11
|
-
|
10
|
+
@ctrl = ctrl
|
11
|
+
@scope = options.delete(:scope) || @ctrl
|
12
|
+
@layout = options.delete(:layout) || 'layout.*'
|
12
13
|
## And get the rest variables to locals
|
13
|
-
locals = options.merge(options.delete(:locals) || {})
|
14
|
+
@locals = options.merge(options.delete(:locals) || {})
|
14
15
|
## Find filename
|
15
|
-
filename = find_file(path)
|
16
|
+
@filename = find_file(path)
|
16
17
|
## Compile Tilt to instance hash
|
17
|
-
@
|
18
|
-
@tilts[filename] ||= Tilt.new(filename)
|
19
|
-
## Render Tilt from instance hash with new options
|
20
|
-
layout_render layout, @tilts[filename].render(scope, locals)
|
18
|
+
tilts[@filename] ||= Tilt.new(@filename)
|
21
19
|
end
|
22
20
|
|
23
|
-
|
21
|
+
def render
|
22
|
+
## Render Tilt from instance hash with new options
|
23
|
+
layout_render tilts[@filename].render(@scope, @locals)
|
24
|
+
end
|
24
25
|
|
25
26
|
private
|
26
27
|
|
28
|
+
def self.tilts
|
29
|
+
@tilts ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def tilts
|
33
|
+
self.class.tilts
|
34
|
+
end
|
35
|
+
|
27
36
|
using GorillaPatch::StringExt
|
28
37
|
|
29
38
|
## TODO: Add `views_dir` for Application and Controller
|
@@ -31,7 +40,7 @@ module Flame
|
|
31
40
|
def find_file(path)
|
32
41
|
## Get full filename
|
33
42
|
Dir[File.join(
|
34
|
-
config[:views_dir],
|
43
|
+
@ctrl.config[:views_dir],
|
35
44
|
"{#{controller_dirs.join(',')},}",
|
36
45
|
"#{path}.*"
|
37
46
|
)].find do |file|
|
@@ -42,18 +51,18 @@ module Flame
|
|
42
51
|
def controller_dirs
|
43
52
|
## Build controller_dirs
|
44
53
|
controller_dir = (
|
45
|
-
|
54
|
+
@ctrl.class.name.underscore.split('_') - %w(controller ctrl)
|
46
55
|
).join('_')
|
47
56
|
[controller_dir, controller_dir.split('/').last]
|
48
57
|
end
|
49
58
|
|
50
|
-
def layout_render(
|
51
|
-
layout_filename = find_file(layout)
|
59
|
+
def layout_render(result)
|
60
|
+
layout_filename = find_file(@layout)
|
52
61
|
## Compile layout to hash
|
53
62
|
return result unless layout_filename
|
54
|
-
|
55
|
-
return result unless
|
56
|
-
|
63
|
+
tilts[layout_filename] ||= Tilt.new(layout_filename)
|
64
|
+
return result unless tilts[layout_filename]
|
65
|
+
tilts[layout_filename].render(@scope, @locals) { result }
|
57
66
|
end
|
58
67
|
end
|
59
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|