smartdown 0.11.4 → 0.12.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.
- data/lib/smartdown/api/date_question.rb +10 -4
- data/lib/smartdown/api/node.rb +2 -1
- data/lib/smartdown/api/question.rb +2 -1
- data/lib/smartdown/engine/interpolator.rb +1 -1
- data/lib/smartdown/model/element/{markdown_paragraph.rb → markdown_line.rb} +1 -1
- data/lib/smartdown/model/elements.rb +51 -0
- data/lib/smartdown/model/node.rb +14 -7
- data/lib/smartdown/parser/base.rb +1 -1
- data/lib/smartdown/parser/element/conditional.rb +9 -8
- data/lib/smartdown/parser/element/front_matter.rb +7 -1
- data/lib/smartdown/parser/element/markdown_blank_line.rb +14 -0
- data/lib/smartdown/parser/element/markdown_line.rb +14 -0
- data/lib/smartdown/parser/node_parser.rb +10 -7
- data/lib/smartdown/parser/node_transform.rb +21 -4
- data/lib/smartdown/version.rb +1 -1
- data/spec/acceptance/parsing_spec.rb +7 -0
- data/spec/api/node_spec.rb +4 -4
- data/spec/api/question_spec.rb +3 -3
- data/spec/engine/conditional_resolver_spec.rb +8 -8
- data/spec/engine/interpolator_spec.rb +11 -11
- data/spec/engine_spec.rb +12 -12
- data/spec/fixtures/acceptance/animal-example-multiple/animal-example-multiple.txt +2 -0
- data/spec/fixtures/acceptance/animal-example-simple/animal-example-simple.txt +2 -0
- data/spec/fixtures/acceptance/cover-sheet/cover-sheet.txt +5 -0
- data/spec/fixtures/acceptance/snippet/snippet.txt +2 -0
- data/spec/model/node_spec.rb +1 -1
- data/spec/parser/base_spec.rb +2 -2
- data/spec/parser/element/conditional_spec.rb +144 -30
- data/spec/parser/element/front_matter_spec.rb +3 -3
- data/spec/parser/element/markdown_line_spec.rb +28 -0
- data/spec/parser/integration/cover_sheet_spec.rb +2 -0
- data/spec/parser/node_parser_spec.rb +55 -27
- data/spec/support/model_builder.rb +3 -3
- data/spec/support_specs/model_builder_spec.rb +12 -12
- metadata +25 -23
- data/lib/smartdown/parser/element/markdown_paragraph.rb +0 -19
- data/spec/parser/element/markdown_paragraph_spec.rb +0 -28
data/spec/engine_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe Smartdown::Engine do
|
|
12
12
|
build_flow("check-uk-visa") do
|
13
13
|
node("check-uk-visa") do
|
14
14
|
heading("Check uk visa")
|
15
|
-
|
15
|
+
line("This is the paragraph")
|
16
16
|
start_button("passport_question")
|
17
17
|
end
|
18
18
|
|
@@ -39,16 +39,16 @@ describe Smartdown::Engine do
|
|
39
39
|
conditional do
|
40
40
|
named_predicate "pred?"
|
41
41
|
true_case do
|
42
|
-
|
42
|
+
line("True case")
|
43
43
|
end
|
44
44
|
false_case do
|
45
|
-
|
45
|
+
line("False case")
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
node("outcome_with_interpolation") do
|
51
|
-
|
51
|
+
line("The answer is %{interpolated_variable}")
|
52
52
|
end
|
53
53
|
end
|
54
54
|
}
|
@@ -56,7 +56,7 @@ describe Smartdown::Engine do
|
|
56
56
|
build_flow("check-uk-visa") do
|
57
57
|
node("check-uk-visa") do
|
58
58
|
heading("Check uk visa")
|
59
|
-
|
59
|
+
line("This is the paragraph")
|
60
60
|
start_button("passport_question")
|
61
61
|
end
|
62
62
|
|
@@ -115,24 +115,24 @@ describe Smartdown::Engine do
|
|
115
115
|
conditional do
|
116
116
|
named_predicate "pred?"
|
117
117
|
true_case do
|
118
|
-
|
118
|
+
line("True case")
|
119
119
|
end
|
120
120
|
false_case do
|
121
|
-
|
121
|
+
line("False case")
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
node("outcome_imaginary_country") do
|
127
|
-
|
127
|
+
line("Imaginary country")
|
128
128
|
end
|
129
129
|
|
130
130
|
node("outcome_with_interpolation") do
|
131
|
-
|
131
|
+
line("The answer is %{interpolated_variable}")
|
132
132
|
end
|
133
133
|
|
134
134
|
node("outcome_passport_colour_specified") do
|
135
|
-
|
135
|
+
line("What a pretty passport")
|
136
136
|
end
|
137
137
|
end
|
138
138
|
}
|
@@ -297,7 +297,7 @@ describe Smartdown::Engine do
|
|
297
297
|
|
298
298
|
let(:expected_node_after_conditional_resolution) {
|
299
299
|
model_builder.node("outcome_no_visa_needed") do
|
300
|
-
|
300
|
+
line("True case")
|
301
301
|
end
|
302
302
|
}
|
303
303
|
|
@@ -315,7 +315,7 @@ describe Smartdown::Engine do
|
|
315
315
|
|
316
316
|
let(:expected_node_after_conditional_resolution) {
|
317
317
|
model_builder.node("outcome_with_interpolation") do
|
318
|
-
|
318
|
+
line("The answer is 42")
|
319
319
|
end
|
320
320
|
}
|
321
321
|
|
data/spec/model/node_spec.rb
CHANGED
@@ -36,7 +36,7 @@ describe Smartdown::Model::Node do
|
|
36
36
|
Smartdown::Model::Element::MarkdownHeading.new("A Heading"),
|
37
37
|
Smartdown::Model::Element::Question::Date.new("a_date_question"),
|
38
38
|
Smartdown::Model::Element::Question::MultipleChoice.new("a_multiple_choice_question"),
|
39
|
-
Smartdown::Model::Element::
|
39
|
+
Smartdown::Model::Element::MarkdownLine.new("Some text"),
|
40
40
|
] }
|
41
41
|
specify { expect(node.questions).to eq elements[1..2] }
|
42
42
|
end
|
data/spec/parser/base_spec.rb
CHANGED
@@ -23,11 +23,11 @@ describe Smartdown::Parser::Base do
|
|
23
23
|
|
24
24
|
# Only one newline
|
25
25
|
it { should parse("\r") }
|
26
|
-
it { should parse("\r\n") }
|
27
|
-
it { should parse("\n\r") }
|
28
26
|
it { should parse("\n") }
|
29
27
|
|
30
28
|
# Not multiple
|
29
|
+
it { should_not parse("\r\n") }
|
30
|
+
it { should_not parse("\n\r") }
|
31
31
|
it { should_not parse("\n\n") }
|
32
32
|
end
|
33
33
|
|
@@ -23,7 +23,11 @@ SOURCE
|
|
23
23
|
should parse(source).as(
|
24
24
|
conditional: {
|
25
25
|
predicate: {named_predicate: "pred1?"},
|
26
|
-
true_case: [
|
26
|
+
true_case: [
|
27
|
+
{line: "#{true_body}"},
|
28
|
+
{blank: "\n"},
|
29
|
+
{blank: "\n"},
|
30
|
+
]
|
27
31
|
}
|
28
32
|
)
|
29
33
|
}
|
@@ -37,7 +41,11 @@ SOURCE
|
|
37
41
|
should eq(
|
38
42
|
Smartdown::Model::Element::Conditional.new(
|
39
43
|
Smartdown::Model::Predicate::Named.new("pred1?"),
|
40
|
-
[
|
44
|
+
[
|
45
|
+
Smartdown::Model::Element::MarkdownLine.new(true_body),
|
46
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
47
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
48
|
+
]
|
41
49
|
)
|
42
50
|
)
|
43
51
|
}
|
@@ -53,7 +61,14 @@ SOURCE
|
|
53
61
|
should parse(source).as(
|
54
62
|
conditional: {
|
55
63
|
predicate: {named_predicate: "pred1?"},
|
56
|
-
true_case: [
|
64
|
+
true_case: [
|
65
|
+
{line: "#{one_line}"},
|
66
|
+
{blank: "\n"},
|
67
|
+
{blank: "\n"},
|
68
|
+
{line: "#{one_line}"},
|
69
|
+
{blank: "\n"},
|
70
|
+
{blank: "\n"},
|
71
|
+
]
|
57
72
|
}
|
58
73
|
)
|
59
74
|
}
|
@@ -68,8 +83,12 @@ SOURCE
|
|
68
83
|
Smartdown::Model::Element::Conditional.new(
|
69
84
|
Smartdown::Model::Predicate::Named.new("pred1?"),
|
70
85
|
[
|
71
|
-
Smartdown::Model::Element::
|
72
|
-
Smartdown::Model::Element::
|
86
|
+
Smartdown::Model::Element::MarkdownLine.new(one_line),
|
87
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
88
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
89
|
+
Smartdown::Model::Element::MarkdownLine.new(one_line),
|
90
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
91
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
73
92
|
]
|
74
93
|
)
|
75
94
|
)
|
@@ -125,8 +144,16 @@ SOURCE
|
|
125
144
|
should parse(source).as(
|
126
145
|
conditional: {
|
127
146
|
predicate: {named_predicate: "pred1?"},
|
128
|
-
true_case: [
|
129
|
-
|
147
|
+
true_case: [
|
148
|
+
{line: "#{true_body}"},
|
149
|
+
{blank: "\n"},
|
150
|
+
{blank: "\n"},
|
151
|
+
],
|
152
|
+
false_case: [
|
153
|
+
{line: "#{false_body}"},
|
154
|
+
{blank: "\n"},
|
155
|
+
{blank: "\n"},
|
156
|
+
]
|
130
157
|
}
|
131
158
|
)
|
132
159
|
}
|
@@ -140,8 +167,16 @@ SOURCE
|
|
140
167
|
should eq(
|
141
168
|
Smartdown::Model::Element::Conditional.new(
|
142
169
|
Smartdown::Model::Predicate::Named.new("pred1?"),
|
143
|
-
[
|
144
|
-
|
170
|
+
[
|
171
|
+
Smartdown::Model::Element::MarkdownLine.new(true_body),
|
172
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
173
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
174
|
+
],
|
175
|
+
[
|
176
|
+
Smartdown::Model::Element::MarkdownLine.new(false_body),
|
177
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
178
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
179
|
+
]
|
145
180
|
)
|
146
181
|
)
|
147
182
|
}
|
@@ -172,10 +207,18 @@ SOURCE
|
|
172
207
|
should parse(source).as(
|
173
208
|
conditional: {
|
174
209
|
predicate: {named_predicate: "pred1?"},
|
175
|
-
true_case: [
|
210
|
+
true_case: [
|
211
|
+
{line: "#{true1_body}"},
|
212
|
+
{blank: "\n"},
|
213
|
+
{blank: "\n"},
|
214
|
+
],
|
176
215
|
false_case: [{conditional: {
|
177
216
|
predicate: {named_predicate: "pred2?"},
|
178
|
-
true_case: [
|
217
|
+
true_case: [
|
218
|
+
{line: "#{true2_body}"},
|
219
|
+
{blank: "\n"},
|
220
|
+
{blank: "\n"},
|
221
|
+
],
|
179
222
|
}}]
|
180
223
|
}
|
181
224
|
)
|
@@ -190,10 +233,18 @@ SOURCE
|
|
190
233
|
should eq(
|
191
234
|
Smartdown::Model::Element::Conditional.new(
|
192
235
|
Smartdown::Model::Predicate::Named.new("pred1?"),
|
193
|
-
[
|
236
|
+
[
|
237
|
+
Smartdown::Model::Element::MarkdownLine.new(true1_body),
|
238
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
239
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
240
|
+
],
|
194
241
|
[Smartdown::Model::Element::Conditional.new(
|
195
242
|
Smartdown::Model::Predicate::Named.new("pred2?"),
|
196
|
-
[
|
243
|
+
[
|
244
|
+
Smartdown::Model::Element::MarkdownLine.new(true2_body),
|
245
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
246
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
247
|
+
]
|
197
248
|
)]
|
198
249
|
)
|
199
250
|
)
|
@@ -230,13 +281,25 @@ SOURCE
|
|
230
281
|
should parse(source).as(
|
231
282
|
conditional: {
|
232
283
|
predicate: {named_predicate: "pred1?"},
|
233
|
-
true_case: [
|
284
|
+
true_case: [
|
285
|
+
{line: "#{true1_body}"},
|
286
|
+
{blank: "\n"},
|
287
|
+
{blank: "\n"},
|
288
|
+
],
|
234
289
|
false_case: [{conditional: {
|
235
290
|
predicate: {named_predicate: "pred2?"},
|
236
|
-
true_case: [
|
291
|
+
true_case: [
|
292
|
+
{line: "#{true2_body}"},
|
293
|
+
{blank: "\n"},
|
294
|
+
{blank: "\n"},
|
295
|
+
],
|
237
296
|
false_case: [{conditional: {
|
238
297
|
predicate: {named_predicate: "pred3?"},
|
239
|
-
true_case: [
|
298
|
+
true_case: [
|
299
|
+
{line: "#{true3_body}"},
|
300
|
+
{blank: "\n"},
|
301
|
+
{blank: "\n"},
|
302
|
+
],
|
240
303
|
}}]
|
241
304
|
}}]
|
242
305
|
}
|
@@ -252,13 +315,25 @@ SOURCE
|
|
252
315
|
should eq(
|
253
316
|
Smartdown::Model::Element::Conditional.new(
|
254
317
|
Smartdown::Model::Predicate::Named.new("pred1?"),
|
255
|
-
[
|
318
|
+
[
|
319
|
+
Smartdown::Model::Element::MarkdownLine.new(true1_body),
|
320
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
321
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
322
|
+
],
|
256
323
|
[Smartdown::Model::Element::Conditional.new(
|
257
324
|
Smartdown::Model::Predicate::Named.new("pred2?"),
|
258
|
-
[
|
325
|
+
[
|
326
|
+
Smartdown::Model::Element::MarkdownLine.new(true2_body),
|
327
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
328
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
329
|
+
],
|
259
330
|
[Smartdown::Model::Element::Conditional.new(
|
260
331
|
Smartdown::Model::Predicate::Named.new("pred3?"),
|
261
|
-
[
|
332
|
+
[
|
333
|
+
Smartdown::Model::Element::MarkdownLine.new(true3_body),
|
334
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
335
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
336
|
+
]
|
262
337
|
)]
|
263
338
|
)]
|
264
339
|
)
|
@@ -296,11 +371,23 @@ SOURCE
|
|
296
371
|
should parse(source).as(
|
297
372
|
conditional: {
|
298
373
|
predicate: {named_predicate: "pred1?"},
|
299
|
-
true_case: [
|
374
|
+
true_case: [
|
375
|
+
{line: "#{true1_body}"},
|
376
|
+
{blank: "\n"},
|
377
|
+
{blank: "\n"},
|
378
|
+
],
|
300
379
|
false_case: [{conditional: {
|
301
380
|
predicate: {named_predicate: "pred2?"},
|
302
|
-
true_case: [
|
303
|
-
|
381
|
+
true_case: [
|
382
|
+
{line: "#{true2_body}"},
|
383
|
+
{blank: "\n"},
|
384
|
+
{blank: "\n"},
|
385
|
+
],
|
386
|
+
false_case: [
|
387
|
+
{line: "#{false_body}"},
|
388
|
+
{blank: "\n"},
|
389
|
+
{blank: "\n"},
|
390
|
+
]
|
304
391
|
}}]
|
305
392
|
}
|
306
393
|
)
|
@@ -316,11 +403,23 @@ SOURCE
|
|
316
403
|
should eq(
|
317
404
|
Smartdown::Model::Element::Conditional.new(
|
318
405
|
Smartdown::Model::Predicate::Named.new("pred1?"),
|
319
|
-
[
|
406
|
+
[
|
407
|
+
Smartdown::Model::Element::MarkdownLine.new(true1_body),
|
408
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
409
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
410
|
+
],
|
320
411
|
[Smartdown::Model::Element::Conditional.new(
|
321
412
|
Smartdown::Model::Predicate::Named.new("pred2?"),
|
322
|
-
[
|
323
|
-
|
413
|
+
[
|
414
|
+
Smartdown::Model::Element::MarkdownLine.new(true2_body),
|
415
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
416
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
417
|
+
],
|
418
|
+
[
|
419
|
+
Smartdown::Model::Element::MarkdownLine.new(false_body),
|
420
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
421
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
422
|
+
]
|
324
423
|
)]
|
325
424
|
)
|
326
425
|
)
|
@@ -354,12 +453,21 @@ SOURCE
|
|
354
453
|
conditional: {
|
355
454
|
predicate: {named_predicate: "pred1?"},
|
356
455
|
true_case: [
|
357
|
-
{
|
456
|
+
{line: "#{first_true_body}"},
|
457
|
+
{blank: "\n"},
|
458
|
+
{blank: "\n"},
|
358
459
|
{conditional: {
|
359
|
-
|
360
|
-
|
460
|
+
predicate: {named_predicate: "pred2?"},
|
461
|
+
true_case: [
|
462
|
+
{line: "#{both_true_body}"},
|
463
|
+
{blank: "\n"},
|
464
|
+
{blank: "\n"},
|
465
|
+
],
|
361
466
|
}},
|
362
|
-
{
|
467
|
+
{blank: "\n"},
|
468
|
+
{line: "#{first_true_body}"},
|
469
|
+
{blank: "\n"},
|
470
|
+
{blank: "\n"},
|
363
471
|
]
|
364
472
|
}
|
365
473
|
)
|
@@ -388,7 +496,13 @@ TAG
|
|
388
496
|
conditional: {
|
389
497
|
predicate: {named_predicate: "pred?"},
|
390
498
|
true_case: [
|
391
|
-
{
|
499
|
+
{line: "$E"},
|
500
|
+
{blank: "\n"},
|
501
|
+
{line: "Bit of content in lovely custom tag"},
|
502
|
+
{blank: "\n"},
|
503
|
+
{line: "$E"},
|
504
|
+
{blank: "\n"},
|
505
|
+
{blank: "\n"},
|
392
506
|
]},
|
393
507
|
)
|
394
508
|
}
|
@@ -5,12 +5,12 @@ describe Smartdown::Parser::Element::FrontMatter do
|
|
5
5
|
|
6
6
|
subject(:parser) { described_class.new }
|
7
7
|
|
8
|
-
it { should parse("
|
9
|
-
it { should parse("
|
8
|
+
it { should parse("---\na: 1\n---\n").as(front_matter: [{name: "a", value: "1"}]) }
|
9
|
+
it { should parse("---\na: 1\nb: 2\n---\n").as(front_matter: [{name: "a", value: "1"}, {name: "b", value: "2"}]) }
|
10
10
|
|
11
11
|
describe "transformed" do
|
12
12
|
let(:node_name) { "my_node" }
|
13
|
-
let(:source) { "
|
13
|
+
let(:source) { "---\na: 1\n---\n" }
|
14
14
|
subject(:transformed) {
|
15
15
|
Smartdown::Parser::NodeInterpreter.new(node_name, source, parser: parser).interpret
|
16
16
|
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'smartdown/parser/element/markdown_line'
|
2
|
+
require 'smartdown/parser/node_interpreter'
|
3
|
+
|
4
|
+
describe Smartdown::Parser::Element::MarkdownLine do
|
5
|
+
|
6
|
+
subject(:parser) { described_class.new }
|
7
|
+
let(:node_name) { "my_node" }
|
8
|
+
|
9
|
+
it { should parse("My para").as(line: "My para") }
|
10
|
+
it { should_not parse("My para\n").as(line: "My para\n") }
|
11
|
+
it { should parse(" My para").as(line: " My para") }
|
12
|
+
it { should_not parse(" My para\nsecond line") }
|
13
|
+
it { should_not parse(" My para\nsecond line\n") }
|
14
|
+
it { should_not parse(" My para\nsecond line \n") }
|
15
|
+
it { should_not parse("Para1\n\nPara2") }
|
16
|
+
|
17
|
+
it { should parse("a b") }
|
18
|
+
|
19
|
+
describe "transformed" do
|
20
|
+
let(:content) { "My para" }
|
21
|
+
subject(:transformed) {
|
22
|
+
Smartdown::Parser::NodeInterpreter.new(node_name, content, parser: parser).interpret
|
23
|
+
}
|
24
|
+
|
25
|
+
it { should eq(Smartdown::Model::Element::MarkdownLine.new(content)) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -20,8 +20,10 @@ SOURCE
|
|
20
20
|
should parse(source).as({
|
21
21
|
body: [
|
22
22
|
{h1: "This is my title"},
|
23
|
-
{
|
24
|
-
{
|
23
|
+
{blank_line: "\n", element: {line: "This is a paragraph of text with stuff"}},
|
24
|
+
{blank_line: "\n", element: {line: "that flows along"}},
|
25
|
+
{blank_line: "\n\n", element: {line: "Another paragraph of text"}},
|
26
|
+
{blank_line: "\n", element: {blank: nil}},
|
25
27
|
]
|
26
28
|
})
|
27
29
|
}
|
@@ -34,7 +36,9 @@ SOURCE
|
|
34
36
|
describe "front matter and body" do
|
35
37
|
let(:source) {
|
36
38
|
<<SOURCE
|
39
|
+
---
|
37
40
|
name: My node
|
41
|
+
---
|
38
42
|
|
39
43
|
# This is my title
|
40
44
|
|
@@ -49,7 +53,8 @@ SOURCE
|
|
49
53
|
],
|
50
54
|
body: [
|
51
55
|
{h1: "This is my title"},
|
52
|
-
{
|
56
|
+
{blank_line: "\n", element: {line: "A paragraph"}},
|
57
|
+
{blank_line: "\n", element: {blank: nil}},
|
53
58
|
]
|
54
59
|
})
|
55
60
|
end
|
@@ -70,13 +75,16 @@ SOURCE
|
|
70
75
|
should parse(source).as({
|
71
76
|
body: [
|
72
77
|
{h1: "This is my title"},
|
73
|
-
{
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
{blank_line: "\n",
|
79
|
+
element: {
|
80
|
+
multiple_choice: {
|
81
|
+
identifier: "my_question",
|
82
|
+
options: [
|
83
|
+
{value: "yes", label: "Yes"},
|
84
|
+
{value: "no", label: "No"}
|
85
|
+
],
|
86
|
+
option_pairs: []}
|
87
|
+
}
|
80
88
|
}
|
81
89
|
]
|
82
90
|
})
|
@@ -102,16 +110,22 @@ SOURCE
|
|
102
110
|
should parse(source).as({
|
103
111
|
body: [
|
104
112
|
{h1: "This is my title"},
|
105
|
-
{
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
113
|
+
{blank_line: "\n",
|
114
|
+
element: {
|
115
|
+
multiple_choice: {
|
116
|
+
identifier: "my_question",
|
117
|
+
options: [
|
118
|
+
{value: "yes", label: "Yes"},
|
119
|
+
{value: "no", label: "No"}
|
120
|
+
],
|
121
|
+
option_pairs: []
|
122
|
+
}
|
123
|
+
}
|
112
124
|
},
|
113
|
-
{h1: "Next node rules"},
|
114
|
-
{
|
125
|
+
{blank_line: "\n", element: {h1: "Next node rules"}},
|
126
|
+
{blank_line: "\n", element:
|
127
|
+
{next_node_rules: [{rule: {predicate: {named_predicate: "pred1?"}, outcome: "outcome"}}]}
|
128
|
+
}
|
115
129
|
]
|
116
130
|
})
|
117
131
|
}
|
@@ -125,8 +139,11 @@ SOURCE
|
|
125
139
|
let(:expected_elements) {
|
126
140
|
[
|
127
141
|
Smartdown::Model::Element::MarkdownHeading.new("This is my title"),
|
142
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
128
143
|
Smartdown::Model::Element::Question::MultipleChoice.new("my_question", "yes"=>"Yes", "no"=>"No"),
|
144
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
129
145
|
Smartdown::Model::Element::MarkdownHeading.new("Next node rules"),
|
146
|
+
Smartdown::Model::Element::MarkdownLine.new("\n"),
|
130
147
|
Smartdown::Model::NextNodeRules.new([
|
131
148
|
Smartdown::Model::Rule.new(Smartdown::Model::Predicate::Named.new("pred1?"), "outcome")
|
132
149
|
])
|
@@ -159,10 +176,18 @@ SOURCE
|
|
159
176
|
it {
|
160
177
|
should parse(source).as({
|
161
178
|
body: [
|
162
|
-
{conditional: {
|
179
|
+
{ conditional: {
|
163
180
|
predicate: {named_predicate: "pred1?"},
|
164
|
-
true_case: [
|
165
|
-
|
181
|
+
true_case: [
|
182
|
+
{line: "Text when true"},
|
183
|
+
{blank: "\n"},
|
184
|
+
{blank: "\n"},
|
185
|
+
],
|
186
|
+
false_case: [
|
187
|
+
{line: "Text when false"},
|
188
|
+
{blank: "\n"},
|
189
|
+
{blank: "\n"},
|
190
|
+
]
|
166
191
|
}}
|
167
192
|
]
|
168
193
|
})
|
@@ -187,8 +212,10 @@ SOURCE
|
|
187
212
|
should parse(source).as({
|
188
213
|
body: [
|
189
214
|
{h1: "This is my title"},
|
190
|
-
{
|
191
|
-
{
|
215
|
+
{blank_line: "\n", element: {line: "This is a paragraph of text with stuff"}},
|
216
|
+
{blank_line: "\n", element: {line: "that flows along"}},
|
217
|
+
{blank_line: "\n\n", element: {line: "Another paragraph of text"}},
|
218
|
+
{blank_line: "\n\n\n", element: {blank: nil}},
|
192
219
|
]
|
193
220
|
})
|
194
221
|
}
|
@@ -199,7 +226,7 @@ SOURCE
|
|
199
226
|
let(:source) {
|
200
227
|
<<SOURCE
|
201
228
|
# Lovely title
|
202
|
-
|
229
|
+
|
203
230
|
line of content
|
204
231
|
SOURCE
|
205
232
|
}
|
@@ -207,8 +234,9 @@ SOURCE
|
|
207
234
|
it "doesn't blow up" do
|
208
235
|
should parse(source).as({
|
209
236
|
body: [
|
210
|
-
{
|
211
|
-
{
|
237
|
+
{h1: "Lovely title" },
|
238
|
+
{blank_line: "\n", element: {line: "line of content" }},
|
239
|
+
{blank_line: "\n", element: {blank: nil }},
|
212
240
|
]
|
213
241
|
})
|
214
242
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'smartdown/model/flow'
|
2
2
|
require 'smartdown/model/node'
|
3
3
|
require 'smartdown/model/element/markdown_heading'
|
4
|
-
require 'smartdown/model/element/
|
4
|
+
require 'smartdown/model/element/markdown_line'
|
5
5
|
require 'smartdown/model/element/start_button'
|
6
6
|
require 'smartdown/model/element/question/multiple_choice'
|
7
7
|
require 'smartdown/model/element/question/date'
|
@@ -41,9 +41,9 @@ class ModelBuilder
|
|
41
41
|
@elements.last
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def line(content)
|
45
45
|
@elements ||= []
|
46
|
-
@elements << Smartdown::Model::Element::
|
46
|
+
@elements << Smartdown::Model::Element::MarkdownLine.new(content)
|
47
47
|
@elements.last
|
48
48
|
end
|
49
49
|
|