@@ -10,28 +10,35 @@ function trimCommandValue(text) {
1010 return command . action + '(\'' + command . value + '\')' ;
1111}
1212exports . trimCommandValue = trimCommandValue ;
13+ function doAction ( type , isArray , actionValue , result , line , index ) {
14+ if ( result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] [ type ] === undefined ) {
15+ result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] [ type ] = [ ] ;
16+ }
17+ if ( ! ! isArray ) {
18+ var valueList = actionValue . slice ( 1 , - 1 ) . split ( ',' ) ;
19+ valueList . forEach ( function ( value ) {
20+ var value = cleanup_1 . trimQuotes ( value . trim ( ) ) ;
21+ result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] [ type ] . push ( value ) ;
22+ } ) ;
23+ }
24+ else {
25+ result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] [ type ] . push ( actionValue ) ;
26+ }
27+ return result ;
28+ }
1329function addToTasks ( result , line , index ) {
1430 var match = Match . isAction ( line ) ;
1531 var action = match . action ;
1632 var task = result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] ;
17- var trimmedAction = line . slice ( action . length + 2 , line . length - 1 ) ;
18- var actionValue = cleanup_1 . trimQuotes ( trimmedAction ) ;
33+ var trimmedContent = line . slice ( action . length + 2 , line . length - 1 ) ;
34+ var actionValue = cleanup_1 . trimQuotes ( trimmedContent ) ;
1935 var isActionArray = Match . isArray ( cleanup_1 . trimQuotes ( actionValue ) ) ;
2036 switch ( action ) {
2137 case 'test' :
22- if ( result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] . tests === undefined ) {
23- result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] . tests = [ ] ;
24- }
25- if ( ! ! isActionArray ) {
26- var valueList = actionValue . slice ( 1 , - 1 ) . split ( ',' ) ;
27- valueList . forEach ( function ( value ) {
28- var value = cleanup_1 . trimQuotes ( value . trim ( ) ) ;
29- result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] . tests . push ( value ) ;
30- } ) ;
31- }
32- else {
33- result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] . tests . push ( actionValue ) ;
34- }
38+ result = doAction ( 'tests' , isActionArray , actionValue , result , line , index ) ;
39+ break ;
40+ case 'hint' :
41+ result = doAction ( 'hints' , isActionArray , actionValue , result , line , index ) ;
3542 break ;
3643 case 'action' :
3744 if ( task . actions === undefined ) {
@@ -50,21 +57,6 @@ function addToTasks(result, line, index) {
5057 }
5158 return result ;
5259 break ;
53- case 'hint' :
54- if ( task . hints === undefined ) {
55- result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] . hints = [ ] ;
56- }
57- if ( ! ! isActionArray ) {
58- var valueList = actionValue . slice ( 1 , - 1 ) . split ( ',' ) ;
59- valueList . forEach ( function ( value ) {
60- var value = cleanup_1 . trimQuotes ( value . trim ( ) ) ;
61- result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] . hints . push ( value ) ;
62- } ) ;
63- }
64- else {
65- result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] . hints . push ( actionValue ) ;
66- }
67- break ;
6860 default :
6961 console . log ( 'Invalid task action' ) ;
7062 }
0 commit comments