Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
267963a9
Commit
267963a9
authored
Aug 03, 2012
by
Mike Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parsing and converting curly bracket variable names on client side
parent
de652ef2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
16 deletions
+25
-16
cms/static/grammars/main.jspeg
+18
-13
common/lib/xmodule/xmodule/js/src/capa/edit.coffee
+7
-3
No files found.
cms/static/grammars/main.jspeg
View file @
267963a9
...
...
@@ -22,7 +22,7 @@ KeyValueString
}
KeyValuePair
= key:KeyValueString
_ ':' _
value:KeyValueString
= key:KeyValueString
' '* ':' ' '*
value:KeyValueString
{
return {'key': key, 'value': value};
}
...
...
@@ -70,7 +70,7 @@ ImageTitle
}
Image
= ImageIdentifier title:ImageTitle?
_ '(' _
url:ImageLink ')' ' '* Linebreak
= ImageIdentifier title:ImageTitle?
' '* '(' ' '*
url:ImageLink ')' ' '* Linebreak
{
return {'type': 'image', 'url': url, 'title': title};
}
...
...
@@ -91,14 +91,24 @@ CorrectAnswerIdentifier
/* StringResponse */
QuotedVariableName
= '"' name:VariableName '"' { return name; }
/ '\'' name:VariableName '\'' { return name; }
VariableName
= '{' chars:([a-zA-Z0-9_]+) '}'
{
return '{' + chars.join("") + '}'
}
StringResponse
= CorrectAnswerIdentifier
_ !'(' value:(QuotedString
/ Text) Linebreak
= CorrectAnswerIdentifier
' '* !'(' value:(QuotedString / QuotedVariableName
/ Text) Linebreak
{
return {'type': 'string', 'answer': $.trim(value)};
}
NumericalOrStringResponse
= CorrectAnswerIdentifier
_ value:NumericalValue _ tolerance:NumericalTolerance? _
Linebreak
= CorrectAnswerIdentifier
' '* value:NumericalValue ' '* tolerance:NumericalTolerance? ' '*
Linebreak
{
if (tolerance == "")
tolerance = "5%"
...
...
@@ -117,7 +127,7 @@ ChoiceTextLine
Choice
= correct:ChoiceIdentifier lines:(ChoiceTextLine)+
{
return {'type': 'choice', 'correct' : correct, 'text': lines.join("")};
return {'type': 'choice', 'correct' : correct, 'text': lines.join("")
.replace(/[\n\r]$/,"")
};
}
MultipleChoice
...
...
@@ -156,12 +166,6 @@ Text
return chars.join("");
}
_AndLines
= (' ' / '\n' / '\t')*
_
= (' ' / '\t')*
Linebreak
= ('\n')
...
...
@@ -308,13 +312,13 @@ NumericalToleranceValueType
= decimal / percentage / integer
NumericalTolerance
= '+-'
_ value:NumericalToleranceValueType _
= '+-'
' '* value:NumericalToleranceValueType ' '*
{
return value;
}
NumericalResponse
= CorrectAnswerIdentifier
_ '(' _ value:NumericalValue _ tolerance:NumericalTolerance? ')' _
Linebreak
= CorrectAnswerIdentifier
' '* '(' ' '* value:NumericalValue ' '* tolerance:NumericalTolerance? ')' ' '*
Linebreak
{
if (tolerance == "")
tolerance = "5%"
...
...
@@ -323,6 +327,7 @@ NumericalResponse
NumericalValue
= additive
/ VariableName
/* Mathematical rules */
...
...
common/lib/xmodule/xmodule/js/src/capa/edit.coffee
View file @
267963a9
...
...
@@ -68,6 +68,10 @@ class @CapaDescriptor
el
.
children
().
last
().
remove
()
return
el
variable_name_wrapper
=
(
expression
)
->
match
=
/^\{(.+)\}$/
.
exec
(
expression
)
return
if
match
then
"$"
+
match
[
1
]
else
expression
for
section
in
parsed
if
section
.
type
==
'text'
newel
=
create_text_element
(
section
.
text
)
...
...
@@ -116,7 +120,7 @@ class @CapaDescriptor
else
if
section
.
type
==
'numerical'
newel
=
$
(
doc
.
createElement
(
'numericalresponse'
))
newel
.
attr
'answer'
,
section
.
answer
newel
.
attr
'answer'
,
variable_name_wrapper
(
section
.
answer
)
tolerance
=
$
(
doc
.
createElement
(
'responseparam'
))
tolerance
.
attr
'type'
,
'tolerance'
...
...
@@ -131,7 +135,7 @@ class @CapaDescriptor
else
if
section
.
type
==
'string'
newel
=
$
(
doc
.
createElement
(
'stringresponse'
))
newel
.
attr
'answer'
,
section
.
answer
newel
.
attr
'answer'
,
variable_name_wrapper
(
section
.
answer
)
newel
.
append
doc
.
createElement
(
'textline'
)
problem
.
append
(
newel
)
...
...
@@ -139,7 +143,7 @@ class @CapaDescriptor
else
if
section
.
type
==
'formula'
formularesponse
=
$
(
doc
.
createElement
(
"formularesponse"
))
formularesponse
.
attr
'samples'
,
section
.
samples
formularesponse
.
attr
'answer'
,
section
.
answer
formularesponse
.
attr
'answer'
,
variable_name_wrapper
(
section
.
answer
)
formularesponse
.
attr
'type'
,
'cs'
tolerance
=
$
(
doc
.
createElement
(
'responseparam'
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment