lux-fw 0.1.35 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.version +1 -1
- data/bin/cli/am +67 -41
- data/bin/cli/assets +1 -1
- data/bin/cli/console +3 -2
- data/bin/cli/eval +11 -2
- data/bin/cli/exceptions +1 -1
- data/bin/cli/generate +4 -0
- data/bin/cli/render +18 -0
- data/bin/cli/routes +3 -1
- data/bin/cli/server +4 -1
- data/bin/lux +10 -1
- data/bin/txt/nginx.conf +35 -18
- data/lib/common/class_attributes.rb +10 -10
- data/lib/common/{before_and_after.rb → class_callbacks.rb} +12 -21
- data/lib/common/crypt.rb +10 -6
- data/lib/common/dynamic_class.rb +12 -7
- data/lib/common/generic_model.rb +6 -6
- data/lib/common/hash_with_indifferent_access.rb +6 -284
- data/lib/{lux/helper/lib/html_tag.rb → common/html_tag_builder.rb} +1 -1
- data/lib/common/policy.rb +2 -2
- data/lib/common/url.rb +6 -4
- data/lib/lux-fw.rb +2 -13
- data/lib/lux/api/api.rb +34 -47
- data/lib/lux/api/lib/dsl.rb +2 -2
- data/lib/lux/api/lib/model_api.rb +40 -23
- data/lib/lux/api/lib/response.rb +30 -5
- data/lib/lux/application/application.rb +182 -0
- data/lib/lux/{controller → application}/lib/nav.rb +18 -21
- data/lib/lux/application/lib/plugs.rb +10 -0
- data/lib/lux/application/lib/render.rb +58 -0
- data/lib/lux/application/lib/route_test.rb +64 -0
- data/lib/lux/cache/cache.rb +27 -16
- data/lib/lux/cell/cell.rb +66 -54
- data/lib/lux/config/config.rb +51 -27
- data/lib/lux/current/current.rb +122 -0
- data/lib/lux/{page → current}/lib/encrypt_params.rb +2 -2
- data/lib/lux/{page → current}/lib/static_file.rb +29 -25
- data/lib/lux/delayed_job/delayed_job.rb +4 -4
- data/lib/lux/error/error.rb +31 -16
- data/lib/lux/helper/helper.rb +32 -37
- data/lib/lux/helper/helpers/application_helper.rb +3 -0
- data/lib/lux/helper/helpers/html_helper.rb +3 -0
- data/lib/lux/helper/helpers/mailer_helper.rb +11 -0
- data/lib/lux/lux.rb +40 -30
- data/lib/lux/mailer/mailer.rb +46 -29
- data/lib/lux/{page → response}/lib/flash.rb +1 -1
- data/lib/lux/response/lib/header.rb +21 -0
- data/lib/lux/response/response.rb +237 -0
- data/lib/lux/template/template.rb +20 -18
- data/lib/overload/array.rb +5 -0
- data/lib/overload/auto_loader.rb +27 -0
- data/lib/overload/blank.rb +8 -2
- data/lib/overload/float.rb +10 -0
- data/lib/overload/hash.rb +5 -12
- data/lib/overload/integer.rb +1 -5
- data/lib/overload/nil.rb +5 -0
- data/lib/overload/object.rb +1 -0
- data/lib/overload/r.rb +5 -0
- data/lib/overload/string.rb +4 -5
- data/lib/overload/{date.rb → time.rb} +23 -3
- metadata +37 -73
- data/bin/forever +0 -65
- data/bin/job_que +0 -39
- data/lib/lux/api/lib/application_api.rb +0 -38
- data/lib/lux/api/lib/doc_builder.rb +0 -19
- data/lib/lux/api/lib/rescue.rb +0 -8
- data/lib/lux/controller/controller.rb +0 -185
- data/lib/lux/controller/lib/plugs.rb +0 -10
- data/lib/lux/html/html.rb +0 -3
- data/lib/lux/html/lib/form.rb +0 -81
- data/lib/lux/html/lib/input.rb +0 -71
- data/lib/lux/html/lib/input_types.rb +0 -287
- data/lib/lux/lib/lux.rb +0 -51
- data/lib/lux/page/lib/response.rb +0 -178
- data/lib/lux/page/page.rb +0 -292
- data/lib/lux/rescue_from/rescue_from.rb +0 -63
- data/lib/plugins/assets/assets_plug.rb +0 -31
- data/lib/plugins/assets/helper_module_adapter.rb +0 -51
- data/lib/plugins/assets/init.rb +0 -4
- data/lib/plugins/db_helpers/array_and_hstore.rb +0 -64
- data/lib/plugins/db_helpers/arrays_and_tags.rb +0 -23
- data/lib/plugins/db_helpers/before_save.rb +0 -44
- data/lib/plugins/db_helpers/cached_find_by.rb +0 -45
- data/lib/plugins/db_helpers/class_and_instance.rb +0 -120
- data/lib/plugins/db_helpers/dataset_plugin.rb +0 -101
- data/lib/plugins/db_helpers/filter_wrappers.rb +0 -21
- data/lib/plugins/db_helpers/link_plugin.rb +0 -95
- data/lib/plugins/db_helpers/localize_plugin.rb +0 -57
- data/lib/plugins/db_helpers/primary_keys.rb +0 -36
- data/lib/plugins/db_helpers/typero_attributes.rb +0 -69
- data/lib/plugins/db_logger/init.rb +0 -18
- data/lib/plugins/db_logger/lux_response_adapter.rb +0 -9
- data/lib/plugins/paginate/helper.rb +0 -32
- data/lib/plugins/paginate/sequel_adapter.rb +0 -18
- data/lib/vendor/mini_assets/lib/asset.rb +0 -71
- data/lib/vendor/mini_assets/lib/asset/css.rb +0 -19
- data/lib/vendor/mini_assets/lib/asset/js.rb +0 -17
- data/lib/vendor/mini_assets/lib/base.rb +0 -69
- data/lib/vendor/mini_assets/lib/base/javascript.rb +0 -13
- data/lib/vendor/mini_assets/lib/base/stylesheet.rb +0 -5
- data/lib/vendor/mini_assets/lib/manifest.rb +0 -18
- data/lib/vendor/mini_assets/lib/opts.rb +0 -16
- data/lib/vendor/mini_assets/mini_assets.rb +0 -74
- data/lib/vendor/oauth/lib/facebook.rb +0 -35
- data/lib/vendor/oauth/lib/github.rb +0 -37
- data/lib/vendor/oauth/lib/google.rb +0 -41
- data/lib/vendor/oauth/lib/linkedin.rb +0 -41
- data/lib/vendor/oauth/lib/stackexchange.rb +0 -37
- data/lib/vendor/oauth/lib/twitter.rb +0 -41
- data/lib/vendor/oauth/oauth.rb +0 -46
data/lib/lux/page/page.rb
DELETED
@@ -1,292 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# we need this for command line
|
4
|
-
Thread.current[:lux] ||= { cache: {} }
|
5
|
-
|
6
|
-
class Lux::Page
|
7
|
-
attr_accessor :headers, :cookies, :session, :files_in_use
|
8
|
-
attr_reader :params, :request, :nav
|
9
|
-
|
10
|
-
BeforeAndAfter.define self, :before, :after
|
11
|
-
|
12
|
-
class << self
|
13
|
-
# expects Rack env object but can acceept url
|
14
|
-
# we need this for testing
|
15
|
-
def prepare env
|
16
|
-
env = Rack::MockRequest.env_for(env) if env.class == String
|
17
|
-
request = Rack::Request.new env
|
18
|
-
page = Lux::Page.new request
|
19
|
-
|
20
|
-
# reset page cache
|
21
|
-
Thread.current[:lux] = { cache:{}, page:page }
|
22
|
-
|
23
|
-
page
|
24
|
-
end
|
25
|
-
|
26
|
-
# default rack env call
|
27
|
-
def call env=nil
|
28
|
-
prepare(env).render
|
29
|
-
rescue
|
30
|
-
Lux::Error.log $!
|
31
|
-
|
32
|
-
raise $! if Lux.config(:show_server_errors)
|
33
|
-
|
34
|
-
[500, {}, ['Lux server error']]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
###
|
39
|
-
|
40
|
-
def initialize request
|
41
|
-
@files_in_use = []
|
42
|
-
@request = request
|
43
|
-
@headers = {}
|
44
|
-
@cookies = {}
|
45
|
-
@session = {}
|
46
|
-
|
47
|
-
@render_start = Time.now
|
48
|
-
|
49
|
-
for cookie in request.env['HTTP_COOKIE'].to_s.split(/;\s*/).map{ |el| el.split('=',2) }
|
50
|
-
@cookies[cookie[0]] = cookie[1]
|
51
|
-
end
|
52
|
-
|
53
|
-
@session = @cookies['__luxs'] ? (JSON.parse Crypt.decrypt @cookies['__luxs'] rescue {}) : {}
|
54
|
-
|
55
|
-
# check for session
|
56
|
-
if Lux.dev? && request.env['HTTP_REFERER'] && request.env['HTTP_REFERER'].index(request.host) && @session.keys.length == 0
|
57
|
-
puts "ERROR: There is no session set!".red
|
58
|
-
end
|
59
|
-
|
60
|
-
# hard sec, bind session to user agent and IP
|
61
|
-
check = get_client_unique_hash
|
62
|
-
@session = {} if @session['_c'] && @session['_c'] != check
|
63
|
-
@session['_c'] = check
|
64
|
-
|
65
|
-
@session = HashWithIndifferentAccess.new(@session)
|
66
|
-
|
67
|
-
if request.post? && Lux.config(:log_to_stdout)
|
68
|
-
ap request.params
|
69
|
-
end
|
70
|
-
|
71
|
-
@params = request.params.h_wia
|
72
|
-
Lux::Page::EncryptParams.decrypt @params
|
73
|
-
|
74
|
-
@nav = Lux::Controller::Nav.new request
|
75
|
-
end
|
76
|
-
|
77
|
-
def get_client_unique_hash
|
78
|
-
Crypt.md5(@request.ip.to_s+@request.env['HTTP_USER_AGENT'].to_s)
|
79
|
-
end
|
80
|
-
|
81
|
-
def status num=nil
|
82
|
-
Lux.log caller if num == 500
|
83
|
-
return @status if @status
|
84
|
-
if num
|
85
|
-
if num.is_numeric?
|
86
|
-
@status ||= num.to_i
|
87
|
-
else
|
88
|
-
@status = case num.to_s
|
89
|
-
when 'StandardError'; 400
|
90
|
-
when 'BadRequestError'; 400
|
91
|
-
when 'UnauthorizedError'; 401
|
92
|
-
when 'ForbidenError'; 403
|
93
|
-
when 'NotFoundError'; 404
|
94
|
-
when 'RateLimitError'; 503
|
95
|
-
else; 500
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
@status
|
101
|
-
end
|
102
|
-
|
103
|
-
def body what=nil
|
104
|
-
@body ||= what
|
105
|
-
|
106
|
-
if @body && block_given?
|
107
|
-
@body = yield @body
|
108
|
-
Lux.error 'Lux.page.body is not a string (bad page.body filter)' unless @body.is_a?(String)
|
109
|
-
end
|
110
|
-
|
111
|
-
@body
|
112
|
-
end
|
113
|
-
|
114
|
-
def body= what
|
115
|
-
body(what)
|
116
|
-
end
|
117
|
-
|
118
|
-
def body! what
|
119
|
-
@body = what
|
120
|
-
end
|
121
|
-
|
122
|
-
def flash message=nil
|
123
|
-
@flash ||= Flash.new @session[:lux_flash]
|
124
|
-
|
125
|
-
message ? @flash.error(message) : @flash
|
126
|
-
end
|
127
|
-
|
128
|
-
def base_domain
|
129
|
-
host = Lux.page.request.host.split('.')
|
130
|
-
host_country = host.pop
|
131
|
-
host_name = host.pop
|
132
|
-
host_name ? "#{host_name}.#{host_country}" : host_country
|
133
|
-
end
|
134
|
-
|
135
|
-
def var
|
136
|
-
Thread.current[:lux][:var] ||= Hashie::Mash.new
|
137
|
-
end
|
138
|
-
|
139
|
-
def host
|
140
|
-
"#{request.env['rack.url_scheme']}://#{request.host}:#{request.port}".sub(':80','')# rescue 'http://locahost:3000'
|
141
|
-
end
|
142
|
-
|
143
|
-
def no_cache? force=nil
|
144
|
-
return false if !force && Lux.prod?
|
145
|
-
@request.env['HTTP_CACHE_CONTROL'] == 'no-cache' ? true : false
|
146
|
-
rescue
|
147
|
-
false
|
148
|
-
end
|
149
|
-
|
150
|
-
def header name, value=:_
|
151
|
-
name = name.downcase
|
152
|
-
@headers[name] = value if value != :_
|
153
|
-
@headers[name]
|
154
|
-
end
|
155
|
-
|
156
|
-
def redirect where=nil, opts={}
|
157
|
-
return @headers['location'] unless where
|
158
|
-
|
159
|
-
@status = opts.delete(:status) || 302
|
160
|
-
opts.map { |k,v| flash.send(k, v) }
|
161
|
-
|
162
|
-
@headers['location'] = where.index('//') ? where : "#{host}#{where}"
|
163
|
-
@body = %[redirecting to #{@headers['location']}\n\n#{opts.values.join("\n")}]
|
164
|
-
end
|
165
|
-
|
166
|
-
def permanent_redirect where
|
167
|
-
redirect where, status:301
|
168
|
-
end
|
169
|
-
|
170
|
-
def content_type type=nil
|
171
|
-
return @content_type unless type
|
172
|
-
|
173
|
-
# can be set only once
|
174
|
-
return @content_type if @content_type
|
175
|
-
|
176
|
-
type = 'application/json' if type == :json
|
177
|
-
type = 'text/plain' if type == :text
|
178
|
-
type = 'text/html' if type == :html
|
179
|
-
|
180
|
-
raise 'Invalid page content-type %s' % type if type === Symbol
|
181
|
-
|
182
|
-
@content_type = type
|
183
|
-
end
|
184
|
-
|
185
|
-
def content_type= type
|
186
|
-
content_type type
|
187
|
-
end
|
188
|
-
|
189
|
-
def etag *args
|
190
|
-
@headers['etag'] ||= 'W/"%s"' % Lux.cache.generate_key(args)
|
191
|
-
|
192
|
-
if @request.env['HTTP_IF_NONE_MATCH'] == @headers['etag']
|
193
|
-
@status = 304
|
194
|
-
body! 'not-modified'
|
195
|
-
# print ' %s>' % Lux.page.status if Lux.config(:log_to_stdout)
|
196
|
-
true
|
197
|
-
else
|
198
|
-
false
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
# execute action once per page
|
203
|
-
def once id, data=nil
|
204
|
-
@once_hash ||= {}
|
205
|
-
return false if @once_hash[id]
|
206
|
-
@once_hash[id] = true
|
207
|
-
yield if block_given?
|
208
|
-
data || true
|
209
|
-
end
|
210
|
-
|
211
|
-
def write_response_body
|
212
|
-
# if @body is not set, this is error now
|
213
|
-
unless @body
|
214
|
-
@status = 500
|
215
|
-
@body = 'Page BODY not defined. Maybe you did not call cell action but method instad.'
|
216
|
-
end
|
217
|
-
|
218
|
-
# respond as JSON if we recive hash
|
219
|
-
if @body.kind_of?(Hash)
|
220
|
-
@body = Lux.dev? ? JSON.pretty_generate(@body) : JSON.generate(@body)
|
221
|
-
|
222
|
-
if Lux.page.request.params[:callback]
|
223
|
-
@body = "#{@request.params[:callback]}(#{ret})"
|
224
|
-
@content_type ||= 'text/javascript'
|
225
|
-
else
|
226
|
-
@content_type ||= 'application/json'
|
227
|
-
end
|
228
|
-
|
229
|
-
@body += "\n"
|
230
|
-
else
|
231
|
-
# if somebody sets @content_type, respect that
|
232
|
-
@body = @body.to_s unless @body.kind_of?(String)
|
233
|
-
@content_type ||= 'text/plain' if @body[0,1] != '<'
|
234
|
-
@content_type ||= 'text/html'
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
def write_response_header
|
239
|
-
domain =
|
240
|
-
if request.host =~ %r{^[\d\.]+$} # if request is IP
|
241
|
-
request.host
|
242
|
-
else
|
243
|
-
base_domain.index('.') ? ".#{base_domain}" : base_domain
|
244
|
-
end
|
245
|
-
|
246
|
-
@session[:lux_flash] = flash.to_h
|
247
|
-
|
248
|
-
# skip adding of cookies and time to strong etag parameters
|
249
|
-
if !@headers['etag'] || @headers['etag'].index('/')
|
250
|
-
@headers['set-cookie'] = "__luxs=#{Crypt.encrypt(@session.to_json)}; Expires=#{(Time.now+1.month).utc}; Path=/; Domain=#{domain};"
|
251
|
-
@headers['x-lux-speed'] = "#{((Time.now-@render_start)*1000).round(1)}ms"
|
252
|
-
end
|
253
|
-
|
254
|
-
@headers['content-type'] ||= "#{@content_type}; charset=utf-8"
|
255
|
-
|
256
|
-
# if "no-store" is present then HTTP_IF_NONE_MATCH is not sent from browser
|
257
|
-
@headers['cache-control'] ||= 'must-revalidate, %s, max-age=0' % (Lux.page.var.user ? :private : :public)
|
258
|
-
|
259
|
-
Lux.page.etag(@body) if Lux.page.request.request_method == 'GET'
|
260
|
-
end
|
261
|
-
|
262
|
-
def write_response
|
263
|
-
write_response_body
|
264
|
-
write_response_header
|
265
|
-
|
266
|
-
@status ||= 200
|
267
|
-
Lux.log " #{@status}, #{@headers['x-lux-speed']}"
|
268
|
-
|
269
|
-
if ENV['LUX_PRINT_ROUTES']
|
270
|
-
print '* Finished route print '
|
271
|
-
puts @status == 404 ? 'without a match'.red : 'with a match'.green
|
272
|
-
exit
|
273
|
-
end
|
274
|
-
|
275
|
-
[@status, @headers, [@body]]
|
276
|
-
end
|
277
|
-
|
278
|
-
def render
|
279
|
-
Lux.log "\n#{Lux.page.request.request_method.white} #{Lux.page.request.path.white}"
|
280
|
-
|
281
|
-
Lux::Config.live_require_check! if Lux.config(:auto_code_reload)
|
282
|
-
|
283
|
-
BeforeAndAfter.execute(self, :before)
|
284
|
-
Lux::Controller.new.rescued_main
|
285
|
-
BeforeAndAfter.execute(self, :after)
|
286
|
-
|
287
|
-
write_response
|
288
|
-
end
|
289
|
-
|
290
|
-
end
|
291
|
-
|
292
|
-
|
@@ -1,63 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# rescue from errors
|
4
|
-
#
|
5
|
-
# in some class
|
6
|
-
# Lux::RescueFrom.define(self) -> defines rescue_from method in class
|
7
|
-
#
|
8
|
-
# to add
|
9
|
-
# rescue_from(UnauthorizedError) { ... }
|
10
|
-
#
|
11
|
-
# and to resolve in the end
|
12
|
-
# @@rescue_from_ivar.call { main }
|
13
|
-
|
14
|
-
class Lux::RescueFrom
|
15
|
-
|
16
|
-
class << self
|
17
|
-
def define klass
|
18
|
-
ClassAttributes.define klass, :rescue_from_hash
|
19
|
-
|
20
|
-
klass.class_eval %[
|
21
|
-
@@rescue_from_ivar = Lux::RescueFrom.new
|
22
|
-
def self.rescue_from(name, &block)
|
23
|
-
@@rescue_from_ivar.add(name, &block)
|
24
|
-
end
|
25
|
-
]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
###
|
30
|
-
|
31
|
-
def initialize
|
32
|
-
@rescues = {}
|
33
|
-
end
|
34
|
-
|
35
|
-
def add name, &block
|
36
|
-
die ":#{name} is not allowed rescue name, only allowed are :default and :allways" if name.is_symbol? && ![:default, :allways].index(name)
|
37
|
-
@rescues[name.to_s] = block
|
38
|
-
end
|
39
|
-
|
40
|
-
# we pass context so we can execute errors it object context
|
41
|
-
def call context
|
42
|
-
begin
|
43
|
-
yield
|
44
|
-
rescue Exception => e
|
45
|
-
raise e unless Lux.page
|
46
|
-
|
47
|
-
return if Lux.page.body && Lux.page.status
|
48
|
-
|
49
|
-
if proc = @rescues[e.class.to_s]
|
50
|
-
proc.call(e.message)
|
51
|
-
context.instance_exec e.message, &proc
|
52
|
-
elsif proc = @rescues['default'] # catch them all
|
53
|
-
context.instance_exec e.message, &proc
|
54
|
-
else
|
55
|
-
raise e
|
56
|
-
end
|
57
|
-
|
58
|
-
context.instance_exec e.message, &@rescues['allways'] if @rescues['allways']
|
59
|
-
|
60
|
-
Lux.page.status e.class
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# plug :local_assets
|
2
|
-
# /compiled_asset/www/js/pjax.coffee
|
3
|
-
# /raw_asset/www/js/pjax.coffee
|
4
|
-
class Lux::Controller
|
5
|
-
def lux_assets_plug
|
6
|
-
|
7
|
-
# only allow clear in dev
|
8
|
-
# clear assets every 4 seconds max
|
9
|
-
if Lux.page.no_cache?
|
10
|
-
Lux.cache.fetch('lux-clear-assets', ttl: 4, log: false, force: false) do
|
11
|
-
puts '* Clearing assets from ./tmp/assets'.yellow
|
12
|
-
`rm -rf ./tmp/assets && mkdir ./tmp/assets`
|
13
|
-
true
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
path = nav.path.join('/')
|
18
|
-
|
19
|
-
if nav.root == 'compiled_asset'
|
20
|
-
asset = MiniAssets::Asset.call(path)
|
21
|
-
page.content_type asset.content_type
|
22
|
-
page.body asset.render
|
23
|
-
|
24
|
-
elsif nav.root == 'raw_asset'
|
25
|
-
Lux.error "You can watch raw files only in development" unless Lux.dev?
|
26
|
-
|
27
|
-
file = Lux.root.join('app/assets/%s' % path)
|
28
|
-
body file.exist? ? file.read : "error: File not found"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# export to all templates
|
2
|
-
# = asset 'www/index.scss'
|
3
|
-
# = asset 'www/index.coffee'
|
4
|
-
module DefaultHelper
|
5
|
-
def asset_include path
|
6
|
-
raise ArgumentError.new("Path can't be empty") if path.empty?
|
7
|
-
|
8
|
-
url = if path.starts_with?('/') || path.include?('//')
|
9
|
-
path
|
10
|
-
else
|
11
|
-
'/compiled_asset/%s' % path
|
12
|
-
end
|
13
|
-
|
14
|
-
ext = url.split('?').first.split('.').last
|
15
|
-
|
16
|
-
if ['coffee', 'js'].include?(ext)
|
17
|
-
%[<script src="#{url}"></script>]
|
18
|
-
else
|
19
|
-
%[<link rel="stylesheet" href="#{url}" />]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# builds full asset path based on resource extension
|
24
|
-
# asset('main/index.coffee')
|
25
|
-
# will render 'app/assets/main/index.coffee' as http://aset.path/assets/main-index-md5hash.js
|
26
|
-
def asset file, dev_file=nil
|
27
|
-
# return second link if it is defined and we are in dev mode
|
28
|
-
return asset_include dev_file if dev_file && Lux.dev?
|
29
|
-
|
30
|
-
# return internet links
|
31
|
-
return asset_include file if file.starts_with?('/') || file.starts_with?('http')
|
32
|
-
|
33
|
-
# return asset link in production or faile unless able
|
34
|
-
unless Lux.config(:compile_assets)
|
35
|
-
@@__asset_menifest ||= MiniAssets::Manifest.new
|
36
|
-
mfile = @@__asset_menifest.get(file)
|
37
|
-
raise 'Compiled asset link for "%s" not found in manifest.json' % file if mfile.empty?
|
38
|
-
return asset_include Lux.config.assets_root.to_s + mfile
|
39
|
-
end
|
40
|
-
|
41
|
-
# try to create list of incuded files and show every one of them
|
42
|
-
data = []
|
43
|
-
asset = MiniAssets.new file
|
44
|
-
|
45
|
-
for file in asset.files
|
46
|
-
data.push asset_include file
|
47
|
-
end
|
48
|
-
|
49
|
-
data.join($/)
|
50
|
-
end
|
51
|
-
end
|
data/lib/plugins/assets/init.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
# inits and saves postgre
|
2
|
-
# string and integer arrays
|
3
|
-
# hstore as hash with indifferent access to keys
|
4
|
-
|
5
|
-
module Sequel::Plugins::LuxArrayAndHstore
|
6
|
-
module ClassMethods
|
7
|
-
end
|
8
|
-
|
9
|
-
module DatasetMethods
|
10
|
-
end
|
11
|
-
|
12
|
-
module InstanceMethods
|
13
|
-
# set right values on
|
14
|
-
def after_initialize
|
15
|
-
db_schema.each do |field, schema|
|
16
|
-
type = schema[:db_type]
|
17
|
-
if type.include?('[]') && !self[field].is_a?(Array)
|
18
|
-
self[field] = self[field].to_s.gsub(/^\{|\}$/, '').split(',')
|
19
|
-
self[field] = self[field].map(&:to_i) if schema[:type] == :integer
|
20
|
-
elsif type == 'jsonb'
|
21
|
-
self[field] ||= {}
|
22
|
-
self[field] = HashWithIndifferentAccess.new(JSON.load(self[field]) || {})
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def before_save
|
28
|
-
@_array_hash_cache_fields = {}
|
29
|
-
|
30
|
-
db_schema.each do |field, schema|
|
31
|
-
if schema[:db_type].include?('[]')
|
32
|
-
@_array_hash_cache_fields[field] = self[field].dup
|
33
|
-
|
34
|
-
data = self[field].to_a
|
35
|
-
data = data.map(&:to_i) if schema[:type] == :integer
|
36
|
-
|
37
|
-
db_data = data.to_json
|
38
|
-
db_data[0,1] = '{'
|
39
|
-
db_data[-1,1] = '}'
|
40
|
-
self[field] = db_data
|
41
|
-
elsif ['json', 'jsonb'].index(schema[:db_type])
|
42
|
-
@_array_hash_cache_fields[field] = self[field].dup
|
43
|
-
|
44
|
-
# we use this to convert symbols in keys to strings
|
45
|
-
self[field] = JSON.load(self[field].to_json).to_json
|
46
|
-
elsif schema[:db_type] == 'boolean'
|
47
|
-
self[field] = false if self[field] == 0
|
48
|
-
self[field] = true if self[field] == 1
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
super
|
53
|
-
end
|
54
|
-
|
55
|
-
def after_save
|
56
|
-
@_array_hash_cache_fields.each { |k, v| self[k] = v }
|
57
|
-
|
58
|
-
super
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
Sequel::Model.plugin :lux_array_and_hstore
|