Skip to content

Commit

Permalink
feat (translator): state markdown generation
Browse files Browse the repository at this point in the history
  • Loading branch information
santanche committed Sep 10, 2020
1 parent e645461 commit 4cd95ce
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
8 changes: 5 additions & 3 deletions src/adonisjs/public/templates/simple/case/quiz_sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
Write here the **stem** of your question.

> Write here the **lead-in** of your question.
+ Answer-key <-> "Feedback for Answer-key"
+ Answer-key <-> "Feedback for Answer-key" >((right))
+ Distractor 1 <-> "Feedback for Distractor 1"
+ Distractor 2 <-> "Feedback for Distractor 2"
+ Distractor 3 <-> "Feedback for Distractor 3"
* Next Question -> Flow.Next
* Next Question -> Flow.Next ((right))?

# Quiz2 (quiz)

Expand All @@ -20,7 +20,7 @@ Write here the **stem** of your question.
+ Distractor 2 <-> "Feedback for Distractor 2"
+ Distractor 3 <-> "Feedback for Distractor 3"
* Next Question -> Flow.Next
* Next Question -> Flow.Next ((right))?

# Feedback (quiz, end)

Expand All @@ -32,6 +32,8 @@ Write here the **feedback**.
* [Enter References](References)
}}

* Next Case -> Flow.Next

# Note (note)

**You answered:** ^Previous.input1^.
Expand Down
4 changes: 2 additions & 2 deletions src/adonisjs/public/translator/item-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@
image:
'![{alternative}]({path}{title})',
option:
'{subtype}{label} {divert} {target}{message}',
'{subtype}{label} {divert} {target}{message}{state}',
entity:
'@{entity}',
input:
'{statement}? {variable}{subtype}{extra}',
choice:
'+ {label} <-> {target}{message}'
'+ {label} <-> {target}{message}{state}'
}

Translator.objTemplates = {
Expand Down
48 changes: 30 additions & 18 deletions src/adonisjs/public/translator/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,25 +734,11 @@ class Translator {
scramble: true,
options: {}
}, compiled[c - 1]._source)
optionGroup.options[compiled[c - 1].label] = {
target: (compiled[c - 1].target)
? compiled[c - 1].target : '(default)'
}
if (compiled[c - 1].message) {
optionGroup.options[compiled[c - 1].label].message =
compiled[c - 1].message
}
this._transferOption(optionGroup.options, compiled[c-1])
compiled[c - 1] = optionGroup
}
if (optionGroup != null) {
optionGroup.options[compiled[c].label] = {
target: (compiled[c].target)
? compiled[c].target : '(default)'
}
if (compiled[c].message) {
optionGroup.options[compiled[c].label].message =
compiled[c].message
}
this._transferOption(optionGroup.options, compiled[c])
optionGroup._source += '\n' + compiled[c]._source
compiled.splice(c, 1)
c--
Expand All @@ -762,6 +748,21 @@ class Translator {
}
}

_transferOption(options, compiledItem) {
options[compiledItem.label] = {
target: (compiledItem.target)
? compiledItem.target : '(default)'
}
if (compiledItem.message) {
options[compiledItem.label].message =
compiledItem.message
}
if (compiledItem.state) {
options[compiledItem.label].state = compiledItem.state
options[compiledItem.label].operation = compiledItem.operation
}
}

// check if both are quoted or subordinated
_equivalentSubQuote (content1, content2) {
return ((content1.blockquote && content2.blockquote) ||
Expand Down Expand Up @@ -1531,6 +1532,11 @@ class Translator {
if (matchArray[3] != null) { option.divert = matchArray[3].trim() }
if (matchArray[4] != null) { option.target = matchArray[4].trim() }
if (matchArray[5] != null) { option.message = matchArray[5].trim() }
if (matchArray[6] != null)
{ option.operation = matchArray[6].trim() }
else if (matchArray[8] != null)
{ option.operation = matchArray[8].trim() }
if (matchArray[7] != null) { option.state = matchArray[7].trim() }

return option
}
Expand Down Expand Up @@ -1575,14 +1581,16 @@ class Translator {
}

_optionObjToMd (obj) {
console.log('=== option markdown')
console.log(obj)
let state = ''
if (obj.state && obj.operation)
state = ' ' + ((obj.operation == ">") ? '>' : '') + '((' + obj.state + '))' + ((obj.operation == "?") ? '?' : '')
return Translator.markdownTemplates.option
.replace('{subtype}', (obj.subtype == '_') ? '' : obj.subtype + ' ')
.replace('{label}', (obj.label) ? obj.label : '')
.replace('{divert}', obj.divert)
.replace('{target}', obj.target)
.replace('{message}', (obj.message) ? '"' + obj.message + '"' : '')
.replace('{state}', state)
}

/*
Expand Down Expand Up @@ -1947,13 +1955,17 @@ class Translator {
if (!first) { md += '\n' }
first = false
const option = obj.options[op]
let state = ''
if (option.state && option.operation)
state = ' ' + ((option.operation == ">") ? '>' : '') + '((' + option.state + '))' + ((option.operation == "?") ? '?' : '')
md += Translator.markdownTemplates.choice
.replace('{label}', op)
.replace('{target}',
(option.target && option.target != '(default)')
? option.target : '')
.replace('{message}',
(option.message ? '"' + option.message + '"' : ''))
.replace("{state}", state)
}
} else {
let extraAttr = ''
Expand Down

0 comments on commit 4cd95ce

Please sign in to comment.