ditty 0.8.0 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/.env.test +2 -0
  3. data/.gitignore +3 -0
  4. data/.pryrc +2 -0
  5. data/.rubocop.yml +23 -4
  6. data/.travis.yml +4 -8
  7. data/CNAME +1 -0
  8. data/Dockerfile +18 -0
  9. data/Gemfile.ci +0 -17
  10. data/Rakefile +2 -2
  11. data/_config.yml +1 -0
  12. data/config.ru +4 -4
  13. data/ditty.gemspec +28 -18
  14. data/docs/CNAME +1 -0
  15. data/docs/_config.yml +1 -0
  16. data/docs/index.md +34 -0
  17. data/exe/ditty +2 -0
  18. data/lib/ditty/cli.rb +41 -5
  19. data/lib/ditty/components/{app.rb → ditty.rb} +18 -16
  20. data/lib/ditty/controllers/{application.rb → application_controller.rb} +63 -34
  21. data/lib/ditty/controllers/{audit_logs.rb → audit_logs_controller.rb} +4 -2
  22. data/lib/ditty/controllers/{auth.rb → auth_controller.rb} +22 -18
  23. data/lib/ditty/controllers/{component.rb → component_controller.rb} +23 -20
  24. data/lib/ditty/controllers/{main.rb → main_controller.rb} +6 -2
  25. data/lib/ditty/controllers/roles_controller.rb +23 -0
  26. data/lib/ditty/controllers/user_login_traits_controller.rb +46 -0
  27. data/lib/ditty/controllers/{users.rb → users_controller.rb} +13 -11
  28. data/lib/ditty/db.rb +7 -5
  29. data/lib/ditty/emails/base.rb +37 -32
  30. data/lib/ditty/generators/crud_generator.rb +114 -0
  31. data/lib/ditty/generators/migration_generator.rb +26 -0
  32. data/lib/ditty/generators/project_generator.rb +52 -0
  33. data/lib/ditty/helpers/component.rb +2 -1
  34. data/lib/ditty/helpers/pundit.rb +24 -8
  35. data/lib/ditty/helpers/response.rb +15 -13
  36. data/lib/ditty/helpers/views.rb +28 -6
  37. data/lib/ditty/listener.rb +6 -4
  38. data/lib/ditty/memcached.rb +8 -0
  39. data/lib/ditty/middleware/accept_extension.rb +2 -2
  40. data/lib/ditty/middleware/error_catchall.rb +2 -2
  41. data/lib/ditty/models/base.rb +9 -0
  42. data/lib/ditty/models/identity.rb +11 -7
  43. data/lib/ditty/models/role.rb +1 -0
  44. data/lib/ditty/models/user.rb +23 -2
  45. data/lib/ditty/policies/role_policy.rb +1 -1
  46. data/lib/ditty/policies/user_login_trait_policy.rb +1 -1
  47. data/lib/ditty/policies/user_policy.rb +1 -1
  48. data/lib/ditty/services/authentication.rb +27 -16
  49. data/lib/ditty/services/email.rb +19 -15
  50. data/lib/ditty/services/logger.rb +26 -20
  51. data/lib/ditty/services/pagination_wrapper.rb +7 -5
  52. data/lib/ditty/services/settings.rb +7 -6
  53. data/lib/ditty/tasks/ditty.rake +19 -1
  54. data/lib/ditty/tasks/omniauth-ldap.rake +2 -2
  55. data/lib/ditty/templates/.gitignore +5 -0
  56. data/lib/ditty/templates/.rspec +2 -0
  57. data/lib/ditty/templates/.rubocop.yml +7 -0
  58. data/lib/ditty/templates/Rakefile +12 -0
  59. data/lib/ditty/templates/application.rb +12 -0
  60. data/lib/ditty/templates/config.ru +37 -0
  61. data/lib/ditty/templates/controller.rb.erb +64 -0
  62. data/lib/ditty/templates/env.example +4 -0
  63. data/lib/ditty/templates/lib/project.rb.erb +5 -0
  64. data/lib/ditty/templates/logs/.empty_directory +0 -0
  65. data/lib/ditty/templates/migration.rb.erb +7 -0
  66. data/lib/ditty/templates/model.rb.erb +26 -0
  67. data/lib/ditty/templates/pids/.empty_directory +0 -0
  68. data/lib/ditty/templates/policy.rb.erb +48 -0
  69. data/{public → lib/ditty/templates/public}/browserconfig.xml +0 -0
  70. data/lib/ditty/templates/public/css/sb-admin-2.min.css +10 -0
  71. data/lib/ditty/templates/public/css/styles.css +13 -0
  72. data/lib/ditty/templates/public/favicon.ico +0 -0
  73. data/{public → lib/ditty/templates/public}/images/apple-icon.png +0 -0
  74. data/{public → lib/ditty/templates/public}/images/favicon-16x16.png +0 -0
  75. data/{public → lib/ditty/templates/public}/images/favicon-32x32.png +0 -0
  76. data/{public → lib/ditty/templates/public}/images/launcher-icon-1x.png +0 -0
  77. data/{public → lib/ditty/templates/public}/images/launcher-icon-2x.png +0 -0
  78. data/{public → lib/ditty/templates/public}/images/launcher-icon-4x.png +0 -0
  79. data/{public → lib/ditty/templates/public}/images/mstile-150x150.png +0 -0
  80. data/{public → lib/ditty/templates/public}/images/safari-pinned-tab.svg +0 -0
  81. data/lib/ditty/templates/public/js/sb-admin-2.min.js +7 -0
  82. data/lib/ditty/templates/public/js/scripts.js +1 -0
  83. data/{public/manifest.json → lib/ditty/templates/public/manifest.json.erb} +2 -2
  84. data/lib/ditty/templates/settings.yml.erb +29 -0
  85. data/lib/ditty/templates/sidekiq.rb +18 -0
  86. data/lib/ditty/templates/sidekiq.yml +9 -0
  87. data/lib/ditty/templates/spec_helper.rb +43 -0
  88. data/lib/ditty/templates/type.rb.erb +21 -0
  89. data/lib/ditty/templates/views/display.haml.tt +20 -0
  90. data/lib/ditty/templates/views/edit.haml.tt +10 -0
  91. data/lib/ditty/templates/views/form.haml.tt +11 -0
  92. data/lib/ditty/templates/views/index.haml.tt +29 -0
  93. data/lib/ditty/templates/views/new.haml.tt +10 -0
  94. data/lib/ditty/version.rb +1 -1
  95. data/lib/ditty.rb +6 -4
  96. data/lib/rubocop/cop/ditty/call_services_directly.rb +2 -2
  97. data/migrate/20181209_add_user_login_traits.rb +4 -4
  98. data/migrate/20190220_add_parent_id_to_roles.rb +9 -0
  99. data/spec/ditty/api_spec.rb +51 -0
  100. data/spec/ditty/controllers/roles_spec.rb +67 -0
  101. data/spec/ditty/controllers/user_login_traits_spec.rb +72 -0
  102. data/spec/ditty/controllers/users_spec.rb +72 -0
  103. data/spec/ditty/emails/base_spec.rb +76 -0
  104. data/spec/ditty/emails/forgot_password_spec.rb +20 -0
  105. data/spec/ditty/helpers/component_spec.rb +85 -0
  106. data/spec/ditty/models/user_spec.rb +36 -0
  107. data/spec/ditty/services/email_spec.rb +36 -0
  108. data/spec/ditty/services/logger_spec.rb +68 -0
  109. data/spec/ditty/services/settings_spec.rb +63 -0
  110. data/spec/ditty_spec.rb +9 -0
  111. data/spec/factories.rb +46 -0
  112. data/spec/fixtures/logger.yml +17 -0
  113. data/spec/fixtures/section.yml +3 -0
  114. data/spec/fixtures/settings.yml +8 -0
  115. data/spec/spec_helper.rb +51 -0
  116. data/spec/support/api_shared_examples.rb +250 -0
  117. data/spec/support/crud_shared_examples.rb +145 -0
  118. data/views/403.haml +1 -1
  119. data/views/404.haml +2 -4
  120. data/views/500.haml +11 -0
  121. data/views/audit_logs/index.haml +32 -33
  122. data/views/auth/forgot_password.haml +32 -16
  123. data/views/auth/identity.haml +14 -13
  124. data/views/auth/ldap.haml +2 -2
  125. data/views/auth/login.haml +23 -17
  126. data/views/auth/register.haml +20 -18
  127. data/views/auth/register_identity.haml +27 -12
  128. data/views/auth/reset_password.haml +36 -19
  129. data/views/blank.haml +43 -0
  130. data/views/embedded.haml +17 -11
  131. data/views/index.haml +1 -1
  132. data/views/layout.haml +45 -30
  133. data/views/partials/actions.haml +15 -14
  134. data/views/partials/content_tag.haml +0 -0
  135. data/views/partials/delete_form.haml +1 -1
  136. data/views/partials/filter_control.haml +2 -2
  137. data/views/partials/footer.haml +6 -5
  138. data/views/partials/form_control.haml +19 -12
  139. data/views/partials/form_tag.haml +1 -1
  140. data/views/partials/navitems.haml +42 -0
  141. data/views/partials/notifications.haml +12 -8
  142. data/views/partials/pager.haml +44 -25
  143. data/views/partials/search.haml +15 -11
  144. data/views/partials/sidebar.haml +15 -37
  145. data/views/partials/sort_ui.haml +2 -0
  146. data/views/partials/topbar.haml +53 -0
  147. data/views/partials/user_associations.haml +32 -0
  148. data/views/quick_start.haml +23 -0
  149. data/views/roles/display.haml +27 -6
  150. data/views/roles/edit.haml +3 -3
  151. data/views/roles/form.haml +1 -0
  152. data/views/roles/index.haml +23 -16
  153. data/views/roles/new.haml +2 -2
  154. data/views/user_login_traits/display.haml +4 -4
  155. data/views/user_login_traits/edit.haml +3 -3
  156. data/views/user_login_traits/index.haml +23 -25
  157. data/views/user_login_traits/new.haml +2 -2
  158. data/views/users/display.haml +14 -15
  159. data/views/users/edit.haml +3 -3
  160. data/views/users/form.haml +0 -0
  161. data/views/users/index.haml +31 -24
  162. data/views/users/login_traits.haml +6 -8
  163. data/views/users/new.haml +2 -2
  164. data/views/users/profile.haml +15 -15
  165. data/views/users/user.haml +1 -1
  166. metadata +271 -63
  167. data/lib/ditty/controllers/roles.rb +0 -13
  168. data/lib/ditty/controllers/user_login_traits.rb +0 -18
  169. data/views/partials/navbar.haml +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b391296636a3f248171d3d71ca4c11466b8cce56f8814c271f2352e241da297
4
- data.tar.gz: 8b136a384187ea59d6d8caa8f46f3dcc7a4a72939ba924ddff0eb8a332828aa1
3
+ metadata.gz: 0ef6903491ad20b85916f196652705811820c13f3ed14552fc9b35687dbe7309
4
+ data.tar.gz: 1431f00aee5e7093757936e5b12231d091d41bcfb798dda53e534d289f43c5dc
5
5
  SHA512:
6
- metadata.gz: 8102d97c1b3516e4f922600055a22b5bff5293dd69fbcb92a5cd233ad0e9f2e52fc6f091e05aebcee9e1dd610e76b0049db29b1eccfd54ff09f794325156cf68
7
- data.tar.gz: c1ad5e59438e58fc6dbc34d5d2a95b1c5da4a0ccb88481fc15b9dd5942ece2d7525adcf52d3d520f9fd2c91dff65829d24a27ad8fb60d66889ac6f9b983c2fba
6
+ metadata.gz: b8383f78d50a4b1a2379b34f5ea81969fc019130dd953e7218d499a7596217ea12eef13d804de7b888da7145fc865bb3e798453f664597951f953df5a06eec00
7
+ data.tar.gz: c36d004df0b9ce15aba2fbf99f376fef6fa5f70a2cc4338163cd360c730f2398ab4a5b3b0c29362ba20a90502397475aa4b4a1769b3acb9f50965eae371b680a
data/.env.test ADDED
@@ -0,0 +1,2 @@
1
+ CC_TEST_REPORTER_ID=289860573c6284a8e277de86848caba84d840be49e35f3601bcd672ab40d1e35
2
+ DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true
data/.gitignore CHANGED
@@ -14,3 +14,6 @@ vendor
14
14
  *.db
15
15
  /Gemfile.dev.lock
16
16
  migrations
17
+ /gems.*
18
+ .env
19
+ .env.*.local
data/.pryrc CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if defined?(PryByebug)
2
4
  Pry.commands.alias_command 'c', 'continue'
3
5
  Pry.commands.alias_command 's', 'step'
data/.rubocop.yml CHANGED
@@ -1,9 +1,28 @@
1
- require: rubocop-rspec
2
-
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-performance
4
+ - rubocop-thread_safety
5
+ - rubocop-sequel
3
6
  AllCops:
4
- TargetRubyVersion: 2.3
5
- Metrics/LineLength:
7
+ NewCops: enable
8
+ TargetRubyVersion: 2.7.1
9
+ Exclude:
10
+ - migrate/**/*
11
+ Layout/LineLength:
6
12
  Max: 120
7
13
  Layout/LeadingCommentSpace:
8
14
  Exclude:
9
15
  - 'config.ru'
16
+ Layout/EndOfLine:
17
+ EnforcedStyle: lf
18
+ Layout/MultilineMethodCallIndentation:
19
+ EnforcedStyle: indented
20
+ IndentationWidth: 2
21
+ Layout/IndentationConsistency:
22
+ EnforcedStyle: indented_internal_methods
23
+ Layout/EndAlignment:
24
+ EnforcedStyleAlignWith: variable
25
+ Metrics/MethodLength:
26
+ CountAsOne: ['array', 'heredoc', 'hash']
27
+ Style/Documentation:
28
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,15 +1,11 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.6.0
5
- - 2.5.3
6
- - 2.4.5
7
- - 2.3.8
4
+ - 3.0
5
+ - 2.7
6
+ - 2.6
8
7
  gemfile: Gemfile.ci
9
8
  env:
10
- global:
11
- - CC_TEST_REPORTER_ID=289860573c6284a8e277de86848caba84d840be49e35f3601bcd672ab40d1e35
12
- - DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true
13
9
  matrix:
14
10
  - DATABASE_URL="sqlite::memory:" RACK_ENV=test
15
11
  before_install:
@@ -21,7 +17,7 @@ before_script:
21
17
  - bundle exec rake ditty:prep
22
18
  script:
23
19
  - bundle exec rake
24
- - bundle exec rubocop --fail-level W lib views specs
20
+ - bundle exec rubocop --fail-level W lib views spec
25
21
  after_script:
26
22
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
27
23
  after_success:
data/CNAME ADDED
@@ -0,0 +1 @@
1
+ ditty.io
data/Dockerfile ADDED
@@ -0,0 +1,18 @@
1
+ FROM ruby:2.5.3-alpine3.8
2
+ LABEL maintainer: "Sergey Shkarupa <s.shkarupa@gmail.com>"
3
+
4
+ RUN apk add --no-cache \
5
+ build-base \
6
+ less \
7
+ git \
8
+ libxml2-dev \
9
+ libxslt-dev \
10
+ sqlite-dev \
11
+ sqlite-doc \
12
+ sqlite-libs \
13
+ && gem install bundler:1.17.3
14
+
15
+ WORKDIR /usr/src/app
16
+
17
+ COPY . ./
18
+ RUN bundle install --jobs=$(nproc) --no-cache --clean
data/Gemfile.ci CHANGED
@@ -2,20 +2,3 @@
2
2
  source 'https://rubygems.org'
3
3
 
4
4
  gemspec
5
-
6
- gem 'faker'
7
- gem 'rubocop'
8
- gem 'rubocop-rspec'
9
- gem 'simplecov', '~> 0.13.0'
10
- gem 'sqlite3'
11
-
12
- if RUBY_VERSION < '2.1'
13
- gem 'sidekiq', '3.0.0'
14
- gem 'activesupport', '<4.0.0'
15
- gem 'omniauth', '~>1.4.2'
16
- elsif RUBY_VERSION < '2.2.0'
17
- gem 'sidekiq', '4.0.0'
18
- gem 'activesupport', '<5.0.0'
19
- else
20
- gem 'activesupport'
21
- end
data/Rakefile CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'rake'
4
4
  require 'ditty'
5
- require 'ditty/components/app'
5
+ require 'ditty/components/ditty'
6
6
 
7
- Ditty.component :app
7
+ Ditty.component :ditty
8
8
 
9
9
  Ditty::Components.tasks
10
10
  require 'bundler/gem_tasks' if File.exist? 'ditty.gemspec'
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-architect
data/config.ru CHANGED
@@ -6,14 +6,14 @@ use Rack::Session::Cookie,
6
6
  # :secure=>!TEST_MODE, # Uncomment if only allowing https:// access
7
7
  secret: File.read('.session_secret')
8
8
 
9
- require 'ditty/components/app'
10
- Ditty.component :app
9
+ require 'ditty/components/ditty'
10
+ Ditty.component :ditty
11
11
 
12
12
  require 'ditty/services/authentication'
13
13
  use OmniAuth::Builder do
14
- Ditty::Services::Authentication.config.each do |prov, config|
14
+ ::Ditty::Services::Authentication.config.each do |prov, config|
15
15
  provider prov, *config[:arguments]
16
16
  end
17
17
  end
18
18
 
19
- run Rack::URLMap.new Ditty::Components.routes
19
+ run Rack::URLMap.new ::Ditty::Components.routes
data/ditty.gemspec CHANGED
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'ditty/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'ditty'
9
- spec.version = Ditty::VERSION
9
+ spec.version = ::Ditty::VERSION
10
10
  spec.authors = ['Jurgens du Toit']
11
11
  spec.email = ['jrgns@jadeit.co.za']
12
12
 
@@ -15,37 +15,47 @@ Gem::Specification.new do |spec|
15
15
  spec.homepage = 'https://github.com/eagerelk/ditty'
16
16
  spec.license = 'MIT'
17
17
 
18
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.files = `git ls-files -z`.split("\x0") #.reject { |f| f.match(%r{^(test|spec|features)/}) }
19
19
  spec.bindir = 'exe'
20
20
  spec.executables = ['ditty']
21
21
  spec.require_paths = ['lib']
22
22
 
23
23
  spec.add_development_dependency 'bundler', '>= 1'
24
- spec.add_development_dependency 'database_cleaner'
24
+ spec.add_development_dependency 'dotenv'
25
+ spec.add_development_dependency 'database_cleaner', '~> 1.0'
25
26
  spec.add_development_dependency 'factory_bot'
26
- spec.add_development_dependency 'rack-test'
27
+ spec.add_development_dependency 'faker'
27
28
  spec.add_development_dependency 'racksh'
29
+ spec.add_development_dependency 'rack-test'
28
30
  spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'rubocop'
32
+ spec.add_development_dependency 'rubocop-performance'
33
+ spec.add_development_dependency 'rubocop-rspec'
34
+ spec.add_development_dependency 'rubocop-sequel'
35
+ spec.add_development_dependency 'rubocop-thread_safety'
36
+ spec.add_development_dependency 'simplecov', '~> 0.13.0'
37
+ spec.add_development_dependency 'sqlite3'
29
38
  spec.add_development_dependency 'timecop'
30
39
 
31
- spec.add_dependency 'activesupport', '>= 3'
32
- spec.add_dependency 'bcrypt', '~> 3.1'
33
- spec.add_dependency 'browser', '~> 2.5'
34
- spec.add_dependency 'haml', '~> 5.0'
35
- spec.add_dependency 'logger', '~> 1.0'
40
+ spec.add_dependency 'activesupport', '>= 6'
41
+ spec.add_dependency 'bcrypt', '>= 3.1'
42
+ spec.add_dependency 'browser', '>= 5.3'
43
+ spec.add_dependency 'dotenv', '>= 2'
44
+ spec.add_dependency 'haml', '>= 5.1.2'
45
+ spec.add_dependency 'logger', '>= 1.0'
36
46
  spec.add_dependency 'mail', '>= 1.7'
37
47
  spec.add_dependency 'oga', '>= 2.14'
38
48
  spec.add_dependency 'omniauth', '~> 1.0'
39
49
  spec.add_dependency 'omniauth-identity', '~> 1.0'
40
50
  spec.add_dependency 'pundit', '~> 1.0'
41
- spec.add_dependency 'rack-contrib', '~> 1.0'
42
- spec.add_dependency 'rack_csrf', '~> 1.0'
43
- spec.add_dependency 'rake', '~> 12.0'
44
- spec.add_dependency 'sequel', '>= 4.0'
45
- spec.add_dependency 'sinatra', '>= 2.0'
46
- spec.add_dependency 'sinatra-contrib', '~> 2.0'
47
- spec.add_dependency 'sinatra-flash', '~> 0.3'
48
- spec.add_dependency 'sinatra-param', '~> 1.5'
51
+ spec.add_dependency 'rack-contrib', '>= 2.0'
52
+ spec.add_dependency 'rack_csrf', '>= 2.0'
53
+ spec.add_dependency 'rake', '>= 13.0'
54
+ spec.add_dependency 'sequel', '>= 5.0'
55
+ spec.add_dependency 'sinatra', '>= 2.1'
56
+ spec.add_dependency 'sinatra-contrib', '>= 2.0'
57
+ spec.add_dependency 'sinatra-flash', '>= 0.3'
58
+ spec.add_dependency 'sinatra-param', '>= 1.6'
49
59
  spec.add_dependency 'thor', '>= 0.20'
50
60
  spec.add_dependency 'tilt', '>= 2'
51
61
  spec.add_dependency 'will_paginate', '>= 3.1'
data/docs/CNAME ADDED
@@ -0,0 +1 @@
1
+ ditty.io
data/docs/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-architect
data/docs/index.md ADDED
@@ -0,0 +1,34 @@
1
+ # Ditty.io
2
+
3
+ Ditty is a Web Application Framework built on top of the [Sinatra](http://sinatrarb.com/) framework.
4
+
5
+ ## Installation
6
+
7
+ Add these lines to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ditty'
11
+ gem 'sqlite3'
12
+ ```
13
+
14
+ You can replace `sqlite3` with a DB adapter of your choice.
15
+
16
+ And then execute:
17
+
18
+ ```bash
19
+ bundle install
20
+ ```
21
+
22
+ Or install it yourself as:
23
+
24
+ ```bash
25
+ gem install ditty
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ 1. Add the components to your rack config file. See the included [`config.ru`](https://github.com/EagerELK/ditty/blob/master/config.ru) file for an example setup
31
+ 2. Set the DB connection as the `DATABASE_URL` ENV variable: `DATABASE_URL=sqlite://development.db`
32
+ 3. Prepare the Ditty folder: `bundle exec ditty prep`
33
+ 3. Run the Ditty migrations: `bundle exec ditty migrate`
34
+ 4. Run the Ditty server: `bundle exec ditty server`
data/exe/ditty CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'ditty/cli'
3
5
 
4
6
  Ditty::CLI.start
data/lib/ditty/cli.rb CHANGED
@@ -1,24 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # https://nandovieira.com/creating-generators-and-executables-with-thor
4
- require 'dotenv/load'
4
+ require 'dotenv/load' rescue LoadError # rubocop:disable Style/RescueModifier - Ignore dotenv/load errors
5
5
  require 'thor'
6
6
  require 'rack'
7
7
  require 'rake'
8
+ require 'ditty/db' if ENV['DATABASE_URL']
9
+ require 'ditty/generators/crud_generator'
10
+ require 'ditty/generators/project_generator'
11
+ require 'ditty/generators/migration_generator'
12
+ require 'ditty/components/ditty'
13
+
14
+ # TODO: Component generator
15
+ # TODO: Add requires into application.rb
16
+ # TODO: Add requires into schema.rb
8
17
 
9
18
  module Ditty
10
19
  class CLI < Thor
11
20
  include Thor::Actions
12
21
 
22
+ register ::Ditty::Generators::CrudGenerator, 'crud', 'crud NAME', 'Generate a CRUD endpoint'
23
+
24
+ register ::Ditty::Generators::ProjectGenerator, 'init', 'init', 'Initialize a Ditty Project'
25
+
26
+ register ::Ditty::Generators::MigrationGenerator, 'migration', 'migration NAME', 'Create a new Sequel migration'
27
+
28
+ default_task :server
29
+
13
30
  desc 'server', 'Start the Ditty server'
14
31
  require './application' if File.exist?('application.rb')
15
- Ditty::Components.tasks
32
+ require 'ditty/db' unless defined?(DB)
33
+ ::Ditty::Components.tasks
34
+
16
35
  def server
17
36
  # Ensure the token files are present
18
37
  Rake::Task['ditty:generate_tokens'].invoke
19
38
 
20
39
  # Prep Ditty
21
- Rake::Task['ditty:prep'].invoke
40
+ Rake::Task['ditty:prep:folders'].invoke
41
+ Rake::Task['ditty:prep:migrations'].invoke
22
42
 
23
43
  # Check the migrations
24
44
  Rake::Task['ditty:migrate:check'].invoke
@@ -28,14 +48,20 @@ module Ditty
28
48
  Rake::Task['ditty:seed'].invoke
29
49
 
30
50
  # RackUP!
51
+ rack_opts = {
52
+ environment: ENV['APP_ENV'] || 'development',
53
+ Port: ENV['APP_PORT'] || 9292,
54
+ Host: ENV['APP_HOST'] || '0.0.0.0',
55
+ config: "config.ru"
56
+ }
31
57
  puts 'Starting the Ditty Server'
32
- Rack::Server.start(config: 'config.ru')
58
+ Rack::Server.start(rack_opts)
33
59
  end
34
60
 
35
61
  desc 'migrate', 'Run the Ditty migrations'
36
62
  def migrate
37
63
  # Prep Ditty
38
- Rake::Task['ditty:prep'].invoke
64
+ Rake::Task['ditty:prep:migrations'].invoke
39
65
 
40
66
  # Run the migrations
41
67
  Rake::Task['ditty:migrate:up'].invoke
@@ -44,5 +70,15 @@ module Ditty
44
70
  Rake::Task['ditty:dump_schema'].invoke
45
71
  puts 'Ditty DB Schema Dumped'
46
72
  end
73
+
74
+ desc 'seed', 'Seed the predefined seeding data'
75
+ def seed
76
+ Rake::Task['ditty:seed'].invoke
77
+ end
78
+
79
+ desc 'console', 'Open a fully loaded console'
80
+ def console
81
+ Rake::Task['ditty:console'].invoke
82
+ end
47
83
  end
48
84
  end
@@ -4,10 +4,10 @@ require 'ditty'
4
4
  require 'ditty/services/settings'
5
5
 
6
6
  module Ditty
7
- class App
7
+ class Ditty
8
8
  def self.load
9
9
  controllers = File.expand_path('../controllers', __dir__)
10
- Dir.glob("#{controllers}/*.rb").each { |f| require f }
10
+ Dir.glob("#{controllers}/*.rb").sort.each { |f| require f }
11
11
 
12
12
  require 'ditty/models/user'
13
13
  require 'ditty/models/role'
@@ -32,28 +32,30 @@ module Ditty
32
32
  def self.routes
33
33
  load
34
34
  {
35
- '/' => ::Ditty::Main,
36
- '/auth' => ::Ditty::Auth,
37
- '/users' => ::Ditty::Users,
38
- '/roles' => ::Ditty::Roles,
39
- '/audit-logs' => ::Ditty::AuditLogs,
40
- '/login-traits' => ::Ditty::UserLoginTraits
35
+ '/' => ::Ditty::MainController,
36
+ '/auth' => ::Ditty::AuthController,
37
+ '/users' => ::Ditty::UsersController,
38
+ '/roles' => ::Ditty::RolesController,
39
+ '/audit-logs' => ::Ditty::AuditLogsController,
40
+ '/login-traits' => ::Ditty::UserLoginTraitsController
41
41
  }
42
42
  end
43
43
 
44
- def self.navigation
44
+ def self.navigation(_request)
45
45
  load
46
46
 
47
47
  [
48
48
  {
49
49
  group: 'User Management',
50
- order: 10,
50
+ order: 50,
51
51
  icon: 'lock',
52
52
  target: ::Ditty::User,
53
53
  items: [
54
54
  { order: 10, link: '/users/', text: 'Users', target: ::Ditty::User, icon: 'user' },
55
55
  { order: 20, link: '/roles/', text: 'Roles', target: ::Ditty::Role, icon: 'check-square' },
56
- { order: 30, link: '/audit-logs/', text: 'Audit Logs', target: ::Ditty::AuditLog, icon: 'history' }
56
+ { order: 30, link: '/audit-logs/', text: 'Audit Logs', target: ::Ditty::AuditLog, icon: 'history' },
57
+ { order: 40, link: '/login-traits/', text: 'User Login Traits', target: ::Ditty::UserLoginTrait,
58
+ icon: 'list' }
57
59
  ]
58
60
  }
59
61
  ]
@@ -63,18 +65,18 @@ module Ditty
63
65
  proc do
64
66
  load
65
67
 
66
- ::Ditty::Role.find_or_create(name: 'super_admin')
67
- ::Ditty::Role.find_or_create(name: 'admin')
68
- ::Ditty::Role.find_or_create(name: 'user')
68
+ sa = ::Ditty::Role.find_or_create(name: 'super_admin')
69
+ admin = ::Ditty::Role.find_or_create(name: 'admin') { |e| e.parent = sa }
70
+ ::Ditty::Role.find_or_create(name: 'user') { |e| e.parent = admin }
69
71
  end
70
72
  end
71
73
 
72
74
  def self.tasks
73
75
  Kernel.load 'ditty/tasks/ditty.rake'
74
- auth_settings = Ditty::Services::Settings[:authentication] || {}
76
+ auth_settings = ::Ditty::Services::Settings[:authentication] || {}
75
77
  Kernel.load 'ditty/tasks/omniauth-ldap.rake' if auth_settings.key?(:ldap)
76
78
  end
77
79
  end
78
80
  end
79
81
 
80
- Ditty::Components.register_component(:app, Ditty::App)
82
+ Ditty::Components.register_component(:ditty, Ditty::Ditty)