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.
Files changed (111) hide show
  1. checksums.yaml +5 -5
  2. data/.version +1 -1
  3. data/bin/cli/am +67 -41
  4. data/bin/cli/assets +1 -1
  5. data/bin/cli/console +3 -2
  6. data/bin/cli/eval +11 -2
  7. data/bin/cli/exceptions +1 -1
  8. data/bin/cli/generate +4 -0
  9. data/bin/cli/render +18 -0
  10. data/bin/cli/routes +3 -1
  11. data/bin/cli/server +4 -1
  12. data/bin/lux +10 -1
  13. data/bin/txt/nginx.conf +35 -18
  14. data/lib/common/class_attributes.rb +10 -10
  15. data/lib/common/{before_and_after.rb → class_callbacks.rb} +12 -21
  16. data/lib/common/crypt.rb +10 -6
  17. data/lib/common/dynamic_class.rb +12 -7
  18. data/lib/common/generic_model.rb +6 -6
  19. data/lib/common/hash_with_indifferent_access.rb +6 -284
  20. data/lib/{lux/helper/lib/html_tag.rb → common/html_tag_builder.rb} +1 -1
  21. data/lib/common/policy.rb +2 -2
  22. data/lib/common/url.rb +6 -4
  23. data/lib/lux-fw.rb +2 -13
  24. data/lib/lux/api/api.rb +34 -47
  25. data/lib/lux/api/lib/dsl.rb +2 -2
  26. data/lib/lux/api/lib/model_api.rb +40 -23
  27. data/lib/lux/api/lib/response.rb +30 -5
  28. data/lib/lux/application/application.rb +182 -0
  29. data/lib/lux/{controller → application}/lib/nav.rb +18 -21
  30. data/lib/lux/application/lib/plugs.rb +10 -0
  31. data/lib/lux/application/lib/render.rb +58 -0
  32. data/lib/lux/application/lib/route_test.rb +64 -0
  33. data/lib/lux/cache/cache.rb +27 -16
  34. data/lib/lux/cell/cell.rb +66 -54
  35. data/lib/lux/config/config.rb +51 -27
  36. data/lib/lux/current/current.rb +122 -0
  37. data/lib/lux/{page → current}/lib/encrypt_params.rb +2 -2
  38. data/lib/lux/{page → current}/lib/static_file.rb +29 -25
  39. data/lib/lux/delayed_job/delayed_job.rb +4 -4
  40. data/lib/lux/error/error.rb +31 -16
  41. data/lib/lux/helper/helper.rb +32 -37
  42. data/lib/lux/helper/helpers/application_helper.rb +3 -0
  43. data/lib/lux/helper/helpers/html_helper.rb +3 -0
  44. data/lib/lux/helper/helpers/mailer_helper.rb +11 -0
  45. data/lib/lux/lux.rb +40 -30
  46. data/lib/lux/mailer/mailer.rb +46 -29
  47. data/lib/lux/{page → response}/lib/flash.rb +1 -1
  48. data/lib/lux/response/lib/header.rb +21 -0
  49. data/lib/lux/response/response.rb +237 -0
  50. data/lib/lux/template/template.rb +20 -18
  51. data/lib/overload/array.rb +5 -0
  52. data/lib/overload/auto_loader.rb +27 -0
  53. data/lib/overload/blank.rb +8 -2
  54. data/lib/overload/float.rb +10 -0
  55. data/lib/overload/hash.rb +5 -12
  56. data/lib/overload/integer.rb +1 -5
  57. data/lib/overload/nil.rb +5 -0
  58. data/lib/overload/object.rb +1 -0
  59. data/lib/overload/r.rb +5 -0
  60. data/lib/overload/string.rb +4 -5
  61. data/lib/overload/{date.rb → time.rb} +23 -3
  62. metadata +37 -73
  63. data/bin/forever +0 -65
  64. data/bin/job_que +0 -39
  65. data/lib/lux/api/lib/application_api.rb +0 -38
  66. data/lib/lux/api/lib/doc_builder.rb +0 -19
  67. data/lib/lux/api/lib/rescue.rb +0 -8
  68. data/lib/lux/controller/controller.rb +0 -185
  69. data/lib/lux/controller/lib/plugs.rb +0 -10
  70. data/lib/lux/html/html.rb +0 -3
  71. data/lib/lux/html/lib/form.rb +0 -81
  72. data/lib/lux/html/lib/input.rb +0 -71
  73. data/lib/lux/html/lib/input_types.rb +0 -287
  74. data/lib/lux/lib/lux.rb +0 -51
  75. data/lib/lux/page/lib/response.rb +0 -178
  76. data/lib/lux/page/page.rb +0 -292
  77. data/lib/lux/rescue_from/rescue_from.rb +0 -63
  78. data/lib/plugins/assets/assets_plug.rb +0 -31
  79. data/lib/plugins/assets/helper_module_adapter.rb +0 -51
  80. data/lib/plugins/assets/init.rb +0 -4
  81. data/lib/plugins/db_helpers/array_and_hstore.rb +0 -64
  82. data/lib/plugins/db_helpers/arrays_and_tags.rb +0 -23
  83. data/lib/plugins/db_helpers/before_save.rb +0 -44
  84. data/lib/plugins/db_helpers/cached_find_by.rb +0 -45
  85. data/lib/plugins/db_helpers/class_and_instance.rb +0 -120
  86. data/lib/plugins/db_helpers/dataset_plugin.rb +0 -101
  87. data/lib/plugins/db_helpers/filter_wrappers.rb +0 -21
  88. data/lib/plugins/db_helpers/link_plugin.rb +0 -95
  89. data/lib/plugins/db_helpers/localize_plugin.rb +0 -57
  90. data/lib/plugins/db_helpers/primary_keys.rb +0 -36
  91. data/lib/plugins/db_helpers/typero_attributes.rb +0 -69
  92. data/lib/plugins/db_logger/init.rb +0 -18
  93. data/lib/plugins/db_logger/lux_response_adapter.rb +0 -9
  94. data/lib/plugins/paginate/helper.rb +0 -32
  95. data/lib/plugins/paginate/sequel_adapter.rb +0 -18
  96. data/lib/vendor/mini_assets/lib/asset.rb +0 -71
  97. data/lib/vendor/mini_assets/lib/asset/css.rb +0 -19
  98. data/lib/vendor/mini_assets/lib/asset/js.rb +0 -17
  99. data/lib/vendor/mini_assets/lib/base.rb +0 -69
  100. data/lib/vendor/mini_assets/lib/base/javascript.rb +0 -13
  101. data/lib/vendor/mini_assets/lib/base/stylesheet.rb +0 -5
  102. data/lib/vendor/mini_assets/lib/manifest.rb +0 -18
  103. data/lib/vendor/mini_assets/lib/opts.rb +0 -16
  104. data/lib/vendor/mini_assets/mini_assets.rb +0 -74
  105. data/lib/vendor/oauth/lib/facebook.rb +0 -35
  106. data/lib/vendor/oauth/lib/github.rb +0 -37
  107. data/lib/vendor/oauth/lib/google.rb +0 -41
  108. data/lib/vendor/oauth/lib/linkedin.rb +0 -41
  109. data/lib/vendor/oauth/lib/stackexchange.rb +0 -37
  110. data/lib/vendor/oauth/lib/twitter.rb +0 -41
  111. data/lib/vendor/oauth/oauth.rb +0 -46
data/bin/forever DELETED
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # better? -> https://github.com/bluepill-rb/bluepill
4
-
5
- # ~/forever/forever.txt
6
- # test: /Users/dux/.rvm/rubies/ruby-2.3.1/bin/ruby /Users/dux/dev/lux-fw/raumdog.com/test.rb
7
- # test2: /Users/dux/.rvm/rubies/ruby-2.3.1/bin/ruby /Users/dux/dev/lux-fw/raumdog.com/test2.rb
8
-
9
- # creates ~/forever/logs and ~/forever/pids
10
- # keeps logs in size
11
-
12
- # 1 1 * * * bash -l -c 'ruby /User/adsad/../forever'
13
-
14
- require 'colorize'
15
- require 'fileutils'
16
-
17
- @root = File.expand_path('~/forever')
18
- @max_file_size_in_mb = 1
19
-
20
- def die(data)
21
- puts data.red
22
- exit
23
- end
24
-
25
- def demonize(id, script)
26
- size = @max_file_size_in_mb * 1_000_000
27
-
28
- # rotate big files
29
- for log_file in ["#{@root}/logs/#{id}.log", "#{@root}/logs/#{id}.err"]
30
- if File.size?(log_file).to_i > (size * 3)
31
- puts "truncate #{log_file} to #{size}".yellow
32
- data = File.read(log_file)
33
- data = data[data.length - size, size]
34
- File.open(log_file, 'w') { |f| f.write(data) }
35
- end
36
- end
37
-
38
- pid_file = "#{@root}/pids/#{id}.pid"
39
- pid = File.read(pid_file).chomp rescue nil
40
-
41
- env_id = "FOREVER_ID=#{id}_END"
42
-
43
- if pid && `ps aux | grep #{env_id} | grep #{pid}`.index(script)
44
- puts "exists #{id.ljust(15)} pid #{pid}".green
45
- else
46
- print "starting #{id.ljust(15)} pid ".yellow
47
- `nohup #{script} #{env_id} >> #{@root}/logs/#{id}.log 2>> #{@root}/logs/#{id}.err < /dev/null & echo $! > #{pid_file}`
48
- puts File.read(pid_file)
49
- end
50
- end
51
-
52
- file = "#{@root}/forever.txt"
53
- die "~/forever/forever.txt not present (#{file})" unless File.exist?(file)
54
-
55
- FileUtils.mkdir_p "#{@root}/logs"
56
- FileUtils.mkdir_p "#{@root}/pids"
57
-
58
- apps = File.read(file).to_s.split("\n")
59
-
60
- for line in apps
61
- next if line[0,1] == '#'
62
- id, script = line.split(/\s*:\s*/, 2)
63
- next unless script
64
- demonize id, script
65
- end
data/bin/job_que DELETED
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- check = `ps ax | grep ruby`.split("\n").select{ |line| line.index($0) }
4
- check.select! { |line| !line.index("#{Process.pid} ") }
5
-
6
- if check.length > 0
7
- puts "Lux job_que allready running"
8
- puts check
9
- exit
10
- end
11
-
12
- eval File.read './lux/loader.rb'
13
- Lux.delay.run!
14
-
15
- # require 'pathname'
16
- # pid_file = Pathname.new("./tmp/job_que.pid")
17
-
18
- # if pid_file.exist?
19
- # pid = pid_file.read
20
- # proc = `ps -p #{pid} -o comm=`
21
- # if proc.to_s.length > 1
22
- # puts "Lux job_que allready running, pid: #{pid}"
23
- # system "ps ax | grep #{pid} | grep ruby"
24
- # exit
25
- # end
26
- # end
27
-
28
- # pid_file.write(Process.pid)
29
- # Kernel.at_exit { pid_file.delete }
30
-
31
-
32
- # Lux.config.redis_server = Redis::Queue.new('__test', 'bp__test', :redis => Redis.new)
33
- # Lux.delay.server = :memory
34
- # Lux.delay.server = :redis
35
- # Lux.delay.push("puts '123 abc > mem'.red")
36
- # Lux.delay.push("puts '123 abc > redis'.red")
37
- # Lux.delay.push(Mailer.confirm_email('rejotl@gmail.com'), :deliver)
38
- # Mailer.confirm_email('rejotl@gmail.com').deliver_later
39
- # Lux.delay.run!
@@ -1,38 +0,0 @@
1
- class ApplicationApi < Lux::Api
2
-
3
- method_attr :user do |value|
4
- raise 'Method attr :%s for :user is not allowed value' % value unless [:user, :guest, :admin].include?(value)
5
- value
6
- end
7
-
8
- before do
9
- if params[:api_key]
10
- User.current = User.find_by api_token: params[:api_key]
11
- error 'Invalid api key' unless User.current
12
- end
13
-
14
- case @method_attr[:user].try(:first)
15
- when :user
16
- error 'Dostupno registriranim korinsicima' unless User.current
17
- when :admin
18
- error 'Samo za ADMIN usere' unless User.current.try(:is_admin)
19
- end
20
- end
21
-
22
- # called at the end of response
23
- def decorate_response!
24
- if Lux.page
25
- response.meta :ip, Lux.page.request.ip
26
- response.meta :user, Lux.page.var.user ? Lux.page.var.user.email : nil
27
- response.meta :http_status, Lux.page.status(200)
28
- # response.error 'Bad request' if response.errors? && Lux.page.status != 200
29
- end
30
-
31
- response.render
32
- end
33
-
34
- def after
35
- decorate_response!
36
- end
37
-
38
- end
@@ -1,19 +0,0 @@
1
- # class Lux::Api
2
- # class << self
3
- # # list all availabe actions in a class
4
- # def actions
5
- # UserApi.instance_methods - UserApi.ancestors[1].instance_methods
6
- # instance_level_actions = UserApi.instance_methods - Object.instance_methods - [:sinatra, :instance_run, :params]
7
- # @@actions[self.to_s].keys + instance_level_actions
8
- # end
9
-
10
- # # get details about action
11
- # def action_details(name)
12
- # @@actions[self.to_s][name] ||= {}
13
- # details = @@actions[self.to_s][name].reject { |key| [:proc].index(key) }
14
- # details[:name] ||= "#{name.to_s} action"
15
- # details[:action] ||= name
16
- # details.h
17
- # end
18
- # end
19
- # end
@@ -1,8 +0,0 @@
1
- Lux::Api.rescue_from(:default) do |msg|
2
- response.error msg
3
-
4
- if Lux.dev? && $!.class != Lux::Api::Error
5
- data[:backtrace] = $!.backtrace.reject{ |el| el.index('/gems/') }.map{ |el| el.sub(Lux.root.to_s, '') }
6
- ap data[:backtrace]
7
- end
8
- end
@@ -1,185 +0,0 @@
1
- class Lux::Controller
2
-
3
- LUX_PRINT_ROUTES = !!ENV['LUX_PRINT_ROUTES'] unless defined?(LUX_PRINT_ROUTES)
4
-
5
- # define common http methods as constants
6
- [:get, :head, :post, :delete, :put, :patch].map(&:to_s).map(&:upcase).each { |m| eval "#{m} ||= '#{m}'" }
7
-
8
- # rescue from errors
9
- Lux::RescueFrom.define(self)
10
-
11
- # this is needed for Rescuce actions to work without Lux prefix
12
- define_singleton_method(:page) { Lux.page }
13
-
14
- ###
15
-
16
- def debug
17
- { :@locale=>@locale, :@nav=>nav, :@subdomain=>@subdomain, :@domain=>@domain }
18
- end
19
-
20
- def body?
21
- Lux.page.body ? true : false
22
- end
23
-
24
- def body data
25
- Lux.page.body(data)
26
- end
27
-
28
- def page
29
- Lux.page
30
- end
31
-
32
- def nav
33
- Lux.page.nav
34
- end
35
-
36
- def params
37
- Lux.page.params
38
- end
39
-
40
- def redirect where, msgs={}
41
- Lux.page.redirect where, msgs
42
- end
43
-
44
- def request
45
- Lux.page.request
46
- end
47
-
48
- # gets only root
49
- def root opts
50
- if LUX_PRINT_ROUTES
51
- @route_target = opts
52
- print_route
53
- end
54
-
55
- call opts unless nav.root
56
- end
57
-
58
- ### plug and default prepares
59
-
60
- def plug(name, &block)
61
- return if body?
62
- m = "#{name}_plug".to_sym
63
- return Lux.error(%[Method "#{m}" not defined in Lux::Controller]) unless respond_to?(m)
64
- send(m, &block)
65
- end
66
-
67
- def rescued_main
68
- if respond_to?(:main)
69
- @@rescue_from_ivar.call(self) { main }
70
- else
71
- Lux.error %[No instance method "main" in Lux::Controller defiend]
72
- end
73
- end
74
-
75
- def print_route
76
- route = case @route
77
- when Regexp
78
- @route.to_s.ljust(20).red
79
- when Symbol
80
- ('/%s' % @route).ljust(20).green
81
- when nil
82
- '/'.ljust(20).green
83
- else
84
- @route.to_s.ljust(20).light_blue
85
- end
86
-
87
- route_target = case @route_target
88
- when Symbol
89
- ':%s' % @route_target
90
- when Array
91
- action = @route_target[1] == 'print-routes' ? @route : @route_target[1]
92
- '%s.action("%s")' % [@route_target[0], action]
93
- else
94
- @route_target
95
- end
96
-
97
- puts '%s => %s (%s)' % [route, route_target.to_s.ljust(40), @route.class]
98
- end
99
-
100
- def route route_object
101
- return if body?
102
-
103
- if route_object.class == Hash
104
- @route = route_object.keys.first
105
- @route_target = route_object.values.first
106
- else
107
- @route = route_object
108
- end
109
-
110
- print_route if LUX_PRINT_ROUTES
111
-
112
- return unless if @route.is_a?(String)
113
- page.nav.to_s.start_with?(@route)
114
- elsif @route.is_a?(Regexp)
115
- page.nav.to_s =~ @route
116
- else
117
- nav.root == @route.to_s
118
- end
119
-
120
- @route_object = route_object
121
-
122
- case @route_target
123
- when Proc
124
- @route_target.call
125
- when Array
126
- call @route_target[0], @route_target[1]
127
- else
128
- call @route_target
129
- end
130
- end
131
- alias :match :route
132
-
133
- def get object
134
- return unless get?
135
- route object
136
- end
137
-
138
- def post object
139
- return unless post?
140
- route object
141
- end
142
-
143
- def get?
144
- Lux.page.request.request_method == 'GET'
145
- end
146
-
147
- def post?
148
- Lux.page.request.request_method == 'POST'
149
- end
150
-
151
- # call :api_router
152
- # call Main::UsersCell
153
- # call Main::UsersCell, :index
154
- # call 'main/orgs#show'
155
- def call object=nil, action=nil
156
- return true if body?
157
-
158
- case object
159
- when Symbol
160
- return send(object)
161
- when String
162
- if object.include?('#')
163
- object = object.split('#')
164
- object[0] = ('%s_cell' % object[0]).classify.constantize
165
- else
166
- object = ('%s_cell' % object).classify.constantize
167
- end
168
- end
169
-
170
- object, action = object if object.is_a? Array
171
-
172
- Lux.log ' %s %s # %s' % [object.to_s.light_blue, nav.path, @route_object]
173
-
174
- if action
175
- object.action action
176
- else
177
- object.call
178
- end
179
-
180
- Lux.error 'Lux cell "%s" called via route "%s" but page body is not set' % [object, @route] unless body?
181
-
182
- true
183
- end
184
-
185
- end
@@ -1,10 +0,0 @@
1
- class Lux::Controller
2
-
3
- def lux_static_files_plug
4
- file = Lux::Page::StaticFile.new(Lux.page.request.path)
5
- return false unless file.is_static_file?
6
- file.read
7
- true
8
- end
9
-
10
- end
data/lib/lux/html/html.rb DELETED
@@ -1,3 +0,0 @@
1
- module Lux::Html
2
-
3
- end
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # = form Lux.page.var.user do |f|
4
- # = f.hidden :company_id
5
- # = f.row :name
6
- # = f.row :counrty_id, :as=>:country
7
- # .custom= f.input :email
8
- # = f.submit 'Save'
9
-
10
- class Lux::Html::Form
11
- def initialize(action, form_opts={})
12
- form_opts[:method] = 'get' if form_opts.delete(:get)
13
- form_opts[:method] ||= 'get' unless action
14
- form_opts[:method] ||= 'post'
15
- form_opts[:method] = form_opts[:method].upcase
16
-
17
- @action = action
18
- @object = action if action.respond_to?(:update)
19
- @form_opts = form_opts
20
- end
21
-
22
- def encrypt data
23
- return unless data
24
- '[protected]:%s' % Crypt.encrypt(data)
25
- end
26
-
27
- def hidden(name, opts={})
28
- fname = @object.class.name.tableize.singularize rescue nil
29
-
30
- if name.respond_to?(:update)
31
- oname = name.class.name.tableize.singularize
32
- if @object && @object.respond_to?("#{oname}_id") # grp
33
- Lux::Page::EncryptParams.hidden_input "#{fname}[#{oname}_id]", name.id
34
- else
35
- [
36
- Lux::Page::EncryptParams.hidden_input("#{fname}[model_id]", name.id),
37
- Lux::Page::EncryptParams.hidden_input("#{fname}[model_type]", name.class.name),
38
- ].join('')
39
- end
40
- else
41
- name = '%s[%s]' % [fname, name] if fname && name.is_a?(Symbol)
42
- Lux::Page::EncryptParams.hidden_input(name, opts[:value])
43
- end
44
- end
45
-
46
- def input(name, opts={})
47
- @name = name
48
- opts[:id] ||= Lux.uid
49
- opts[:value] ||= Lux.page.params[name] if @form_opts[:method] == 'GET'
50
- input_object = Lux::Html::Input.new(@object)
51
- data = input_object.render(name, opts)
52
- @type = input_object.type
53
- data
54
- end
55
-
56
- def data=(body)
57
- @data = body
58
- end
59
-
60
- def render
61
- render_form
62
- @form_opts.tag(:form, @data)
63
- end
64
-
65
- def render_form
66
- @data = %[<ul>#{@data}</ul>]
67
- @form_opts[:class] = 'custom-class'
68
- end
69
-
70
- def submit(name=nil)
71
- name ||= 'Submit'
72
- %[<button>#{name}</button>]
73
- end
74
-
75
- def row(name, opts={})
76
- node = input(name, opts)
77
- label = %[<label for="#{opts[:id]}">#{opts[:label] || name.to_s.humanize}</label>]
78
- %[<p class="as-#{opts[:as]}">#{label}#{node}<span class="error"></span></p>]
79
- end
80
- end
81
-