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
@@ -0,0 +1,75 @@
|
|
1
|
+
class TimeDifference
|
2
|
+
TIMES ||= [
|
3
|
+
[:year, 60 * 60 * 24 * 365],
|
4
|
+
[:month, 60 * 60 * 24 * 30],
|
5
|
+
[:day, 60 * 60 * 24],
|
6
|
+
[:hour, 60 * 60],
|
7
|
+
[:minute, 60]
|
8
|
+
]
|
9
|
+
|
10
|
+
LOCALE ||= {
|
11
|
+
today: {
|
12
|
+
en: 'today',
|
13
|
+
hr: 'danas'
|
14
|
+
},
|
15
|
+
in: {
|
16
|
+
en: 'in',
|
17
|
+
hr: 'za'
|
18
|
+
},
|
19
|
+
before: {
|
20
|
+
en: 'before',
|
21
|
+
hr: 'prije'
|
22
|
+
},
|
23
|
+
in_few_econds: {
|
24
|
+
en: 'in few seconds',
|
25
|
+
hr: 'za par sekundi'
|
26
|
+
},
|
27
|
+
just_happend: {
|
28
|
+
en: 'just happend',
|
29
|
+
hr: 'upravo sada'
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
def initialize start_date, end_date = nil, klass = nil
|
34
|
+
unless end_date
|
35
|
+
@end_date = start_date
|
36
|
+
@start_date = Time.now
|
37
|
+
end
|
38
|
+
|
39
|
+
@klass = klass
|
40
|
+
end
|
41
|
+
|
42
|
+
def humanize
|
43
|
+
diff = (@start_date.to_i - @end_date.to_i).abs
|
44
|
+
|
45
|
+
if @klass == Date && diff < TIMES[2][1]
|
46
|
+
return locale(:today)
|
47
|
+
# @start_date < @end_date ? locale(:in_few_econds) : locale(:just_happend)
|
48
|
+
end
|
49
|
+
|
50
|
+
TIMES.each do |(key, ref)|
|
51
|
+
value = diff / ref
|
52
|
+
return part(key, value) if value > 0
|
53
|
+
end
|
54
|
+
|
55
|
+
@start_date < @end_date ? locale(:in_few_econds) : locale(:just_happend)
|
56
|
+
end
|
57
|
+
|
58
|
+
# def set_locale key, value
|
59
|
+
# raise ArgumentError.new('Key not found') unless locale(key)
|
60
|
+
|
61
|
+
# LOCALE[key] = value
|
62
|
+
# end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def part key, value
|
67
|
+
kind = @start_date < @end_date ? locale(:in) : locale(:before)
|
68
|
+
text = [value, value > 1 ? '%ss' % key : key].join(' ')
|
69
|
+
[kind, text].join(' ')
|
70
|
+
end
|
71
|
+
|
72
|
+
def locale name
|
73
|
+
LOCALE[name][:en]
|
74
|
+
end
|
75
|
+
end
|
data/lib/loader.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
Encoding.default_internal = Encoding.default_external = 'utf-8'
|
2
|
+
|
3
|
+
Sequel.extension :inflector
|
4
|
+
Sequel::Model.plugin :after_initialize
|
5
|
+
Sequel::Model.plugin :def_dataset_method
|
6
|
+
|
7
|
+
Sequel.database_timezone = :utc
|
8
|
+
# Sequel.default_timezone = +2
|
9
|
+
|
10
|
+
# load basic lux libs
|
11
|
+
require_relative './overload/dir'
|
12
|
+
require_relative './lux/lux'
|
13
|
+
|
14
|
+
Lux::Config.set_defaults
|
15
|
+
|
16
|
+
# load all lux libs
|
17
|
+
[:overload, :common, :lux].each do |f|
|
18
|
+
Dir.require_all Lux.fw_root.join('./lib/%s' % f)
|
19
|
+
end
|
20
|
+
|
21
|
+
String.inflections do |inflect|
|
22
|
+
# inflect.plural /^(ox)$/i, '\1\2en'
|
23
|
+
# inflect.singular /^(ox)en/i, '\1'
|
24
|
+
# inflect.irregular 'octopus', 'octopi'
|
25
|
+
inflect.plural 'bonus', 'bonuses'
|
26
|
+
inflect.plural 'clothing', 'clothes'
|
27
|
+
inflect.plural 'people', 'people'
|
28
|
+
inflect.singular /news$/, 'news'
|
29
|
+
inflect.singular /Data$/i, 'Data'
|
30
|
+
end
|
31
|
+
|
32
|
+
# load Tilt parsers
|
33
|
+
Haml::Template.options[:escape_html] = false
|
34
|
+
# Tilt.register Tilt::ERBTemplate, 'erb'
|
35
|
+
# Tilt.register Haml::Template, 'haml'
|
36
|
+
|
37
|
+
# ensure we are not loading lux in lux folder
|
38
|
+
if Lux.root != Lux.fw_root
|
39
|
+
# create folders if needed
|
40
|
+
['./log', './tmp'].each { |d| `mkdir #{d}` unless Dir.exist?(d) }
|
41
|
+
end
|
@@ -1,57 +1,15 @@
|
|
1
|
-
## Lux::Application
|
1
|
+
## Lux.app (Lux::Application)
|
2
2
|
|
3
|
-
|
4
|
-
* calls `before`, `routes` and `after` class filters on every request
|
5
|
-
* routes requests to controllers via `map`, `root` and `call` methods
|
6
|
-
|
7
|
-
### Instance methods
|
8
|
-
|
9
|
-
#### root
|
10
|
-
|
11
|
-
executes if nav.root is empty
|
12
|
-
|
13
|
-
#### map
|
14
|
-
|
15
|
-
map specific nav root to Controller and calls if root mathes
|
16
|
-
|
17
|
-
for example if path is /blogs
|
18
|
-
|
19
|
-
`map blogs: Main::BlogController`
|
20
|
-
|
21
|
-
will call instance method call with @path expanded
|
22
|
-
|
23
|
-
`Main::BlogController.new.call(*@path)`
|
24
|
-
|
25
|
-
more examples
|
26
|
-
|
27
|
-
* `map blog: BlogController` will call `BlogController.action(:blog)`
|
28
|
-
* `map blog: 'blog#single'` will call `BlogController.action(:single)`
|
29
|
-
* `map blog: -> { BlogController.custom(:whatever) }`
|
30
|
-
|
31
|
-
### call
|
32
|
-
|
33
|
-
Calls specific controller action inside call.
|
34
|
-
|
35
|
-
```ruby
|
36
|
-
call 'main/links#index'
|
37
|
-
call [Main::LinksController, :index]
|
38
|
-
call -> { [200, {}, ['OK']]}
|
39
|
-
```
|
40
|
-
|
41
|
-
### Router example
|
3
|
+
Main application controller and router
|
42
4
|
|
43
|
-
|
44
|
-
|
45
|
-
* taget can be 5 object variants, look at root example
|
46
|
-
* "root" method calls object if nav.root is blank?
|
47
|
-
* "map" method calls object if nav.first == match
|
48
|
-
* "namespace" method accepts block that wraps map calls.
|
5
|
+
* can capture errors with `rescue_from` class method
|
6
|
+
* calls `before`, `routes` and `after` class filters on every request
|
49
7
|
|
50
8
|
```ruby
|
51
9
|
Lux.app do
|
52
10
|
|
53
11
|
def api_router
|
54
|
-
error :forbiden, 'Only POST requests are allowed' if Lux.prod? && !post?
|
12
|
+
error :forbiden, 'Only POST requests are allowed' if Lux.env.prod? && !post?
|
55
13
|
Lux::Api.call nav.path
|
56
14
|
end
|
57
15
|
|
@@ -63,40 +21,48 @@ Lux.app do
|
|
63
21
|
error 404
|
64
22
|
end
|
65
23
|
|
24
|
+
rescue_from :all do |error|
|
25
|
+
case error
|
26
|
+
when PG::ConnectionBad
|
27
|
+
# ...
|
28
|
+
when Lux::Error
|
29
|
+
# ...
|
30
|
+
else
|
31
|
+
end
|
32
|
+
|
66
33
|
###
|
67
34
|
|
68
35
|
routes do
|
69
36
|
# we show on root method, that target can be multiple object types, 5 variants
|
37
|
+
# this target is valid target for any of the follwing methods: get, post, map, call, root
|
70
38
|
root [RootController, :index] # calls RootController#index
|
71
|
-
root 'root#
|
72
|
-
root
|
73
|
-
|
74
|
-
root 'root
|
75
|
-
|
76
|
-
#
|
77
|
-
|
78
|
-
|
79
|
-
#
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
map :search # map "/search" to MainController#search
|
86
|
-
map '/login' # map "/login" to MainController#login
|
39
|
+
root 'root#index' # calls RootController#index
|
40
|
+
root 'root' # calls RootController#call
|
41
|
+
|
42
|
+
root 'main/root'
|
43
|
+
|
44
|
+
# simple route, only for GET
|
45
|
+
map.about 'static#about' if get?
|
46
|
+
|
47
|
+
# execute blok if request_type is POST
|
48
|
+
post? do
|
49
|
+
# map "/api" to "api_router" method
|
50
|
+
map.api :api_router
|
51
|
+
# or
|
52
|
+
map api: :api_router
|
87
53
|
end
|
88
54
|
|
89
55
|
# map "/foo/dux/baz" route to MainController#foo with params[:bar] == 'dux'
|
90
56
|
map '/foo/:bar/baz' => 'main#foo'
|
91
57
|
|
92
|
-
#
|
93
|
-
|
58
|
+
# call method "city_map", if it returns true, proceed
|
59
|
+
map :city do
|
94
60
|
# call MainController#city if request.method == 'GET'
|
95
|
-
map 'main#city'
|
61
|
+
map 'main#city'
|
96
62
|
end
|
97
63
|
|
98
64
|
# if we match '/foo' route
|
99
|
-
|
65
|
+
map 'foo' do
|
100
66
|
# call MainController#foo with params[:bar] == '...'
|
101
67
|
map '/baz/:bar' => 'main#foo'
|
102
68
|
end
|
@@ -104,44 +70,40 @@ Lux.app do
|
|
104
70
|
end
|
105
71
|
```
|
106
72
|
|
107
|
-
|
73
|
+
#### Instance methods
|
108
74
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
#
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
75
|
+
* routes requests to controllers via `map`, `root` and `call` methods
|
76
|
+
* taget can be 3 object variants, look at the `call` example
|
77
|
+
* `map` maps requests to controller actions
|
78
|
+
* `map.about => 'main#about' if get?` -> map '/about' to `MainControler#about` if request is `GET`
|
79
|
+
* `map about: 'main#about'` -> map '/about' to `MainControler#about`
|
80
|
+
* `root` will call only for root
|
81
|
+
* `map.about => 'main#about' if get?` -> map '/about' to `MainControler#about` if request is `GET`
|
82
|
+
* `map about: 'main#about'` -> map '/about' to `MainControler#about`
|
83
|
+
* `call` calls specific controller action inside call - stops routing parsing
|
84
|
+
* `call 'main/links#index'` - call `Main::LinksController#index`
|
85
|
+
* `call [Main::LinksController, :index]` - call `Main::LinksController#index`
|
86
|
+
* `call -> { [200, {}, ['OK']]}` - return HTTP 200 - OK
|
87
|
+
|
88
|
+
#### Class filters
|
89
|
+
|
90
|
+
There are a few route filtes
|
91
|
+
* `config` # pre boot app config
|
92
|
+
* `boot` # after rack app boot (web only)
|
93
|
+
* `info` # called by "lux config" cli
|
94
|
+
* `before` # before any page load
|
95
|
+
* `routes` # routes resolve
|
96
|
+
* `after` # after any page load
|
97
|
+
* `rescue_from` # on routing error
|
98
|
+
|
99
|
+
|
100
|
+
#### Router example
|
132
101
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
102
|
+
For Lux routing you need to know only few things
|
103
|
+
|
104
|
+
* `get?`, `post?`, `delete?`, ... will be true of false based HTTP_REQUEST type
|
105
|
+
* `get? { @exec_if_true }` works as well
|
106
|
+
* `map"`method accepts block that wraps map calls.
|
107
|
+
* `map :city do ...` will call `city_map` method. it has to return falsey if no match
|
108
|
+
* `map 'city' do ...` will check if we are under `/city/*` nav namespace
|
137
109
|
|
138
|
-
if Lux.prod?
|
139
|
-
Lux.config.error_logger = proc do |error|
|
140
|
-
# log and show error page in a production
|
141
|
-
key = SimpleException.log error
|
142
|
-
Lux.cache.fetch('error-mail-%s' % key) { Mailer.error(error, key).deliver }
|
143
|
-
Lux.logger(:exceptions).error [key, User.current.try(:email).or('guest'), error.message].join(' - ')
|
144
|
-
key
|
145
|
-
end
|
146
|
-
end
|
147
|
-
```
|