lux-fw 0.2.3 → 0.5.32
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 +33 -0
- data/bin/build_gem +76 -0
- data/bin/cli/config.rb +44 -0
- data/bin/cli/console.rb +61 -0
- data/bin/cli/dbconsole.rb +8 -0
- data/bin/cli/eval.rb +32 -0
- data/bin/cli/generate.rb +88 -0
- data/bin/cli/get.rb +12 -0
- data/bin/cli/new.rb +22 -0
- data/bin/cli/routes.rb +90 -0
- data/bin/cli/secrets.rb +40 -0
- data/bin/cli/server.rb +24 -0
- data/bin/cli/stats.rb +133 -0
- data/bin/lux +24 -65
- data/lib/common/class_attributes.rb +40 -64
- data/lib/common/class_callbacks.rb +34 -51
- data/lib/common/crypt.rb +10 -8
- data/lib/common/free_struct.rb +42 -0
- data/lib/common/hash_with_indifferent_access.rb +1 -1
- data/lib/common/html_tag_builder.rb +26 -2
- data/lib/common/url.rb +58 -40
- data/lib/lux/application/application.rb +290 -117
- data/lib/lux/application/lib/nav.rb +64 -38
- data/lib/lux/application/lib/render.rb +2 -1
- data/lib/lux/cache/cache.rb +87 -62
- data/lib/lux/cache/lib/{ram.rb → memory.rb} +5 -7
- data/lib/lux/cache/lib/null.rb +6 -8
- data/lib/lux/config/config.rb +109 -52
- data/lib/lux/config/lib/plugin.rb +65 -0
- data/lib/lux/config/lib/secrets.rb +48 -0
- data/lib/lux/controller/controller.rb +241 -0
- data/lib/lux/current/current.rb +33 -47
- data/lib/lux/current/lib/session.rb +72 -0
- data/lib/lux/delayed_job/delayed_job.rb +14 -7
- data/lib/lux/delayed_job/lib/memory.rb +7 -5
- data/lib/lux/delayed_job/lib/redis.rb +1 -1
- data/lib/lux/error/error.rb +164 -62
- data/lib/lux/event_bus/event_bus.rb +27 -0
- data/lib/lux/lux.rb +103 -66
- data/lib/lux/mailer/mailer.rb +23 -25
- data/lib/lux/response/lib/file.rb +81 -0
- data/lib/lux/response/lib/header.rb +14 -1
- data/lib/lux/response/response.rb +64 -56
- data/lib/lux/view/cell.rb +102 -0
- data/lib/lux/{helper → view}/helper.rb +39 -23
- data/lib/lux/view/lib/cell_helpers.rb +29 -0
- data/lib/lux/{helper/helpers/mailer_helper.rb → view/lib/helper_modules.rb} +7 -1
- data/lib/lux/{template/template.rb → view/view.rb} +21 -24
- data/lib/lux-fw.rb +4 -2
- data/lib/overload/array.rb +12 -6
- data/lib/overload/blank.rb +0 -1
- data/lib/overload/dir.rb +18 -0
- data/lib/overload/file.rb +1 -6
- data/lib/overload/hash.rb +56 -13
- data/lib/overload/integer.rb +2 -2
- data/lib/overload/it.rb +4 -4
- data/lib/overload/object.rb +37 -8
- data/lib/overload/{r.rb → raise_variants.rb} +23 -4
- data/lib/overload/string.rb +22 -6
- data/misc/demo/app/cells/demo_cell.rb +12 -0
- data/misc/demo/app/controllers/application_controller.rb +7 -0
- data/misc/demo/app/controllers/main/root_controller.rb +9 -0
- data/misc/demo/app/routes.rb +5 -0
- data/misc/demo/config/application.rb +14 -0
- data/misc/demo/config/assets.rb +6 -0
- data/misc/demo/config/environment.rb +7 -0
- data/misc/puma_auto_tune.rb +43 -0
- data/misc/unicorn.rb +37 -0
- data/{lib/lux → plugins}/api/api.rb +46 -29
- data/plugins/api/lib/attr.rb +31 -0
- data/{lib/lux → plugins}/api/lib/dsl.rb +3 -6
- data/{lib/lux → plugins}/api/lib/error.rb +0 -0
- data/{lib/lux → plugins}/api/lib/model_api.rb +51 -12
- data/{lib/lux → plugins}/api/lib/response.rb +31 -17
- data/{bin/cli/am → plugins/db/auto_migrate/auto_migrate.rb} +18 -35
- data/plugins/db/helpers/array_search.rb +27 -0
- data/plugins/db/helpers/before_save_filters.rb +32 -0
- data/plugins/db/helpers/composite_primary_keys.rb +36 -0
- data/plugins/db/helpers/core.rb +94 -0
- data/plugins/db/helpers/dataset_methods.rb +138 -0
- data/plugins/db/helpers/enums_plugin.rb +52 -0
- data/plugins/db/helpers/find_precache.rb +31 -0
- data/plugins/db/helpers/link_objects.rb +84 -0
- data/plugins/db/helpers/schema_checks.rb +83 -0
- data/plugins/db/helpers/typero_adapter.rb +71 -0
- data/plugins/db/logger/config.rb +22 -0
- data/plugins/db/logger/lux_response_adapter.rb +10 -0
- data/plugins/db/paginate/helper.rb +32 -0
- data/plugins/db/paginate/sequel_adapter.rb +23 -0
- data/plugins/exceptions/simple_exception.rb +64 -0
- data/plugins/favicon/favicon.rb +10 -0
- data/plugins/html/html_form.rb +118 -0
- data/plugins/html/html_input.rb +98 -0
- data/plugins/html/html_menu.rb +79 -0
- data/plugins/html/input_types.rb +346 -0
- data/plugins/js_widgets/js_widgets.rb +15 -0
- data/plugins/oauth/lib/facebook.rb +35 -0
- data/plugins/oauth/lib/github.rb +38 -0
- data/plugins/oauth/lib/google.rb +41 -0
- data/plugins/oauth/lib/linkedin.rb +41 -0
- data/plugins/oauth/lib/stackexchange.rb +41 -0
- data/plugins/oauth/lib/twitter.rb +38 -0
- data/plugins/oauth/oauth.rb +42 -0
- data/{lib/common → plugins/policy}/policy.rb +6 -7
- data/tasks/loader.rb +49 -0
- metadata +151 -49
- data/bin/cli/assets +0 -41
- data/bin/cli/console +0 -51
- data/bin/cli/dev +0 -1
- data/bin/cli/eval +0 -24
- data/bin/cli/exceptions +0 -62
- data/bin/cli/generate +0 -86
- data/bin/cli/get +0 -5
- data/bin/cli/nginx +0 -34
- data/bin/cli/production +0 -1
- data/bin/cli/render +0 -18
- data/bin/cli/routes +0 -14
- data/bin/cli/server +0 -4
- data/bin/cli/stat +0 -1
- data/bin/cli/systemd +0 -36
- data/bin/txt/nginx.conf +0 -46
- data/bin/txt/siege-and-puma.txt +0 -3
- data/lib/common/base32.rb +0 -47
- data/lib/common/dynamic_class.rb +0 -28
- data/lib/common/folder_model.rb +0 -50
- data/lib/common/generic_model.rb +0 -62
- data/lib/lux/application/lib/plugs.rb +0 -10
- data/lib/lux/application/lib/route_test.rb +0 -64
- data/lib/lux/cache/lib/memcached.rb +0 -3
- data/lib/lux/cell/cell.rb +0 -261
- data/lib/lux/current/lib/static_file.rb +0 -103
- data/lib/lux/helper/helpers/application_helper.rb +0 -3
- data/lib/lux/helper/helpers/html_helper.rb +0 -3
- data/lib/overload/auto_loader.rb +0 -27
- data/lib/overload/module.rb +0 -10
- data/lib/overload/string_inflections.rb +0 -8
data/lib/lux/cell/cell.rb
DELETED
@@ -1,261 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Cells can be called in few ways
|
4
|
-
# Cell.call path
|
5
|
-
# Cell.action action_name, path
|
6
|
-
# Cell.new.action_name *args
|
7
|
-
|
8
|
-
class Lux::Cell
|
9
|
-
# define maser layout
|
10
|
-
# string is template, symbol is metod pointer and lambda is lambda
|
11
|
-
ClassAttributes.define self, :layout
|
12
|
-
|
13
|
-
# define helper contest, by defult derived from class name
|
14
|
-
ClassAttributes.define self, :helper
|
15
|
-
|
16
|
-
# before and after any action filter, ignored in cells, after is called just before render
|
17
|
-
ClassCallbacks.define self, :before, :before_action, :before_render, :after
|
18
|
-
|
19
|
-
class << self
|
20
|
-
# class call method, should not be overridden
|
21
|
-
def call
|
22
|
-
Lux.current.files_in_use.push "app/cells/#{self.to_s.underscore}.rb"
|
23
|
-
|
24
|
-
cell = new
|
25
|
-
cell.filter :before
|
26
|
-
cell.call
|
27
|
-
|
28
|
-
return if Lux.current.response.body
|
29
|
-
|
30
|
-
# we want to exec filter after the call
|
31
|
-
cell.filter :before_action
|
32
|
-
end
|
33
|
-
|
34
|
-
# create mock function, to enable template rendering
|
35
|
-
# mock :index, :login
|
36
|
-
def mock *args
|
37
|
-
args.each do |el|
|
38
|
-
define_method el do
|
39
|
-
true
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# simple shortcut allows direct call to action, bypasing call
|
45
|
-
def action *args
|
46
|
-
new.action(*args)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
### INSTANCE METHODS
|
51
|
-
|
52
|
-
attr_reader :cell_action
|
53
|
-
|
54
|
-
def initialize
|
55
|
-
# before and after should be exected only once
|
56
|
-
@executed_filters = {}
|
57
|
-
@base_template = self.class.to_s.include?('::') ? self.class.to_s.sub(/Cell$/,'').underscore : self.class.to_s.sub(/Cell$/,'').downcase
|
58
|
-
end
|
59
|
-
|
60
|
-
# default call method, should be overitten
|
61
|
-
# expects arguments as flat array
|
62
|
-
# usually called by router
|
63
|
-
def call
|
64
|
-
action(:index)
|
65
|
-
end
|
66
|
-
|
67
|
-
# execute before and after filters, only once
|
68
|
-
def filter fiter_name
|
69
|
-
# move this to ClassCallbacks class?
|
70
|
-
return if @executed_filters[fiter_name]
|
71
|
-
@executed_filters[fiter_name] = true
|
72
|
-
|
73
|
-
ClassCallbacks.execute(self, fiter_name)
|
74
|
-
end
|
75
|
-
|
76
|
-
def cache *args, &block
|
77
|
-
Lux.cache.fetch *args, &block
|
78
|
-
end
|
79
|
-
|
80
|
-
# action(:show, 2)
|
81
|
-
# action(:select', ['users'])
|
82
|
-
def action method_name, *args
|
83
|
-
raise ArgumentError.new('Cell action called with blank action name argument') if method_name.blank?
|
84
|
-
|
85
|
-
# maybe before filter rendered page
|
86
|
-
return if response.body
|
87
|
-
|
88
|
-
method_name = method_name.to_s.gsub('-', '_').gsub(/[^\w]/, '')
|
89
|
-
|
90
|
-
Lux.log " #{self.class.to_s}(:#{method_name})".light_blue
|
91
|
-
Lux.current.files_in_use.push "app/cells/#{self.class.to_s.underscore}.rb"
|
92
|
-
|
93
|
-
@cell_action = method_name
|
94
|
-
|
95
|
-
unless respond_to? method_name
|
96
|
-
raise NotFoundError.new('Method %s not found' % method_name) unless Lux.config(:show_server_errors)
|
97
|
-
|
98
|
-
list = methods - Lux::Cell.instance_methods
|
99
|
-
err = [%[No instance method "#{method_name}" found in class "#{self.class.to_s}"]]
|
100
|
-
err.push ["Expected so see def show(id) ..."] if method_name == 'show!'
|
101
|
-
err.push %[You have defined \n- #{(list).join("\n- ")}]
|
102
|
-
return Lux.error(err.join("\n\n"))
|
103
|
-
end
|
104
|
-
|
105
|
-
filter :before
|
106
|
-
return if response.body
|
107
|
-
|
108
|
-
filter :before_action
|
109
|
-
return if response.body
|
110
|
-
|
111
|
-
send method_name, *args
|
112
|
-
filter :after
|
113
|
-
|
114
|
-
return if response.body
|
115
|
-
render
|
116
|
-
end
|
117
|
-
|
118
|
-
# render :show, id
|
119
|
-
# render :index
|
120
|
-
# render 'main/root/index'
|
121
|
-
# render :profile, name:'Dux'
|
122
|
-
# render text: 'ok'
|
123
|
-
def render name=nil, opts={}
|
124
|
-
return if response.body
|
125
|
-
return if @no_render
|
126
|
-
|
127
|
-
filter :before_render
|
128
|
-
|
129
|
-
if name.is_hash?
|
130
|
-
opts = name
|
131
|
-
name = nil
|
132
|
-
end
|
133
|
-
|
134
|
-
opts[:template] = name if name
|
135
|
-
|
136
|
-
render_resolve_body opts
|
137
|
-
|
138
|
-
Lux.cache.set(opts[:cache], response.body) if opts[:cache]
|
139
|
-
end
|
140
|
-
|
141
|
-
# renders template to string
|
142
|
-
def render_part
|
143
|
-
Lux::Template.render_part("#{@base_template}/#{@cell_action}", instance_variables_hash, namespace)
|
144
|
-
end
|
145
|
-
|
146
|
-
def render_to_string name=nil, opts={}
|
147
|
-
opts[:set_page_body] = false
|
148
|
-
render name, opts
|
149
|
-
end
|
150
|
-
|
151
|
-
def send_file
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
private
|
156
|
-
# called be render
|
157
|
-
def render_resolve_body opts
|
158
|
-
# resolve basic types
|
159
|
-
if opts[:text]
|
160
|
-
response.content_type = 'text/plain'
|
161
|
-
return response.body(opts[:text])
|
162
|
-
elsif opts[:html]
|
163
|
-
response.content_type = 'text/html'
|
164
|
-
return response.body(opts[:html])
|
165
|
-
elsif opts[:json]
|
166
|
-
response.content_type = 'application/json'
|
167
|
-
return response.body(opts[:json])
|
168
|
-
end
|
169
|
-
|
170
|
-
# resolve page data, without template
|
171
|
-
page_data = opts[:data] || Proc.new do
|
172
|
-
if template = opts.delete(:template)
|
173
|
-
template = template.to_s
|
174
|
-
template = "#{@base_template}/#{template}" unless template.starts_with?('/')
|
175
|
-
else
|
176
|
-
template = "#{@base_template}/#{@cell_action}"
|
177
|
-
end
|
178
|
-
|
179
|
-
Lux::Template.render_part(template, helper)
|
180
|
-
end.call
|
181
|
-
|
182
|
-
# resolve data with layout
|
183
|
-
layout = opts.delete(:layout)
|
184
|
-
layout = nil if layout.class == TrueClass
|
185
|
-
layout = false if @layout.class == FalseClass
|
186
|
-
|
187
|
-
if layout.class != FalseClass
|
188
|
-
layout_define = layout || self.class.layout
|
189
|
-
|
190
|
-
layout = case layout_define
|
191
|
-
when String
|
192
|
-
layout = layout_define
|
193
|
-
when Symbol
|
194
|
-
send(layout_define)
|
195
|
-
when Proc
|
196
|
-
layout_define.call
|
197
|
-
else
|
198
|
-
"#{@base_template.split('/')[0]}/layout"
|
199
|
-
end
|
200
|
-
|
201
|
-
page_data = Lux::Template.new(layout, helper).render_part do
|
202
|
-
page_data
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
response.body(page_data) unless opts[:set_page_body].is_false?
|
207
|
-
|
208
|
-
page_data
|
209
|
-
end
|
210
|
-
|
211
|
-
def etag *args
|
212
|
-
response.etag *args
|
213
|
-
end
|
214
|
-
|
215
|
-
def halt status, desc=nil
|
216
|
-
response.status = status
|
217
|
-
response.body = desc || "Hatlt code #{status}"
|
218
|
-
|
219
|
-
throw :done
|
220
|
-
end
|
221
|
-
|
222
|
-
# helper functions
|
223
|
-
def current
|
224
|
-
Lux.current
|
225
|
-
end
|
226
|
-
|
227
|
-
def request
|
228
|
-
Lux.current.request
|
229
|
-
end
|
230
|
-
|
231
|
-
def response
|
232
|
-
Lux.current.response
|
233
|
-
end
|
234
|
-
|
235
|
-
def params
|
236
|
-
Lux.current.params
|
237
|
-
end
|
238
|
-
|
239
|
-
def nav
|
240
|
-
Lux.current.nav
|
241
|
-
end
|
242
|
-
|
243
|
-
def redirect where, flash={}
|
244
|
-
Lux.current.redirect where, flash
|
245
|
-
end
|
246
|
-
|
247
|
-
def session
|
248
|
-
Lux.current.session
|
249
|
-
end
|
250
|
-
|
251
|
-
def namespace
|
252
|
-
@base_template.split('/')[0].to_sym
|
253
|
-
end
|
254
|
-
|
255
|
-
def helper ns=nil
|
256
|
-
Lux::Helper.new self, :html, self.class.helper, ns
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
ApplicationCell = Class.new Lux::Cell
|
261
|
-
|
@@ -1,103 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Lux::Current::StaticFile
|
4
|
-
MIMME_TYPES = {
|
5
|
-
txt: 'text/plain',
|
6
|
-
html: 'text/html',
|
7
|
-
gif: 'image/gif',
|
8
|
-
jpg: 'image/jpeg',
|
9
|
-
jpeg: 'image/jpeg',
|
10
|
-
png: 'image/png',
|
11
|
-
ico: 'image/png', # image/x-icon
|
12
|
-
css: 'text/css',
|
13
|
-
map: 'application/json',
|
14
|
-
js: 'application/javascript',
|
15
|
-
gz: 'application/x-gzip',
|
16
|
-
zip: 'application/x-gzip',
|
17
|
-
svg: 'image/svg+xml',
|
18
|
-
mp3: 'application/mp3',
|
19
|
-
woff: 'application/x-font-woff',
|
20
|
-
woff2: 'application/x-font-woff',
|
21
|
-
ttf: 'application/font-ttf',
|
22
|
-
eot: 'application/vnd.ms-fontobject',
|
23
|
-
otf: 'application/font-otf',
|
24
|
-
doc: 'application/msword'
|
25
|
-
}
|
26
|
-
|
27
|
-
class << self
|
28
|
-
def deliver file
|
29
|
-
new(file).deliver
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
###
|
34
|
-
|
35
|
-
def initialize file
|
36
|
-
@file = file
|
37
|
-
end
|
38
|
-
|
39
|
-
def c
|
40
|
-
Lux.current
|
41
|
-
end
|
42
|
-
|
43
|
-
def is_static_file?
|
44
|
-
return false unless @file.index('.')
|
45
|
-
|
46
|
-
path = @file.split('/')
|
47
|
-
path.pop
|
48
|
-
|
49
|
-
file = path.shift
|
50
|
-
ext = @file.split('.').last
|
51
|
-
|
52
|
-
return false if ext.to_s.length == 0
|
53
|
-
return false unless MIMME_TYPES[ext.to_sym]
|
54
|
-
|
55
|
-
true
|
56
|
-
end
|
57
|
-
|
58
|
-
def resolve_content_type
|
59
|
-
mimme = MIMME_TYPES[@ext.to_sym]
|
60
|
-
|
61
|
-
unless mimme
|
62
|
-
c.response.body('Mimme type not supported')
|
63
|
-
c.response.status(406)
|
64
|
-
return
|
65
|
-
end
|
66
|
-
|
67
|
-
c.response.content_type = mimme
|
68
|
-
end
|
69
|
-
|
70
|
-
def deliver data=nil
|
71
|
-
file = File.exist?(@file) ? @file : Lux.root.join("public#{@file}")
|
72
|
-
|
73
|
-
unless File.exists?(file)
|
74
|
-
if @file == '/favicon.ico'
|
75
|
-
file = Lux.fw_root.join('misc/lux.png')
|
76
|
-
else
|
77
|
-
raise NotFoundError, %[Static file not found]
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
@ext = file.to_s.split('.').last
|
82
|
-
|
83
|
-
resolve_content_type
|
84
|
-
|
85
|
-
file_mtime = File.mtime(file).utc.to_s
|
86
|
-
key = Crypt.sha1(file+file_mtime.to_s)
|
87
|
-
|
88
|
-
c.response.headers['cache-control'] = 'max-age=31536000, public'
|
89
|
-
c.response.headers['etag'] = '"%s"' % key
|
90
|
-
c.response.headers['last-modified'] = file_mtime
|
91
|
-
|
92
|
-
# IF etags match, returnfrom cache
|
93
|
-
if c.request.env['HTTP_IF_NONE_MATCH'] == key
|
94
|
-
c.response.status(304)
|
95
|
-
c.response.body('not-modified')
|
96
|
-
return
|
97
|
-
end
|
98
|
-
|
99
|
-
c.response.body data || File.read(file)
|
100
|
-
|
101
|
-
true
|
102
|
-
end
|
103
|
-
end
|
data/lib/overload/auto_loader.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
def constantize
|
3
|
-
Object.const_get('::'+self)
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
class Object
|
8
|
-
def self.const_missing klass
|
9
|
-
file = klass.to_s.tableize.singularize
|
10
|
-
paths = [
|
11
|
-
'models',
|
12
|
-
'lib',
|
13
|
-
'vendor',
|
14
|
-
file.split('_').last.pluralize
|
15
|
-
].map { |it| './app/%s/%s.rb' % [it, file] }
|
16
|
-
|
17
|
-
klass_file = paths.find { |it| File.exist?(it) } or
|
18
|
-
raise NameError.new('Can not find and autoload class "%s", looked in %s' % [klass, paths.map{ |it| "\n#{it}" }.join('')])
|
19
|
-
|
20
|
-
# puts '* autoload: %s from %s' % [file, klass_file]
|
21
|
-
|
22
|
-
require klass_file
|
23
|
-
|
24
|
-
Object.const_get(klass)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
data/lib/overload/module.rb
DELETED