lux-fw 0.2.3 → 0.5.32

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 (138) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/bin/README.md +33 -0
  4. data/bin/build_gem +76 -0
  5. data/bin/cli/config.rb +44 -0
  6. data/bin/cli/console.rb +61 -0
  7. data/bin/cli/dbconsole.rb +8 -0
  8. data/bin/cli/eval.rb +32 -0
  9. data/bin/cli/generate.rb +88 -0
  10. data/bin/cli/get.rb +12 -0
  11. data/bin/cli/new.rb +22 -0
  12. data/bin/cli/routes.rb +90 -0
  13. data/bin/cli/secrets.rb +40 -0
  14. data/bin/cli/server.rb +24 -0
  15. data/bin/cli/stats.rb +133 -0
  16. data/bin/lux +24 -65
  17. data/lib/common/class_attributes.rb +40 -64
  18. data/lib/common/class_callbacks.rb +34 -51
  19. data/lib/common/crypt.rb +10 -8
  20. data/lib/common/free_struct.rb +42 -0
  21. data/lib/common/hash_with_indifferent_access.rb +1 -1
  22. data/lib/common/html_tag_builder.rb +26 -2
  23. data/lib/common/url.rb +58 -40
  24. data/lib/lux/application/application.rb +290 -117
  25. data/lib/lux/application/lib/nav.rb +64 -38
  26. data/lib/lux/application/lib/render.rb +2 -1
  27. data/lib/lux/cache/cache.rb +87 -62
  28. data/lib/lux/cache/lib/{ram.rb → memory.rb} +5 -7
  29. data/lib/lux/cache/lib/null.rb +6 -8
  30. data/lib/lux/config/config.rb +109 -52
  31. data/lib/lux/config/lib/plugin.rb +65 -0
  32. data/lib/lux/config/lib/secrets.rb +48 -0
  33. data/lib/lux/controller/controller.rb +241 -0
  34. data/lib/lux/current/current.rb +33 -47
  35. data/lib/lux/current/lib/session.rb +72 -0
  36. data/lib/lux/delayed_job/delayed_job.rb +14 -7
  37. data/lib/lux/delayed_job/lib/memory.rb +7 -5
  38. data/lib/lux/delayed_job/lib/redis.rb +1 -1
  39. data/lib/lux/error/error.rb +164 -62
  40. data/lib/lux/event_bus/event_bus.rb +27 -0
  41. data/lib/lux/lux.rb +103 -66
  42. data/lib/lux/mailer/mailer.rb +23 -25
  43. data/lib/lux/response/lib/file.rb +81 -0
  44. data/lib/lux/response/lib/header.rb +14 -1
  45. data/lib/lux/response/response.rb +64 -56
  46. data/lib/lux/view/cell.rb +102 -0
  47. data/lib/lux/{helper → view}/helper.rb +39 -23
  48. data/lib/lux/view/lib/cell_helpers.rb +29 -0
  49. data/lib/lux/{helper/helpers/mailer_helper.rb → view/lib/helper_modules.rb} +7 -1
  50. data/lib/lux/{template/template.rb → view/view.rb} +21 -24
  51. data/lib/lux-fw.rb +4 -2
  52. data/lib/overload/array.rb +12 -6
  53. data/lib/overload/blank.rb +0 -1
  54. data/lib/overload/dir.rb +18 -0
  55. data/lib/overload/file.rb +1 -6
  56. data/lib/overload/hash.rb +56 -13
  57. data/lib/overload/integer.rb +2 -2
  58. data/lib/overload/it.rb +4 -4
  59. data/lib/overload/object.rb +37 -8
  60. data/lib/overload/{r.rb → raise_variants.rb} +23 -4
  61. data/lib/overload/string.rb +22 -6
  62. data/misc/demo/app/cells/demo_cell.rb +12 -0
  63. data/misc/demo/app/controllers/application_controller.rb +7 -0
  64. data/misc/demo/app/controllers/main/root_controller.rb +9 -0
  65. data/misc/demo/app/routes.rb +5 -0
  66. data/misc/demo/config/application.rb +14 -0
  67. data/misc/demo/config/assets.rb +6 -0
  68. data/misc/demo/config/environment.rb +7 -0
  69. data/misc/puma_auto_tune.rb +43 -0
  70. data/misc/unicorn.rb +37 -0
  71. data/{lib/lux → plugins}/api/api.rb +46 -29
  72. data/plugins/api/lib/attr.rb +31 -0
  73. data/{lib/lux → plugins}/api/lib/dsl.rb +3 -6
  74. data/{lib/lux → plugins}/api/lib/error.rb +0 -0
  75. data/{lib/lux → plugins}/api/lib/model_api.rb +51 -12
  76. data/{lib/lux → plugins}/api/lib/response.rb +31 -17
  77. data/{bin/cli/am → plugins/db/auto_migrate/auto_migrate.rb} +18 -35
  78. data/plugins/db/helpers/array_search.rb +27 -0
  79. data/plugins/db/helpers/before_save_filters.rb +32 -0
  80. data/plugins/db/helpers/composite_primary_keys.rb +36 -0
  81. data/plugins/db/helpers/core.rb +94 -0
  82. data/plugins/db/helpers/dataset_methods.rb +138 -0
  83. data/plugins/db/helpers/enums_plugin.rb +52 -0
  84. data/plugins/db/helpers/find_precache.rb +31 -0
  85. data/plugins/db/helpers/link_objects.rb +84 -0
  86. data/plugins/db/helpers/schema_checks.rb +83 -0
  87. data/plugins/db/helpers/typero_adapter.rb +71 -0
  88. data/plugins/db/logger/config.rb +22 -0
  89. data/plugins/db/logger/lux_response_adapter.rb +10 -0
  90. data/plugins/db/paginate/helper.rb +32 -0
  91. data/plugins/db/paginate/sequel_adapter.rb +23 -0
  92. data/plugins/exceptions/simple_exception.rb +64 -0
  93. data/plugins/favicon/favicon.rb +10 -0
  94. data/plugins/html/html_form.rb +118 -0
  95. data/plugins/html/html_input.rb +98 -0
  96. data/plugins/html/html_menu.rb +79 -0
  97. data/plugins/html/input_types.rb +346 -0
  98. data/plugins/js_widgets/js_widgets.rb +15 -0
  99. data/plugins/oauth/lib/facebook.rb +35 -0
  100. data/plugins/oauth/lib/github.rb +38 -0
  101. data/plugins/oauth/lib/google.rb +41 -0
  102. data/plugins/oauth/lib/linkedin.rb +41 -0
  103. data/plugins/oauth/lib/stackexchange.rb +41 -0
  104. data/plugins/oauth/lib/twitter.rb +38 -0
  105. data/plugins/oauth/oauth.rb +42 -0
  106. data/{lib/common → plugins/policy}/policy.rb +6 -7
  107. data/tasks/loader.rb +49 -0
  108. metadata +151 -49
  109. data/bin/cli/assets +0 -41
  110. data/bin/cli/console +0 -51
  111. data/bin/cli/dev +0 -1
  112. data/bin/cli/eval +0 -24
  113. data/bin/cli/exceptions +0 -62
  114. data/bin/cli/generate +0 -86
  115. data/bin/cli/get +0 -5
  116. data/bin/cli/nginx +0 -34
  117. data/bin/cli/production +0 -1
  118. data/bin/cli/render +0 -18
  119. data/bin/cli/routes +0 -14
  120. data/bin/cli/server +0 -4
  121. data/bin/cli/stat +0 -1
  122. data/bin/cli/systemd +0 -36
  123. data/bin/txt/nginx.conf +0 -46
  124. data/bin/txt/siege-and-puma.txt +0 -3
  125. data/lib/common/base32.rb +0 -47
  126. data/lib/common/dynamic_class.rb +0 -28
  127. data/lib/common/folder_model.rb +0 -50
  128. data/lib/common/generic_model.rb +0 -62
  129. data/lib/lux/application/lib/plugs.rb +0 -10
  130. data/lib/lux/application/lib/route_test.rb +0 -64
  131. data/lib/lux/cache/lib/memcached.rb +0 -3
  132. data/lib/lux/cell/cell.rb +0 -261
  133. data/lib/lux/current/lib/static_file.rb +0 -103
  134. data/lib/lux/helper/helpers/application_helper.rb +0 -3
  135. data/lib/lux/helper/helpers/html_helper.rb +0 -3
  136. data/lib/overload/auto_loader.rb +0 -27
  137. data/lib/overload/module.rb +0 -10
  138. data/lib/overload/string_inflections.rb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f17bf48ba9c67072d7a9cba132b0c8c29fb25f79bc424e39f0d4bc39b16981e
4
- data.tar.gz: ea0a19540ee7c21cebea07b6ea6ad27e967a448d1865a51097b7fe22f305e244
3
+ metadata.gz: 809c29122351db4ad4bd4de489f14f54c263b8911cc6d41b91d411beeaffe959
4
+ data.tar.gz: f4912bd49fbe63229dbccab2582c13cdf308299e4194a001c150e5e54765e7ae
5
5
  SHA512:
6
- metadata.gz: a286aecb1572cb1b7929449c914f4bed7faae1b199c63e663300eae36a5a58d40cb3c8480a59974d8a74a1dbc2a3a2269130f070bd2e3eafc6cf5dc64e4729f0
7
- data.tar.gz: 4490adeaa98e7ac83bf413511baa383f152ded339ee0fa8c97d29cab141653da1eea76059f210296b4c3e465259e484c68c20bd7d172fe94420c4c9863b688cd
6
+ metadata.gz: d919b51494836f5e12af3fe372689ed721607205d92bc2668dc075f795b65cb867bd0b642b228bf98cdca30e071acaf4fbaf10c68dc5057a2ddfc43ef88ea660
7
+ data.tar.gz: 2e514b0713c9d3dd9ad2e7c4ff91386a30fc839335a60ffa7c10d504eea8a2b1b8f76785c2568d2bd0ecc8f697d6ba5c6d674bf59fe45c502cf3b510b90490c4
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.5.32
data/bin/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Lux command line helper
2
+
3
+ If you run command `lux` in your app home folder, you will see something like this.
4
+
5
+ ```
6
+ [master] $ lux
7
+ Lux (/Users/dux/dev/apps/my/gems/lux-fw, v0.5.20)
8
+ Commands:
9
+ lux config # Show server config
10
+ lux console # Start console
11
+ lux dbconsole # Get PSQL console for current database
12
+ lux evaluate # Eval ruby string in context of Lux::Application
13
+ lux generate # Genrate models, cells, ...
14
+ lux get # Get single page by path "lux get /login"
15
+ lux help [COMMAND] # Describe available commands or one specific command
16
+ lux routes # Print routes
17
+ lux secrets # Edit, show and compile secrets
18
+ lux server # Start web server
19
+ lux stats # Print project stats
20
+
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
28
+ rake db:am # Automigrate schema
29
+ rake exceptions # Show exceptions
30
+ rake exceptions:clear # Clear all excpetions
31
+ rake nginx:edit # Edit nginx config
32
+ rake nginx:generate # Generate sample config
33
+ ```
data/bin/build_gem ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ require 'awesome_print'
5
+
6
+ class Doc
7
+
8
+ attr_reader :data
9
+
10
+ def initialize file
11
+ @file = Pathname.new file
12
+ @data = {}
13
+ read
14
+ end
15
+
16
+ private
17
+
18
+ def read
19
+ comments = []
20
+ last_line = ''
21
+
22
+ for line in @file.read.split($/)
23
+ line = line.sub /^\s+/, ''
24
+
25
+ if line[0,1] == '#'
26
+ line = '# ```ruby' if line == '# ```' && !comments.include?('```ruby')
27
+ comments.push line.sub('# ', '')
28
+ elsif line.include?('def ') && last_line[0,1] == '#' && comments[0]
29
+ m = line.split(/\s+/)
30
+ @data[m[1]] = comments
31
+ comments = []
32
+ else
33
+ comments = []
34
+ end
35
+
36
+ last_line = line
37
+ end
38
+ end
39
+ end
40
+
41
+ components = ['application', 'controller', 'view', 'current', 'mailer', 'config', 'cache', 'error', 'response']
42
+
43
+ data = []
44
+
45
+ for c, desc in components
46
+ klass = 'Lux::%s' % c.capitalize
47
+ readme = Pathname.new 'lib/lux/%s/README.md' % c
48
+ code = Pathname.new 'lib/lux/%s/%s.rb' % [c, c]
49
+
50
+ data << ''
51
+ data << readme.read.sub(/\s+$/, '')
52
+
53
+ blocks = Doc.new(code.to_s).data
54
+
55
+ if blocks.first
56
+ data << ''
57
+ data << '### %s methods' % klass
58
+
59
+ for name, parts in blocks
60
+ data << ''
61
+ data << '#### %s' % name
62
+ data << ''
63
+ data << parts.join($/)
64
+ end
65
+ end
66
+ end
67
+
68
+ out = File.read('lib/README.md')
69
+ out += data.join $/
70
+
71
+ File.write './README.md', out
72
+
73
+ `rm -rf misc/demo/public/assets`
74
+ `rm -rf misc/demo/node_modules`
75
+ `rm -rf misc/demo/Gemfile.lock`
76
+ `rm -rf misc/demo/package.json`
data/bin/cli/config.rb ADDED
@@ -0,0 +1,44 @@
1
+ LuxCli.class_eval do
2
+ desc :config, 'Show server config'
3
+ method_option :mode, aliases: '-m', default: 'production', desc: 'One of the server modes(dev, log, production)'
4
+ def config
5
+ ENV['LUX_MODE'] = options[:mode]
6
+
7
+ require './config/application.rb'
8
+
9
+ puts 'LUX_MODE=%s (-m flag)' % ENV['LUX_MODE'].green
10
+ puts
11
+ puts 'config:'
12
+ Lux.config.sort.each do |key , value|
13
+ value = case value
14
+ when TrueClass
15
+ 'true'.green
16
+ when FalseClass
17
+ 'false'.red
18
+ when String
19
+ "#{value.white}"
20
+ when Proc
21
+ 'proc { ... }'
22
+ else
23
+ value
24
+ end
25
+
26
+ name = ' Lux.config.%s' % key.white
27
+ print name.ljust(47)
28
+ puts '= %s' % value
29
+ end
30
+
31
+ puts
32
+ puts 'servers:'
33
+ puts ' Lux.delay.server = %s' % Lux.delay.server
34
+ puts ' Lux.cache.server = %s' % Lux.cache.server
35
+
36
+ puts
37
+ puts 'plugins:'
38
+ Lux.plugin.keys.each do |key|
39
+ puts ' Lux.plugin.%s - %s' % [key.ljust(22).white, Lux.plugin.get(key).folder]
40
+ end
41
+
42
+ Object.class_callback :info, Lux::Application
43
+ end
44
+ end
@@ -0,0 +1,61 @@
1
+ require 'pry'
2
+
3
+ class Object
4
+ def cp data
5
+ data = JSON.pretty_generate(data.to_hash) if data.respond_to?(:to_hash)
6
+ Clipboard.copy data
7
+ 'copied'
8
+ end
9
+
10
+ # 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
19
+ end
20
+ end
21
+
22
+
23
+ ARGV[0] = 'console' if ARGV[0] == 'c'
24
+
25
+ LuxCli.class_eval do
26
+ desc :console, 'Start console'
27
+ def console
28
+ $lux_start_time = Time.now
29
+
30
+ require 'awesome_print'
31
+ require 'clipboard'
32
+ require './config/application'
33
+
34
+ Lux.config.dump_errors = true
35
+ Lux.config.log_to_stdout = true
36
+
37
+ if File.exist?('./config/console.rb')
38
+ puts '* loading ./config/console.rb'
39
+ require './config/console'
40
+ else
41
+ puts '* ./config/console.rb not found'
42
+ end
43
+
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 }
49
+ else
50
+ data.ai
51
+ end
52
+
53
+ output.puts out
54
+ }
55
+
56
+ # create mock session
57
+ Lux::Current.new '/'
58
+
59
+ Pry.start
60
+ end
61
+ end
@@ -0,0 +1,8 @@
1
+ LuxCli.class_eval do
2
+ desc :dbconsole, 'Get PSQL console for current database'
3
+ def dbconsole
4
+ require './config/environment'
5
+
6
+ system "psql '%s'" % ENV.fetch('DB_URL') { Lux.secrets.db_url }
7
+ end
8
+ end
data/bin/cli/eval.rb ADDED
@@ -0,0 +1,32 @@
1
+ LuxCli.class_eval do
2
+ desc :evaluate, 'Eval ruby string in context of Lux::Application'
3
+ 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
31
+ end
32
+ end
@@ -0,0 +1,88 @@
1
+ require 'fileutils'
2
+ require 'sequel'
3
+ require 'pp'
4
+
5
+ Sequel.extension :inflector
6
+
7
+ module LuxGenerate
8
+ extend self
9
+
10
+ def generate object=nil, objects=nil
11
+ unless object
12
+ puts "./generate [object singular]".red
13
+ exit
14
+ end
15
+
16
+ template_dir = 'config/templates'
17
+ exit puts "Lux::View dir #{template_dir} is not accessible" unless Dir.exists?(template_dir)
18
+
19
+ tpl_desc = {
20
+ p:'api',
21
+ m:'model',
22
+ a:'admin',
23
+ c:'cell',
24
+ v:'view'
25
+ }
26
+
27
+ @object = object
28
+ @objects = objects || @object.pluralize
29
+
30
+ puts "Singular : #{@object.yellow}"
31
+ puts "Plural : #{@objects.yellow}"
32
+
33
+ def parse_vars(data)
34
+ object = @object
35
+ objects = @objects
36
+ klass = @object.classify
37
+
38
+ data.gsub(/\{\{([^\}]+)\}\}/) { eval $1 }
39
+ end
40
+
41
+ # get all files
42
+ templates = {}
43
+ for el in Dir["./#{template_dir}/*.*"].map{ |file| file.split('/').last }
44
+ begin
45
+ data = parse_vars(File.read("#{template_dir}/#{el}"))
46
+ rescue
47
+ puts '-'
48
+ puts "File error: #{el.red}: #{$!.message}"
49
+ exit
50
+ end
51
+ type = el[0,1]
52
+
53
+ path = el.split('|', 2)[1]
54
+ path = parse_vars(path).gsub('#','/')
55
+
56
+ templates[type] ||= []
57
+ templates[type].push [path, data]
58
+ end
59
+
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(', ')}"
62
+ print "Execute : "
63
+
64
+ parse_templates = STDIN.gets.chomp
65
+
66
+ for type in templates.keys
67
+ next unless parse_templates.index(type)
68
+ for el in templates[type]
69
+ file, data = *el
70
+ if File.exists?(file)
71
+ print 'exists'.yellow.rjust(20)
72
+ else
73
+ FileUtils.mkdir_p(file.sub(/\/[^\/]+$/,'')) rescue false
74
+ File.open(file, 'w') { |f| f.write(data) }
75
+ print 'created'.green.rjust(20)
76
+ end
77
+ puts ": #{file}"
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ LuxCli.class_eval do
84
+ desc :generate, 'Genrate models, cells, ...'
85
+ def generate object, objects=nil
86
+ LuxGenerate.generate object, objects
87
+ end
88
+ end
data/bin/cli/get.rb ADDED
@@ -0,0 +1,12 @@
1
+ LuxCli.class_eval do
2
+ desc :get, 'Get single page by path "lux get /login"'
3
+ method_option :hide, desc: 'Hide body', type: :boolean, aliases: "-h", default: false
4
+ def get path
5
+ require './config/application'
6
+
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]
11
+ end
12
+ end
data/bin/cli/new.rb ADDED
@@ -0,0 +1,22 @@
1
+ LuxCli.class_eval do
2
+ desc 'new APP_NAME', 'Creates new lux application'
3
+ def new app_folder
4
+ Cli.die 'Folder allready exists' if Dir.exist?(app_folder)
5
+
6
+ Dir.mkdir(app_folder)
7
+
8
+ demo_path = Pathname.new(__dir__).join('../../misc/demo').to_s
9
+
10
+ Cli.run "rsync -a -v --ignore-existing '#{demo_path}/' ./#{app_folder}"
11
+
12
+ Dir.chdir(app_folder) do
13
+ Cli.run "bundle install"
14
+ Cli.run "bundle exec lux_assets install"
15
+ end
16
+
17
+ puts
18
+ puts 'Success! now:'.green
19
+ puts 'cd %s' % app_folder
20
+ puts 'lux s'
21
+ end
22
+ end
data/bin/cli/routes.rb ADDED
@@ -0,0 +1,90 @@
1
+ LuxCli.class_eval do
2
+ desc :routes, 'Print routes'
3
+ def routes
4
+ require './config/application'
5
+
6
+ # overload route methods to print routes
7
+ ::Lux::Application.class_eval do
8
+ def error *args
9
+ end
10
+
11
+ def indent value=nil
12
+ @indent ||= 0
13
+ @indent += value if value
14
+ ' ' * @indent
15
+ end
16
+
17
+ def show_route route, target
18
+ route = route.keys.first if route.is_a?(Hash)
19
+
20
+ controller = nil
21
+
22
+ if route.is_a?(Array)
23
+ for rut in route
24
+ rut = rut.to_s
25
+ rut = [@prefix, rut].join('/') if @prefix
26
+ print "#{indent}/#{rut}".ljust(50)
27
+ puts ["#{target}_controller".classify, rut].join ' # '
28
+ end
29
+ return
30
+ elsif target.is_a?(String)
31
+ target = target.split('#')
32
+ target[0] += '_controller'
33
+ target[0] = target[0].classify
34
+ controller = target[0].constantize rescue nil
35
+ target = target.join(' # ')
36
+ else
37
+ controller = target
38
+ target = target
39
+ end
40
+
41
+ route = route.to_s
42
+ route = [@prefix, route].join('/') if @prefix
43
+ route = '/%s' % route unless route.include?('/')
44
+ route += '/*' unless target.include?('#')
45
+ route = "#{@prefix}/*" if route .include?('#')
46
+ print "#{indent}#{route}".ljust(50)
47
+ print target.ljust(50)
48
+
49
+ if controller && !target.include?('#')
50
+ puts
51
+ for el in controller.instance_methods(false)
52
+ print " #{route.to_s.sub('/*', '/')}#{el}".ljust(50)
53
+ puts [target, el].join(' # ')
54
+ end
55
+ else
56
+ puts
57
+ end
58
+ end
59
+
60
+ def map obj, &block
61
+ if @target
62
+ target = @target.is_a?(String) && !@target.include?('#') ? @target + "##{obj}" : @target
63
+ show_route obj, target
64
+ elsif obj.is_a?(Hash)
65
+ show_route obj.keys.first, obj.values.first
66
+ elsif block_given?
67
+ @target = obj
68
+ yield
69
+ @target = nil
70
+ end
71
+ end
72
+
73
+ def namespace name
74
+ name = ':%s' % name if name.is_a?(Symbol)
75
+ @prefix = '%s/%s' % [@prefix, name]
76
+ puts '%s (namespace)' % name.yellow
77
+ indent 1
78
+ yield
79
+ indent -1
80
+ @prefix = nil
81
+ end
82
+ end
83
+
84
+ begin
85
+ Lux::Application.render '/route-mock'
86
+ rescue => e
87
+ "#{e.class} - #{e.message}"
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,40 @@
1
+ LuxCli.class_eval do
2
+ desc :secrets, 'Edit, show and compile secrets'
3
+ def secrets
4
+ require 'lux-fw'
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
+ # show secret for easier debuging and dump secrets
36
+ Cli.info 'secret: "%s"' % @secrets.secret
37
+ Cli.info 'dump for ENV %s' % Lux.env
38
+ puts @secrets.to_h.pretty_generate
39
+ end
40
+ end
data/bin/cli/server.rb ADDED
@@ -0,0 +1,24 @@
1
+ if ARGV[0] == 's'
2
+ ARGV[0] = 'server'
3
+ elsif ARGV[0] == 'ss'
4
+ # production mode with logging
5
+ ARGV = %w{server -m log }
6
+ end
7
+
8
+ LuxCli.class_eval do
9
+ desc :server, 'Start web server'
10
+ 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'
13
+ method_option :rerun, aliases: '-r', default: false, desc: 'rerun app on every file chenge', type: :boolean
14
+ def server
15
+ mode = 'LUX_MODE=%s' % options[:mode]
16
+ env = options[:env][0,1] == 'p' ? 'production' : 'development'
17
+
18
+ if options[:rerun]
19
+ Cli.run "#{mode} rerun -p '**/*.{rb,ru}' -d . -d #{LUX_ROOT} 'lux s -p #{options[:port]}'"
20
+ else
21
+ Cli.run "#{mode} puma -e #{env} -p #{options[:port]}"
22
+ end
23
+ end
24
+ end
data/bin/cli/stats.rb ADDED
@@ -0,0 +1,133 @@
1
+ class LuxStat
2
+ def call name, title=nil
3
+ puts (title || name.to_s.capitalize).yellow
4
+ send name
5
+ puts
6
+ end
7
+
8
+ def controllers
9
+ list_method_classes Lux::Controller
10
+ end
11
+
12
+ def cells
13
+ list_method_classes ViewCell
14
+ end
15
+
16
+ def models
17
+ list = ObjectSpace
18
+ .each_object(Class)
19
+ .select{ |it| it.ancestors.include?(ApplicationModel) }
20
+ .map(&:to_s)
21
+ .sort
22
+ .drop(1)
23
+ .map(&:constantize)
24
+
25
+ desc = list.length.pluralize(:models)
26
+ mcnt = list.inject(0){ |t, m| t + m.instance_methods(false).length }
27
+
28
+ list = list.map(&:to_s)
29
+
30
+ while data = get_line(list, 100)
31
+ puts ' ' + data
32
+ end
33
+
34
+ puts " #{desc} and #{mcnt.pluralize(:method)}".blue
35
+ end
36
+
37
+ def views
38
+ view_dirs = Dir
39
+ .entries('./app/views')
40
+ .drop(2)
41
+ .select { |it| File.directory?('./app/views/%s' % it) }
42
+
43
+ for dir in view_dirs
44
+ files = `find app/views/#{dir}/ -type f`.count($/)
45
+ puts " #{files.pluralize(:file).rjust(9).white} in #{dir.blue}"
46
+
47
+ end
48
+ end
49
+
50
+ def total
51
+ dirs = Dir
52
+ .entries('./app')
53
+ .drop(2)
54
+ .select { |it| File.directory?('./app/%s' % it) }
55
+
56
+ max_len = dirs.max_by(&:length).length + 1
57
+
58
+ for el in dirs
59
+ files = `find ./app/#{el}/ -type f`.count($/)
60
+ lines = `find ./app/#{el}/ -type f | xargs wc -l`.split($/).last.to_i
61
+ puts " #{files.pluralize(:files).rjust(9).white} and #{lines.pluralize(:lines).rjust(12).white} in #{el.blue}"
62
+ end
63
+ end
64
+
65
+ def total_ext
66
+ for ext in [:js, :coffee, :scss, :css, :rb, :haml, :html]
67
+ lines = `find ./app -type f -name '*.#{ext}' | xargs wc -l`.split($/)
68
+ cnt = lines.pop.to_i
69
+ puts "#{ext.to_s.rjust(8).white} #{cnt.pluralize(:line).rjust(14)} in #{lines.length.pluralize(:files)}"
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+
76
+ def get_line list, len
77
+ data = list.shift || return
78
+
79
+ while data.length < len
80
+ el = list.shift
81
+ return data unless el
82
+ data += ', %s' % el
83
+ end
84
+
85
+ data
86
+ end
87
+
88
+ def list_method_classes name
89
+ classes = ObjectSpace
90
+ .each_object(Class)
91
+ .select{ |it| it.ancestors.include?(name) }
92
+ .reject{ |it| it == name }
93
+ .map(&:to_s)
94
+ .reject{ |it| it[0,1]=='#' }
95
+ .sort
96
+ .map(&:constantize)
97
+
98
+ max = classes.inject(0) { |t, it| t = it.to_s.length if it.to_s.length > t; t }
99
+ n_methods = 0
100
+
101
+ for klass in classes
102
+ list = klass.instance_methods(false).map(&:to_s)
103
+ next unless list.first
104
+
105
+ n_methods += list.length
106
+
107
+ prefix = ' ' + klass.to_s.ljust(max + 2).white
108
+
109
+ while data = get_line(list, 100 - max)
110
+ print prefix
111
+ puts data
112
+ prefix = ' ' * max + ' '
113
+ end
114
+ end
115
+
116
+ puts " #{n_methods.pluralize('method')} in #{classes.length.pluralize('classes')}".blue
117
+ end
118
+ end
119
+
120
+ LuxCli.class_eval do
121
+ desc :stats, 'Print project stats'
122
+ def stats
123
+ require './config/application'
124
+
125
+ stat = LuxStat.new
126
+ stat.call :controllers
127
+ stat.call :cells if defined?(ViewCell)
128
+ stat.call :models
129
+ stat.call :views
130
+ stat.call :total, 'Totals per folder in ./app'
131
+ stat.call :total_ext, 'Totals per file type in ./app'
132
+ end
133
+ end