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
@@ -1,57 +0,0 @@
1
- module Sequel::Plugins::LuxLocalize
2
- module ClassMethods
3
- # in any modal
4
- # localize :name
5
- # to make :name multilang
6
- # and to create :name_en, :name_de, ...
7
- def localize(name)
8
- unless db_schema[name]
9
- puts "Field [:#{name}] does not exist in #{self.to_s}".red
10
- end
11
-
12
- unless (db_schema[name][:db_type] rescue nil) == 'jsonb'
13
- puts "Field [:#{name}] in #{self.to_s} is not of type [jsonb]".red
14
- end
15
-
16
- class_eval %[
17
- def #{name}(locale=nil)
18
- field = self[:#{name}]
19
- field ||= {}
20
- locale ||= Locale.current
21
- return field[locale] if field[locale] && !field[locale].start_with?('?')
22
- val = field[Locale::DEFAULT].to_s
23
- Lux.dev? ? '?'+val : val
24
- end
25
-
26
- def #{name}=(value)
27
- self[:#{name}] ||= {} # if self[:#{name}].class.to_s != 'Hash'
28
- self[:#{name}][Locale.current] = value
29
- end
30
- ]
31
-
32
- for lang in Locale.all
33
- class_eval %[
34
- def #{name}_#{lang}
35
- #{name}('#{lang}')
36
- end
37
-
38
- def #{name}_#{lang}=(value)
39
- value = nil if value.start_with?('?')
40
- self[:#{name}] ||= {}
41
- self[:#{name}]['#{lang}'] = value
42
- end
43
- ]
44
- end
45
- end
46
- end
47
-
48
- module InstanceMethods
49
-
50
- end
51
-
52
- def DatasetMethods
53
-
54
- end
55
- end
56
-
57
- Sequel::Model.plugin :lux_localize
@@ -1,36 +0,0 @@
1
- # define composite key and check before save
2
- # class OrgUser < ApplicationModel
3
- # primary_keys :org_id, :user_id
4
- # end
5
-
6
- module Sequel::Plugins::PrimaryKeys
7
- module ClassMethods
8
- def primary_keys(*args)
9
- unless args[0]
10
- return respond_to?(:_primary_keys) ? _primary_keys : [:id]
11
- end
12
-
13
- define_singleton_method(:_primary_keys) { args }
14
- end
15
- end
16
-
17
- module InstanceMethods
18
- def before_save
19
- klass = self.class
20
-
21
- if klass.respond_to?(:_primary_keys)
22
- check = klass._primary_keys.inject(klass.dataset) do |record, field|
23
- record = record.where("#{field}=?", send(field))
24
- end
25
-
26
- check = check.xwhere('id<>?', id) if self[:id]
27
-
28
- raise StandardError, 'Record allredy exists (primary_keys check)' if check.first
29
- end
30
-
31
- super
32
- end
33
- end
34
- end
35
-
36
- Sequel::Model.plugin :primary_keys
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'typero'
4
-
5
- module Sequel::Plugins::TyperoAttributes
6
- module ClassMethods
7
- def attributes(&block)
8
- self.instance_variable_set :@typero_rule, Typero.new(&block)
9
- end
10
-
11
- def typero_schema
12
- self.instance_variable_get :@typero_rule
13
- end
14
- end
15
-
16
- module InstanceMethods
17
- # calling typero! on any object will validate all fields
18
- def typero! field_name=nil
19
- typero = self.class.typero_schema || return
20
-
21
- typero.validate(self) { |name, err| errors.add(name, err) unless (errors.on(name) || []).include?(err) }
22
-
23
- # this are rules unique to database, so we check them here
24
- typero.rules.each do |field, rule|
25
- # check uniqe fields
26
- if rule[:uniq]
27
- id = self[:id] || 0
28
- value = self[field]
29
-
30
- # we only check if field is changed
31
- if column_changed?(field) && self.class.xwhere('LOWER(%s)=LOWER(?) and id<>?' % field, value, id).first
32
- error = rule[:uniq].class == TrueClass ? %[Value '"#{value}"' for #{field} allready exists] : rule[:uniq]
33
- errors.add(field, error) unless (errors.on(field) || []).include?(error)
34
- end
35
- end
36
-
37
- # check protected fields
38
- if rule[:protected] && self[:id]
39
- if column_changed?(field)
40
- error = rule[:protected].class == TrueClass ? "value once defined can't be overwritten." : rule[:protected]
41
- errors.add(field, error) unless (errors.on(field) || []).include?(error)
42
- end
43
- end
44
- end
45
-
46
- # check single field if single field given
47
- if field_name
48
- raise ArgumentError.new 'Field :%s not found in %s' % [field_name, self] unless self[field_name]
49
- return unless errors.on(field_name)
50
-
51
- errors.on(field_name).join(', ')
52
- end
53
-
54
- true
55
- end
56
-
57
- def validate
58
- typero!
59
- super
60
- end
61
- end
62
-
63
- module DatasetMethods
64
-
65
- end
66
- end
67
-
68
- Sequel::Model.plugin :typero_attributes
69
-
@@ -1,18 +0,0 @@
1
- # Logs DB queries in console
2
- # to active just load the file
3
- logger = Logger.new(STDOUT)
4
-
5
- logger.formatter = proc { |severity, datetime, progname, msg|
6
- elms = msg.split(/\(|s\)\s/, 3)
7
- time = (elms[1].to_f * 1000).round(1)
8
- if Thread.current[:db_q]
9
- Thread.current[:db_q][:time] += elms[1].to_f
10
- Thread.current[:db_q][:cnt] += 1
11
-
12
- # append debug=true as query-string to see database queries
13
- Lux.log(" #{Thread.current[:db_q][:cnt].to_s.rjust(2)}. #{time} : #{elms[2].to_s.cyan}\n") if Thread.current[:db_q]
14
- end
15
- }
16
-
17
- DB.loggers << logger
18
-
@@ -1,9 +0,0 @@
1
- class Lux::Page
2
- before do
3
- Thread.current[:db_q] = { time: 0.0, cnt: 0 }
4
- end
5
-
6
- after do
7
- Lux.log " #{Thread.current[:db_q][:cnt]} DB queries, #{(Thread.current[:db_q][:time]*1000).round(1)} ms" if Thread.current[:db_q][:cnt] > 0
8
- end
9
- end
@@ -1,32 +0,0 @@
1
- module DefaultHelper
2
-
3
- def paginate list
4
- return unless list.respond_to?(:paginate_size)
5
- return nil if list.paginate_page == 1 && list.length < list.paginate_size
6
-
7
- ret = ['<div class="paginate"><div>']
8
-
9
- if list.paginate_page > 1
10
- url = Url.current
11
- list.paginate_page == 1 ? url.delete(list.paginate_param) : url.qs(list.paginate_param, list.paginate_page-1)
12
- ret.push %[<a href="#{url.relative}">&larr;</a>]
13
- else
14
- ret.push %[<span>&larr;</span>]
15
- end
16
-
17
- ret.push %[<i>#{list.paginate_page == 1 ? '&bull;' : list.paginate_page}</i>]
18
-
19
- if list.paginate_size == list.length
20
- url = Url.current
21
- url.qs(list.paginate_param, list.paginate_page+1)
22
- ret.push %[<a href="#{url.relative}">&rarr;</a>]
23
- else
24
- ret.push %[<span>&rarr;</span>]
25
- end
26
-
27
- ret.push '</div></div>'
28
- ret.join('')
29
- end
30
-
31
- end
32
-
@@ -1,18 +0,0 @@
1
- module Sequel::Plugins::LuxSimplePaginate
2
- module DatasetMethods
3
- def page size: 20, param: :page, page: nil
4
- page = (page || Lux.page.params[param]).to_i
5
- page = 1 if page < 1
6
-
7
- ret = paginate(page, size).all
8
- ret.define_singleton_method(:paginate_param) do; param ;end
9
- ret.define_singleton_method(:paginate_page) do; page ;end
10
- ret.define_singleton_method(:paginate_size) do; size ;end
11
-
12
- ret
13
- end
14
- end
15
- end
16
-
17
- Sequel::Model.db.extension :pagination
18
- Sequel::Model.plugin :lux_simple_paginate
@@ -1,71 +0,0 @@
1
- class MiniAssets::Asset
2
- def self.call source
3
- ext = source.split('.').last
4
- base = ['css', 'sass', 'scss'].include?(ext) ? MiniAssets::Asset::Css : MiniAssets::Asset::Js
5
- base.new source
6
- end
7
-
8
- def initialize source
9
- @ext = source.split('.').last.to_sym
10
- @source = opts.app_root.join source
11
- @target = opts.public_root.join source
12
-
13
- cache_file = source.gsub('/', '-')
14
-
15
- if environment_prefix?
16
- prefix = opts.production? ? :p : :d
17
- cache_file = '%s-%s' % [prefix, cache_file]
18
- end
19
-
20
- @cache = opts.tmp_root.join cache_file
21
- end
22
-
23
- def opts
24
- MiniAssets::Opts
25
- end
26
-
27
- def environment_prefix?
28
- false
29
- end
30
-
31
- def run! what
32
- puts what.yellow
33
-
34
- stdin, stdout, stderr, wait_thread = Open3.popen3(what)
35
-
36
- error = stderr.gets
37
- while line = stderr.gets do
38
- error += line
39
- end
40
-
41
- # node-sass prints to stderror on complete
42
- error = nil if error && error.index('Rendering Complete, saving .css file...')
43
-
44
- if error
45
- @cache.unlink if @cache.exist?
46
- @error = error
47
- end
48
- end
49
-
50
- def comment text
51
- '/* %s */' % text
52
- end
53
-
54
- def cached?
55
- @cache.exist? && @cache.ctime > @source.ctime
56
- end
57
-
58
- def render
59
- func = 'compile_%s' % @ext
60
-
61
- # if custom method exists, execute it and return cache
62
- # othervise just read source
63
- if respond_to?(func)
64
- send func unless cached?
65
- @cache.read
66
- else
67
- @source.read
68
- end
69
- end
70
- end
71
-
@@ -1,19 +0,0 @@
1
- class MiniAssets::Asset::Css < MiniAssets::Asset
2
- def content_type
3
- 'text/css'
4
- end
5
-
6
- def environment_prefix?
7
- true
8
- end
9
-
10
- def compile_scss
11
- compile_sass
12
- end
13
-
14
- def compile_sass
15
- node_sass = './node_modules/node-sass/bin/node-sass'
16
- node_opts = opts.production? ? '--output-style compressed' : '--source-comments'
17
- run! "#{node_sass} #{node_opts} '#{@source}' '#{@cache}'"
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- class MiniAssets::Asset::Js < MiniAssets::Asset
2
- def content_type
3
- 'text/javascript'
4
- end
5
-
6
- def compile_coffee
7
- coffee_path = './node_modules/coffee-script/bin/coffee'
8
- coffee_opts = opts.production? ? '-cp' : '-Mcp --no-header'
9
-
10
- run! "#{coffee_path} #{coffee_opts} '#{@source}' > '#{@cache}'"
11
-
12
- data = @cache.read
13
- data = data.gsub(%r{//#\ssourceURL=[\w\-\.\/]+/app/assets/}, '//# sourceURL=/raw_asset/')
14
-
15
- @cache.write data
16
- end
17
- end
@@ -1,69 +0,0 @@
1
- # base class for production rendering
2
- # MiniAssets.call('js/main/index.coffee').render
3
- # MiniAssets::Base::JavasScript.new sorurce, files
4
-
5
- class MiniAssets::Base
6
- attr_reader :files
7
-
8
- def initialize source, files
9
- @source = source
10
- @files = files
11
- end
12
-
13
- def join_string
14
- "\n"
15
- end
16
-
17
- def render_production
18
- nil
19
- end
20
-
21
- def gzip
22
- run! 'gzip -k %s' % @target
23
- end
24
-
25
- def run! what
26
- puts what.yellow
27
- system what
28
- end
29
-
30
- def opts
31
- MiniAssets::Opts
32
- end
33
-
34
- # this should only be called in builder for production "lux assets"
35
- def render
36
- data = []
37
-
38
- @files.each do |file|
39
- asset = asset_class.new file
40
- data.push asset.comment 'Source: %s' % file unless opts.production?
41
- data.push asset.render
42
- end
43
-
44
- data = data.join(join_string)
45
- type = asset_class.to_s.split('::').last.downcase
46
-
47
- @target = opts.public_root.join '%s-%s.%s' % [@source.to_s.gsub(/[^\w]+/,'-'), Digest::SHA1.hexdigest(data), type]
48
-
49
- # unless target exists, build it and minify it
50
- unless @target.exist?
51
- @target.write data
52
-
53
- render_production
54
- gzip
55
-
56
- # force old time stamp
57
- run! 'touch -t 201001010101 %s' % @target
58
- run! 'touch -t 201001010101 %s.gz' % @target
59
- end
60
-
61
- # update manifest (if needed)
62
- target = @target.to_s.split('/public').last
63
- manifest = MiniAssets::Manifest.new
64
- manifest.add @source, target
65
-
66
- target
67
- end
68
- end
69
-
@@ -1,13 +0,0 @@
1
- class MiniAssets::Base::JavaScript < MiniAssets::Base
2
- def asset_class
3
- MiniAssets::Asset::Js
4
- end
5
-
6
- def join_string
7
- ";\n"
8
- end
9
-
10
- def render_production
11
- run! './node_modules/minifier/index.js --no-comments -o "%{file}" "%{file}"' % { file: @target }
12
- end
13
- end