quby-compiler 0.5.23 → 0.5.24
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/quby/compiler/entities/question.rb +1 -11
- data/lib/quby/compiler/outputs/quby_frontend_v1_serializer.rb +9 -1
- data/lib/quby/compiler/outputs/quby_frontend_v2_serializer.rb +32 -3
- data/lib/quby/compiler/version.rb +1 -1
- metadata +2 -3
- data/lib/quby/compiler/dsl/merge(values(:v_1, :v_2), values(v_4).rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4562dd43458813b4fcb9602d10ec82732aea08c22ca12dd1f0b0b934dd25282b
|
4
|
+
data.tar.gz: '041953ff8c41909b57b03f98fa20f14bb6094d4392b911cbc56a464b454ad6d1'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 280c9f616bf3d451f82ccb35ab8eda3e5f1983b1a050171cebe12c4f59e334e61a4d58f51172ed69663733cb65bb7d44e1ef716d219e248745e6cc87ed5cce8e
|
7
|
+
data.tar.gz: 4c7ce2ae68ddd2c044dd24d02b7d29f7172b19a6424a8728328d3b79a352f97a0a5e9a9634928703670e27c14e7138d1fac2b76010a015fdf9a61acae1c0bd30
|
data/CHANGELOG.md
CHANGED
@@ -10,8 +10,6 @@ module Quby
|
|
10
10
|
|
11
11
|
MARKDOWN_ATTRIBUTES = %w(description title).freeze
|
12
12
|
|
13
|
-
set_callback :after_dsl_enhance, :expand_depends_on_input_keys
|
14
|
-
|
15
13
|
# Standard attributes
|
16
14
|
attr_accessor :key
|
17
15
|
validates :key, presence: true, 'quby/compiler/type': {is_a: Symbol}
|
@@ -183,7 +181,7 @@ module Quby
|
|
183
181
|
|
184
182
|
# Require subquestions of required questions by default
|
185
183
|
options[:required] = true if @parent&.validations&.first&.fetch(:type, nil) == :requires_answer
|
186
|
-
@validations << {type: :requires_answer, explanation: options[:error_explanation]} if options[:required]
|
184
|
+
@validations << {type: :requires_answer, explanation: options[:error_explanation] } if options[:required]
|
187
185
|
|
188
186
|
if @type == :float
|
189
187
|
@validations << {type: :valid_float, explanation: options[:error_explanation]}
|
@@ -232,14 +230,6 @@ module Quby
|
|
232
230
|
end
|
233
231
|
# rubocop:enable AccessorMethodName
|
234
232
|
|
235
|
-
def expand_depends_on_input_keys
|
236
|
-
return unless @depends_on
|
237
|
-
@depends_on = questionnaire.expand_input_keys(@depends_on)
|
238
|
-
@extra_data[:"depends-on"] = @depends_on.to_json
|
239
|
-
rescue => e
|
240
|
-
raise e.class, "Question #{key} depends_on contains an error: #{e.message}"
|
241
|
-
end
|
242
|
-
|
243
233
|
def col_span
|
244
234
|
options.length > 0 && type != :select ? options.length : @col_span
|
245
235
|
end
|
@@ -68,7 +68,7 @@ module Quby
|
|
68
68
|
description: question.description,
|
69
69
|
presentation: question.presentation,
|
70
70
|
hidden: question.hidden,
|
71
|
-
depends_on: question
|
71
|
+
depends_on: expand_depends_on_input_keys(question),
|
72
72
|
default_position: question.default_position,
|
73
73
|
col_span: question.col_span,
|
74
74
|
row_span: question.row_span,
|
@@ -366,6 +366,14 @@ module Quby
|
|
366
366
|
exclude_end: range.exclude_end?
|
367
367
|
}
|
368
368
|
end
|
369
|
+
|
370
|
+
def expand_depends_on_input_keys(question)
|
371
|
+
return unless question.depends_on.present?
|
372
|
+
|
373
|
+
questionnaire.expand_input_keys(question.depends_on)
|
374
|
+
rescue => e
|
375
|
+
raise e.class, "Question #{question.key} depends_on contains an error: #{e.message}"
|
376
|
+
end
|
369
377
|
end
|
370
378
|
end
|
371
379
|
end
|
@@ -90,7 +90,7 @@ module Quby
|
|
90
90
|
{
|
91
91
|
type: 'info',
|
92
92
|
key: info_block.key,
|
93
|
-
html: handle_html(info_block.html, type: :
|
93
|
+
html: handle_html(info_block.html, type: :prose, v1_markdown: false),
|
94
94
|
startOpen: info_block.start_open,
|
95
95
|
items: info_block.items.map { panel_item(_1) }.compact
|
96
96
|
}
|
@@ -289,15 +289,44 @@ module Quby
|
|
289
289
|
@questionnaire.validations.map do |validation|
|
290
290
|
validation.config.compact
|
291
291
|
.transform_keys{ _1.to_s.camelize(:lower) }
|
292
|
-
.tap
|
292
|
+
.tap { |validation_hsh|
|
293
293
|
# otherwise ruby will put a (?-mix around the regex, which js errors on.
|
294
294
|
validation_hsh['matcher'] = validation_hsh['matcher'].source.to_s if validation_hsh['matcher']
|
295
295
|
validation_hsh['type'] = 'minimum_date' if validation_hsh['type'] == :minimum && validation_hsh['subtype'] == :date
|
296
296
|
validation_hsh['type'] = 'maximum_date' if validation_hsh['type'] == :maximum && validation_hsh['subtype'] == :date
|
297
|
-
|
297
|
+
validation_hsh['dependsOnQuestions'] = depends_on(validation_hsh) if validation_hsh['type'] == :requires_answer
|
298
|
+
validation_hsh['dependsOnOptions'] = depends_on_options(validation_hsh) if validation_hsh['type'] == :requires_answer
|
299
|
+
}.compact.as_json
|
298
300
|
end
|
299
301
|
end
|
300
302
|
|
303
|
+
def depends_on(validation_hsh)
|
304
|
+
question = @questionnaire.question_hash[validation_hsh['fieldKey']]
|
305
|
+
return unless question.depends_on.present?
|
306
|
+
|
307
|
+
question.depends_on.select { @questionnaire.question_hash.key?(_1) }
|
308
|
+
end
|
309
|
+
|
310
|
+
def depends_on_options(validation_hsh)
|
311
|
+
question = @questionnaire.question_hash[validation_hsh['fieldKey']]
|
312
|
+
return unless question.depends_on.present?
|
313
|
+
|
314
|
+
question.depends_on
|
315
|
+
.map(&:to_s)
|
316
|
+
.reject { @questionnaire.question_hash.key?(_1) }
|
317
|
+
.map { |key|
|
318
|
+
question_key, option_key = key.split(/_(?=[^_]+$)/) # split on last _, works for all existing questionnaires.
|
319
|
+
if @questionnaire.question_hash.key?(question_key)
|
320
|
+
if @questionnaire.question_hash[question_key].options.any? { _1.key.to_s == option_key } # single_select
|
321
|
+
next [question_key, option_key]
|
322
|
+
elsif @questionnaire.question_hash[question_key].options.any? { _1.key.to_s == key } # multi_select
|
323
|
+
next [question_key, key]
|
324
|
+
end
|
325
|
+
end
|
326
|
+
raise "#{validation_hsh['fieldKey']} depends_on: can't find key '#{question_key}_#{option_key}'."
|
327
|
+
}.group_by(&:first).transform_values{ _1.map(&:last) }
|
328
|
+
end
|
329
|
+
|
301
330
|
def handle_html(html, type: :simple, v1_markdown: true)
|
302
331
|
if layout_version == :v2
|
303
332
|
case type
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quby-compiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Veldthuis
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-07-07 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activemodel
|
@@ -151,7 +151,6 @@ files:
|
|
151
151
|
- lib/quby/compiler/dsl/charting/radar_chart_builder.rb
|
152
152
|
- lib/quby/compiler/dsl/helpers.rb
|
153
153
|
- lib/quby/compiler/dsl/info_block_builder.rb
|
154
|
-
- lib/quby/compiler/dsl/merge(values(:v_1, :v_2), values(v_4).rb
|
155
154
|
- lib/quby/compiler/dsl/panel_builder.rb
|
156
155
|
- lib/quby/compiler/dsl/question_builder.rb
|
157
156
|
- lib/quby/compiler/dsl/questionnaire_builder.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
merge(values(:v_1, :v_2), values(v_4).recode(1 => 3)).sum
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
divide(value(:v_2), multiply(value(:v_1), value(:v_1)))
|
6
|
-
|
7
|
-
w / l * l
|
8
|
-
|
9
|
-
|
10
|
-
sexp_variable :key1 do
|
11
|
-
foo = values(:v_1, :v_2)
|
12
|
-
bar = recode(foo, 1 => 3)
|
13
|
-
bla = merge(foo, bar)
|
14
|
-
sum(bla)
|
15
|
-
|
16
|
-
end
|