flame 4.12.2 → 4.12.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flame/application.rb +4 -0
- data/lib/flame/controller.rb +20 -6
- data/lib/flame/dispatcher.rb +6 -1
- data/lib/flame/render.rb +13 -17
- data/lib/flame/route.rb +14 -2
- data/lib/flame/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ed5d54f5f6821749a7324ead082677cb04d669e
|
4
|
+
data.tar.gz: 228dbe656d57d35ab38a75780ead602461a73827
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d702039c0a51e0041d5bc41fb8b15c62bb1c9eb943fd2c6bfa74b88a8024f310921c9c22445fd8270e23a43815412fa9508ee42413aed7407a83b7efb89b93b2
|
7
|
+
data.tar.gz: 5347d0bc63a7c39d725369de0d1c8afa7707ef41cd95ea18aa282d8d61379903cb28b4353c0f731d6f45ddba853fc7603deb9c4a4cc41e19dd10004de2f8e5de
|
data/lib/flame/application.rb
CHANGED
data/lib/flame/controller.rb
CHANGED
@@ -17,7 +17,7 @@ module Flame
|
|
17
17
|
def_delegators(
|
18
18
|
:@dispatcher,
|
19
19
|
:config, :request, :params, :halt, :session, :response, :status, :body,
|
20
|
-
:default_body
|
20
|
+
:default_body, :cached_tilts
|
21
21
|
)
|
22
22
|
|
23
23
|
## Initialize the controller for request execution
|
@@ -44,19 +44,33 @@ module Flame
|
|
44
44
|
## @param path [String] path
|
45
45
|
## @example Redirect to '/hello'
|
46
46
|
## redirect '/hello'
|
47
|
+
## @overload redirect(uri)
|
48
|
+
## Redirect to the URI location
|
49
|
+
## @param uri [URI] URI object
|
50
|
+
## @example Redirect to 'http://example.com'
|
51
|
+
## redirect URI::HTTP.build(host: 'example.com')
|
47
52
|
## @overload redirect(*args)
|
48
53
|
## Redirect to the path of `path_to` method
|
49
54
|
## @param args arguments for `path_to` method
|
50
55
|
## @example Redirect to `show` method of `ArticlesController` with id = 2
|
51
56
|
## redirect ArticlesController, :show, id: 2
|
52
57
|
def redirect(*params)
|
58
|
+
probably_url = params.first
|
59
|
+
probably_url = probably_url.to_s if probably_url.is_a? URI
|
53
60
|
response.redirect(
|
54
|
-
|
61
|
+
probably_url.is_a?(String) ? probably_url : path_to(*params)
|
55
62
|
)
|
56
63
|
end
|
57
64
|
|
58
|
-
|
59
|
-
|
65
|
+
## Set the Content-Disposition to "attachment" with the specified filename,
|
66
|
+
## instructing the user agents to prompt to save,
|
67
|
+
## and set Content-Type by filename.
|
68
|
+
## @param filename [String, nil] filename of attachment
|
69
|
+
## @param disposition [Symbol, String] main content for Content-Disposition
|
70
|
+
## @example Set Content-Disposition header without filename
|
71
|
+
## attachment
|
72
|
+
## @example Set Content-Disposition header with filename and Content-Type
|
73
|
+
## attachment 'style.css'
|
60
74
|
def attachment(filename = nil, disposition = :attachment)
|
61
75
|
content_dis = 'Content-Disposition'
|
62
76
|
response[content_dis] = disposition.to_s
|
@@ -88,7 +102,7 @@ module Flame
|
|
88
102
|
## @param method [Symbol] name of the controller method
|
89
103
|
def execute(method)
|
90
104
|
# send method
|
91
|
-
body send(method, *
|
105
|
+
body send(method, *extract_params_for(method).values)
|
92
106
|
end
|
93
107
|
|
94
108
|
## Default method for Internal Server Error, can be inherited
|
@@ -98,7 +112,7 @@ module Flame
|
|
98
112
|
|
99
113
|
private
|
100
114
|
|
101
|
-
def
|
115
|
+
def extract_params_for(action)
|
102
116
|
# p action, params, parameters
|
103
117
|
method(action).parameters.each_with_object({}) do |parameter, result|
|
104
118
|
key = parameter.last
|
data/lib/flame/dispatcher.rb
CHANGED
@@ -137,6 +137,11 @@ module Flame
|
|
137
137
|
"<h1>#{Rack::Utils::HTTP_STATUS_CODES[status]}</h1>"
|
138
138
|
end
|
139
139
|
|
140
|
+
## All cached tilts (views) for application by Flame::Render
|
141
|
+
def cached_tilts
|
142
|
+
@app.class.cached_tilts
|
143
|
+
end
|
144
|
+
|
140
145
|
private
|
141
146
|
|
142
147
|
## Find route and try execute it
|
@@ -161,7 +166,7 @@ module Flame
|
|
161
166
|
# p 'rescue from dispatcher'
|
162
167
|
dump_error(exception)
|
163
168
|
status 500
|
164
|
-
controller
|
169
|
+
controller&.send(:server_error, exception)
|
165
170
|
# p 're raise exception from dispatcher'
|
166
171
|
# raise exception
|
167
172
|
end
|
data/lib/flame/render.rb
CHANGED
@@ -11,17 +11,17 @@ require 'gorilla-patch/inflections'
|
|
11
11
|
module Flame
|
12
12
|
## Helper for render functionality
|
13
13
|
class Render
|
14
|
-
def initialize(
|
14
|
+
def initialize(controller, path, options = {})
|
15
15
|
## Take options for rendering
|
16
|
-
@
|
17
|
-
@scope = options.delete(:scope) || @
|
16
|
+
@controller = controller
|
17
|
+
@scope = options.delete(:scope) || @controller
|
18
18
|
@layout = options.delete(:layout)
|
19
19
|
@layout = 'layout.*' if @layout.nil?
|
20
20
|
## And get the rest variables to locals
|
21
21
|
@locals = options.merge(options.delete(:locals) || {})
|
22
22
|
## Find filename
|
23
23
|
@filename = find_file(path)
|
24
|
-
# @
|
24
|
+
# @controller.instance_exec { halt 404 } unless @filename
|
25
25
|
return unless @filename
|
26
26
|
@layout = nil if File.basename(@filename)[0] == '_'
|
27
27
|
end
|
@@ -39,25 +39,17 @@ module Flame
|
|
39
39
|
|
40
40
|
private
|
41
41
|
|
42
|
-
class << self
|
43
|
-
# private
|
44
|
-
|
45
|
-
def tilts
|
46
|
-
@tilts ||= {}
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
42
|
def views_dir
|
51
|
-
@
|
43
|
+
@controller.config[:views_dir]
|
52
44
|
end
|
53
45
|
|
54
46
|
## Compile file with Tilt engine
|
55
47
|
## @param filename [String] filename
|
56
48
|
def compile_file(filename = @filename)
|
57
|
-
cached =
|
49
|
+
cached = @controller.cached_tilts[filename]
|
58
50
|
return cached if @cache && cached
|
59
51
|
compiled = Tilt.new(filename)
|
60
|
-
|
52
|
+
@controller.cached_tilts[filename] ||= compiled if @cache
|
61
53
|
compiled
|
62
54
|
end
|
63
55
|
|
@@ -95,8 +87,12 @@ module Flame
|
|
95
87
|
|
96
88
|
## Find possible directories for the controller
|
97
89
|
def controller_dirs
|
98
|
-
parts = @
|
99
|
-
|
90
|
+
parts = @controller.class.underscore.split('/').map do |part|
|
91
|
+
%w[_controller _ctrl]
|
92
|
+
.find { |suffix| part.chomp! suffix }
|
93
|
+
part
|
94
|
+
## Alternative, but slower by ~50%:
|
95
|
+
# part.sub(/_(controller|ctrl)$/, '')
|
100
96
|
end
|
101
97
|
combine_parts(parts).map! { |path| path.join('/') }
|
102
98
|
end
|
data/lib/flame/route.rb
CHANGED
@@ -73,7 +73,15 @@ module Flame
|
|
73
73
|
|
74
74
|
## Compare by path parts count (more is matter)
|
75
75
|
def <=>(other)
|
76
|
-
other.path_parts
|
76
|
+
self_parts, other_parts = [self, other].map(&:path_parts)
|
77
|
+
path_parts_size = other_parts.size <=> self_parts.size
|
78
|
+
return path_parts_size unless path_parts_size.zero?
|
79
|
+
other_parts.zip(self_parts)
|
80
|
+
.reduce(0) do |result, (other_part, self_part)|
|
81
|
+
break 1 if part_arg?(self_part) && !part_arg?(other_part)
|
82
|
+
break -1 if part_arg?(other_part) && !part_arg?(self_part)
|
83
|
+
result
|
84
|
+
end
|
77
85
|
end
|
78
86
|
|
79
87
|
def self.path_merge(*parts)
|
@@ -82,6 +90,10 @@ module Flame
|
|
82
90
|
|
83
91
|
private
|
84
92
|
|
93
|
+
def part_arg?(part)
|
94
|
+
part.start_with? ARG_CHAR
|
95
|
+
end
|
96
|
+
|
85
97
|
## Helpers for `compare_attributes`
|
86
98
|
def compare_attribute(name, value)
|
87
99
|
case name
|
@@ -117,7 +129,7 @@ module Flame
|
|
117
129
|
def request_contain_required_path_parts?(request_parts)
|
118
130
|
req_path_parts = @path_parts.reject { |part| part[1] == ARG_CHAR_OPT }
|
119
131
|
fixed_path_parts = @path_parts.reject { |part| part[0] == ARG_CHAR }
|
120
|
-
(
|
132
|
+
(fixed_path_parts - request_parts).empty? &&
|
121
133
|
request_parts.count >= req_path_parts.count
|
122
134
|
end
|
123
135
|
|
data/lib/flame/version.rb
CHANGED
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: 4.12.
|
4
|
+
version: 4.12.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -127,6 +127,9 @@ dependencies:
|
|
127
127
|
- - "~>"
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: '1.1'
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 1.1.1
|
130
133
|
type: :development
|
131
134
|
prerelease: false
|
132
135
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -134,6 +137,9 @@ dependencies:
|
|
134
137
|
- - "~>"
|
135
138
|
- !ruby/object:Gem::Version
|
136
139
|
version: '1.1'
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 1.1.1
|
137
143
|
- !ruby/object:Gem::Dependency
|
138
144
|
name: rack-test
|
139
145
|
requirement: !ruby/object:Gem::Requirement
|