decko 0.11.2 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/bin/decko +2 -2
  3. data/lib/card_controller.rb +29 -0
  4. data/{rails/controllers → lib}/card_controller/errors.rb +12 -13
  5. data/lib/card_controller/mark.rb +66 -0
  6. data/lib/{decko → card_controller}/response.rb +5 -61
  7. data/lib/card_controller/rest.rb +105 -0
  8. data/lib/decko.rb +3 -17
  9. data/lib/decko/all.rb +2 -0
  10. data/lib/decko/application.rb +22 -53
  11. data/lib/decko/cli.rb +2 -8
  12. data/lib/decko/commands.rb +17 -110
  13. data/lib/decko/commands/application.rb +2 -2
  14. data/lib/decko/commands/cucumber_command.rb +8 -7
  15. data/lib/decko/commands/cucumber_command/parser.rb +30 -26
  16. data/lib/decko/engine.rb +3 -16
  17. data/lib/decko/generators.rb +17 -0
  18. data/lib/decko/mods_spec_helper.rb +1 -1
  19. data/lib/decko/script_decko_loader.rb +5 -23
  20. data/lib/decko/tasks/alias.rb +4 -5
  21. data/lib/decko/tasks/cucumber.rake +61 -44
  22. data/lib/decko/tasks/db.rake +9 -2
  23. data/lib/decko/tasks/decko.rake +7 -6
  24. data/lib/decko/tasks/decko/docs.rake +1 -1
  25. data/lib/decko/tasks/decko/seed.rake +9 -4
  26. data/lib/generators/deck/deck_generator.rb +12 -0
  27. data/rails/engine-routes.rb +1 -1
  28. metadata +28 -70
  29. data/lib/decko/commands/command.rb +0 -28
  30. data/lib/decko/commands/rake_command.rb +0 -41
  31. data/lib/decko/commands/rake_command/parser.rb +0 -34
  32. data/lib/decko/commands/rspec_command.rb +0 -36
  33. data/lib/decko/commands/rspec_command/parser.rb +0 -96
  34. data/lib/decko/config/environments/cucumber.rb +0 -40
  35. data/lib/decko/config/environments/cypress.rb +0 -100
  36. data/lib/decko/config/environments/development.rb +0 -95
  37. data/lib/decko/config/environments/production.rb +0 -73
  38. data/lib/decko/config/environments/profile.rb +0 -32
  39. data/lib/decko/config/environments/test.rb +0 -68
  40. data/lib/decko/config/initializers/secret_token.rb +0 -14
  41. data/lib/decko/config/initializers/sedate_parser.rb +0 -7
  42. data/lib/decko/config/initializers/session_store.rb +0 -2
  43. data/lib/decko/generators/deck/USAGE +0 -9
  44. data/lib/decko/generators/deck/deck_generator.rb +0 -133
  45. data/lib/decko/generators/deck/deck_generator/deck_helper.rb +0 -110
  46. data/lib/decko/generators/deck/deck_generator/interactive.rb +0 -120
  47. data/lib/decko/generators/deck/deck_generator/rails_overrides.rb +0 -54
  48. data/lib/decko/generators/deck/templates/Gemfile.erb +0 -56
  49. data/lib/decko/generators/deck/templates/Rakefile.erb +0 -7
  50. data/lib/decko/generators/deck/templates/bin/spring.erb +0 -20
  51. data/lib/decko/generators/deck/templates/config.ru.erb +0 -11
  52. data/lib/decko/generators/deck/templates/config/application.rb.erb +0 -107
  53. data/lib/decko/generators/deck/templates/config/boot.rb.erb +0 -11
  54. data/lib/decko/generators/deck/templates/config/cucumber.yml +0 -1
  55. data/lib/decko/generators/deck/templates/config/databases/frontbase.yml +0 -34
  56. data/lib/decko/generators/deck/templates/config/databases/ibm_db.yml +0 -89
  57. data/lib/decko/generators/deck/templates/config/databases/jdbc.yml +0 -65
  58. data/lib/decko/generators/deck/templates/config/databases/jdbcmysql.yml +0 -36
  59. data/lib/decko/generators/deck/templates/config/databases/jdbcpostgresql.yml +0 -46
  60. data/lib/decko/generators/deck/templates/config/databases/jdbcsqlite3.yml +0 -23
  61. data/lib/decko/generators/deck/templates/config/databases/mysql.yml +0 -37
  62. data/lib/decko/generators/deck/templates/config/databases/oracle.yml +0 -42
  63. data/lib/decko/generators/deck/templates/config/databases/postgresql.yml +0 -39
  64. data/lib/decko/generators/deck/templates/config/databases/sqlite3.yml +0 -21
  65. data/lib/decko/generators/deck/templates/config/deck.yml +0 -10
  66. data/lib/decko/generators/deck/templates/config/environment.rb.erb +0 -5
  67. data/lib/decko/generators/deck/templates/config/initializers/cypress.rb +0 -12
  68. data/lib/decko/generators/deck/templates/config/puma.rb +0 -16
  69. data/lib/decko/generators/deck/templates/config/routes.rb.erb +0 -11
  70. data/lib/decko/generators/deck/templates/config/storage.yml +0 -0
  71. data/lib/decko/generators/deck/templates/gitignore +0 -18
  72. data/lib/decko/generators/deck/templates/pryrc +0 -6
  73. data/lib/decko/generators/deck/templates/public/files/htaccess +0 -9
  74. data/lib/decko/generators/deck/templates/public/robots.txt +0 -13
  75. data/lib/decko/generators/deck/templates/rspec.erb +0 -6
  76. data/lib/decko/generators/deck/templates/script/decko +0 -6
  77. data/lib/decko/generators/deck/templates/script/decko_cucumber +0 -8
  78. data/lib/decko/generators/deck/templates/script/decko_rspec +0 -8
  79. data/lib/decko/generators/deck/templates/script/delayed_job +0 -5
  80. data/lib/decko/generators/deck/templates/simplecov.rb.erb +0 -34
  81. data/lib/decko/generators/deck/templates/spec/javascripts/support/deck_jasmine.yml.erb +0 -56
  82. data/lib/decko/generators/deck/templates/spec/javascripts/support/decko_jasmine.yml.erb +0 -74
  83. data/lib/decko/generators/deck/templates/spec/spec_helper.rb +0 -1
  84. data/rails/controllers/application_controller.rb +0 -2
  85. data/rails/controllers/card_controller.rb +0 -122
  86. data/script/autospec +0 -4
  87. data/script/decko +0 -6
  88. data/script/rails +0 -6
  89. data/script/test_filter +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bb1203eba43f58959d97efbfb758f1381d7db1ac7816d73cb5dfa033dc6643b
4
- data.tar.gz: 496f2f2b1d9552f716379e9d25e6ebf24085993e4030ff656d717e7f9cd68b14
3
+ metadata.gz: 8bb3b3da3fa9c6e8e1fe97ee9ab4fa406b7c3dcb5850db324c1404ac378de442
4
+ data.tar.gz: 4878e14c56ef66cc61cc376aa6c6f0a2cdbc9c0dc7e6b4d4308b140f8b688c91
5
5
  SHA512:
6
- metadata.gz: 6ced715eed9b7f6c0956598955021106a396a1beb82cac21762ddcf9f69aefc6f94121945e20e6d1a434237cf3dddee35f75b474510e11bf6ebfa63ee51570a2
7
- data.tar.gz: bf9643036097f1475b8aab433419b20f27a46a85d4dd1fb4397ffd207a4fee607265cb32d8839cd2473e74db97ec63ecb263acd15c0746679a3f584fd5482a99
6
+ metadata.gz: afbfc8a1b33c3e00f4734fb89c25c02abdadb6fb50e9b31b1056409123ccd9237a23069332ef1aea8f0c8f1372a6e47408e9deef742b123c817bffb08c48d736
7
+ data.tar.gz: a8a564f378ecbbb8ac75f0087f2f5e9daa93fd000962ded9e90779caf09fe9c6dcd543c150ea3a35dfcd03b05050c9a0b58782070c0a49d2016033bf14e8a60a
data/bin/decko CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- git_path = File.expand_path("../../../.git", __FILE__)
3
+ git_path = File.expand_path("../../.git", __dir__)
4
4
 
5
5
  if File.exist?(git_path)
6
- railties_path = File.expand_path("../../lib", __FILE__)
6
+ railties_path = File.expand_path("../lib", __dir__)
7
7
  $LOAD_PATH.unshift(railties_path)
8
8
  end
9
9
  require "decko/cli"
@@ -0,0 +1,29 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ # Decko's only controller.
4
+ class CardController < ActionController::Base
5
+ include Mark
6
+ include Rest
7
+ include Response
8
+ include Errors
9
+ extend Errors::Rescue
10
+
11
+ # NOTE: including Card::Env::Location triggers card loading, which triggers mod loading,
12
+ # which can include initializers that add to the CardController class.
13
+ # It's important that it come *after* the modules above, so that mod modules
14
+ # can override them.
15
+ include ::Card::Env::Location
16
+
17
+ layout nil
18
+ attr_reader :card
19
+
20
+ before_action :setup, except: [:asset]
21
+ before_action :authenticate, except: [:asset]
22
+ before_action :load_mark, only: [:read]
23
+ before_action :load_card, except: [:asset]
24
+ before_action :load_action, only: [:read]
25
+ before_action :refresh_card, only: %i[create update delete]
26
+
27
+ rescue_from_class(*Card::Error::UserError.user_error_classes)
28
+ rescue_from_class StandardError if rescue_all?
29
+ end
@@ -1,21 +1,23 @@
1
1
  # Decko's only controller.
2
2
  class CardController
3
- class << self
4
- def rescue_from_class *klasses
5
- klasses.each do |klass|
6
- rescue_from(klass) { |exception| handle_exception exception }
3
+ # controller error handling
4
+ module Errors
5
+ # controller class method to handle top-level error rescuing
6
+ module Rescue
7
+ def rescue_from_class *klasses
8
+ klasses.each do |klass|
9
+ rescue_from(klass) { |exception| handle_exception exception }
10
+ end
7
11
  end
8
- end
9
12
 
10
- def rescue_all?
11
- Cardio.config.rescue_all_in_controller
13
+ def rescue_all?
14
+ Cardio.config.rescue_all_in_controller
15
+ end
12
16
  end
13
- end
14
17
 
15
- # controller error handling
16
- module Errors
17
18
  def handle_exception exception
18
19
  raise exception if debug_exception?(exception)
20
+
19
21
  @card ||= Card.new
20
22
  error = Card::Error.report exception, card
21
23
  show error.class.view, error.class.status_code
@@ -29,7 +31,4 @@ class CardController
29
31
  Card[:debugger]&.content =~ /on/ # && !Card::Env.ajax?
30
32
  end
31
33
  end
32
-
33
- rescue_from_class(*Card::Error::UserError.user_error_classes)
34
- rescue_from_class StandardError if rescue_all?
35
34
  end
@@ -0,0 +1,66 @@
1
+ class CardController
2
+ # methods for interpretation of card marks requested
3
+ module Mark
4
+ private
5
+
6
+ def load_mark
7
+ params[:mark] = interpret_mark params[:mark]
8
+ end
9
+
10
+ def interpret_mark mark
11
+ case mark
12
+ when "*previous"
13
+ # Why support this? It's only needed in Success, right? Deprecate?
14
+ hard_redirect Card::Env.previous_location
15
+ when nil
16
+ implicit_mark
17
+ else
18
+ explicit_mark mark
19
+ end
20
+ end
21
+
22
+ def explicit_mark mark
23
+ # we should find the place where we produce these bad urls
24
+ mark.valid_encoding? ? mark : mark.force_encoding("ISO-8859-1").encode("UTF-8")
25
+ end
26
+
27
+ def implicit_mark
28
+ case
29
+ when initial_setup
30
+ ""
31
+ when (name = mark_from_card_hash)
32
+ name
33
+ when view_does_not_require_name?
34
+ ""
35
+ else
36
+ home_mark
37
+ end
38
+ end
39
+
40
+ def home_mark
41
+ Card::Rule.global_setting(:home) || "Home"
42
+ end
43
+
44
+ def view_does_not_require_name?
45
+ return false unless (view = params[:view]&.to_sym)
46
+
47
+ Card::Set::Format::AbstractFormat::ViewOpts.unknown_ok[view]
48
+ end
49
+
50
+ def mark_from_card_hash
51
+ params.dig :card, :name
52
+ end
53
+
54
+ # alters params
55
+ def initial_setup
56
+ return unless Card::Auth.needs_setup? && Card::Env.html?
57
+
58
+ prepare_setup_card!
59
+ end
60
+
61
+ def prepare_setup_card!
62
+ params[:card] = { type_id: Card.default_accounted_type_id }
63
+ params[:view] = "setup"
64
+ end
65
+ end
66
+ end
@@ -1,4 +1,4 @@
1
- module Decko
1
+ class CardController
2
2
  # methods for managing decko responses
3
3
  module Response
4
4
  def response_format
@@ -72,13 +72,8 @@ module Decko
72
72
 
73
73
  def require_card_for_soft_redirect!
74
74
  return if card.is_a? Card
75
- raise Card::Error, "tried to do soft redirect without a card"
76
- end
77
75
 
78
- # (obviously) deprecated
79
- def send_deprecated_asset
80
- filename = [params[:mark], params[:format]].compact.join(".")
81
- send_file asset_file_path(filename), x_sendfile: true
76
+ raise Card::Error, "tried to do soft redirect without a card"
82
77
  end
83
78
 
84
79
  def asset_file_path filename
@@ -107,64 +102,13 @@ module Decko
107
102
  end
108
103
 
109
104
  def format_name_from_params
110
- if explicit_file_format? then :file
111
- elsif params[:format].present? then params[:format].to_sym
112
- else request.format.to_sym
113
- end
105
+ return :file if explicit_file_format?
106
+
107
+ (params[:format].present? ? params[:format] : request.format).to_sym
114
108
  end
115
109
 
116
110
  def explicit_file_format?
117
111
  params[:explicit_file] || !Card::Format.registered.member?(request.format)
118
112
  end
119
-
120
- def interpret_mark mark
121
- case mark
122
- when "*previous"
123
- # Why support this? It's only needed in Success, right? Deprecate?
124
- return hard_redirect(Card::Env.previous_location)
125
- when nil
126
- implicit_mark
127
- else
128
- explicit_mark mark
129
- end
130
- end
131
-
132
- def explicit_mark mark
133
- # we should find the place where we produce these bad urls
134
- mark.valid_encoding? ? mark : mark.force_encoding("ISO-8859-1").encode("UTF-8")
135
- end
136
-
137
- def implicit_mark
138
- case
139
- when initial_setup then ""
140
- when (name = params.dig :card, :name) then name
141
- when view_does_not_require_name? then ""
142
- else home_mark
143
- end
144
- end
145
-
146
- def home_mark
147
- Card::Rule.global_setting(:home) || "Home"
148
- end
149
-
150
- def view_does_not_require_name?
151
- return false unless (view = params[:view]&.to_sym)
152
- Card::Set::Format::AbstractFormat::ViewOpts.unknown_ok[view]
153
- end
154
-
155
- # alters params
156
- def initial_setup
157
- return unless initial_setup?
158
- prepare_setup_card!
159
- end
160
-
161
- def initial_setup?
162
- Card::Auth.needs_setup? && Card::Env.html?
163
- end
164
-
165
- def prepare_setup_card!
166
- params[:card] = { type_id: Card.default_accounted_type_id }
167
- params[:view] = "setup"
168
- end
169
113
  end
170
114
  end
@@ -0,0 +1,105 @@
1
+ class CardController
2
+ # RESTful action methods for card
3
+ module Rest
4
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
+ # PUBLIC METHODS
6
+
7
+ def create
8
+ handle { card.save! }
9
+ end
10
+
11
+ def read
12
+ show
13
+ end
14
+
15
+ def update
16
+ card.new_card? ? create : handle { card.update! params[:card]&.to_unsafe_h }
17
+ end
18
+
19
+ def delete
20
+ handle { card.delete! }
21
+ end
22
+
23
+ # @deprecated
24
+ def asset
25
+ body = "Decko installation error: missing asset symlinks"
26
+ Rails.logger.info "#{body}.\n >>> Try `rake decko:update_assets_symlink`"
27
+ render body: body, status: 404
28
+ end
29
+
30
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31
+ # PRIVATE METHODS
32
+
33
+ private
34
+
35
+ def setup
36
+ Card::Machine.refresh_script_and_style unless params[:explicit_file]
37
+ Card::Cache.renew
38
+ Card::Env.reset controller: self
39
+ end
40
+
41
+ def authenticate
42
+ Card::Auth.signin_with params
43
+ end
44
+
45
+ def load_card
46
+ @card = Card.uri_fetch params
47
+ raise Card::Error::NotFound unless card
48
+
49
+ record_as_main
50
+ end
51
+
52
+ def load_action
53
+ card.select_action_by_params params
54
+ return unless params[:edit_draft] && card.drafts.present?
55
+
56
+ card.content = card.last_draft_content
57
+ end
58
+
59
+ # TODO: refactor this away this when new layout handling is ready
60
+ def record_as_main
61
+ Card::Env[:main_name] = params[:main] || card&.name || ""
62
+ end
63
+
64
+ def refresh_card
65
+ @card = card.refresh
66
+ end
67
+
68
+ # ----------( HELPER METHODS ) -------------
69
+
70
+ def handle
71
+ Card::Env.success card.name
72
+ yield ? cud_success : raise(Card::Error::UserError)
73
+ end
74
+
75
+ # successful create, update, or delete act
76
+ def cud_success
77
+ success = Card::Env.success.in_context card.name
78
+ if success.reload?
79
+ reload # instruct JSON to reload
80
+ else
81
+ redirect_cud_success success
82
+ end
83
+ end
84
+
85
+ def show view=nil, status=200
86
+ card.action = :read
87
+ format = load_format status
88
+ result = render_page format, view
89
+ status = format.error_status || status
90
+ respond format, result, status
91
+ end
92
+
93
+ def render_page format, view
94
+ view ||= view_from_params
95
+ card.act do
96
+ format.page self, view, Card::Env.slot_opts
97
+ end
98
+ end
99
+
100
+ def view_from_params
101
+ %i[view v].each { |k| return params[k] if params[k].present? }
102
+ nil
103
+ end
104
+ end
105
+ end
data/lib/decko.rb CHANGED
@@ -1,23 +1,9 @@
1
-
2
1
  module Decko
3
- DECKO_GEM_ROOT = File.expand_path("../..", __FILE__)
2
+ DECKO_GEM_ROOT = File.expand_path("..", __dir__)
4
3
 
5
4
  class << self
6
- def root
7
- Rails.root
8
- end
9
-
10
- def application
11
- Rails.application
12
- end
13
-
14
- def config
15
- application.config
16
- end
17
-
18
- def paths
19
- application.paths
20
- end
5
+ delegate :application, :root, to: :Rails
6
+ delegate :config, :paths, to: :application
21
7
 
22
8
  def gem_root
23
9
  DECKO_GEM_ROOT
data/lib/decko/all.rb CHANGED
@@ -1 +1,3 @@
1
+ # backwards compatibility for old decks that require decko/all
2
+
1
3
  require "decko/application"
@@ -1,16 +1,20 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
- require "decko/engine"
4
- require_relative "config/initializers/sedate_parser"
3
+ require "action_controller/railtie"
4
+ require "cardio/application"
5
5
 
6
- Bundler.require :default, *Rails.groups
6
+ # require_relative "config/initializers/sedate_parser"
7
7
 
8
8
  module Decko
9
- class Application < Rails::Application
10
- initializer :load_decko_environment_config,
9
+ # The application class from which all decko applications inherit
10
+ class Application < Cardio::Application
11
+ require "decko/engine"
12
+
13
+ card_environment_initializer
14
+
15
+ initializer "decko.load_environment_config",
11
16
  before: :load_environment_config, group: :all do
12
- add_path paths, "lib/decko/config/environments", glob: "#{Rails.env}.rb"
13
- paths["lib/decko/config/environments"].existent.each do |environment|
17
+ paths["decko/config/environments"].existent.each do |environment|
14
18
  require environment
15
19
  end
16
20
  end
@@ -24,36 +28,9 @@ module Decko
24
28
  end
25
29
  end
26
30
 
27
- def add_path paths, path, options={}
28
- root = options.delete(:root) || Decko.gem_root
29
- options[:with] = File.join(root, (options[:with] || path))
30
- paths.add path, options
31
- end
32
-
33
31
  def config
34
- @config ||= begin
35
- config = super
36
-
37
- Cardio.set_config config
38
-
39
- # any config settings below:
40
- # (a) do not apply to Card used outside of a Decko context
41
- # (b) cannot be overridden in a deck's application.rb, but
42
- # (c) CAN be overridden in an environment file
43
-
44
- # therefore, in general, they should be restricted to settings that
45
- # (1) are specific to the web environment, and
46
- # (2) should not be overridden
47
- # ..and we should address (c) above!
48
-
49
- # general card settings (overridable and not) should be in cardio.rb
50
- # overridable decko-specific settings don't have a place yet
51
- # but should probably follow the cardio pattern.
52
-
32
+ @config ||= super.tap do |config|
53
33
  # config.load_defaults "6.0"
54
- config.autoloader = :zeitwerk
55
- config.load_default = "6.0"
56
- config.i18n.enforce_available_locales = true
57
34
  # config.active_record.raise_in_transactional_callbacks = true
58
35
 
59
36
  config.allow_concurrency = false
@@ -61,30 +38,22 @@ module Decko
61
38
  config.assets.version = "1.0"
62
39
 
63
40
  config.filter_parameters += [:password]
64
-
65
- # Rails.autoloaders.log!
66
- Rails.autoloaders.main.ignore(File.join(Cardio.gem_root, "lib/card/seed_consts.rb"))
67
- config
41
+ config.autoload_paths += Dir["#{Decko.gem_root}/lib"]
42
+ decko_path_defaults config.paths
68
43
  end
69
44
  end
70
45
 
71
- def paths
72
- @paths ||= begin
73
- paths = super
74
- Cardio.set_paths paths
75
-
76
- paths.add "files"
46
+ private
77
47
 
78
- paths["app/models"] = []
79
- paths["app/mailers"] = []
48
+ def decko_path_defaults paths
49
+ paths.add "decko/config/environments",
50
+ with: File.join(Decko.gem_root, "config/environments"),
51
+ glob: "#{Rails.env}.rb"
80
52
 
81
- unless paths["config/routes.rb"].existent.present?
82
- add_path paths, "config/routes.rb",
83
- with: "rails/application-routes.rb"
84
- end
53
+ return if paths["config/routes.rb"].existent.present?
85
54
 
86
- paths
87
- end
55
+ paths.add "config/routes.rb",
56
+ with: File.join(Decko.gem_root, "rails/application-routes.rb")
88
57
  end
89
58
  end
90
59
  end