alembic 0.14.0 → 0.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26fff39c56e3627fa327fc6ae59d02d9d034687db485abf2e7d991e19beac021
4
- data.tar.gz: e8eb409d6bff630da792f4d084138e6c48d7d7b443a659e257a31f19b91e0627
3
+ metadata.gz: df412b5e51656af183c1272085c276a062e48e21b10c96dc879d64802cc2f1f3
4
+ data.tar.gz: a50967fb05d36e74f384629c4339de6bf1f6a1bfebb555deb125180669fdf65a
5
5
  SHA512:
6
- metadata.gz: 45395f01c87606d7a626341112ed4b99c27ba1e4b11b82cb8cc186a8e33f2b3279f9f7542c625f8f879b37327defa4a57ac7bbcfef3846f1b5053d02abf65076
7
- data.tar.gz: 523ec9fda8a088f4843bcb3b5347bca4771a523fd42e7c9314ea128792f1279d97186418bcaf56b8b6c650b4f93b9a31f42f7c20789eb61d537f9b6afa123ae3
6
+ metadata.gz: 299c2fbfc3638afc343191ae323c59adc0a4198b8f50f393cfdb0b0b61ada4e94117c925171817b980bc06d7a3453da6c87aa6499c4dbb6b4a4ad95c2c986491
7
+ data.tar.gz: 5bf2cf3497adf09bd4b934252b34563e92d54f3466bb4796c548fcf520e8bb93bcb27c17b1038e56aec515bc75228d777a3489d7a9d9fa454c27718c6c509faa
@@ -0,0 +1,21 @@
1
+ module Alembic
2
+ module Manage
3
+ class QuizzesController < EasyFlow::Manage::BaseController
4
+ hosted_by FLOW_HOST
5
+
6
+ def new
7
+ @flow = hosted_flows.new
8
+ end
9
+
10
+ def create
11
+ @flow = hosted_flows.new(params.require(:quiz).permit(:title))
12
+
13
+ if Flow::TitledStart.new(@flow).save
14
+ redirect_to easy_flow.manage_flow_path(@flow), notice: "Quiz created."
15
+ else
16
+ render :new, status: :unprocessable_entity
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,46 @@
1
+ module Alembic
2
+ module Flow
3
+ class TitledStart
4
+ FALLBACK_SLUG = "quiz"
5
+ MADE_SLUG_LENGTH = 100
6
+ TRIES_FOR_A_FREE_SLUG = 3
7
+ SLUGS_THE_ROUTES_USE = %w[manage pages runs].freeze
8
+
9
+ def initialize(flow)
10
+ @flow = flow
11
+ end
12
+
13
+ def save
14
+ return refuse_blank_title if @flow.title.blank?
15
+
16
+ tries = 0
17
+ begin
18
+ @flow.slug = free_slug
19
+ @flow.save
20
+ rescue ActiveRecord::RecordNotUnique
21
+ retry if (tries += 1) < TRIES_FOR_A_FREE_SLUG
22
+ raise
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def refuse_blank_title
29
+ @flow.errors.add(:title, :blank)
30
+ false
31
+ end
32
+
33
+ def free_slug
34
+ made = @flow.title.parameterize.first(MADE_SLUG_LENGTH).chomp("-").presence || FALLBACK_SLUG
35
+ numbered = (2..).lazy.map { |number| "#{made}-#{number}" }
36
+ taken = unavailable
37
+
38
+ [ made ].chain(numbered).find { |candidate| taken.exclude?(candidate) }
39
+ end
40
+
41
+ def unavailable
42
+ EasyFlow::Definition.where(host: @flow.host, owner: @flow.owner).pluck(:slug) + SLUGS_THE_ROUTES_USE
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,11 @@
1
+ <% content_for(:title, "New quiz") %>
2
+
3
+ <%= ui_page(max_width: :md) do %>
4
+ <%= ui_page_header(title: "New quiz") %>
5
+
6
+ <%= ui_form(action: alembic.manage_quizzes_path, method: :post) do %>
7
+ <%= ui_form_field(attribute: "quiz[title]", label: "Title", value: @flow.title, errors: @flow.errors.full_messages_for(:title)) %>
8
+
9
+ <%= ui_button(label: "Create", type: :submit) %>
10
+ <% end %>
11
+ <% end %>
data/config/routes.rb CHANGED
@@ -18,6 +18,8 @@ Alembic::Engine.routes.draw do
18
18
  get :step
19
19
  end
20
20
  end
21
+
22
+ resources :quizzes, only: [ :new, :create ]
21
23
  end
22
24
 
23
25
  constraints(->(request) { request.path_info.match?(%r{\A/manage/flows(/|\z)}) }) do
@@ -1,3 +1,3 @@
1
1
  module Alembic
2
- VERSION = "0.14.0"
2
+ VERSION = "0.15.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alembic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider
@@ -95,6 +95,7 @@ files:
95
95
  - app/controllers/alembic/manage/page_blocks_controller.rb
96
96
  - app/controllers/alembic/manage/pages_controller.rb
97
97
  - app/controllers/alembic/manage/previews_controller.rb
98
+ - app/controllers/alembic/manage/quizzes_controller.rb
98
99
  - app/controllers/alembic/pages_controller.rb
99
100
  - app/controllers/concerns/alembic/manage/authenticates_admin.rb
100
101
  - app/controllers/concerns/alembic/owned_pages.rb
@@ -115,6 +116,7 @@ files:
115
116
  - app/models/alembic/flow/run_summary.rb
116
117
  - app/models/alembic/flow/summaries.rb
117
118
  - app/models/alembic/flow/summary_version.rb
119
+ - app/models/alembic/flow/titled_start.rb
118
120
  - app/models/alembic/flow/uploaded_question.rb
119
121
  - app/models/alembic/flow/uploaded_questions.rb
120
122
  - app/models/alembic/outputs/band.rb
@@ -161,6 +163,7 @@ files:
161
163
  - app/views/alembic/manage/pages/_block_content.html.erb
162
164
  - app/views/alembic/manage/pages/index.html.erb
163
165
  - app/views/alembic/manage/pages/show.html.erb
166
+ - app/views/alembic/manage/quizzes/new.html.erb
164
167
  - app/views/alembic/pages/show.html.erb
165
168
  - app/views/layouts/alembic/application.html.erb
166
169
  - config/routes.rb