smartdown 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/lib/smartdown/api/country_question.rb +21 -0
- data/lib/smartdown/api/flow.rb +5 -2
- data/lib/smartdown/api/previous_question.rb +2 -0
- data/lib/smartdown/api/question_page.rb +4 -1
- data/lib/smartdown/model/answer/country.rb +28 -0
- data/lib/smartdown/model/answer/text.rb +4 -0
- data/lib/smartdown/model/element/question/country.rb +15 -0
- data/lib/smartdown/parser/base.rb +0 -9
- data/lib/smartdown/parser/element/country_question.rb +21 -0
- data/lib/smartdown/parser/element/date_question.rb +8 -11
- data/lib/smartdown/parser/element/multiple_choice_question.rb +6 -11
- data/lib/smartdown/parser/element/salary_question.rb +8 -11
- data/lib/smartdown/parser/element/text_question.rb +9 -12
- data/lib/smartdown/parser/flow_interpreter.rb +10 -3
- data/lib/smartdown/parser/node_interpreter.rb +2 -1
- data/lib/smartdown/parser/node_parser.rb +2 -0
- data/lib/smartdown/parser/node_transform.rb +27 -0
- data/lib/smartdown/parser/question.rb +37 -0
- data/lib/smartdown/version.rb +1 -1
- data/spec/engine/interpolator_spec.rb +44 -0
- data/spec/model/answer/country_spec.rb +31 -0
- data/spec/parser/element/country_question_spec.rb +70 -0
- metadata +20 -11
data/README.md
CHANGED
@@ -106,6 +106,19 @@ to your outbound flight.
|
|
106
106
|
* no: No
|
107
107
|
```
|
108
108
|
|
109
|
+
### 'Country' question
|
110
|
+
|
111
|
+
A 'country' question allows the user to select a country from a drop-down list.
|
112
|
+
|
113
|
+
```markdown
|
114
|
+
## Where do you want to get married?
|
115
|
+
|
116
|
+
[country: marriage_country, countries: all_countries]
|
117
|
+
```
|
118
|
+
|
119
|
+
Where `all_countries` is the name of a data-plugin method that will return a hash of
|
120
|
+
country slugs/names.
|
121
|
+
|
109
122
|
### Date
|
110
123
|
|
111
124
|
```markdown
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'smartdown/api/question'
|
2
|
+
require 'smartdown/model/element/question/country'
|
3
|
+
|
4
|
+
module Smartdown
|
5
|
+
module Api
|
6
|
+
class CountryQuestion < Question
|
7
|
+
def options
|
8
|
+
question = elements.find{|element| element.is_a? Smartdown::Model::Element::Question::Country}
|
9
|
+
question.countries.map do |choice|
|
10
|
+
OpenStruct.new(:label => choice[1], :value => choice[0])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
question = elements.find{|element| element.is_a? Smartdown::Model::Element::Question::Country}
|
16
|
+
question.name
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/smartdown/api/flow.rb
CHANGED
@@ -12,8 +12,11 @@ module Smartdown
|
|
12
12
|
|
13
13
|
attr_reader :scenario_sets
|
14
14
|
|
15
|
-
def initialize(smartdown_input,
|
16
|
-
|
15
|
+
def initialize(smartdown_input, options = {})
|
16
|
+
initial_state = options.fetch(:initial_state, {})
|
17
|
+
data_module = options.fetch(:data_module, nil)
|
18
|
+
|
19
|
+
@smartdown_flow = Smartdown::Parser::FlowInterpreter.new(smartdown_input, data_module).interpret
|
17
20
|
@engine = Smartdown::Engine.new(@smartdown_flow, initial_state)
|
18
21
|
@scenario_sets = Smartdown::Parser::ScenarioSetsInterpreter.new(smartdown_input).interpret
|
19
22
|
end
|
@@ -10,6 +10,8 @@ module Smartdown
|
|
10
10
|
def initialize(elements, response)
|
11
11
|
if element = elements.find{|element| element.is_a? Smartdown::Model::Element::Question::MultipleChoice}
|
12
12
|
@question = MultipleChoice.new(elements)
|
13
|
+
elsif element = elements.find{|element| element.is_a? Smartdown::Model::Element::Question::Country}
|
14
|
+
@question = CountryQuestion.new(elements)
|
13
15
|
elsif element = elements.find{|element| element.is_a? Smartdown::Model::Element::Question::Date}
|
14
16
|
@question = DateQuestion.new(elements)
|
15
17
|
elsif element = elements.find{|element| element.is_a? Smartdown::Model::Element::Question::Salary}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'smartdown/api/multiple_choice'
|
2
2
|
require 'smartdown/api/date_question'
|
3
|
+
require 'smartdown/api/country_question'
|
3
4
|
require 'smartdown/api/salary_question'
|
4
5
|
require 'smartdown/api/text_question'
|
5
6
|
|
@@ -10,8 +11,10 @@ module Smartdown
|
|
10
11
|
elements.slice_before do |element|
|
11
12
|
element.is_a? Smartdown::Model::Element::MarkdownHeading
|
12
13
|
end.map do |question_element_group|
|
13
|
-
if question_element_group.find{|element| element.is_a? Smartdown::Model::Element::Question::MultipleChoice}
|
14
|
+
if question_element_group.find{|element| element.is_a? Smartdown::Model::Element::Question::MultipleChoice }
|
14
15
|
Smartdown::Api::MultipleChoice.new(question_element_group)
|
16
|
+
elsif question_element_group.find{ |element| element.is_a?(Smartdown::Model::Element::Question::Country) }
|
17
|
+
Smartdown::Api::CountryQuestion.new(question_element_group)
|
15
18
|
elsif question_element_group.find{|element| element.is_a? Smartdown::Model::Element::Question::Date}
|
16
19
|
Smartdown::Api::DateQuestion.new(question_element_group)
|
17
20
|
elsif question_element_group.find{|element| element.is_a? Smartdown::Model::Element::Question::Salary}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Smartdown
|
4
|
+
module Model
|
5
|
+
module Answer
|
6
|
+
class Country < Base
|
7
|
+
def value_type
|
8
|
+
::String
|
9
|
+
end
|
10
|
+
|
11
|
+
def humanize
|
12
|
+
question.countries[value]
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def parse_value(value)
|
17
|
+
check_value_not_nil(value)
|
18
|
+
if valid?
|
19
|
+
unless question.countries.keys.include? value
|
20
|
+
@error = "Invalid country"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'smartdown/model/answer/country'
|
2
|
+
|
3
|
+
module Smartdown
|
4
|
+
module Model
|
5
|
+
module Element
|
6
|
+
module Question
|
7
|
+
class Country < Struct.new(:name, :countries, :alias)
|
8
|
+
def answer_type
|
9
|
+
Smartdown::Model::Answer::Country
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'smartdown/parser/base'
|
2
|
+
require 'smartdown/parser/question'
|
3
|
+
|
4
|
+
module Smartdown
|
5
|
+
module Parser
|
6
|
+
module Element
|
7
|
+
class CountryQuestion < Question
|
8
|
+
|
9
|
+
rule(:question_type) {
|
10
|
+
str("country")
|
11
|
+
}
|
12
|
+
|
13
|
+
rule(:country_question) {
|
14
|
+
question_tag.as(:country)
|
15
|
+
}
|
16
|
+
|
17
|
+
root(:country_question)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,21 +1,18 @@
|
|
1
1
|
require 'smartdown/parser/base'
|
2
|
+
require 'smartdown/parser/question'
|
2
3
|
|
3
4
|
module Smartdown
|
4
5
|
module Parser
|
5
6
|
module Element
|
6
|
-
class DateQuestion <
|
7
|
+
class DateQuestion < Question
|
8
|
+
rule(:question_type) {
|
9
|
+
str("date")
|
10
|
+
}
|
11
|
+
|
7
12
|
rule(:date_question) {
|
8
|
-
(
|
9
|
-
str("[date:") >>
|
10
|
-
optional_space >>
|
11
|
-
question_identifier.as(:identifier) >>
|
12
|
-
optional_space >>
|
13
|
-
option_pair.repeat.as(:option_pairs) >>
|
14
|
-
str("]") >>
|
15
|
-
optional_space >>
|
16
|
-
line_ending
|
17
|
-
).as(:date)
|
13
|
+
question_tag.as(:date)
|
18
14
|
}
|
15
|
+
|
19
16
|
root(:date_question)
|
20
17
|
end
|
21
18
|
end
|
@@ -1,18 +1,13 @@
|
|
1
1
|
require 'smartdown/parser/base'
|
2
|
+
require 'smartdown/parser/question'
|
2
3
|
|
3
4
|
module Smartdown
|
4
5
|
module Parser
|
5
6
|
module Element
|
6
|
-
class MultipleChoiceQuestion <
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
question_identifier.as(:identifier) >>
|
11
|
-
optional_space >>
|
12
|
-
option_pair.repeat.as(:option_pairs) >>
|
13
|
-
str("]") >>
|
14
|
-
optional_space >>
|
15
|
-
line_ending
|
7
|
+
class MultipleChoiceQuestion < Question
|
8
|
+
|
9
|
+
rule(:question_type) {
|
10
|
+
str("choice")
|
16
11
|
}
|
17
12
|
|
18
13
|
rule(:option_definition_line) {
|
@@ -27,7 +22,7 @@ module Smartdown
|
|
27
22
|
|
28
23
|
rule(:multiple_choice_question) {
|
29
24
|
(
|
30
|
-
|
25
|
+
question_tag >>
|
31
26
|
(option_definition_line >> line_ending).repeat(1).as(:options)
|
32
27
|
).as(:multiple_choice)
|
33
28
|
}
|
@@ -1,21 +1,18 @@
|
|
1
1
|
require 'smartdown/parser/base'
|
2
|
+
require 'smartdown/parser/question'
|
2
3
|
|
3
4
|
module Smartdown
|
4
5
|
module Parser
|
5
6
|
module Element
|
6
|
-
class SalaryQuestion <
|
7
|
+
class SalaryQuestion < Question
|
8
|
+
rule(:question_type) {
|
9
|
+
str("salary")
|
10
|
+
}
|
11
|
+
|
7
12
|
rule(:salary_question) {
|
8
|
-
(
|
9
|
-
str("[salary:") >>
|
10
|
-
optional_space >>
|
11
|
-
question_identifier.as(:identifier) >>
|
12
|
-
optional_space >>
|
13
|
-
option_pair.repeat.as(:option_pairs) >>
|
14
|
-
str("]") >>
|
15
|
-
optional_space >>
|
16
|
-
line_ending
|
17
|
-
).as(:salary)
|
13
|
+
question_tag.as(:salary)
|
18
14
|
}
|
15
|
+
|
19
16
|
root(:salary_question)
|
20
17
|
end
|
21
18
|
end
|
@@ -1,21 +1,18 @@
|
|
1
|
-
require 'smartdown/parser/
|
1
|
+
require 'smartdown/parser/question'
|
2
2
|
|
3
3
|
module Smartdown
|
4
4
|
module Parser
|
5
5
|
module Element
|
6
|
-
class TextQuestion <
|
6
|
+
class TextQuestion < Question
|
7
|
+
|
8
|
+
rule(:question_type) {
|
9
|
+
str("text")
|
10
|
+
}
|
11
|
+
|
7
12
|
rule(:text_question) {
|
8
|
-
(
|
9
|
-
str("[text:") >>
|
10
|
-
optional_space >>
|
11
|
-
question_identifier.as(:identifier) >>
|
12
|
-
optional_space >>
|
13
|
-
option_pair.repeat.as(:option_pairs) >>
|
14
|
-
str("]") >>
|
15
|
-
optional_space >>
|
16
|
-
line_ending
|
17
|
-
).as(:text)
|
13
|
+
question_tag.as(:text)
|
18
14
|
}
|
15
|
+
|
19
16
|
root(:text_question)
|
20
17
|
end
|
21
18
|
end
|
@@ -18,10 +18,11 @@ module Smartdown
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class FlowInterpreter
|
21
|
-
attr_reader :flow_input
|
21
|
+
attr_reader :flow_input, :data_module
|
22
22
|
|
23
|
-
def initialize(flow_input)
|
23
|
+
def initialize(flow_input, data_module=nil)
|
24
24
|
@flow_input = pre_parse(flow_input)
|
25
|
+
@data_module = data_module
|
25
26
|
end
|
26
27
|
|
27
28
|
def interpret
|
@@ -42,7 +43,7 @@ module Smartdown
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def interpret_node(input_data)
|
45
|
-
Smartdown::Parser::NodeInterpreter.new(input_data.name, input_data.read).interpret
|
46
|
+
Smartdown::Parser::NodeInterpreter.new(input_data.name, input_data.read, options).interpret
|
46
47
|
rescue Parslet::ParseFailed => error
|
47
48
|
raise ParseError.new(input_data.name, error)
|
48
49
|
end
|
@@ -50,6 +51,12 @@ module Smartdown
|
|
50
51
|
def pre_parse(flow_input)
|
51
52
|
SnippetPreParser.parse(flow_input)
|
52
53
|
end
|
54
|
+
|
55
|
+
def options
|
56
|
+
{}.tap do |opts|
|
57
|
+
opts[:data_module] = data_module if data_module
|
58
|
+
end
|
59
|
+
end
|
53
60
|
end
|
54
61
|
end
|
55
62
|
end
|
@@ -12,8 +12,9 @@ module Smartdown
|
|
12
12
|
def initialize(name, source, options = {})
|
13
13
|
@name = name
|
14
14
|
@source = source
|
15
|
+
data_module = options.fetch(:data_module, {})
|
15
16
|
@parser = options.fetch(:parser, Smartdown::Parser::NodeParser.new)
|
16
|
-
@transform = options.fetch(:transform, Smartdown::Parser::NodeTransform.new)
|
17
|
+
@transform = options.fetch(:transform, Smartdown::Parser::NodeTransform.new(data_module))
|
17
18
|
end
|
18
19
|
|
19
20
|
def interpret
|
@@ -6,6 +6,7 @@ require 'smartdown/parser/element/multiple_choice_question'
|
|
6
6
|
require 'smartdown/parser/element/date_question'
|
7
7
|
require 'smartdown/parser/element/salary_question'
|
8
8
|
require 'smartdown/parser/element/text_question'
|
9
|
+
require 'smartdown/parser/element/country_question'
|
9
10
|
require 'smartdown/parser/element/markdown_heading'
|
10
11
|
require 'smartdown/parser/element/markdown_paragraph'
|
11
12
|
require 'smartdown/parser/element/conditional'
|
@@ -21,6 +22,7 @@ module Smartdown
|
|
21
22
|
Element::DateQuestion.new |
|
22
23
|
Element::SalaryQuestion.new |
|
23
24
|
Element::TextQuestion.new |
|
25
|
+
Element::CountryQuestion.new |
|
24
26
|
Rules.new |
|
25
27
|
Element::StartButton.new |
|
26
28
|
Element::NextSteps.new |
|
@@ -6,6 +6,7 @@ require 'smartdown/model/rule'
|
|
6
6
|
require 'smartdown/model/nested_rule'
|
7
7
|
require 'smartdown/model/next_node_rules'
|
8
8
|
require 'smartdown/model/element/question/multiple_choice'
|
9
|
+
require 'smartdown/model/element/question/country'
|
9
10
|
require 'smartdown/model/element/question/date'
|
10
11
|
require 'smartdown/model/element/question/salary'
|
11
12
|
require 'smartdown/model/element/question/text'
|
@@ -27,6 +28,22 @@ require 'smartdown/model/predicate/comparison/less'
|
|
27
28
|
module Smartdown
|
28
29
|
module Parser
|
29
30
|
class NodeTransform < Parslet::Transform
|
31
|
+
|
32
|
+
attr_reader :data_module
|
33
|
+
|
34
|
+
def initialize data_module=nil, &block
|
35
|
+
super(&block)
|
36
|
+
|
37
|
+
@data_module = data_module || {}
|
38
|
+
end
|
39
|
+
|
40
|
+
#TODO: Horrible monkey patching, should try to submit a PR to parselet
|
41
|
+
#to allow modification of bindings?
|
42
|
+
def call_on_match(bindings, block)
|
43
|
+
bindings.merge! data_module
|
44
|
+
super(bindings, block)
|
45
|
+
end
|
46
|
+
|
30
47
|
rule(body: subtree(:body)) {
|
31
48
|
Smartdown::Model::Node.new(
|
32
49
|
node_name, body, Smartdown::Model::FrontMatter.new({})
|
@@ -74,6 +91,16 @@ module Smartdown
|
|
74
91
|
)
|
75
92
|
}
|
76
93
|
|
94
|
+
rule(:country => {identifier: simple(:identifier), :option_pairs => subtree(:option_pairs)}) {
|
95
|
+
country_data_method = Smartdown::Parser::OptionPairs.transform(option_pairs).fetch('countries', nil)
|
96
|
+
country_hash = (eval country_data_method).call
|
97
|
+
Smartdown::Model::Element::Question::Country.new(
|
98
|
+
identifier.to_s,
|
99
|
+
country_hash,
|
100
|
+
Smartdown::Parser::OptionPairs.transform(option_pairs).fetch('alias', nil)
|
101
|
+
)
|
102
|
+
}
|
103
|
+
|
77
104
|
rule(:date => {identifier: simple(:identifier), :option_pairs => subtree(:option_pairs)}) {
|
78
105
|
Smartdown::Model::Element::Question::Date.new(
|
79
106
|
identifier.to_s,
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'smartdown/parser/base'
|
2
|
+
require 'smartdown/parser/predicates'
|
3
|
+
|
4
|
+
module Smartdown
|
5
|
+
module Parser
|
6
|
+
module Element
|
7
|
+
class Question < Base
|
8
|
+
|
9
|
+
rule(:option_pair) {
|
10
|
+
comma >>
|
11
|
+
optional_space >>
|
12
|
+
identifier.as(:key) >>
|
13
|
+
colon >>
|
14
|
+
optional_space >>
|
15
|
+
identifier.as(:value) >>
|
16
|
+
optional_space
|
17
|
+
}
|
18
|
+
|
19
|
+
rule(:question_tag) {
|
20
|
+
(
|
21
|
+
str("[") >>
|
22
|
+
question_type >>
|
23
|
+
str(':') >>
|
24
|
+
optional_space >>
|
25
|
+
identifier.as(:identifier) >>
|
26
|
+
optional_space >>
|
27
|
+
option_pair.repeat.as(:option_pairs) >>
|
28
|
+
str("]") >>
|
29
|
+
optional_space >>
|
30
|
+
line_ending
|
31
|
+
)
|
32
|
+
}
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/smartdown/version.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#TODO: this "require" for money is here for now since there is no associated question type for money yet
|
3
3
|
require 'smartdown/model/answer/money'
|
4
|
+
require 'smartdown/model/element/question/country'
|
4
5
|
require 'smartdown/engine/interpolator'
|
5
6
|
require 'smartdown/engine/state'
|
6
7
|
require 'parslet'
|
@@ -126,4 +127,47 @@ describe Smartdown::Engine::Interpolator do
|
|
126
127
|
expect(interpolated_node.elements.first.content).to eq("£12.33")
|
127
128
|
end
|
128
129
|
end
|
130
|
+
|
131
|
+
context "a paragraph containing a text answer" do
|
132
|
+
let(:elements) { [Smartdown::Model::Element::MarkdownParagraph.new('%{text_answer}')] }
|
133
|
+
let(:state) {
|
134
|
+
Smartdown::Engine::State.new(
|
135
|
+
current_node: node.name,
|
136
|
+
text_answer: Smartdown::Model::Answer::Text.new('I AM TEXT, HEAR ME RAWR')
|
137
|
+
)
|
138
|
+
}
|
139
|
+
it "interpolates the result" do
|
140
|
+
expect(interpolated_node.elements.first.content).to eq("I AM TEXT, HEAR ME RAWR")
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "a paragraph containing a multuple-choice answer" do
|
145
|
+
let(:elements) { [Smartdown::Model::Element::MarkdownParagraph.new('%{multiple_choice_answer}')] }
|
146
|
+
let(:choices) { { 'dog' => 'Dog', 'growlithe' => 'Growlithe', 'arcanine' => 'Arcanine' } }
|
147
|
+
let(:question) { Smartdown::Model::Element::Question::MultipleChoice.new('arcanine', choices) }
|
148
|
+
let(:state) {
|
149
|
+
Smartdown::Engine::State.new(
|
150
|
+
current_node: node.name,
|
151
|
+
multiple_choice_answer: Smartdown::Model::Answer::MultipleChoice.new('arcanine', question)
|
152
|
+
)
|
153
|
+
}
|
154
|
+
it "interpolates the result" do
|
155
|
+
expect(interpolated_node.elements.first.content).to eq("Arcanine")
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context "a paragraph containing a country answer" do
|
160
|
+
let(:elements) { [Smartdown::Model::Element::MarkdownParagraph.new('%{country_answer}')] }
|
161
|
+
let(:country_hash) { { 'united-kingdom' => 'United Kingdom' } }
|
162
|
+
let(:question) { Smartdown::Model::Element::Question::Country.new('united-kingdom', country_hash) }
|
163
|
+
let(:state) {
|
164
|
+
Smartdown::Engine::State.new(
|
165
|
+
current_node: node.name,
|
166
|
+
country_answer: Smartdown::Model::Answer::Country.new('united-kingdom', question)
|
167
|
+
)
|
168
|
+
}
|
169
|
+
it "interpolates the result" do
|
170
|
+
expect(interpolated_node.elements.first.content).to eq("United Kingdom")
|
171
|
+
end
|
172
|
+
end
|
129
173
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
describe Smartdown::Model::Answer::Country do
|
2
|
+
let(:text_string) { "United Kingdom" }
|
3
|
+
subject(:instance) { described_class.new(text_string) }
|
4
|
+
|
5
|
+
|
6
|
+
let(:answer_string) { "country" }
|
7
|
+
subject(:answer) { described_class.new(answer_string, multiple_choice_question) }
|
8
|
+
let(:multiple_choice_question) {
|
9
|
+
Smartdown::Model::Element::Question::Country.new("question",
|
10
|
+
{"country" => "Lovely country"}
|
11
|
+
)
|
12
|
+
}
|
13
|
+
|
14
|
+
describe "#humanize" do
|
15
|
+
it "returns the humanized answer" do
|
16
|
+
expect(answer.humanize).to eq "Lovely country"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "errors" do
|
21
|
+
context "format is incorrect" do
|
22
|
+
let(:answer_string) { "kasjdf" }
|
23
|
+
specify { expect(answer.error).to eql "Invalid country" }
|
24
|
+
end
|
25
|
+
|
26
|
+
context "answer not filled in" do
|
27
|
+
let(:answer_string) { nil }
|
28
|
+
specify { expect(answer.error).to eql "Please answer this question" }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'smartdown/parser/node_parser'
|
2
|
+
require 'smartdown/parser/node_interpreter'
|
3
|
+
require 'smartdown/parser/element/country_question'
|
4
|
+
|
5
|
+
describe Smartdown::Parser::Element::CountryQuestion do
|
6
|
+
subject(:parser) { described_class.new }
|
7
|
+
let(:data_module) { { 'country_data_all' => ->{{}} } }
|
8
|
+
|
9
|
+
context "with question tag and countries" do
|
10
|
+
let(:source) { "[country: country_of_residence, countries: country_data_all]" }
|
11
|
+
|
12
|
+
it "parses" do
|
13
|
+
should parse(source).as(
|
14
|
+
country: {
|
15
|
+
identifier: "country_of_residence",
|
16
|
+
option_pairs:[
|
17
|
+
{
|
18
|
+
key: 'countries',
|
19
|
+
value: 'country_data_all',
|
20
|
+
},
|
21
|
+
]
|
22
|
+
}
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "transformed" do
|
27
|
+
let(:node_name) { "my_node" }
|
28
|
+
subject(:transformed) {
|
29
|
+
Smartdown::Parser::NodeInterpreter.new(node_name, source, data_module: data_module, parser: parser).interpret
|
30
|
+
}
|
31
|
+
|
32
|
+
it { should eq(Smartdown::Model::Element::Question::Country.new("country_of_residence", {})) }
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with question tag and countries, and alias" do
|
38
|
+
let(:source) { "[country: country_of_residence, countries: country_data_all, alias: birthplace]" }
|
39
|
+
|
40
|
+
it "parses" do
|
41
|
+
should parse(source).as(
|
42
|
+
country: {
|
43
|
+
identifier: "country_of_residence",
|
44
|
+
option_pairs:[
|
45
|
+
{
|
46
|
+
key: 'countries',
|
47
|
+
value: 'country_data_all',
|
48
|
+
},
|
49
|
+
{
|
50
|
+
key: 'alias',
|
51
|
+
value: 'birthplace',
|
52
|
+
},
|
53
|
+
]
|
54
|
+
}
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "transformed" do
|
59
|
+
let(:node_name) { "my_node" }
|
60
|
+
subject(:transformed) {
|
61
|
+
Smartdown::Parser::NodeInterpreter.new(node_name, source, data_module: data_module, parser: parser).interpret
|
62
|
+
}
|
63
|
+
|
64
|
+
it { should eq(Smartdown::Model::Element::Question::Country.new("country_of_residence", {}, "birthplace")) }
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2014-07-09 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parslet
|
16
|
-
requirement: &
|
16
|
+
requirement: &9477660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.6.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *9477660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &9476740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *9476740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &9475460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *9475460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: gem_publisher
|
49
|
-
requirement: &
|
49
|
+
requirement: &9474100 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *9474100
|
58
58
|
description:
|
59
59
|
email: david.heath@digital.cabinet-office.gov.uk
|
60
60
|
executables:
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/smartdown/engine.rb
|
67
67
|
- lib/smartdown/parser/predicates.rb
|
68
68
|
- lib/smartdown/parser/node_transform.rb
|
69
|
+
- lib/smartdown/parser/question.rb
|
69
70
|
- lib/smartdown/parser/node_interpreter.rb
|
70
71
|
- lib/smartdown/parser/snippet_pre_parser.rb
|
71
72
|
- lib/smartdown/parser/base.rb
|
@@ -80,6 +81,7 @@ files:
|
|
80
81
|
- lib/smartdown/parser/element/markdown_paragraph.rb
|
81
82
|
- lib/smartdown/parser/element/start_button.rb
|
82
83
|
- lib/smartdown/parser/element/front_matter.rb
|
84
|
+
- lib/smartdown/parser/element/country_question.rb
|
83
85
|
- lib/smartdown/parser/element/multiple_choice_question.rb
|
84
86
|
- lib/smartdown/parser/element/next_steps.rb
|
85
87
|
- lib/smartdown/parser/element/markdown_heading.rb
|
@@ -97,6 +99,7 @@ files:
|
|
97
99
|
- lib/smartdown/api/directory_input.rb
|
98
100
|
- lib/smartdown/api/previous_question.rb
|
99
101
|
- lib/smartdown/api/outcome.rb
|
102
|
+
- lib/smartdown/api/country_question.rb
|
100
103
|
- lib/smartdown/api/multiple_choice.rb
|
101
104
|
- lib/smartdown/api/text_question.rb
|
102
105
|
- lib/smartdown/api/previous_question_page.rb
|
@@ -127,6 +130,7 @@ files:
|
|
127
130
|
- lib/smartdown/model/answer/date.rb
|
128
131
|
- lib/smartdown/model/answer/base.rb
|
129
132
|
- lib/smartdown/model/answer/salary.rb
|
133
|
+
- lib/smartdown/model/answer/country.rb
|
130
134
|
- lib/smartdown/model/answer/money.rb
|
131
135
|
- lib/smartdown/model/answer/multiple_choice.rb
|
132
136
|
- lib/smartdown/model/answer/text.rb
|
@@ -137,6 +141,7 @@ files:
|
|
137
141
|
- lib/smartdown/model/element/markdown_heading.rb
|
138
142
|
- lib/smartdown/model/element/question/date.rb
|
139
143
|
- lib/smartdown/model/element/question/salary.rb
|
144
|
+
- lib/smartdown/model/element/question/country.rb
|
140
145
|
- lib/smartdown/model/element/question/multiple_choice.rb
|
141
146
|
- lib/smartdown/model/element/question/text.rb
|
142
147
|
- lib/smartdown/model/next_node_rules.rb
|
@@ -156,6 +161,7 @@ files:
|
|
156
161
|
- spec/parser/predicates_spec.rb
|
157
162
|
- spec/parser/element/next_steps_spec.rb
|
158
163
|
- spec/parser/element/multiple_choice_question_spec.rb
|
164
|
+
- spec/parser/element/country_question_spec.rb
|
159
165
|
- spec/parser/element/conditional_spec.rb
|
160
166
|
- spec/parser/element/start_button_parser_spec.rb
|
161
167
|
- spec/parser/element/date_question_spec.rb
|
@@ -224,6 +230,7 @@ files:
|
|
224
230
|
- spec/model/answer/base_spec.rb
|
225
231
|
- spec/model/answer/salary_spec.rb
|
226
232
|
- spec/model/answer/date_spec.rb
|
233
|
+
- spec/model/answer/country_spec.rb
|
227
234
|
- spec/model/predicates/set_membership_spec.rb
|
228
235
|
- spec/model/predicates/combined_spec.rb
|
229
236
|
- spec/model/predicates/comparison_spec.rb
|
@@ -245,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
245
252
|
version: '0'
|
246
253
|
segments:
|
247
254
|
- 0
|
248
|
-
hash: -
|
255
|
+
hash: -2036017641587620978
|
249
256
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
257
|
none: false
|
251
258
|
requirements:
|
@@ -254,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
261
|
version: '0'
|
255
262
|
segments:
|
256
263
|
- 0
|
257
|
-
hash: -
|
264
|
+
hash: -2036017641587620978
|
258
265
|
requirements: []
|
259
266
|
rubyforge_project:
|
260
267
|
rubygems_version: 1.8.11
|
@@ -273,6 +280,7 @@ test_files:
|
|
273
280
|
- spec/parser/predicates_spec.rb
|
274
281
|
- spec/parser/element/next_steps_spec.rb
|
275
282
|
- spec/parser/element/multiple_choice_question_spec.rb
|
283
|
+
- spec/parser/element/country_question_spec.rb
|
276
284
|
- spec/parser/element/conditional_spec.rb
|
277
285
|
- spec/parser/element/start_button_parser_spec.rb
|
278
286
|
- spec/parser/element/date_question_spec.rb
|
@@ -341,6 +349,7 @@ test_files:
|
|
341
349
|
- spec/model/answer/base_spec.rb
|
342
350
|
- spec/model/answer/salary_spec.rb
|
343
351
|
- spec/model/answer/date_spec.rb
|
352
|
+
- spec/model/answer/country_spec.rb
|
344
353
|
- spec/model/predicates/set_membership_spec.rb
|
345
354
|
- spec/model/predicates/combined_spec.rb
|
346
355
|
- spec/model/predicates/comparison_spec.rb
|