ditty 0.7.1 → 0.10.1

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 (185) 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 +24 -8
  6. data/.travis.yml +4 -8
  7. data/CNAME +1 -0
  8. data/Dockerfile +18 -0
  9. data/Gemfile.ci +0 -15
  10. data/Rakefile +5 -4
  11. data/Readme.md +24 -2
  12. data/_config.yml +1 -0
  13. data/config.ru +4 -4
  14. data/ditty.gemspec +31 -20
  15. data/docs/CNAME +1 -0
  16. data/docs/_config.yml +1 -0
  17. data/docs/index.md +34 -0
  18. data/exe/ditty +2 -0
  19. data/lib/ditty.rb +30 -4
  20. data/lib/ditty/cli.rb +38 -5
  21. data/lib/ditty/components/ditty.rb +82 -0
  22. data/lib/ditty/controllers/application_controller.rb +267 -0
  23. data/lib/ditty/controllers/{audit_logs.rb → audit_logs_controller.rb} +5 -7
  24. data/lib/ditty/controllers/{auth.rb → auth_controller.rb} +56 -32
  25. data/lib/ditty/controllers/{component.rb → component_controller.rb} +35 -24
  26. data/lib/ditty/controllers/{main.rb → main_controller.rb} +7 -7
  27. data/lib/ditty/controllers/roles_controller.rb +23 -0
  28. data/lib/ditty/controllers/user_login_traits_controller.rb +46 -0
  29. data/lib/ditty/controllers/{users.rb → users_controller.rb} +17 -20
  30. data/lib/ditty/db.rb +9 -5
  31. data/lib/ditty/emails/base.rb +48 -34
  32. data/lib/ditty/generators/crud_generator.rb +114 -0
  33. data/lib/ditty/generators/migration_generator.rb +26 -0
  34. data/lib/ditty/generators/project_generator.rb +52 -0
  35. data/lib/ditty/helpers/authentication.rb +6 -5
  36. data/lib/ditty/helpers/component.rb +11 -2
  37. data/lib/ditty/helpers/pundit.rb +24 -8
  38. data/lib/ditty/helpers/response.rb +38 -15
  39. data/lib/ditty/helpers/views.rb +48 -6
  40. data/lib/ditty/listener.rb +44 -14
  41. data/lib/ditty/memcached.rb +8 -0
  42. data/lib/ditty/middleware/accept_extension.rb +4 -2
  43. data/lib/ditty/middleware/error_catchall.rb +4 -2
  44. data/lib/ditty/models/audit_log.rb +1 -0
  45. data/lib/ditty/models/base.rb +13 -0
  46. data/lib/ditty/models/identity.rb +10 -7
  47. data/lib/ditty/models/role.rb +2 -0
  48. data/lib/ditty/models/user.rb +40 -3
  49. data/lib/ditty/models/user_login_trait.rb +17 -0
  50. data/lib/ditty/policies/audit_log_policy.rb +6 -6
  51. data/lib/ditty/policies/role_policy.rb +3 -3
  52. data/lib/ditty/policies/user_login_trait_policy.rb +45 -0
  53. data/lib/ditty/policies/user_policy.rb +3 -3
  54. data/lib/ditty/rubocop.rb +3 -0
  55. data/lib/ditty/seed.rb +2 -0
  56. data/lib/ditty/services/authentication.rb +31 -15
  57. data/lib/ditty/services/email.rb +22 -12
  58. data/lib/ditty/services/logger.rb +30 -13
  59. data/lib/ditty/services/pagination_wrapper.rb +9 -5
  60. data/lib/ditty/services/settings.rb +19 -7
  61. data/lib/ditty/tasks/ditty.rake +127 -0
  62. data/lib/ditty/tasks/omniauth-ldap.rake +43 -0
  63. data/lib/ditty/templates/.gitignore +5 -0
  64. data/lib/ditty/templates/.rspec +2 -0
  65. data/lib/ditty/templates/.rubocop.yml +7 -0
  66. data/lib/ditty/templates/Rakefile +12 -0
  67. data/lib/ditty/templates/application.rb +12 -0
  68. data/lib/ditty/templates/config.ru +37 -0
  69. data/lib/ditty/templates/controller.rb.erb +64 -0
  70. data/lib/ditty/templates/env.example +4 -0
  71. data/lib/ditty/templates/lib/project.rb.erb +5 -0
  72. data/lib/ditty/templates/migration.rb.erb +7 -0
  73. data/lib/ditty/templates/model.rb.erb +26 -0
  74. data/lib/ditty/templates/pids/.empty_directory +0 -0
  75. data/lib/ditty/templates/policy.rb.erb +48 -0
  76. data/{public → lib/ditty/templates/public}/browserconfig.xml +0 -0
  77. data/lib/ditty/templates/public/css/sb-admin-2.min.css +10 -0
  78. data/lib/ditty/templates/public/css/styles.css +13 -0
  79. data/lib/ditty/templates/public/favicon.ico +0 -0
  80. data/{public → lib/ditty/templates/public}/images/apple-icon.png +0 -0
  81. data/{public → lib/ditty/templates/public}/images/favicon-16x16.png +0 -0
  82. data/{public → lib/ditty/templates/public}/images/favicon-32x32.png +0 -0
  83. data/{public → lib/ditty/templates/public}/images/launcher-icon-1x.png +0 -0
  84. data/{public → lib/ditty/templates/public}/images/launcher-icon-2x.png +0 -0
  85. data/{public → lib/ditty/templates/public}/images/launcher-icon-4x.png +0 -0
  86. data/{public → lib/ditty/templates/public}/images/mstile-150x150.png +0 -0
  87. data/{public → lib/ditty/templates/public}/images/safari-pinned-tab.svg +0 -0
  88. data/lib/ditty/templates/public/js/sb-admin-2.min.js +7 -0
  89. data/lib/ditty/templates/public/js/scripts.js +1 -0
  90. data/{public/manifest.json → lib/ditty/templates/public/manifest.json.erb} +2 -2
  91. data/lib/ditty/templates/settings.yml.erb +19 -0
  92. data/lib/ditty/templates/sidekiq.rb +18 -0
  93. data/lib/ditty/templates/sidekiq.yml +9 -0
  94. data/lib/ditty/templates/spec_helper.rb +43 -0
  95. data/lib/ditty/templates/type.rb.erb +21 -0
  96. data/lib/ditty/templates/views/display.haml.tt +20 -0
  97. data/lib/ditty/templates/views/edit.haml.tt +10 -0
  98. data/lib/ditty/templates/views/form.haml.tt +11 -0
  99. data/lib/ditty/templates/views/index.haml.tt +29 -0
  100. data/lib/ditty/templates/views/new.haml.tt +10 -0
  101. data/lib/ditty/version.rb +1 -1
  102. data/lib/rubocop/cop/ditty/call_services_directly.rb +42 -0
  103. data/migrate/20181209_add_user_login_traits.rb +16 -0
  104. data/migrate/20181209_extend_audit_log.rb +12 -0
  105. data/migrate/20190220_add_parent_id_to_roles.rb +9 -0
  106. data/spec/ditty/api_spec.rb +51 -0
  107. data/spec/ditty/controllers/roles_spec.rb +67 -0
  108. data/spec/ditty/controllers/user_login_traits_spec.rb +72 -0
  109. data/spec/ditty/controllers/users_spec.rb +72 -0
  110. data/spec/ditty/emails/base_spec.rb +76 -0
  111. data/spec/ditty/emails/forgot_password_spec.rb +20 -0
  112. data/spec/ditty/helpers/component_spec.rb +85 -0
  113. data/spec/ditty/models/user_spec.rb +36 -0
  114. data/spec/ditty/services/email_spec.rb +36 -0
  115. data/spec/ditty/services/logger_spec.rb +68 -0
  116. data/spec/ditty/services/settings_spec.rb +63 -0
  117. data/spec/ditty_spec.rb +9 -0
  118. data/spec/factories.rb +46 -0
  119. data/spec/fixtures/logger.yml +17 -0
  120. data/spec/fixtures/section.yml +3 -0
  121. data/spec/fixtures/settings.yml +8 -0
  122. data/spec/spec_helper.rb +51 -0
  123. data/spec/support/api_shared_examples.rb +250 -0
  124. data/spec/support/crud_shared_examples.rb +145 -0
  125. data/views/403.haml +2 -0
  126. data/views/404.haml +2 -4
  127. data/views/500.haml +11 -0
  128. data/views/audit_logs/index.haml +32 -28
  129. data/views/auth/forgot_password.haml +32 -16
  130. data/views/auth/identity.haml +14 -13
  131. data/views/auth/ldap.haml +17 -0
  132. data/views/auth/login.haml +23 -17
  133. data/views/auth/register.haml +20 -18
  134. data/views/auth/register_identity.haml +27 -12
  135. data/views/auth/reset_password.haml +36 -19
  136. data/views/blank.haml +43 -0
  137. data/views/emails/forgot_password.haml +1 -1
  138. data/views/emails/layouts/action.haml +10 -6
  139. data/views/emails/layouts/alert.haml +2 -1
  140. data/views/emails/layouts/billing.haml +2 -1
  141. data/views/embedded.haml +17 -11
  142. data/views/error.haml +8 -3
  143. data/views/index.haml +1 -1
  144. data/views/layout.haml +45 -30
  145. data/views/partials/actions.haml +15 -14
  146. data/views/partials/content_tag.haml +0 -0
  147. data/views/partials/delete_form.haml +1 -1
  148. data/views/partials/filter_control.haml +2 -2
  149. data/views/partials/footer.haml +13 -5
  150. data/views/partials/form_control.haml +30 -19
  151. data/views/partials/form_tag.haml +1 -1
  152. data/views/partials/navitems.haml +42 -0
  153. data/views/partials/notifications.haml +12 -8
  154. data/views/partials/pager.haml +44 -25
  155. data/views/partials/search.haml +15 -11
  156. data/views/partials/sidebar.haml +15 -37
  157. data/views/partials/sort_ui.haml +2 -0
  158. data/views/partials/timespan_selector.haml +64 -0
  159. data/views/partials/topbar.haml +53 -0
  160. data/views/partials/user_associations.haml +32 -0
  161. data/views/quick_start.haml +23 -0
  162. data/views/roles/display.haml +27 -6
  163. data/views/roles/edit.haml +3 -3
  164. data/views/roles/form.haml +1 -0
  165. data/views/roles/index.haml +23 -14
  166. data/views/roles/new.haml +2 -2
  167. data/views/user_login_traits/display.haml +32 -0
  168. data/views/user_login_traits/edit.haml +10 -0
  169. data/views/user_login_traits/form.haml +5 -0
  170. data/views/user_login_traits/index.haml +28 -0
  171. data/views/user_login_traits/new.haml +10 -0
  172. data/views/users/display.haml +15 -16
  173. data/views/users/edit.haml +3 -3
  174. data/views/users/form.haml +0 -0
  175. data/views/users/index.haml +31 -24
  176. data/views/users/login_traits.haml +25 -0
  177. data/views/users/new.haml +2 -2
  178. data/views/users/profile.haml +17 -15
  179. data/views/users/user.haml +1 -1
  180. metadata +314 -76
  181. data/lib/ditty/components/app.rb +0 -77
  182. data/lib/ditty/controllers/application.rb +0 -175
  183. data/lib/ditty/controllers/roles.rb +0 -16
  184. data/lib/ditty/rake_tasks.rb +0 -102
  185. data/views/partials/navbar.haml +0 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c15560015979ad1fc7afda1efc7becd871635867ace4fa364f47eb6473baf5e4
4
- data.tar.gz: 2ea52af0c53587b08562f5a594b7f0b951638310f60a4c5ce2ce5ac937e2efbd
3
+ metadata.gz: e785b1b4a84258a46e98753a5de394897bc6d002b88d2fc6629b30b33b52614e
4
+ data.tar.gz: '094a55847cc4ec09bf1dc9307c9efcffa5b59b498fd407de5950e656e5a5e516'
5
5
  SHA512:
6
- metadata.gz: 0aa2bd4eb180cf51106d4d645e0effd68a924c866bba915f26526e30d4dfe11d8f800ac32e1779c738e606a39b1a6b003b4039902b43d8a1cde1f2cc2890f9e6
7
- data.tar.gz: 39c61fef5b3fad41838de4903b88e16df4b606bd9249421d2db9ede59ed75855f2bc0936aaf84e1a8dc8cce17a0d966520cffaf50196446f91ba20e165ee8b9e
6
+ metadata.gz: fa7d54c43ac02d1f04a690f2bca5a529b3c65eefa0f287ab44594910bca2b8022656b58e2aef805a52307364481c35be2ba1b1e4b3a97b3450cab1b9acb27d1f
7
+ data.tar.gz: 847143f0f0d20c67b3451a86e780ec44b914210ceec4498c9218ebc05f7f7277107b1998ca5f273aad0ad1ad45ceb051b81204fe87e6cb91e88ee2ef6af7b49c
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,12 +1,28 @@
1
- Metrics/LineLength:
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-performance
4
+ - rubocop-thread_safety
5
+ - rubocop-sequel
6
+ AllCops:
7
+ NewCops: enable
8
+ TargetRubyVersion: 2.7.1
9
+ Exclude:
10
+ - migrate/**/*
11
+ Layout/LineLength:
2
12
  Max: 120
3
-
4
- Style/NumericPredicate:
5
- Enabled: false
6
-
7
13
  Layout/LeadingCommentSpace:
8
14
  Exclude:
9
15
  - 'config.ru'
10
-
11
- AllCops:
12
- TargetRubyVersion: 2.2
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.5.1
5
- - 2.4.0
6
- - 2.3.3
7
- - 2.2.6
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
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,18 +2,3 @@
2
2
  source 'https://rubygems.org'
3
3
 
4
4
  gemspec
5
-
6
- gem 'rubocop'
7
- gem 'simplecov', '~> 0.13.0'
8
- gem 'sqlite3'
9
-
10
- if RUBY_VERSION < '2.1'
11
- gem 'sidekiq', '3.0.0'
12
- gem 'activesupport', '<4.0.0'
13
- gem 'omniauth', '~>1.4.2'
14
- elsif RUBY_VERSION < '2.2.0'
15
- gem 'sidekiq', '4.0.0'
16
- gem 'activesupport', '<5.0.0'
17
- else
18
- gem 'activesupport'
19
- end
data/Rakefile CHANGED
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rake'
4
- require 'bundler/gem_tasks'
5
- require 'ditty/rake_tasks'
6
-
7
4
  require 'ditty'
8
- require 'ditty/components/app'
5
+ require 'ditty/components/ditty'
6
+
7
+ Ditty.component :ditty
9
8
 
9
+ Ditty::Components.tasks
10
+ require 'bundler/gem_tasks' if File.exist? 'ditty.gemspec'
10
11
  begin
11
12
  require 'rspec/core/rake_task'
12
13
  RSpec::Core::RakeTask.new(:spec)
data/Readme.md CHANGED
@@ -1,6 +1,7 @@
1
1
  [![Build Status](https://travis-ci.org/EagerELK/ditty.svg?branch=master)](https://travis-ci.org/EagerELK/ditty)
2
2
  [![Code Climate](https://codeclimate.com/github/EagerELK/ditty/badges/gpa.svg)](https://codeclimate.com/github/EagerELK/ditty)
3
3
  [![Test Coverage](https://codeclimate.com/github/EagerELK/ditty/badges/coverage.svg)](https://codeclimate.com/github/EagerELK/ditty/coverage)
4
+ [![Inline docs](http://inch-ci.org/github/EagerELK/ditty.svg?branch=master)](http://inch-ci.org/github/EagerELK/ditty)
4
5
 
5
6
  # Ditty
6
7
 
@@ -33,12 +34,33 @@ gem install ditty
33
34
 
34
35
  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
35
36
  2. Set the DB connection as the `DATABASE_URL` ENV variable: `DATABASE_URL=sqlite://development.db`
37
+ 3. Prepare the Ditty folder: `bundle exec ditty prep`
36
38
  3. Run the Ditty migrations: `bundle exec ditty migrate`
37
39
  4. Run the Ditty server: `bundle exec ditty server`
38
40
 
39
- ## Components
41
+ ### Components
40
42
 
41
- The application can now be further extended by creating components.
43
+ The application can now be further extended by creating [components](https://github.com/EagerELK/ditty/wiki/Creating-a-Component).
44
+
45
+ ### Rubocop Cops
46
+
47
+ Ditty provides a number of [Rubocop](https://github.com/rubocop-hq/rubocop) cops
48
+ to ensure that the Ditty framework is used correctly. Enable this by adding the
49
+ following to your `.rubocop.yml` file:
50
+
51
+ ```yaml
52
+ require: ditty/rubocop
53
+ ```
54
+
55
+ You can run Ditty specific cops as follows:
56
+
57
+ ```bash
58
+ bundle exec rubocop --only Ditty
59
+ ```
60
+
61
+ Adding the `-a` flag to the invocation will automatically fix some of the issues
62
+ for you, but, as always, ensure you have a working copy of your code before
63
+ running this.
42
64
 
43
65
  ## Development
44
66
 
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,38 +15,49 @@ 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
- spec.add_development_dependency 'bundler', '~> 1.12'
24
- spec.add_development_dependency 'database_cleaner'
23
+ spec.add_development_dependency 'bundler', '>= 1'
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 'haml', '~> 5.0'
34
- spec.add_dependency 'logger', '~> 1.0'
35
- spec.add_dependency 'oga', '>= 2.14'
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'
47
+ spec.add_dependency 'oga', '>= 2.14'
37
48
  spec.add_dependency 'omniauth', '~> 1.0'
38
49
  spec.add_dependency 'omniauth-identity', '~> 1.0'
39
50
  spec.add_dependency 'pundit', '~> 1.0'
40
- spec.add_dependency 'rack-contrib', '~> 1.0'
41
- spec.add_dependency 'rack_csrf', '~> 1.0'
42
- spec.add_dependency 'rake', '~> 12.0'
43
- spec.add_dependency 'sequel', '>= 4.0'
44
- spec.add_dependency 'sinatra', '>= 2.0'
45
- spec.add_dependency 'sinatra-contrib', '~> 2.0'
46
- spec.add_dependency 'sinatra-flash', '~> 0.3'
47
- spec.add_dependency 'sinatra-param', '~> 1.5'
48
- spec.add_dependency 'tilt', '>= 2'
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'
60
+ spec.add_dependency 'tilt', '>= 2'
50
61
  spec.add_dependency 'will_paginate', '>= 3.1'
51
62
  spec.add_dependency 'wisper', '~> 2.0'
52
63
  end
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.rb CHANGED
@@ -6,6 +6,8 @@ require 'ditty/services/logger'
6
6
  module Ditty
7
7
  class ComponentError < StandardError; end
8
8
 
9
+ class TemplateNotFoundError < StandardError; end
10
+
9
11
  # A thread safe cache class, offering only #[] and #[]= methods,
10
12
  # each protected by a mutex.
11
13
  # Ripped off from Roda - https://github.com/jeremyevans/roda
@@ -30,6 +32,10 @@ module Ditty
30
32
  @mutex.synchronize { @hash.map(&block) }
31
33
  end
32
34
 
35
+ def each(&block)
36
+ @mutex.synchronize { @hash.each(&block) }
37
+ end
38
+
33
39
  def inject(memo, &block)
34
40
  @mutex.synchronize { @hash.inject(memo, &block) }
35
41
  end
@@ -37,6 +43,10 @@ module Ditty
37
43
  def each_with_object(memo, &block)
38
44
  @mutex.synchronize { @hash.each_with_object(memo, &block) }
39
45
  end
46
+
47
+ def key?(key)
48
+ @hash.key? key
49
+ end
40
50
  end
41
51
 
42
52
  # Ripped off from Roda - https://github.com/jeremyevans/roda
@@ -52,17 +62,23 @@ module Ditty
52
62
  h = @components
53
63
  unless (component = h[name])
54
64
  require "ditty/components/#{name}"
55
- raise ComponentError, "Component #{name} did not register itself correctly in Ditty::Components" unless (component = h[name])
65
+ unless (component = h[name])
66
+ raise ComponentError, "Component #{name} did not register itself correctly in Ditty::Components"
67
+ end
56
68
  end
57
69
  component
58
70
  end
59
71
 
72
+ def self.component?(name)
73
+ @components.key? name
74
+ end
75
+
60
76
  # Register the given component with Component, so that it can be loaded using #component
61
77
  # with a symbol. Should be used by component files. Example:
62
78
  #
63
79
  # Ditty::Components.register_component(:component_name, ComponentModule)
64
80
  def self.register_component(name, mod)
65
- Ditty::Services::Logger.instance.info "Registering #{mod} as #{name}"
81
+ ::Ditty::Services::Logger.info "Registering #{mod} as #{name}"
66
82
  @components[name] = mod
67
83
  end
68
84
 
@@ -80,9 +96,9 @@ module Ditty
80
96
 
81
97
  # Return an ordered list of navigation items:
82
98
  # `[{order:0, link:'/users/', text:'Users'}, {order:1, link:'/roles/', text:'Roles'}]
83
- def self.navigation
99
+ def self.navigation(request)
84
100
  nav = components.each_with_object([]) do |comp, memo|
85
- memo.concat comp[1].navigation if comp[1].respond_to?(:navigation)
101
+ memo.concat comp[1].navigation(request) if comp[1].respond_to?(:navigation)
86
102
  end
87
103
  nav.sort_by { |v| v[:order] }
88
104
  end
@@ -111,6 +127,15 @@ module Ditty
111
127
  end
112
128
  end
113
129
 
130
+ def self.tasks
131
+ require 'rake'
132
+ require 'rake/tasklib'
133
+ require 'ditty/db' unless defined? DB
134
+ components.each do |_name, comp|
135
+ comp.tasks if comp.respond_to?(:tasks)
136
+ end
137
+ end
138
+
114
139
  module Base
115
140
  module ClassMethods
116
141
  # Load a new component into the current class. A component can be a module
@@ -121,6 +146,7 @@ module Ditty
121
146
  # Component.component :csrf
122
147
  def component(component, *args, &block)
123
148
  raise ComponentError, 'Cannot add a component to a frozen Component class' if frozen?
149
+
124
150
  component = Components.load_component(component) if component.is_a?(Symbol)
125
151
  include(component::InstanceMethods) if defined?(component::InstanceMethods)
126
152
  extend(component::ClassMethods) if defined?(component::ClassMethods)