quby-compiler 0.6.0 → 0.6.2

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: 9aa19b0ae3da964273f613a8705e3b63e699dc14fc9793f67e13b891f5e6f42f
4
- data.tar.gz: 8b2e41485f4d05711ea4098f1bbc23fdfe6e43fac6764047760434bbc04c41b3
3
+ metadata.gz: fdf056bcbbea1730c248d8cfb73d3fc7b51ff2f4ead55bd02781d6c81d1e5505
4
+ data.tar.gz: c974d4e4c67f8582325eaaf630ad71f4d7859a7835a15e125fb5407ad87e3b10
5
5
  SHA512:
6
- metadata.gz: 127e6a879195d5ee84994016e53e7dbb99cb5a188023df2156e708f1e7ca57464d589b7c49adbae203acefbd1ad2eaecf943fa069466d82209a624f477f611dd
7
- data.tar.gz: 5256bfbd80fa05c961cd7cfd0c59c78c35fa6b24fb3581534a7a10d926f58ab5432cdc674ee9ad9abd5262981657f6d164914229a2c28c0a6d836372fff5a08a
6
+ metadata.gz: 107f7a4d9cc66dd69c8acde899737d1111c82e1e4e520916a9325372d2f181e64795448b192ecd7d6073641d4bead30ec6d3bfcfd56d01b72fd4d1179f9e8568
7
+ data.tar.gz: 614dd011da028989a99c8c43fafce188c9662b205c15241e8df5489479afe1a433287eb984a2ed3a192716bc15ffe5fb29c8e84dfa6127b1f7a51544c550575e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # 0.6.2
2
+
3
+ * dsl:
4
+ * Add text option to info_blocks, so you can start with the key.
5
+ * Allow label for placeholder option.
6
+ * quby2.json
7
+ * Use . between panel/info_block key and default key for items, for more consistency. Remove double panel key for items with default key.
8
+ * Don't camelcase translation keys for quby2, no real benefit and was wrongly camelcasing html keys.
9
+
10
+ # 0.6.1
11
+
12
+ * Switch to oj for serializing, since JSON.serialize is dumb as ^%#$& (not serializing inner object)
13
+ * allow visibility_rule call within float questions, like integer.
14
+ * Remove empty outputs from Instance.compile.
15
+
1
16
  # 0.6.0
2
17
 
3
18
  * dsl:
@@ -29,6 +29,10 @@ module Quby
29
29
  info_block.items << Entities::Text.new('', html_content: value.to_s, key:)
30
30
  end
31
31
 
32
+ def text(key:, html: nil, md: nil, **options)
33
+ info_block.items << Entities::Text.new(key:, md:, html_content: html, **options)
34
+ end
35
+
32
36
  def question(key, **options, &block)
33
37
  options = default_question_options.merge(options).merge(questionnaire:)
34
38
 
@@ -53,7 +57,7 @@ module Quby
53
57
  def fallback_key
54
58
  raise "Item without key in #{info_block.key}" if questionnaire.translatable?
55
59
 
56
- "#{info_block.key}_item_#{info_block.items.size}"
60
+ "#{info_block.key}.item_#{info_block.items.size}"
57
61
  end
58
62
  end
59
63
  end
@@ -95,7 +95,7 @@ module Quby
95
95
  def fallback_key
96
96
  raise "Item without key in #{@panel.key}" if @questionnaire.translatable?
97
97
 
98
- "#{@panel.key}_item_#{@panel.items.size}"
98
+ "#{@panel.key}.item_#{@panel.items.size}"
99
99
  end
100
100
  end
101
101
  end
@@ -10,6 +10,7 @@ module Quby
10
10
  include Units
11
11
  include Sizes
12
12
  include CompareVisibilityRule
13
+ include VisibilityRule
13
14
 
14
15
  def initialize(key, **options, &block)
15
16
  super
@@ -1,3 +1,5 @@
1
+ require "oj"
2
+
1
3
  module Quby
2
4
  module Compiler
3
5
  class Instance
@@ -37,7 +39,7 @@ module Quby
37
39
  roqua: Output.new(
38
40
  key: :roqua,
39
41
  filename: "roqua.json",
40
- content: JSON.pretty_generate(Outputs::RoquaSerializer.new(questionnaire).as_json),
42
+ content: Oj.dump(Outputs::RoquaSerializer.new(questionnaire).as_json, mode: :json, indent: 2),
41
43
  ),
42
44
  seeds: Output.new(
43
45
  key: :seeds,
@@ -47,19 +49,19 @@ module Quby
47
49
  quby_frontend_v1: Output.new(
48
50
  key: :quby_frontend_v1,
49
51
  filename: "quby-frontend-v1.json",
50
- content: JSON.pretty_generate(Outputs::QubyFrontendV1Serializer.new(questionnaire).as_json),
52
+ content: Oj.dump(Outputs::QubyFrontendV1Serializer.new(questionnaire).as_json, mode: :json, indent: 2),
51
53
  ),
52
54
  quby_frontend_v2: Output.new(
53
55
  key: :quby_frontend_v2,
54
56
  filename: "quby-frontend-v2.json",
55
- content: JSON.pretty_generate(Outputs::QubyFrontendV2Serializer.new(questionnaire, translations: all_translations).as_json),
57
+ content: Oj.dump(Outputs::QubyFrontendV2Serializer.new(questionnaire, translations: all_translations).as_json, mode: :json, indent: 2),
56
58
  ),
57
- locale: questionnaire.translatable? && Output.new(
59
+ locale: questionnaire.translatable?.presence && Output.new(
58
60
  key: :locale,
59
61
  filename: "#{LOCALE_FILE_PREFIX}#{questionnaire.language}.json",
60
- content: JSON.pretty_generate(original_locale),
62
+ content: Oj.dump(original_locale, mode: :json, indent: 2),
61
63
  ),
62
- },
64
+ }.compact
63
65
  }
64
66
  ensure
65
67
  # We can only close and remove the file once serializers have finished.
@@ -31,7 +31,7 @@ module Quby
31
31
  items.flat_map { |item|
32
32
  case item
33
33
  when Quby::Compiler::Entities::Text
34
- { "#{panel.key}.#{item.key}" => item.html }
34
+ { "#{item.key}" => item.html }
35
35
  when Quby::Compiler::Entities::Question
36
36
  questions_for_question(item).flat_map { |question|
37
37
  question_locale_values(question, panel:)
@@ -178,10 +178,11 @@ module Quby
178
178
  end
179
179
 
180
180
  def select_question(question)
181
+ placeholder = question.all_options.find(&:placeholder)
181
182
  {
182
183
  **base_question(question),
183
184
  children: children(question),
184
- placeholder: question.all_options.find { _1.placeholder }&.description,
185
+ placeholder: placeholder&.label || placeholder&.description,
185
186
  }.compact
186
187
  end
187
188
 
@@ -330,8 +331,7 @@ module Quby
330
331
  key.ends_with?("context_free_title") \
331
332
  || key.ends_with?("context_free_description") \
332
333
  || key == "short_description"
333
- } \
334
- .transform_keys! { |k| k.to_s.split('.').tap{ _1[-1] = _1[-1].camelize(:lower) }.join('.') }
334
+ }
335
335
  }
336
336
  end
337
337
 
@@ -45,7 +45,7 @@ module Quby
45
45
  outcome_description: questionnaire.outcome_description,
46
46
  questions: questions,
47
47
  scores: scores,
48
- anonymous_conditions: questionnaire.anonymous_conditions,
48
+ anonymous_conditions: questionnaire.anonymous_conditions.as_json,
49
49
  flags: flags,
50
50
  textvars: textvars,
51
51
  license: questionnaire.license,
@@ -1,5 +1,5 @@
1
1
  module Quby
2
2
  module Compiler
3
- VERSION = "0.6.0"
3
+ VERSION = "0.6.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quby-compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
@@ -93,6 +93,20 @@ dependencies:
93
93
  - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '1.8'
96
+ - !ruby/object:Gem::Dependency
97
+ name: oj
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
96
110
  - !ruby/object:Gem::Dependency
97
111
  name: redcarpet
98
112
  requirement: !ruby/object:Gem::Requirement