lux-fw 0.5.36 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.version +1 -1
- data/bin/README.md +26 -13
- data/bin/cli/benchmark.rb +18 -0
- data/bin/cli/cerb.rb +90 -0
- data/bin/cli/config.rb +4 -11
- data/bin/cli/console.rb +72 -30
- data/bin/cli/eval.rb +5 -27
- data/bin/cli/generate.rb +9 -11
- data/bin/cli/get.rb +14 -6
- data/bin/cli/memory.rb +12 -0
- data/bin/cli/new.rb +2 -0
- data/bin/cli/secrets.rb +3 -31
- data/bin/cli/server.rb +28 -9
- data/bin/cli/stats.rb +26 -20
- data/bin/cli/template.rb +10 -0
- data/bin/generate_doc +168 -0
- data/bin/lux +73 -10
- data/lib/README.md +18 -8
- data/lib/common/crypt.rb +60 -9
- data/lib/common/string_base.rb +54 -15
- data/lib/common/struct_opts.rb +30 -0
- data/lib/common/time_difference.rb +75 -0
- data/lib/loader.rb +41 -0
- data/lib/lux/application/README.md +67 -105
- data/lib/lux/application/application.rb +87 -329
- data/lib/lux/application/lib/magic_routes.rb +22 -0
- data/lib/lux/application/lib/nav.rb +218 -99
- data/lib/lux/application/lib/render.rb +47 -67
- data/lib/lux/application/lib/routes.rb +242 -0
- data/lib/lux/application/lib/shared.rb +47 -0
- data/lib/lux/application/lux_adapter.rb +6 -0
- data/lib/lux/application/lux_config.rb +26 -0
- data/lib/lux/cache/Find Results +24 -0
- data/lib/lux/cache/README.md +28 -35
- data/lib/lux/cache/cache.rb +78 -26
- data/lib/lux/cache/lib/memcached_server.rb +36 -0
- data/lib/lux/cache/lib/memory_server.rb +44 -0
- data/lib/lux/cache/lib/null_server.rb +33 -0
- data/lib/lux/cache/lib/sqlite_server.rb +62 -0
- data/lib/lux/cache/lux_adapter.rb +19 -0
- data/lib/lux/config/config.rb +93 -144
- data/lib/lux/config/lux_adapter.rb +27 -0
- data/lib/lux/controller/README.md +67 -12
- data/lib/lux/controller/controller.rb +237 -187
- data/lib/lux/current/README.md +29 -10
- data/lib/lux/current/current.rb +166 -77
- data/lib/lux/current/lib/current.rb +6 -0
- data/lib/lux/current/lib/encrypt_params.rb +38 -36
- data/lib/lux/current/lib/session.rb +86 -65
- data/lib/lux/current/lux_adapter.rb +5 -0
- data/lib/lux/environment/README.md +24 -0
- data/lib/lux/environment/environment.rb +91 -0
- data/lib/lux/environment/lux_adapter.rb +13 -0
- data/lib/lux/error/README.md +18 -19
- data/lib/lux/error/error.rb +207 -152
- data/lib/lux/error/lux_adapter.rb +9 -0
- data/lib/lux/logger/README.md +45 -0
- data/lib/lux/logger/lux_adapter.rb +27 -0
- data/lib/lux/lux.rb +72 -129
- data/lib/lux/mailer/README.md +12 -5
- data/lib/lux/mailer/lux_config.rb +4 -0
- data/lib/lux/mailer/mailer.rb +81 -59
- data/lib/lux/plugin/README.md +19 -0
- data/lib/lux/plugin/lux_adapter.rb +8 -0
- data/lib/lux/plugin/plugin.rb +65 -0
- data/lib/lux/render/README.md +100 -0
- data/lib/lux/render/render.rb +12 -0
- data/lib/lux/response/README.md +57 -1
- data/lib/lux/response/lib/file.rb +87 -65
- data/lib/lux/response/lib/flash.rb +49 -34
- data/lib/lux/response/lib/header.rb +34 -33
- data/lib/lux/response/response.rb +252 -164
- data/lib/lux/template/helper.rb +130 -0
- data/lib/lux/template/inline_render_proxy.rb +31 -0
- data/lib/lux/template/lux_adapter.rb +5 -0
- data/lib/lux/template/template.rb +127 -0
- data/lib/lux-fw.rb +15 -33
- data/lib/overload/array.rb +33 -7
- data/lib/overload/blank.rb +8 -3
- data/lib/overload/boolean.rb +46 -0
- data/lib/overload/class.rb +28 -0
- data/lib/overload/dir.rb +117 -7
- data/lib/overload/file.rb +40 -5
- data/lib/overload/float.rb +38 -3
- data/lib/overload/hash.rb +81 -91
- data/lib/overload/integer.rb +15 -0
- data/lib/overload/json.rb +26 -0
- data/lib/overload/nil.rb +4 -8
- data/lib/overload/object.rb +91 -24
- data/lib/overload/pathname.rb +11 -0
- data/lib/overload/raise_variants.rb +26 -36
- data/lib/overload/string.rb +100 -27
- data/lib/overload/thread_simple.rb +100 -0
- data/lib/overload/time.rb +60 -38
- data/tasks/loader.rb +20 -7
- metadata +170 -169
- data/bin/.DS_Store +0 -0
- data/bin/build_gem +0 -77
- data/bin/cli/dbconsole.rb +0 -8
- data/bin/cli/routes.rb +0 -90
- data/lib/.DS_Store +0 -0
- data/lib/common/.DS_Store +0 -0
- data/lib/common/class_attributes.rb +0 -51
- data/lib/common/class_callbacks.rb +0 -47
- data/lib/common/free_struct.rb +0 -42
- data/lib/common/hash_with_indifferent_access.rb +0 -74
- data/lib/common/html_tag_builder.rb +0 -91
- data/lib/common/method_attr.rb +0 -69
- data/lib/common/url.rb +0 -191
- data/lib/lux/.DS_Store +0 -0
- data/lib/lux/README.md +0 -10
- data/lib/lux/cache/.DS_Store +0 -0
- data/lib/lux/cache/lib/memory.rb +0 -36
- data/lib/lux/cache/lib/null.rb +0 -21
- data/lib/lux/config/README.md +0 -63
- data/lib/lux/config/lib/plugin.rb +0 -65
- data/lib/lux/config/lib/secrets.rb +0 -48
- data/lib/lux/current/.DS_Store +0 -0
- data/lib/lux/delayed_job/.DS_Store +0 -0
- data/lib/lux/delayed_job/README.md +0 -3
- data/lib/lux/delayed_job/delayed_job.rb +0 -51
- data/lib/lux/delayed_job/lib/memory.rb +0 -16
- data/lib/lux/delayed_job/lib/nsq.rb +0 -3
- data/lib/lux/delayed_job/lib/postgre.rb +0 -6
- data/lib/lux/delayed_job/lib/redis.rb +0 -19
- data/lib/lux/event_bus/README.md +0 -36
- data/lib/lux/event_bus/event_bus.rb +0 -27
- data/lib/lux/view/README.md +0 -85
- data/lib/lux/view/cell.rb +0 -102
- data/lib/lux/view/helper.rb +0 -120
- data/lib/lux/view/lib/cell_helpers.rb +0 -29
- data/lib/lux/view/view.rb +0 -95
- data/lib/overload/it.rb +0 -29
- data/plugins/api/README.md +0 -49
- data/plugins/api/api.rb +0 -153
- data/plugins/api/lib/attr.rb +0 -31
- data/plugins/api/lib/dsl.rb +0 -52
- data/plugins/api/lib/error.rb +0 -3
- data/plugins/api/lib/model_api.rb +0 -203
- data/plugins/api/lib/response.rb +0 -85
- data/plugins/db/.DS_Store +0 -0
- data/plugins/db/README.md +0 -29
- data/plugins/db/auto_migrate/auto_migrate.rb +0 -268
- data/plugins/db/auto_migrate/db.rake +0 -15
- data/plugins/db/helpers/array_search.rb +0 -27
- data/plugins/db/helpers/before_save_filters.rb +0 -32
- data/plugins/db/helpers/composite_primary_keys.rb +0 -36
- data/plugins/db/helpers/core.rb +0 -94
- data/plugins/db/helpers/dataset_methods.rb +0 -138
- data/plugins/db/helpers/enums_plugin.rb +0 -52
- data/plugins/db/helpers/find_precache.rb +0 -31
- data/plugins/db/helpers/link_objects.rb +0 -84
- data/plugins/db/helpers/schema_checks.rb +0 -83
- data/plugins/db/helpers/typero_adapter.rb +0 -71
- data/plugins/db/logger/config.rb +0 -22
- data/plugins/db/logger/lux_response_adapter.rb +0 -10
- data/plugins/db/paginate/helper.rb +0 -32
- data/plugins/db/paginate/sequel_adapter.rb +0 -23
- data/plugins/exceptions/exceptions.rake +0 -43
- data/plugins/exceptions/simple_exception.rb +0 -64
- data/plugins/favicon/favicon.rb +0 -10
- data/plugins/html/README.md +0 -3
- data/plugins/html/html_form.rb +0 -118
- data/plugins/html/html_input.rb +0 -98
- data/plugins/html/html_menu.rb +0 -79
- data/plugins/html/input_types.rb +0 -346
- data/plugins/js_widgets/README.md +0 -5
- data/plugins/js_widgets/js/html_tag.coffee +0 -42
- data/plugins/js_widgets/js/widgets.coffee +0 -161
- data/plugins/js_widgets/js_widgets.rb +0 -15
- data/plugins/oauth/lib/facebook.rb +0 -35
- data/plugins/oauth/lib/github.rb +0 -38
- data/plugins/oauth/lib/google.rb +0 -41
- data/plugins/oauth/lib/linkedin.rb +0 -41
- data/plugins/oauth/lib/stackexchange.rb +0 -41
- data/plugins/oauth/lib/twitter.rb +0 -38
- data/plugins/oauth/oauth.rb +0 -42
- data/plugins/policy/policy.rb +0 -53
- data/tasks/nginx.rake +0 -23
- /data/lib/lux/{view/lib → mailer}/helper_modules.rb +0 -0
@@ -1,249 +1,299 @@
|
|
1
|
-
#
|
1
|
+
# filters stack for call - before, before_action, :action, after
|
2
|
+
# if action is missing capture it via def action_missing name
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
module Lux
|
5
|
+
class Controller
|
6
|
+
include ClassCallbacks
|
7
|
+
include ::Lux::Application::Shared
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
class_attribute :layout
|
9
|
+
# define master layout
|
10
|
+
# string is template, symbol is method pointer and lambda is lambda
|
11
|
+
cattr :layout, class: true
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
# define helper contest, by defult derived from class name
|
14
|
+
# cattr :helper, class: true
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
+
# custom template root instead calcualted one
|
17
|
+
cattr :template_root, default: './app/views', class: true
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
# before and after any action filter, ignored in controllers, after is called just before render
|
20
|
+
define_callback :before
|
21
|
+
define_callback :before_action
|
22
|
+
define_callback :before_render
|
23
|
+
|
24
|
+
class << self
|
25
|
+
# simple shortcut allows direct call to action, bypasing call
|
26
|
+
def action *args
|
27
|
+
new.action(*args)
|
28
|
+
end
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
30
|
+
# create mock function, to enable template rendering
|
31
|
+
# mock :index, :login
|
32
|
+
def mock *args
|
33
|
+
args.each do |el|
|
34
|
+
define_method(el) { true }
|
35
|
+
end
|
28
36
|
end
|
29
37
|
end
|
30
|
-
end
|
31
38
|
|
32
|
-
|
39
|
+
### INSTANCE METHODS
|
33
40
|
|
34
|
-
|
41
|
+
IVARS ||= Struct.new 'LuxControllerIvars', :template_sufix, :action, :layout, :render_cache
|
42
|
+
RENDER_OPTS ||= Struct.new 'LuxControllerRenderOpts', :inline, :text, :plain, :html, :json, :javascript, :xml, :cache, :template, :layout, :render_to_string, :status, :ttl, :content_type
|
35
43
|
|
36
|
-
|
37
|
-
# before and after should be exected only once
|
38
|
-
@executed_filters = {}
|
39
|
-
@base_template = self.class.to_s.include?('::') ? self.class.to_s.sub(/Controller$/,'').underscore : self.class.to_s.sub(/Controller$/,'').downcase
|
40
|
-
end
|
44
|
+
attr_reader :controller_action
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
def initialize
|
47
|
+
# before and after should be exected only once
|
48
|
+
@lux = IVARS.new
|
49
|
+
@lux.template_sufix = self.class.to_s.sub(/Controller$/,'').underscore.downcase.split('/').first
|
50
|
+
end
|
47
51
|
|
48
|
-
|
49
|
-
|
52
|
+
# action(:show)
|
53
|
+
# action(:select', ['users'])
|
54
|
+
def action method_name, *args
|
55
|
+
if method_name.blank?
|
56
|
+
raise ArgumentError.new('Controller action called with blank action name argument')
|
57
|
+
end
|
50
58
|
|
51
|
-
|
52
|
-
|
53
|
-
|
59
|
+
if method_name.is_a?(Symbol)
|
60
|
+
raise Lux.error.internal_server_error('Forbiden action name :%s' % method_name) if [:action, :error].include?(method_name)
|
61
|
+
else
|
62
|
+
return controller_action_call(method_name, *args)
|
63
|
+
end
|
54
64
|
|
55
|
-
|
56
|
-
# action(:select', ['users'])
|
57
|
-
def action method_name, *args
|
58
|
-
raise ArgumentError.new('Controller action called with blank action name argument') if method_name.blank?
|
65
|
+
method_name = method_name.to_s.gsub('-', '_').gsub(/[^\w]/, '')
|
59
66
|
|
60
|
-
|
67
|
+
# dev console log
|
68
|
+
Lux.log { ' %s#%s (action)'.light_blue % [self.class, method_name] }
|
69
|
+
# Lux.log { ' %s' % self.class.source_location }
|
61
70
|
|
62
|
-
|
63
|
-
Lux.log " #{self.class.to_s}##{method_name}".light_blue
|
71
|
+
@lux.action = method_name.to_sym
|
64
72
|
|
65
|
-
|
66
|
-
if @controller_format = current.nav.format
|
67
|
-
current.nav.format = nil
|
68
|
-
end
|
73
|
+
run_callback :before, @lux.action
|
69
74
|
|
70
|
-
|
71
|
-
|
75
|
+
catch :done do
|
76
|
+
unless response.body?
|
77
|
+
run_callback :before_action, @lux.action
|
72
78
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
79
|
+
# if action not found
|
80
|
+
if respond_to?(method_name)
|
81
|
+
send method_name, *args
|
82
|
+
else
|
83
|
+
action_missing method_name
|
84
|
+
end
|
85
|
+
|
86
|
+
render
|
87
|
+
end
|
88
|
+
end
|
89
|
+
rescue => error
|
90
|
+
rescue_from error
|
78
91
|
end
|
79
92
|
|
80
|
-
|
93
|
+
def timeout seconds
|
94
|
+
Lux.current.var[:app_timeout] = seconds
|
95
|
+
end
|
81
96
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
on_error(e)
|
86
|
-
end
|
97
|
+
def flash
|
98
|
+
response.flash
|
99
|
+
end
|
87
100
|
|
88
|
-
|
89
|
-
|
90
|
-
|
101
|
+
def rescue_from error
|
102
|
+
Lux::Error.log error
|
103
|
+
data = Lux.env.show_errors? ? Lux::Error.inline(error) : 'Server error: %s (%s)' % [error.message, error.class]
|
104
|
+
render html: data, status: 400
|
105
|
+
end
|
91
106
|
|
92
|
-
|
93
|
-
raise error
|
94
|
-
end
|
107
|
+
private
|
95
108
|
|
96
|
-
|
97
|
-
|
98
|
-
|
109
|
+
# delegated to current
|
110
|
+
define_method(:get?) { request.request_method == 'GET' }
|
111
|
+
define_method(:post?) { request.request_method == 'POST' }
|
112
|
+
define_method(:etag) { |*args| current.response.etag *args }
|
113
|
+
define_method(:layout) { |arg = :_nil| arg == :_nil ? @lux.layout : (@lux.layout = arg) }
|
114
|
+
define_method(:cache_control) { |arg| response.headers['cache-control'] = arg }
|
99
115
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
on_error Lux::Error.new(404, '%s document Not Found' % @controller_format.to_s.upcase) if @controller_format
|
116
|
+
# send file to browser
|
117
|
+
def send_file file, opts = {}
|
118
|
+
response.send_file(file, opts)
|
119
|
+
end
|
105
120
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
121
|
+
# does not set the body, returns body string
|
122
|
+
def render_to_string name=nil, opts={}
|
123
|
+
opts[:render_to_string] = true
|
124
|
+
render name, opts
|
110
125
|
end
|
111
126
|
|
112
|
-
|
127
|
+
# shortcut to render javascript
|
128
|
+
def render_javascript name=nil, opts={}
|
129
|
+
opts[:content_type] = :javascript
|
130
|
+
opts[:layout] = false
|
131
|
+
render name, opts
|
132
|
+
end
|
113
133
|
|
114
|
-
|
134
|
+
# render :index
|
135
|
+
# render 'main/root/index'
|
136
|
+
# render text: 'ok'
|
137
|
+
def render name = nil, opts = {}
|
138
|
+
return if response.body?
|
115
139
|
|
116
|
-
|
117
|
-
|
140
|
+
if name.class == Hash
|
141
|
+
opts.merge! name
|
142
|
+
else
|
143
|
+
opts[:template] = name
|
144
|
+
end
|
118
145
|
|
119
|
-
|
120
|
-
if opts.cache
|
121
|
-
Lux.cache.fetch(opts.cache, opts.ttl || 3600) { render_resolve(opts) }
|
122
|
-
else
|
123
|
-
render_resolve(opts)
|
124
|
-
end
|
146
|
+
opts = RENDER_OPTS.new **opts
|
125
147
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
response.body { page }
|
130
|
-
throw :done
|
131
|
-
end
|
132
|
-
end
|
148
|
+
# set response status and content_type
|
149
|
+
response.status opts.status if opts.status
|
150
|
+
response.content_type = opts.content_type if opts.content_type
|
133
151
|
|
134
|
-
|
135
|
-
|
136
|
-
render name, opts
|
137
|
-
end
|
152
|
+
# match rails nameing
|
153
|
+
opts.text = opts.plain if opts.plain
|
138
154
|
|
139
|
-
|
140
|
-
|
141
|
-
opts[:layout] = false
|
142
|
-
render name, opts
|
143
|
-
end
|
155
|
+
# copy value from render_cache
|
156
|
+
opts.cache = @lux.render_cache if @lux.render_cache
|
144
157
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
158
|
+
# we do not want to cache pages that have flashes in response
|
159
|
+
opts.cache = nil if response.flash.present?
|
160
|
+
|
161
|
+
# define which layout we use
|
162
|
+
opts.layout ||= @lux.layout.nil? ? self.class.cattr.layout : @lux.layout
|
163
|
+
|
164
|
+
# render static types
|
165
|
+
for el in [:text, :html, :json, :javascript, :xml]
|
166
|
+
if value = opts[el]
|
167
|
+
response.body value, content_type: el
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
data = if cache = opts.cache
|
172
|
+
return if etag(cache)
|
173
|
+
|
174
|
+
add_info = true
|
175
|
+
from_cache = Lux.cache.fetch opts.cache, ttl: 1_000_000 do
|
176
|
+
add_info = false
|
177
|
+
render_template(opts)
|
178
|
+
end
|
179
|
+
|
180
|
+
if add_info && from_cache
|
181
|
+
response.header['x-lux-cache'] = 'render-cache'
|
182
|
+
from_cache += '<!-- from page cache -->' if from_cache =~ %r{</html>\s*$}
|
183
|
+
end
|
184
|
+
|
185
|
+
from_cache
|
186
|
+
else
|
187
|
+
render_template(opts)
|
167
188
|
end
|
189
|
+
|
190
|
+
response.body data
|
168
191
|
end
|
169
192
|
|
170
|
-
|
171
|
-
|
193
|
+
def render_template opts
|
194
|
+
run_callback :before_render, @lux.action
|
172
195
|
|
173
|
-
|
174
|
-
layout = opts.layout
|
175
|
-
layout = nil if layout.class == TrueClass
|
176
|
-
layout = false if current.var[:controller_layout].class == FalseClass
|
196
|
+
local_helper = self.helper opts.layout.or(cattr.layout) # if layout is false (for dialogs) we fallback to controller default layout
|
177
197
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
layout_define = layout || self.class.layout
|
198
|
+
page_template = cattr.template_root + opts.template.to_s
|
199
|
+
Lux.current.var.root_template_path = page_template.sub(%r{/[\w]+$}, '')
|
200
|
+
data = opts.inline || Lux::Template.render(local_helper, page_template)
|
182
201
|
|
183
|
-
layout
|
184
|
-
|
185
|
-
|
186
|
-
when Symbol
|
187
|
-
send(layout_define)
|
188
|
-
when Proc
|
189
|
-
layout_define.call
|
190
|
-
else
|
191
|
-
'layouts/%s' % @base_template.split('/')[0]
|
202
|
+
if opts.layout
|
203
|
+
path = Lux::Template.find_layout cattr.template_root, opts.layout
|
204
|
+
data = Lux::Template.render(local_helper, path) { data }
|
192
205
|
end
|
193
206
|
|
194
|
-
|
207
|
+
data
|
195
208
|
end
|
196
|
-
end
|
197
209
|
|
198
|
-
|
199
|
-
|
200
|
-
template = template.to_s
|
201
|
-
template = "#{@base_template}/#{template}" unless template.starts_with?('/')
|
202
|
-
else
|
203
|
-
template = "#{@base_template}/#{@controller_action}"
|
210
|
+
def namespace
|
211
|
+
self.class.to_s.split('::').first.underscore.to_sym
|
204
212
|
end
|
205
213
|
|
206
|
-
|
207
|
-
|
214
|
+
def helper helper
|
215
|
+
helper = nil unless helper
|
216
|
+
Lux::Template::Helper.new self, :html, helper
|
217
|
+
end
|
218
|
+
|
219
|
+
# respond_to :js do ...
|
220
|
+
# respond_to do |format| ...
|
221
|
+
def respond_to ext=nil
|
222
|
+
if ext
|
223
|
+
if ext == nav.format
|
224
|
+
yield if block_given?
|
225
|
+
true
|
226
|
+
elsif nav.format
|
227
|
+
Lux.error.not_found '%s document Not Found' % nav.format.to_s.upcase
|
228
|
+
end
|
229
|
+
else
|
230
|
+
yield nav.format
|
231
|
+
end
|
232
|
+
end
|
208
233
|
|
209
|
-
|
210
|
-
|
211
|
-
|
234
|
+
def cache *args, &block
|
235
|
+
Lux.cache.fetch *args, &block
|
236
|
+
end
|
212
237
|
|
213
|
-
|
214
|
-
|
238
|
+
def render_cache key = :_nil
|
239
|
+
if key == :_nil
|
240
|
+
@lux.render_cache
|
241
|
+
else
|
242
|
+
unless @lux.render_cache == false
|
243
|
+
@lux.render_cache = key
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
215
247
|
|
216
|
-
|
217
|
-
|
218
|
-
end
|
248
|
+
def controller_action_call controller_action, *args
|
249
|
+
object, action = nil
|
219
250
|
|
220
|
-
|
221
|
-
|
222
|
-
|
251
|
+
if controller_action.is_a?(String)
|
252
|
+
object, action = controller_action.split('#') if controller_action.include?('#')
|
253
|
+
object = ('%s_controller' % object).classify.constantize
|
254
|
+
elsif object.is_a?(Array)
|
255
|
+
object, action = controller_action
|
256
|
+
else
|
257
|
+
raise ArgumentError.new('Not supported')
|
258
|
+
end
|
223
259
|
|
224
|
-
|
225
|
-
|
260
|
+
object.action action.to_sym, *args
|
261
|
+
end
|
226
262
|
|
227
|
-
|
228
|
-
|
263
|
+
def action_missing name
|
264
|
+
path = [cattr.template_root, @lux.template_sufix, name].join('/')
|
265
|
+
|
266
|
+
if template = Dir['%s.*' % path].first
|
267
|
+
unless Lux.config.use_autoroutes
|
268
|
+
raise 'Autoroute for "%s" is found but it is disabled in Lux.config.use_autoroutes' % name
|
269
|
+
end
|
270
|
+
|
271
|
+
self.class.define_method(name) {}
|
272
|
+
Lux.log ' created method %s#%s | found template %s'.yellow % [self.class, name, template]
|
273
|
+
return true
|
274
|
+
else
|
275
|
+
# if called via super from `action_missing', return false,
|
276
|
+
# so once can easily fallback to custom template search pattern
|
277
|
+
return false if caller[0].include?("`action_missing'")
|
278
|
+
end
|
229
279
|
|
230
|
-
|
231
|
-
end
|
280
|
+
message = 'Method "%s" not found found in "%s" (nav: %s).' % [name, self.class, nav]
|
232
281
|
|
233
|
-
|
234
|
-
|
235
|
-
|
282
|
+
if Lux.env.show_errors?
|
283
|
+
defined_methods = (methods - Lux::Controller.instance_methods).map(&:to_s)
|
284
|
+
defined = '<br /><br />Defined methods %s' % defined_methods.sort.to_ul
|
236
285
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
286
|
+
if Lux.config.use_autoroutes
|
287
|
+
root = [cattr.template_root, @lux.template_sufix].join('/')
|
288
|
+
files = Dir.files(root).sort.filter {|f| f =~ /^[a-z]/ }.map {|f| f.sub(/\.\w+$/, '') }
|
289
|
+
files = files - defined_methods
|
290
|
+
defined += '<br />Defined via templates in %s%s' % [root, files.to_ul]
|
291
|
+
else
|
292
|
+
defined += 'Defined templates - disabled'
|
293
|
+
end
|
243
294
|
end
|
244
|
-
|
245
|
-
|
295
|
+
|
296
|
+
raise Lux::Error.not_found [message, defined].join(' ')
|
246
297
|
end
|
247
298
|
end
|
248
|
-
|
249
299
|
end
|
data/lib/lux/current/README.md
CHANGED
@@ -1,14 +1,33 @@
|
|
1
|
-
## Lux::Current
|
1
|
+
## Lux.current (Lux::Current)
|
2
2
|
|
3
|
-
|
3
|
+
Lux handles state of the app in the single object, stored in `Thread.current`, available everywhere.
|
4
4
|
|
5
|
-
|
5
|
+
You are not forced to use this object, but you can if you want to.
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
```ruby
|
8
|
+
current.session # session, encoded in cookie
|
9
|
+
current.locale # locale, default nil
|
10
|
+
current.request # Rack request
|
11
|
+
current.response # Lux response object
|
12
|
+
current.nav # lux nav object
|
13
|
+
current.cookies # Rack cookies
|
14
|
+
current.can_clear_cache # set to true if user can force refresh cache
|
15
|
+
current.var # CleaHash to store global variables
|
16
|
+
current[:user] # current.var.user
|
17
|
+
current.uid # new unique ID in a page, per response
|
18
|
+
current.secure_token # Get or check current session secure token
|
14
19
|
|
20
|
+
# Execute only once in current scope
|
21
|
+
current.once { @data }
|
22
|
+
current.once(key, @data)
|
23
|
+
|
24
|
+
# Cache in current response scope
|
25
|
+
current.cache(key) {}
|
26
|
+
|
27
|
+
# Set current.can_clear_cache = true if user is able to clear cache with SHIFT+refresh
|
28
|
+
current.no_cache? # false
|
29
|
+
current.can_clear_cache = true
|
30
|
+
current.no_cache? # true if env['HTTP_CACHE_CONTROL'] == 'no-cache'
|
31
|
+
|
32
|
+
|
33
|
+
```
|