journea 0.1.0
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.
- checksums.yaml +7 -0
- data/LICENSE +8 -0
- data/README.md +131 -0
- data/Rakefile +26 -0
- data/app/controllers/journea/engine_controller.rb +19 -0
- data/app/controllers/journea/journeys_controller.rb +10 -0
- data/app/controllers/journea/steps_controller.rb +52 -0
- data/app/helpers/journea/form_helper.rb +25 -0
- data/app/models/journea/journey.rb +54 -0
- data/app/models/journea/journey_transition.rb +17 -0
- data/app/models/journea/keyvalue.rb +5 -0
- data/app/views/application/_back_link.html.haml +5 -0
- data/config/initializers/simple_form.rb +179 -0
- data/config/locales/simple_form.en.yml +31 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20161201153630_create_journey_transitions.rb +22 -0
- data/db/migrate/20161201162349_create_journeys_table.rb +10 -0
- data/db/migrate/20161202162350_create_keyvalues_table.rb +11 -0
- data/lib/generators/journea/install_generator.rb +76 -0
- data/lib/generators/journea/templates/assets/application.js +23 -0
- data/lib/generators/journea/templates/assets/application.scss +49 -0
- data/lib/generators/journea/templates/config/initializers/journea.rb +23 -0
- data/lib/generators/journea/templates/config/initializers/journea2.rb +24 -0
- data/lib/generators/journea/templates/controllers/pages_controller.rb.example +2 -0
- data/lib/generators/journea/templates/views/application.html.haml +20 -0
- data/lib/generators/journea/templates/views/pages/start.html.haml.example +12 -0
- data/lib/generators/journea/templates/views/shared/error_messages.html.haml.example +7 -0
- data/lib/generators/journea/templates/views/steps/step.html.haml.example +8 -0
- data/lib/journea.rb +25 -0
- data/lib/journea/data.rb +20 -0
- data/lib/journea/engine.rb +27 -0
- data/lib/journea/state_machine.rb +40 -0
- data/lib/journea/step.rb +32 -0
- data/lib/journea/version.rb +3 -0
- data/lib/simple_form_object.rb +146 -0
- data/lib/tasks/journea_tasks.rake +4 -0
- data/lib/templates/erb/scaffold/_form.html.erb +13 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +5 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/pages_controller.rb +4 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/steps/address_step.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/app/views/pages/start.html.erb +1 -0
- data/spec/dummy/app/views/steps/address.html.erb +5 -0
- data/spec/dummy/app/views/steps/name.html.erb +5 -0
- data/spec/dummy/app/views/steps/phone_number.html.erb +0 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +34 -0
- data/spec/dummy/bin/update +29 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/config/application.rb +14 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +9 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +86 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/journea.rb +8 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/puma.rb +47 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +42 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +57 -0
- data/spec/dummy/log/test.log +448 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/EA/EAR2KaBsPQau6HwaTGrxV7EGMwAWyS-4C8pGVDU1Z-Q.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/JZ/JZuPFgM2mLQgAHB-r7Pt_TdGW3DRWPrplT7xPjnCJSE.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/LT/LTt1oE1gi9m65YRwUp78DuufkCOfi3sa3Qa05_ykADk.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Lj/LjRKOqtrClPtb97phuIWI7HHA8-p5J5nKHVE_zEycxo.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/QM/QMxUWUtpFaqwG3RI9t3m38QtFAOvHpiY3LphKJiVRTc.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/St/StFuOi5bd69ceiqz2D6EOCmRzHgwY0IxERsMfiCneGM.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Vj/VjCUmI9pp5eD8BlYATbwJ4ZOk0438rwvtDrsttyWbfQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Wl/WlLcUIADXcUxaOt8Gq59uQbO0mquikyz7jxiJjXjhaI.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/YH/YHo__TrFq5y8rpx49T8d8ecyvMLbHFbnhz7IBV7pM98.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Zu/ZuLXgeX6x_Dx8sCUbzuTtWu42HzQXWe7eooTgsonTnc.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/aG/aG1tp1pv4kBiSKx9ixZH5xiRXH-rGa0Hi6sdl4SHw6g.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/aw/awTDtuorxLsRLIGEYCefR-PTN7yptoaGRLEk13vHVLA.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/b_/b_Itlk9QZZd7Rvf8kcA4yLP1R5Acu7jB-m1xQiSU0qE.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/cW/cWHxYOqms7abJ-dzXyrn2G7nadJicU5kkC8SduS06yc.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/cb/cbX7RFavWZoWojlrsXhsy4FN46UOfMwZYStkLHT5HJw.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/eY/eYTHvo0Wl2TD2vipDcJ966HHXGrA4ZlJaiA2DnftKhM.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/f4/f4CpFuYmsdh1EvlFVjsl1WmM2QA9_z9AuOebEOw4mts.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/gH/gHSjqTBRSW22rP9mSj8XW6huEXKpcIOehvF-2fvuShQ.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/m0/m0smDeM83DcmOVpX9zos6AIX40E9Tf2j26tyvKFgMwc.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mW/mWrwQwWUQpAlMCLQ8dGv5VkAXd-TxvAtB5WPg9l09-A.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mX/mX1nlsL_SWOB4y22W5FheRX0YEONKyOY7xUeIvRiHco.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/n_/n_xYqQYhwEMQknb3jFQnjlxxBE9TzMNHCdJ-bEyZFIw.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/nx/nxTv3sKVUQZADJyM3dPaVmUA78MIsMLD_K279yN_GsI.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/oA/oAtzk5ZeF7lWCwNufspgWqtv_dQN_n5GumFNB4ScfBE.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/rA/rACdJeX3jZNkhx4awGhdZeMdOfmARubkoVKVAZdwYog.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/sC/sCEBZXwTjRpEzThf7YHzHNfkAupMVOx_Ko7WNMAFHS0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/x7/x7PYh8DJvPykcEqpVab2vcY9-GFz-3cqtoMlRAu94Uc.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yT/yTOf3QInGfDlRZlwZNDBLlbma19FQRHM035AKRxcRyw.cache +0 -0
- data/spec/features/journey_spec.rb +9 -0
- data/spec/lib/simple_form_object/attribute_spec.rb +74 -0
- data/spec/lib/simple_form_object/delegation_spec.rb +50 -0
- data/spec/lib/simple_form_object/model_spec.rb +90 -0
- data/spec/lib/steps_spec.rb +0 -0
- data/spec/requests/journeys_spec.rb +6 -0
- data/spec/spec_helper.rb +44 -0
- metadata +449 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
en:
|
|
2
|
+
simple_form:
|
|
3
|
+
"yes": 'Yes'
|
|
4
|
+
"no": 'No'
|
|
5
|
+
required:
|
|
6
|
+
text: 'required'
|
|
7
|
+
mark: '*'
|
|
8
|
+
# You can uncomment the line below if you need to overwrite the whole required html.
|
|
9
|
+
# When using html, text and mark won't be used.
|
|
10
|
+
# html: '<abbr title="required">*</abbr>'
|
|
11
|
+
error_notification:
|
|
12
|
+
default_message: "Please review the problems below:"
|
|
13
|
+
# Examples
|
|
14
|
+
# labels:
|
|
15
|
+
# defaults:
|
|
16
|
+
# password: 'Password'
|
|
17
|
+
# user:
|
|
18
|
+
# new:
|
|
19
|
+
# email: 'E-mail to sign in.'
|
|
20
|
+
# edit:
|
|
21
|
+
# email: 'E-mail.'
|
|
22
|
+
# hints:
|
|
23
|
+
# defaults:
|
|
24
|
+
# username: 'User name to sign in.'
|
|
25
|
+
# password: 'No special characters, please.'
|
|
26
|
+
# include_blanks:
|
|
27
|
+
# defaults:
|
|
28
|
+
# age: 'Rather not say'
|
|
29
|
+
# prompts:
|
|
30
|
+
# defaults:
|
|
31
|
+
# age: 'Select your age'
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class CreateJourneyTransitions < ActiveRecord::Migration[5.0]
|
|
2
|
+
def change
|
|
3
|
+
create_table :journea_journey_transitions do |t|
|
|
4
|
+
t.string :to_state, null: false
|
|
5
|
+
t.text :metadata, default: "{}"
|
|
6
|
+
t.integer :sort_key, null: false
|
|
7
|
+
t.integer :journey_id, null: false
|
|
8
|
+
t.boolean :most_recent, null: false
|
|
9
|
+
t.timestamps null: false
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
add_index(:journea_journey_transitions,
|
|
13
|
+
[:journey_id, :sort_key],
|
|
14
|
+
unique: true,
|
|
15
|
+
name: "index_journey_transitions_parent_sort")
|
|
16
|
+
add_index(:journea_journey_transitions,
|
|
17
|
+
[:journey_id, :most_recent],
|
|
18
|
+
unique: true,
|
|
19
|
+
where: "most_recent",
|
|
20
|
+
name: "index_journey_transitions_parent_most_recent")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module Journea
|
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
|
3
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
4
|
+
|
|
5
|
+
def init
|
|
6
|
+
@steps = []
|
|
7
|
+
@install_assets = false
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def setup_deps
|
|
11
|
+
@install_assets = yes?("Do you want to install the GOV.UK styles?")
|
|
12
|
+
if @install_assets
|
|
13
|
+
gem "govuk_template"
|
|
14
|
+
gem "govuk_frontend_toolkit"
|
|
15
|
+
gem "govuk_elements_rails"
|
|
16
|
+
end
|
|
17
|
+
gem "haml-rails", "~> 0.9"
|
|
18
|
+
Bundler.with_clean_env do
|
|
19
|
+
run "bundle install"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def setup_assets
|
|
24
|
+
return unless @install_assets
|
|
25
|
+
|
|
26
|
+
copy_file "views/application.html.haml", "app/views/layouts/application.html.haml"
|
|
27
|
+
remove_file "app/views/layouts/application.html.erb"
|
|
28
|
+
copy_file "assets/application.js", "app/assets/javascripts/application.js"
|
|
29
|
+
copy_file "assets/application.scss", "app/assets/stylesheets/application.scss"
|
|
30
|
+
remove_file "app/assets/stylesheets/application.css"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def create_start_page
|
|
34
|
+
return unless yes?("Do you need a start page?")
|
|
35
|
+
|
|
36
|
+
puts "Generating start page..."
|
|
37
|
+
copy_file "views/pages/start.html.haml.example", "app/views/pages/start.html.haml"
|
|
38
|
+
copy_file "controllers/pages_controller.rb.example", "app/controllers/pages_controller.rb"
|
|
39
|
+
route "root 'pages#start'"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def generate_steps
|
|
43
|
+
begin
|
|
44
|
+
puts "How many steps do you need to generate?"
|
|
45
|
+
step_number = gets.chomp
|
|
46
|
+
step_number = Integer(step_number)
|
|
47
|
+
rescue
|
|
48
|
+
print "Please enter an integer number:"
|
|
49
|
+
retry
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
if step_number > 0
|
|
53
|
+
copy_file "views/shared/error_messages.html.haml.example", "app/views/shared/_error_messages.html.haml"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
step_number.times do |i|
|
|
57
|
+
name = ask "What is the name of step #{i + 1}?"
|
|
58
|
+
puts "Generating #{name} step..."
|
|
59
|
+
@name = name.downcase.strip
|
|
60
|
+
@steps << name
|
|
61
|
+
create_file "app/steps/#{@name}_step.rb", "class #{name.capitalize}Step < Journea::Step \nend"
|
|
62
|
+
template "views/steps/step.html.haml.example", "app/views/steps/#{@name}.html.haml"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def create_initializer
|
|
67
|
+
puts "generating initializer"
|
|
68
|
+
inside "config" do
|
|
69
|
+
inside "initializers" do
|
|
70
|
+
template "journea.rb"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
route "mount Journea::Engine, at: '/journey'"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require jquery
|
|
14
|
+
//= require jquery_ujs
|
|
15
|
+
//= require details.polyfill
|
|
16
|
+
//= require vendor/polyfills/bind
|
|
17
|
+
//= require govuk_toolkit
|
|
18
|
+
//= require_tree .
|
|
19
|
+
|
|
20
|
+
$( document ).ready(function() {
|
|
21
|
+
var $buttons = $('label input[type=radio], label input[type=checkbox]')
|
|
22
|
+
var selectionButtons = new GOVUK.SelectionButtons($buttons)
|
|
23
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
|
11
|
+
* It is generally better to create a new file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
@import 'govuk-elements';
|
|
18
|
+
|
|
19
|
+
.error {
|
|
20
|
+
label {
|
|
21
|
+
@extend .form-label-bold;
|
|
22
|
+
}
|
|
23
|
+
.selection-button-radio {
|
|
24
|
+
@extend .form-label;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.radio_buttons .radio {
|
|
29
|
+
label {
|
|
30
|
+
@extend .block-label;
|
|
31
|
+
@extend .selection-button-radio;
|
|
32
|
+
margin-bottom: 10px !important;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.check_boxes .checkbox {
|
|
37
|
+
label {
|
|
38
|
+
@extend .block-label;
|
|
39
|
+
@extend .selection-button-checkbox;
|
|
40
|
+
margin-bottom: 10px !important;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
td.numeric {
|
|
45
|
+
font-size: 19px !important;
|
|
46
|
+
&.bold {
|
|
47
|
+
font-weight: bold;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Journea.configure_steps do
|
|
2
|
+
# step :first_step, initial: true
|
|
3
|
+
# step :second_step
|
|
4
|
+
#
|
|
5
|
+
# transition from: :first_step, to: :second
|
|
6
|
+
#
|
|
7
|
+
# before_transition(to: :second_step) do |journea|
|
|
8
|
+
# end
|
|
9
|
+
|
|
10
|
+
<% @steps.each_with_index do |step, i| -%>
|
|
11
|
+
<% if i == 0 -%>
|
|
12
|
+
step :<%= step %>, initial: true
|
|
13
|
+
<% else -%>
|
|
14
|
+
step :<%= step %>
|
|
15
|
+
<% end -%>
|
|
16
|
+
<% end -%>
|
|
17
|
+
|
|
18
|
+
<% @steps.each_with_index do |step, i| -%>
|
|
19
|
+
<% if @steps[i + 1].present? -%>
|
|
20
|
+
transition from: :<%= step %>, to: :<%= @steps[i + 1] %>
|
|
21
|
+
<% end -%>
|
|
22
|
+
<% end -%>
|
|
23
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Journea.configure_steps do
|
|
2
|
+
# step :first_step, initial: true
|
|
3
|
+
# step :second_step
|
|
4
|
+
#
|
|
5
|
+
# transition from: :first_step, to: :second
|
|
6
|
+
#
|
|
7
|
+
# before_transition(to: :second_step) do |journea|
|
|
8
|
+
# end
|
|
9
|
+
|
|
10
|
+
<%- @steps.each_with_index do |step, i| -%>
|
|
11
|
+
<%- if i == 0 %>
|
|
12
|
+
* step :<%= step %>, initial: true
|
|
13
|
+
<%- else -%>
|
|
14
|
+
step :<%= step %>
|
|
15
|
+
<%- end -%>
|
|
16
|
+
<%- end -%>
|
|
17
|
+
|
|
18
|
+
<% @steps.each_with_index do |step, i| %>
|
|
19
|
+
<% if @steps[i + 1].present? %>
|
|
20
|
+
transition from: :<%= step -%>, to: :<%= @steps[i + 1] -%>
|
|
21
|
+
|
|
22
|
+
<% end %>
|
|
23
|
+
<% end %>
|
|
24
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
- content_for(:head) do
|
|
2
|
+
= stylesheet_link_tag "application", media: "all"
|
|
3
|
+
/[if IE 8] <haml_loud> stylesheet_link_tag "ie8" </haml_loud>
|
|
4
|
+
= javascript_include_tag "application"
|
|
5
|
+
= csrf_meta_tags
|
|
6
|
+
- content_for :header_class, 'with-proposition'
|
|
7
|
+
- content_for :proposition_header do
|
|
8
|
+
.header-proposition
|
|
9
|
+
.content
|
|
10
|
+
%nav#proposition-menu
|
|
11
|
+
= link_to t('global_proposition_header'), '/', id: "proposition-name"
|
|
12
|
+
- content_for(:content) do
|
|
13
|
+
%main#content{:role => "main"}
|
|
14
|
+
= yield :datashift_journey_state_jumper
|
|
15
|
+
.phase-banner-alpha
|
|
16
|
+
%p
|
|
17
|
+
%strong.phase-tag= t(".proof_of_concept")
|
|
18
|
+
= render 'back_link'
|
|
19
|
+
= yield
|
|
20
|
+
= render template: "layouts/govuk_template"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
%body
|
|
2
|
+
.grid-row.start-page
|
|
3
|
+
.column-two-thirds
|
|
4
|
+
%header.text
|
|
5
|
+
%h1#groupLabel.form-title.heading-large
|
|
6
|
+
Start
|
|
7
|
+
%h2.heading-small Summary
|
|
8
|
+
%ul.list.list-bullet.text
|
|
9
|
+
%li Requirement 1
|
|
10
|
+
%li Requirement 2
|
|
11
|
+
|
|
12
|
+
= link_to 'Start now', journea.journeys_path, class: 'button button-start', role: 'button', method: :post
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
- if @step.errors.any?
|
|
2
|
+
.error-summary
|
|
3
|
+
.heading-medium.error-summary-heading
|
|
4
|
+
There #{'is'.pluralize(@step.errors.count)} #{pluralize(@step.errors.count, "error")} with the information you've provided.
|
|
5
|
+
%ul.error-summary-list
|
|
6
|
+
- @step.errors.messages.each do |element, message|
|
|
7
|
+
= link_to_input_with_error(element, message)
|
data/lib/journea.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Auto require all dependencies in the gemspec
|
|
2
|
+
Gem.loaded_specs["journea"].dependencies.each do |d|
|
|
3
|
+
begin
|
|
4
|
+
require d.name
|
|
5
|
+
|
|
6
|
+
# At this point in time unsure why exceptions are being swallowed here so
|
|
7
|
+
# am having to disable the cop for this section of code.
|
|
8
|
+
# rubocop:disable Lint/HandleExceptions
|
|
9
|
+
rescue(LoadError)
|
|
10
|
+
# Gem require failed
|
|
11
|
+
# puts "Couldn't require #{d.name}"
|
|
12
|
+
end
|
|
13
|
+
# rubocop:enable Lint/HandleExceptions
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
require "journea/engine"
|
|
17
|
+
require "journea/step"
|
|
18
|
+
require "journea/state_machine"
|
|
19
|
+
require "journea/data"
|
|
20
|
+
|
|
21
|
+
module Journea
|
|
22
|
+
def self.configure_steps(&block)
|
|
23
|
+
StateMachine.class_eval(&block)
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/journea/data.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Journea
|
|
2
|
+
class Data
|
|
3
|
+
|
|
4
|
+
attr_reader :keyvalues
|
|
5
|
+
|
|
6
|
+
def initialize(keyvalue_collection)
|
|
7
|
+
@keyvalues = keyvalue_collection
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# TODO: Currently having to eat this rubocop error until such time as we
|
|
11
|
+
# understand what form the respond_to_missing? should take
|
|
12
|
+
# rubocop:disable Style/MethodMissing
|
|
13
|
+
def method_missing(method_sym, *arguments, &block)
|
|
14
|
+
val = keyvalues.find_by(key: method_sym).value
|
|
15
|
+
return val if val.present?
|
|
16
|
+
super
|
|
17
|
+
end
|
|
18
|
+
# rubocop:enable Style/MethodMissing
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Journea
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
isolate_namespace Journea
|
|
4
|
+
|
|
5
|
+
config.generators do |g|
|
|
6
|
+
g.test_framework :rspec, fixture: false
|
|
7
|
+
g.fixture_replacement :factory_girl, dir: "spec/factories"
|
|
8
|
+
g.assets false
|
|
9
|
+
g.helper false
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
initializer :append_migrations do |app|
|
|
13
|
+
# From: https://blog.pivotal.io/labs/labs/leave-your-migrations-in-your-rails-engines
|
|
14
|
+
unless app.root.to_s.match root.to_s
|
|
15
|
+
config.paths["db/migrate"].expanded.each do |expanded_path|
|
|
16
|
+
app.config.paths["db/migrate"] << expanded_path
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
initializer :statesman, before: :load_config_initializers do
|
|
22
|
+
Statesman.configure do
|
|
23
|
+
storage_adapter(Statesman::Adapters::ActiveRecord)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Journea
|
|
2
|
+
class StateMachine
|
|
3
|
+
include Statesman::Machine
|
|
4
|
+
|
|
5
|
+
def self.step(*args)
|
|
6
|
+
# Instead of using Statesman 'state', this let's us use 'step'
|
|
7
|
+
state(*args)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def previous_step
|
|
11
|
+
return nil unless last_transition.present?
|
|
12
|
+
last_transition.metadata["previous_state"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def next_step
|
|
16
|
+
raise "No next step defined" if allowed_transitions.empty?
|
|
17
|
+
allowed_transitions.first.to_sym
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def transition_to_next_step
|
|
21
|
+
transition_to!(next_step, previous_state: current_state)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def in_initial_state?
|
|
25
|
+
current_state
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Monkey patch to prevent hard fail on transitioning between unsupported routes
|
|
29
|
+
def validate_transition(options = { from: nil, to: nil, metadata: nil })
|
|
30
|
+
from = to_s_or_nil(options[:from])
|
|
31
|
+
to = to_s_or_nil(options[:to])
|
|
32
|
+
|
|
33
|
+
# Call all guards, they raise exceptions if they fail
|
|
34
|
+
guards_for(from: from, to: to).each do |guard|
|
|
35
|
+
guard.call(@object, last_transition, options[:metadata])
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|