lux-fw 0.5.36 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/bin/README.md +26 -13
  4. data/bin/cli/benchmark.rb +18 -0
  5. data/bin/cli/cerb.rb +90 -0
  6. data/bin/cli/config.rb +4 -11
  7. data/bin/cli/console.rb +72 -30
  8. data/bin/cli/eval.rb +5 -27
  9. data/bin/cli/generate.rb +9 -11
  10. data/bin/cli/get.rb +14 -6
  11. data/bin/cli/memory.rb +12 -0
  12. data/bin/cli/new.rb +2 -0
  13. data/bin/cli/secrets.rb +3 -31
  14. data/bin/cli/server.rb +28 -9
  15. data/bin/cli/stats.rb +26 -20
  16. data/bin/cli/template.rb +10 -0
  17. data/bin/generate_doc +168 -0
  18. data/bin/lux +73 -10
  19. data/lib/README.md +18 -8
  20. data/lib/common/crypt.rb +60 -9
  21. data/lib/common/string_base.rb +54 -15
  22. data/lib/common/struct_opts.rb +30 -0
  23. data/lib/common/time_difference.rb +75 -0
  24. data/lib/loader.rb +41 -0
  25. data/lib/lux/application/README.md +67 -105
  26. data/lib/lux/application/application.rb +87 -329
  27. data/lib/lux/application/lib/magic_routes.rb +22 -0
  28. data/lib/lux/application/lib/nav.rb +218 -99
  29. data/lib/lux/application/lib/render.rb +47 -67
  30. data/lib/lux/application/lib/routes.rb +242 -0
  31. data/lib/lux/application/lib/shared.rb +47 -0
  32. data/lib/lux/application/lux_adapter.rb +6 -0
  33. data/lib/lux/application/lux_config.rb +26 -0
  34. data/lib/lux/cache/Find Results +24 -0
  35. data/lib/lux/cache/README.md +28 -35
  36. data/lib/lux/cache/cache.rb +78 -26
  37. data/lib/lux/cache/lib/memcached_server.rb +36 -0
  38. data/lib/lux/cache/lib/memory_server.rb +44 -0
  39. data/lib/lux/cache/lib/null_server.rb +33 -0
  40. data/lib/lux/cache/lib/sqlite_server.rb +62 -0
  41. data/lib/lux/cache/lux_adapter.rb +19 -0
  42. data/lib/lux/config/config.rb +93 -144
  43. data/lib/lux/config/lux_adapter.rb +27 -0
  44. data/lib/lux/controller/README.md +67 -12
  45. data/lib/lux/controller/controller.rb +237 -187
  46. data/lib/lux/current/README.md +29 -10
  47. data/lib/lux/current/current.rb +166 -77
  48. data/lib/lux/current/lib/current.rb +6 -0
  49. data/lib/lux/current/lib/encrypt_params.rb +38 -36
  50. data/lib/lux/current/lib/session.rb +86 -65
  51. data/lib/lux/current/lux_adapter.rb +5 -0
  52. data/lib/lux/environment/README.md +24 -0
  53. data/lib/lux/environment/environment.rb +91 -0
  54. data/lib/lux/environment/lux_adapter.rb +13 -0
  55. data/lib/lux/error/README.md +18 -19
  56. data/lib/lux/error/error.rb +207 -152
  57. data/lib/lux/error/lux_adapter.rb +9 -0
  58. data/lib/lux/logger/README.md +45 -0
  59. data/lib/lux/logger/lux_adapter.rb +27 -0
  60. data/lib/lux/lux.rb +72 -129
  61. data/lib/lux/mailer/README.md +12 -5
  62. data/lib/lux/mailer/lux_config.rb +4 -0
  63. data/lib/lux/mailer/mailer.rb +81 -59
  64. data/lib/lux/plugin/README.md +19 -0
  65. data/lib/lux/plugin/lux_adapter.rb +8 -0
  66. data/lib/lux/plugin/plugin.rb +65 -0
  67. data/lib/lux/render/README.md +100 -0
  68. data/lib/lux/render/render.rb +12 -0
  69. data/lib/lux/response/README.md +57 -1
  70. data/lib/lux/response/lib/file.rb +87 -65
  71. data/lib/lux/response/lib/flash.rb +49 -34
  72. data/lib/lux/response/lib/header.rb +34 -33
  73. data/lib/lux/response/response.rb +252 -164
  74. data/lib/lux/template/helper.rb +130 -0
  75. data/lib/lux/template/inline_render_proxy.rb +31 -0
  76. data/lib/lux/template/lux_adapter.rb +5 -0
  77. data/lib/lux/template/template.rb +127 -0
  78. data/lib/lux-fw.rb +15 -33
  79. data/lib/overload/array.rb +33 -7
  80. data/lib/overload/blank.rb +8 -3
  81. data/lib/overload/boolean.rb +46 -0
  82. data/lib/overload/class.rb +28 -0
  83. data/lib/overload/dir.rb +117 -7
  84. data/lib/overload/file.rb +40 -5
  85. data/lib/overload/float.rb +38 -3
  86. data/lib/overload/hash.rb +81 -91
  87. data/lib/overload/integer.rb +15 -0
  88. data/lib/overload/json.rb +26 -0
  89. data/lib/overload/nil.rb +4 -8
  90. data/lib/overload/object.rb +91 -24
  91. data/lib/overload/pathname.rb +11 -0
  92. data/lib/overload/raise_variants.rb +26 -36
  93. data/lib/overload/string.rb +100 -27
  94. data/lib/overload/thread_simple.rb +100 -0
  95. data/lib/overload/time.rb +60 -38
  96. data/tasks/loader.rb +20 -7
  97. metadata +170 -169
  98. data/bin/.DS_Store +0 -0
  99. data/bin/build_gem +0 -77
  100. data/bin/cli/dbconsole.rb +0 -8
  101. data/bin/cli/routes.rb +0 -90
  102. data/lib/.DS_Store +0 -0
  103. data/lib/common/.DS_Store +0 -0
  104. data/lib/common/class_attributes.rb +0 -51
  105. data/lib/common/class_callbacks.rb +0 -47
  106. data/lib/common/free_struct.rb +0 -42
  107. data/lib/common/hash_with_indifferent_access.rb +0 -74
  108. data/lib/common/html_tag_builder.rb +0 -91
  109. data/lib/common/method_attr.rb +0 -69
  110. data/lib/common/url.rb +0 -191
  111. data/lib/lux/.DS_Store +0 -0
  112. data/lib/lux/README.md +0 -10
  113. data/lib/lux/cache/.DS_Store +0 -0
  114. data/lib/lux/cache/lib/memory.rb +0 -36
  115. data/lib/lux/cache/lib/null.rb +0 -21
  116. data/lib/lux/config/README.md +0 -63
  117. data/lib/lux/config/lib/plugin.rb +0 -65
  118. data/lib/lux/config/lib/secrets.rb +0 -48
  119. data/lib/lux/current/.DS_Store +0 -0
  120. data/lib/lux/delayed_job/.DS_Store +0 -0
  121. data/lib/lux/delayed_job/README.md +0 -3
  122. data/lib/lux/delayed_job/delayed_job.rb +0 -51
  123. data/lib/lux/delayed_job/lib/memory.rb +0 -16
  124. data/lib/lux/delayed_job/lib/nsq.rb +0 -3
  125. data/lib/lux/delayed_job/lib/postgre.rb +0 -6
  126. data/lib/lux/delayed_job/lib/redis.rb +0 -19
  127. data/lib/lux/event_bus/README.md +0 -36
  128. data/lib/lux/event_bus/event_bus.rb +0 -27
  129. data/lib/lux/view/README.md +0 -85
  130. data/lib/lux/view/cell.rb +0 -102
  131. data/lib/lux/view/helper.rb +0 -120
  132. data/lib/lux/view/lib/cell_helpers.rb +0 -29
  133. data/lib/lux/view/view.rb +0 -95
  134. data/lib/overload/it.rb +0 -29
  135. data/plugins/api/README.md +0 -49
  136. data/plugins/api/api.rb +0 -153
  137. data/plugins/api/lib/attr.rb +0 -31
  138. data/plugins/api/lib/dsl.rb +0 -52
  139. data/plugins/api/lib/error.rb +0 -3
  140. data/plugins/api/lib/model_api.rb +0 -203
  141. data/plugins/api/lib/response.rb +0 -85
  142. data/plugins/db/.DS_Store +0 -0
  143. data/plugins/db/README.md +0 -29
  144. data/plugins/db/auto_migrate/auto_migrate.rb +0 -268
  145. data/plugins/db/auto_migrate/db.rake +0 -15
  146. data/plugins/db/helpers/array_search.rb +0 -27
  147. data/plugins/db/helpers/before_save_filters.rb +0 -32
  148. data/plugins/db/helpers/composite_primary_keys.rb +0 -36
  149. data/plugins/db/helpers/core.rb +0 -94
  150. data/plugins/db/helpers/dataset_methods.rb +0 -138
  151. data/plugins/db/helpers/enums_plugin.rb +0 -52
  152. data/plugins/db/helpers/find_precache.rb +0 -31
  153. data/plugins/db/helpers/link_objects.rb +0 -84
  154. data/plugins/db/helpers/schema_checks.rb +0 -83
  155. data/plugins/db/helpers/typero_adapter.rb +0 -71
  156. data/plugins/db/logger/config.rb +0 -22
  157. data/plugins/db/logger/lux_response_adapter.rb +0 -10
  158. data/plugins/db/paginate/helper.rb +0 -32
  159. data/plugins/db/paginate/sequel_adapter.rb +0 -23
  160. data/plugins/exceptions/exceptions.rake +0 -43
  161. data/plugins/exceptions/simple_exception.rb +0 -64
  162. data/plugins/favicon/favicon.rb +0 -10
  163. data/plugins/html/README.md +0 -3
  164. data/plugins/html/html_form.rb +0 -118
  165. data/plugins/html/html_input.rb +0 -98
  166. data/plugins/html/html_menu.rb +0 -79
  167. data/plugins/html/input_types.rb +0 -346
  168. data/plugins/js_widgets/README.md +0 -5
  169. data/plugins/js_widgets/js/html_tag.coffee +0 -42
  170. data/plugins/js_widgets/js/widgets.coffee +0 -161
  171. data/plugins/js_widgets/js_widgets.rb +0 -15
  172. data/plugins/oauth/lib/facebook.rb +0 -35
  173. data/plugins/oauth/lib/github.rb +0 -38
  174. data/plugins/oauth/lib/google.rb +0 -41
  175. data/plugins/oauth/lib/linkedin.rb +0 -41
  176. data/plugins/oauth/lib/stackexchange.rb +0 -41
  177. data/plugins/oauth/lib/twitter.rb +0 -38
  178. data/plugins/oauth/oauth.rb +0 -42
  179. data/plugins/policy/policy.rb +0 -53
  180. data/tasks/nginx.rake +0 -23
  181. /data/lib/lux/{view/lib → mailer}/helper_modules.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f88cd45d785eba48eb2321f58d7d6c5e8748339a6dffef24181be783724fed5c
4
- data.tar.gz: 368139721b7d25d90839e1b9d948130134c9b6f2bed642a10d75a8e81ba1ed1e
3
+ metadata.gz: 26a5ad14f0ac275820255d8ac96fa2cf583d41bbac8ba84c3d49a6702844591f
4
+ data.tar.gz: f29c9147d212b63be1d78678f13a7e80988f70af77b7c37b8b6f5d0a9b8b6cb9
5
5
  SHA512:
6
- metadata.gz: f38a00ea2a8d43814645f05dd4e59d39d81b6bff5ac29542ae1c41dbb7082f04a050e33d667c9d7a3a09dba285bd0786e7784869595f6ab340cb1bbb96558bde
7
- data.tar.gz: 381f478c2e06dd5123f04764b8515b4f8f6e4e438a222c7f89e6e8b5e05cb58952424640c19e2b1d14b2570f7fb646646b4820469e845b9631a526b226cc80e0
6
+ metadata.gz: 684d38dede88154e2c8a553868a3d575406524b61e3d9160821b75c7c07ac54db0665365250f9e000cd3ba81f1bf35028734ca5bc391b32e65e5c71fdcb455d8
7
+ data.tar.gz: 711b5774c246d76d1d785c0c8da79fda930a68ec9f26989937cbfa26f60d6f320d6acb12f97d798957a294c50fc952c642702cd52a3ed4a4faf94cb0744ef3cd
data/.version CHANGED
@@ -1 +1 @@
1
- 0.5.36
1
+ 0.6.2
data/bin/README.md CHANGED
@@ -1,14 +1,15 @@
1
- # Lux command line helper
1
+ ## Lux command line helper
2
2
 
3
- If you run command `lux` in your app home folder, you will see something like this.
3
+ You can run command `lux` in your app home folder.
4
4
 
5
- ```
6
- [master] $ lux
7
- Lux (/Users/dux/dev/apps/my/gems/lux-fw, v0.5.20)
5
+ If you have `capistrano` or `mina` installed, you will see linked tasks here as well.
6
+
7
+ ```bash
8
+ $ lux
8
9
  Commands:
9
10
  lux config # Show server config
10
11
  lux console # Start console
11
- lux dbconsole # Get PSQL console for current database
12
+ lux erb # Parse and process *.erb templates
12
13
  lux evaluate # Eval ruby string in context of Lux::Application
13
14
  lux generate # Genrate models, cells, ...
14
15
  lux get # Get single page by path "lux get /login"
@@ -18,16 +19,28 @@ Commands:
18
19
  lux server # Start web server
19
20
  lux stats # Print project stats
20
21
 
21
- Or use one of rake tasks
22
- rake assets:clear # Clear all assets
23
- rake assets:compile # Compile assets to public/assets and generate mainifest.json
24
- rake assets:install # Install all needed packages via yarn
25
- rake assets:monitor # Monitor for file changes
26
- rake assets:s3_upload # Upload assets to S3
27
- rake assets:show # Show all files/data in manifest
22
+ Rake tasks:
23
+ rake assets:compile # Build and generate manifest
24
+ rake assets:install # Install example rollup.config.js, package.json and Procfile
28
25
  rake db:am # Automigrate schema
26
+ rake db:console # Run PSQL console
27
+ rake db:create # Create database
28
+ rake db:drop # Drop database
29
+ rake db:dump[name] # Dump database backup
30
+ rake db:reset # Reset database (drop, create, auto migrate, seed)
31
+ rake db:restore[name] # Restore database backup
32
+ rake db:seed:gen # Create seeds from models
33
+ rake db:seed:load # Load seeds from db/seeds
34
+ rake docker:bash # Get bash to web server while docker-compose up
35
+ rake docker:build # Build docker image named stemical
36
+ rake docker:up # copose up
29
37
  rake exceptions # Show exceptions
30
38
  rake exceptions:clear # Clear all excpetions
39
+ rake images:reupload # Reupload images to S3
40
+ rake job:process # Process delayed job que tasks (NSQ, Faktory, ...)
41
+ rake job:start # Start delayed job que tasks Server (NSQ, Faktory, ...)
31
42
  rake nginx:edit # Edit nginx config
32
43
  rake nginx:generate # Generate sample config
44
+ rake start # Run local dev server
45
+ rake stat:goaccess # Goaccess access stat builder
33
46
  ```
@@ -0,0 +1,18 @@
1
+ def draw_load_speed what
2
+ time = Benchmark.realtime { yield }
3
+ puts "#{(time * 1000).to_i.to_s.rjust(4) } ms #{what}"
4
+ end
5
+
6
+ LuxCli.class_eval do
7
+ desc :benchmark, 'Benchmark app boot time'
8
+ def benchmark
9
+ require "benchmark"
10
+
11
+ def Kernel.require what
12
+ draw_load_speed(what) { super }
13
+ end
14
+
15
+ draw_load_speed('./config/env.rb') { require './config/env'; puts ' --'}
16
+ draw_load_speed('./config/app.rb') { require './config/app' }
17
+ end
18
+ end
data/bin/cli/cerb.rb ADDED
@@ -0,0 +1,90 @@
1
+ class ErbParser
2
+ def self.parse file
3
+ new(file).parse_file
4
+ end
5
+
6
+ ###
7
+
8
+ def initialize file
9
+ @file = file
10
+ end
11
+
12
+ def import_css folder
13
+ Dir.find(folder, ext: [:css, :scss], invert: true) { '@import "%s";' }
14
+ end
15
+
16
+ def import_js folder
17
+ Dir.find(folder, ext: [:js, :coffee]) { 'import "%s";' }
18
+ end
19
+
20
+ def import_svelte folder:, prefix:
21
+ out = []
22
+ out.push ''
23
+
24
+ for file in Dir.find(folder, ext: [:svelte])
25
+ name = file.split('/').last.split('.').first.downcase
26
+
27
+ # cant call classify because we can have block in singular and plural
28
+ # block-post and block-posts and become SvelteBlockPost
29
+ klass = "Svelte_#{prefix}_#{name}".gsub(/[^\w]/, '_') #.classify
30
+
31
+ out.push "import #{klass} from './#{file}';";
32
+ out.push "Svelte.bind('#{prefix}-#{name.gsub('_', '-')}', #{klass});"
33
+ out.push ''
34
+ end
35
+
36
+ out.join($/)
37
+ end
38
+
39
+ def import folder
40
+ @file.include?('.js.') ? import_js(folder) : import_css(folder)
41
+ end
42
+
43
+ def parse_file
44
+ f = Pathname.new(@file)
45
+ data = f.read
46
+ # data = data.gsub(/\n<%/, '<%')
47
+
48
+ Dir.chdir f.dirname.to_s do
49
+ data = ERB.new(data).result(binding).gsub('././', './')
50
+ end
51
+
52
+ data
53
+ end
54
+ end
55
+
56
+ ###
57
+
58
+ LuxCli.class_eval do
59
+ desc :cerb, 'Parse and process *.cerb templates (cli erb)'
60
+ def cerb file=nil
61
+ # To create server side template, create file ending in .erb
62
+
63
+ require './config/app'
64
+
65
+ if file
66
+ puts ErbParser.parse(file)
67
+ else
68
+ commmand = "find . -type file | grep --color=never \\.cerb$"
69
+ puts commmand.gray
70
+ files = `#{commmand}`
71
+ .split($/)
72
+ .reject { |f| f.include?('/views/') }
73
+
74
+ Cli.die 'No erb templates found' unless files.first
75
+
76
+ for local in files
77
+ next if local.include?('/.')
78
+
79
+ target = local.sub(/\.cerb$/, '')
80
+
81
+ out = []
82
+ out.push "/* Generated from #{local} */"
83
+ out.push ErbParser.parse(local)
84
+ File.write(target, out.join("\n\n"))
85
+
86
+ puts 'Assets compile: %s -> %s (%s)' % [local.green, target, File.size(target).to_filesize]
87
+ end
88
+ end
89
+ end
90
+ end
data/bin/cli/config.rb CHANGED
@@ -2,12 +2,8 @@ LuxCli.class_eval do
2
2
  desc :config, 'Show server config'
3
3
  method_option :mode, aliases: '-m', default: 'production', desc: 'One of the server modes(dev, log, production)'
4
4
  def config
5
- ENV['LUX_MODE'] = options[:mode]
5
+ require './config/app.rb'
6
6
 
7
- require './config/application.rb'
8
-
9
- puts 'LUX_MODE=%s (-m flag)' % ENV['LUX_MODE'].green
10
- puts
11
7
  puts 'config:'
12
8
  Lux.config.sort.each do |key , value|
13
9
  value = case value
@@ -20,25 +16,22 @@ LuxCli.class_eval do
20
16
  when Proc
21
17
  'proc { ... }'
22
18
  else
23
- value
19
+ value.inspect
24
20
  end
25
21
 
26
- name = ' Lux.config.%s' % key.white
22
+ name = ' Lux.config.%s' % key.to_s.white
27
23
  print name.ljust(47)
28
24
  puts '= %s' % value
29
25
  end
30
26
 
31
27
  puts
32
28
  puts 'servers:'
33
- puts ' Lux.delay.server = %s' % Lux.delay.server
34
- puts ' Lux.cache.server = %s' % Lux.cache.server
29
+ puts ' Lux.cache.server = %s' % Lux.cache.server
35
30
 
36
31
  puts
37
32
  puts 'plugins:'
38
33
  Lux.plugin.keys.each do |key|
39
34
  puts ' Lux.plugin.%s - %s' % [key.ljust(22).white, Lux.plugin.get(key).folder]
40
35
  end
41
-
42
- Object.class_callback :info, Lux::Application
43
36
  end
44
37
  end
data/bin/cli/console.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'pry'
2
-
3
1
  class Object
4
2
  def cp data
5
3
  data = JSON.pretty_generate(data.to_hash) if data.respond_to?(:to_hash)
@@ -7,32 +5,52 @@ class Object
7
5
  'copied'
8
6
  end
9
7
 
8
+ # reload code changes
9
+ def reload!
10
+ Lux.config.on_reload_code.call :cli
11
+ end
12
+
13
+ # prettify last sql command
14
+ def sql! sql=nil
15
+ require 'niceql'
16
+ puts Niceql::Prettifier.prettify_sql sql || $last_sql_command
17
+ end
18
+
19
+ def c
20
+ Lux.error.clear_screen
21
+ end
22
+
10
23
  # show method info
11
- # show User, :secure_hash
12
- def show klass, m
13
- klass = klass.class unless klass.respond_to?(:new)
14
- el = klass.instance_method(m)
15
- puts el.source_location.or([]).join(':').yellow
16
- puts '-'
17
- puts el.source
18
- nil
24
+ # m User, :secure_hash
25
+ def m object, mtd = nil
26
+ if mtd
27
+ info = object.method(mtd)
28
+ puts info.source_location.or([]).join(':').yellow
29
+ puts '-'
30
+ puts info.source
31
+ nil
32
+ else
33
+ if object.respond_to?(:superclass)
34
+ object.methods - object.superclass.methods
35
+ else
36
+ object.methods - object.class.superclass.methods
37
+ end
38
+ end
19
39
  end
20
40
  end
21
41
 
22
-
23
42
  ARGV[0] = 'console' if ARGV[0] == 'c'
24
43
 
25
44
  LuxCli.class_eval do
26
45
  desc :console, 'Start console'
27
- def console
28
- $lux_start_time = Time.now
46
+ def console *args
47
+ ENV['LUX_ENV'] = 'clre'
29
48
 
30
- require 'awesome_print'
31
- require 'clipboard'
32
- require './config/application'
49
+ require 'amazing_print'
50
+ require './config/app'
33
51
 
34
- Lux.config.dump_errors = true
35
- Lux.config.log_to_stdout = true
52
+ # create mock session
53
+ Lux::Current.new '/'
36
54
 
37
55
  if File.exist?('./config/console.rb')
38
56
  puts '* loading ./config/console.rb'
@@ -41,21 +59,45 @@ LuxCli.class_eval do
41
59
  puts '* ./config/console.rb not found'
42
60
  end
43
61
 
44
- # AwesomePrint.pry!
45
- # nice object dump in console
46
- Pry.print = proc { |output, data|
47
- out = if data.is_a?(Hash)
48
- data.class.to_s+"\n"+JSON.pretty_generate(data).gsub(/"(\w+)":/) { '"%s":' % $1.yellow }
62
+ Pry.pager = false
63
+
64
+ Pry.config.print = proc do |output, value|
65
+ if value.is_a?(Method)
66
+ output.puts value.inspect
67
+ elsif value.is_a?(String)
68
+ output.puts value
49
69
  else
50
- data.ai
70
+ ap value
51
71
  end
72
+ end
52
73
 
53
- output.puts out
54
- }
74
+ if args.first
75
+ command = args.join(' ')
55
76
 
56
- # create mock session
57
- Lux::Current.new '/'
77
+ if command.ends_with?('.rb')
78
+ puts 'Load : %s' % command.light_blue
79
+ load command
80
+ else
81
+ puts 'Command : %s' % command.light_blue
82
+ data = eval command
83
+ puts '-'
84
+ Pry.config.print.call $stdout, data
85
+ end
86
+ else
87
+ # custom history loader
88
+ history = Pathname.new Lux.root.join('./.pry_history')
89
+
90
+ Thread.new do
91
+ # load in started pry session
92
+ sleep 0.5
93
+ if history.exist?
94
+ lines = history.read.split($/).uniq - ['exit']
95
+ lines.each {|l| Pry.history.push(l) }
96
+ end
97
+ end
98
+ Pry.start
58
99
 
59
- Pry.start
100
+ history.write Pry.history.to_a.uniq.last(100).join($/)
101
+ end
60
102
  end
61
- end
103
+ end
data/bin/cli/eval.rb CHANGED
@@ -1,32 +1,10 @@
1
+ ARGV[0] = 'eval' if ARGV[0] == 'e'
2
+
1
3
  LuxCli.class_eval do
2
4
  desc :evaluate, 'Eval ruby string in context of Lux::Application'
3
5
  def evaluate *args
4
- require './config/application'
5
-
6
- Lux.start
7
-
8
- if File.exist?('./config/console.rb')
9
- puts '* loading ./config/console.rb'
10
- load './config/console.rb'
11
- end
12
-
13
- command = ARGV.drop(1).join('; ')
14
-
15
- puts 'Command : %s' % command.light_blue
16
-
17
- data = eval command
18
-
19
- puts '-'
20
- puts 'Class : %s' % data.class
21
- puts '-'
22
-
23
- if data.is_a?(String) && data.include?('</body>')
24
- require 'nokogiri'
25
- puts Nokogiri::XML(data, &:noblanks)
26
- else
27
- ap data
28
- end
29
-
30
- exit
6
+ require 'amazing_print'
7
+ require './config/app'
8
+ console *args
31
9
  end
32
10
  end
data/bin/cli/generate.rb CHANGED
@@ -8,19 +8,16 @@ module LuxGenerate
8
8
  extend self
9
9
 
10
10
  def generate object=nil, objects=nil
11
- unless object
12
- puts "./generate [object singular]".red
13
- exit
14
- end
11
+ Cli.die "./generate [object singular]" unless object
15
12
 
16
13
  template_dir = 'config/templates'
17
- exit puts "Lux::View dir #{template_dir} is not accessible" unless Dir.exists?(template_dir)
14
+ Cli.die "Lux::Template dir #{template_dir} is not accessible" unless Dir.exist?(template_dir)
18
15
 
19
16
  tpl_desc = {
20
17
  p:'api',
21
18
  m:'model',
22
19
  a:'admin',
23
- c:'cell',
20
+ c:'controller',
24
21
  v:'view'
25
22
  }
26
23
 
@@ -34,6 +31,7 @@ module LuxGenerate
34
31
  object = @object
35
32
  objects = @objects
36
33
  klass = @object.classify
34
+ klasses = klass.pluralize
37
35
 
38
36
  data.gsub(/\{\{([^\}]+)\}\}/) { eval $1 }
39
37
  end
@@ -57,8 +55,8 @@ module LuxGenerate
57
55
  templates[type].push [path, data]
58
56
  end
59
57
 
60
- # # puts "Lux::Views : #{templates.keys.sort.map{ |el| tpl_desc[el.to_sym] ? tpl_desc[el.to_sym].sub(el, el.upcase.yellow) : el.yellow }.join(', ')}"
61
- puts "Lux::Views : #{templates.keys.map{ |el| "#{tpl_desc[el.to_sym]}(#{el.yellow})" }.join(', ')}"
58
+ # # puts "Lux::Templates : #{templates.keys.sort.map{ |el| tpl_desc[el.to_sym] ? tpl_desc[el.to_sym].sub(el, el.upcase.yellow) : el.yellow }.join(', ')}"
59
+ puts "Templates : #{templates.keys.map{ |el| "#{tpl_desc[el.to_sym]}(#{el.yellow})" }.join(', ')}"
62
60
  print "Execute : "
63
61
 
64
62
  parse_templates = STDIN.gets.chomp
@@ -67,14 +65,14 @@ module LuxGenerate
67
65
  next unless parse_templates.index(type)
68
66
  for el in templates[type]
69
67
  file, data = *el
70
- if File.exists?(file)
68
+ if File.exist?(file)
71
69
  print 'exists'.yellow.rjust(20)
72
70
  else
73
71
  FileUtils.mkdir_p(file.sub(/\/[^\/]+$/,'')) rescue false
74
72
  File.open(file, 'w') { |f| f.write(data) }
75
73
  print 'created'.green.rjust(20)
76
74
  end
77
- puts ": #{file}"
75
+ puts " #{file}"
78
76
  end
79
77
  end
80
78
  end
@@ -85,4 +83,4 @@ LuxCli.class_eval do
85
83
  def generate object, objects=nil
86
84
  LuxGenerate.generate object, objects
87
85
  end
88
- end
86
+ end
data/bin/cli/get.rb CHANGED
@@ -1,12 +1,20 @@
1
1
  LuxCli.class_eval do
2
2
  desc :get, 'Get single page by path "lux get /login"'
3
- method_option :hide, desc: 'Hide body', type: :boolean, aliases: "-h", default: false
3
+ method_option :body, desc: 'Show body', type: :boolean, aliases: "-b", default: false
4
+ method_option :info, desc: 'Show info', type: :boolean, aliases: "-i", default: false
5
+ method_option :type, desc: 'Request type', type: :boolean, aliases: "-i", default: false
4
6
  def get path
5
- require './config/application'
7
+ require './config/app'
6
8
 
7
- data = Lux.app.render(path)
8
- data[:body] = 'BODY lenght: %s kB' % (data[:body].length.to_f/1024).round(1) if options[:hide]
9
- ap data
10
- puts '-h true if you want to hide body' unless options[:hide]
9
+ Cli.die "Use\n -b to show body\n -i to show info" unless options[:body] || options[:info]
10
+
11
+ data = Lux.app.new(path).render
12
+
13
+ if options[:body]
14
+ puts data[:body]
15
+ elsif options[:info]
16
+ data[:body] = 'BODY lenght: %s kB' % (data[:body].length.to_f/1024).round(1)
17
+ ap data.to_h
18
+ end
11
19
  end
12
20
  end
data/bin/cli/memory.rb ADDED
@@ -0,0 +1,12 @@
1
+ LuxCli.class_eval do
2
+ desc :memory, 'Show memory usage'
3
+ def memory
4
+ require 'memory_profiler'
5
+
6
+ report = MemoryProfiler.report do
7
+ require './config/app'
8
+ end
9
+
10
+ report.pretty_print retained_strings: 5, allocated_strings: 5#(to_file: "profile.txt")
11
+ end
12
+ end
data/bin/cli/new.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  LuxCli.class_eval do
2
4
  desc 'new APP_NAME', 'Creates new lux application'
3
5
  def new app_folder
data/bin/cli/secrets.rb CHANGED
@@ -3,38 +3,10 @@ LuxCli.class_eval do
3
3
  def secrets
4
4
  require 'lux-fw'
5
5
 
6
- @secrets = Lux::Config::Secrets.new
7
-
8
- # create secret from template (config/secrets.enc)
9
- # or read file (tmp/secrets.yaml) if one exist
10
- unless @secrets.read_file.exist?
11
- if @secrets.secret_file.exist?
12
- @secrets.read_file.write @secrets.encoded_data
13
- Cli.info 'CREATED read file %s from secrets file' % @secrets.read_file
14
- # encoded = JWT.encode @secrets.read_file.read, @secrets.secret, @secrets.strength
15
- # @secrets.secret_file.write encoded
16
- # Cli.info 'Written secret file %s' % @secrets.secret_file
17
- else
18
- data = "version: 1\n\n"
19
- data += %w[shared production development].map{ |it| "%s:\n key: value" % it }.join("\n\n")
20
- @secrets.read_file.write data
21
- Cli.info '@Secrets file "%s" created from template.' % @secrets.read_file
22
- end
23
- end
24
-
25
- # edit ecrets file
26
- vim = `which vim`.chomp.or('vi')
27
- system '%s %s' % [vim, @secrets.read_file]
28
-
29
- # write secrets file if needed
30
- if !@secrets.secret_file.exist? || (@secrets.secret_file.ctime < @secrets.read_file.ctime)
31
- @secrets.write
32
- Cli.info 'Written secret file %s' % @secrets.secret_file
33
- end
34
-
35
6
  # show secret for easier debuging and dump secrets
36
- Cli.info 'secret: "%s"' % @secrets.secret
37
7
  Cli.info 'dump for ENV %s' % Lux.env
38
- puts @secrets.to_h.pretty_generate
8
+
9
+ Cli.info 'dump for secrets'
10
+ puts Lux.secrets.to_h.to_jsonp(true)
39
11
  end
40
12
  end
data/bin/cli/server.rb CHANGED
@@ -1,24 +1,43 @@
1
+ # RACK_ENV = test dev/development prod/production
2
+ # live acts as production. RACK_ENV=live; Lux.env.prod? # true
3
+ # LUX_ENV = clre - add any for dev env options. Emit all -> production settings
4
+ # Lux.env.no_cache? # true
5
+ # Lux.env.screen_log? # true
6
+ # Lux.env.reload_code? # true
7
+ # Lux.env.reload_code? # true
8
+
9
+ # no code reload with logging
10
+ # lux s -c
11
+
1
12
  if ARGV[0] == 's'
2
13
  ARGV[0] = 'server'
3
- elsif ARGV[0] == 'ss'
4
- # production mode with logging
5
- ARGV = %w{server -m log }
14
+ end
15
+
16
+ # lux ss -> lux -opt le (only log and errors dump, no cacing and code reload)
17
+ if ARGV[0] == 'ss'
18
+ ARGV[0] = 'server'
19
+ ARGV[1] = '-o'
20
+ ARGV[2] = 'le'
6
21
  end
7
22
 
8
23
  LuxCli.class_eval do
9
24
  desc :server, 'Start web server'
10
25
  method_option :port, aliases: '-p', default: 3000, desc: 'Port to run app on', type: :numeric
11
- method_option :mode, aliases: '-m', default: 'dev', desc: 'One of the server modes(dev, log, production)'
12
- method_option :env, aliases: '-e', default: 'd', desc: 'Environemnt, only first chart counts'
26
+ method_option :env, aliases: '-e', desc: 'Environemnt, only first chart counts (%s)'
13
27
  method_option :rerun, aliases: '-r', default: false, desc: 'rerun app on every file chenge', type: :boolean
28
+ method_option :opt, aliases: '-o', default: 'clre', desc: 'lux options (clre - cache, screen log, code reload, errors)', type: :string
14
29
  def server
15
- mode = 'LUX_MODE=%s' % options[:mode]
16
- env = options[:env][0,1] == 'p' ? 'production' : 'development'
30
+ trap("SIGINT") { Cli.die 'ctrl+c exit' }
31
+
32
+ ENV['RACK_ENV'] = options[:env] if options[:env]
33
+ ENV['LUX_ENV'] = options[:opt]
34
+
35
+ command = "RACK_ENV=#{ENV['RACK_ENV']} LUX_ENV=#{ENV['LUX_ENV']} bundle exec puma -p #{options[:port]}"
17
36
 
18
37
  if options[:rerun]
19
- Cli.run "#{mode} rerun -p '**/*.{rb,ru}' -d . -d #{LUX_ROOT} 'lux s -p #{options[:port]}'"
38
+ Cli.run "find #{LUX_ROOT} . -name *.rb | entr -r #{command}"
20
39
  else
21
- Cli.run "#{mode} puma -e #{env} -p #{options[:port]}"
40
+ Cli.run command
22
41
  end
23
42
  end
24
43
  end