Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
keeleliin
keeleliin-wrapper
Commits
7e4228a1
Commit
7e4228a1
authored
Aug 12, 2015
by
priit
Browse files
Mitme faili haldamise toetus
parent
87a2dc1a
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/mapper/commandModel.js
View file @
7e4228a1
var
logger
=
require
(
'
log4js
'
).
getLogger
(
'
command_model
'
);
var
sessionService
=
require
(
'
../service/sessionService
'
);
var
async
=
require
(
'
async
'
);
function
CommandModel
(){
...
...
@@ -21,7 +22,7 @@ function CommandModel(){
this
.
stdOutExtension
=
stdOutExtension
;
};
this
.
set
Text
Value
=
function
(
key
,
value
)
{
this
.
set
Key
Value
=
function
(
key
,
value
)
{
self
.
keyValues
[
key
]
=
value
;
};
...
...
@@ -42,33 +43,26 @@ function CommandModel(){
logger
.
debug
(
'
Output path added:
'
+
key
+
'
'
+
self
.
outputPaths
[
key
]
);
};
this
.
render
=
function
(
callback
)
{
this
.
render
=
function
(
cb
)
{
for
(
i
in
self
.
outputPaths
){
self
.
keyValues
[
i
]
=
self
.
outputPaths
[
i
];
}
//store file values
if
(
fileValues
.
length
>
0
){
self
.
_storeToFile
(
0
,
callback
);
}
else
{
callback
();
}
};
this
.
_storeToFile
=
function
(
index
,
callback
)
{
var
fileValue
=
fileValues
[
index
];
sessionService
.
storeToFile
(
self
.
session
.
id
,
fileValue
[
'
value
'
],{},
function
(
err
,
path
)
{
if
(
err
)
return
callback
(
err
);
self
.
keyValues
[
fileValue
[
'
key
'
]]
=
path
;
index
=
index
+
1
;
if
(
fileValues
.
length
<
index
){
self
.
_storeToFile
(
index
,
callback
);
}
else
{
callback
();
async
.
each
(
fileValues
,
function
(
fileValue
,
callback
)
{
sessionService
.
storeToFile
(
self
.
session
.
id
,
fileValue
[
'
value
'
],{},
function
(
err
,
path
)
{
if
(
err
)
return
callback
(
err
);
self
.
keyValues
[
fileValue
[
'
key
'
]]
=
path
;
callback
();
});
},
function
(
err
)
{
cb
(
err
);
}
}
);
}
);
}
;
}
module
.
exports
=
CommandModel
;
src/mapper/localCommand.js
View file @
7e4228a1
...
...
@@ -5,12 +5,9 @@ function LocalCommand( commandModel ) {
var
self
=
this
;
var
keyValues
=
commandModel
.
keyValues
;
logger
.
debug
(
keyValues
);
var
commandTemplate
=
commandModel
.
serviceProperties
.
commandTemplate
;
this
.
templateParams
=
commandTemplate
.
match
(
/
\[(
.*
?)
]/g
);
var
templateParams
=
commandTemplate
.
match
(
/
\[(
.*
?)
]/g
);
var
commandParts
=
commandTemplate
.
split
(
'
'
);
this
.
command
=
""
;
...
...
@@ -26,26 +23,39 @@ function LocalCommand( commandModel ) {
this
.
_parseParams
=
function
()
{
for
(
index
in
this
.
templateParams
){
for
(
index
in
templateParams
){
var
property
Item
=
this
.
templateParams
[
index
];
var
propertyKey
=
property
Item
.
substr
(
1
,
(
property
Item
.
length
-
2
));
var
property
=
templateParams
[
index
];
var
propertyKey
=
property
.
substr
(
1
,
(
property
.
length
-
2
));
var
value
=
keyValues
[
propertyKey
];
if
(
!
value
){
throw
new
Error
(
'
Value not detected for property
'
+
propertyKey
);
}
self
.
_
replace
PropertyValue
(
property
Item
,
value
);
self
.
_
setCommand
PropertyValue
(
property
,
value
);
}
};
this
.
_replacePropertyValue
=
function
(
propertyItem
,
value
)
{
this
.
_setCommandPropertyValue
=
function
(
propertyItem
,
value
)
{
var
newCommandParts
=
[];
for
(
i
in
commandParts
)
{
var
part
=
commandParts
[
i
];
commandParts
[
i
]
=
part
.
replace
(
propertyItem
,
value
);
if
(
commandParts
[
i
]
==
propertyItem
){
if
(
Array
.
isArray
(
value
)){
for
(
j
in
value
){
newCommandParts
.
push
(
value
[
j
]);
}
}
else
{
newCommandParts
.
push
(
value
);
}
}
else
{
newCommandParts
.
push
(
commandParts
[
i
]);
}
}
commandParts
=
newCommandParts
;
};
}
...
...
wrapper/simpleLocalCommand.js
View file @
7e4228a1
...
...
@@ -47,8 +47,7 @@ function SimpleLocalCommand(){
var
model
=
new
CommandModel
();
model
.
serviceProperties
.
commandTemplate
=
config
.
wrapper
.
command
.
commandTemplate
;
model
.
init
(
session
);
model
.
setTextValue
(
'
data
'
,
session
.
getFiles
(
'
content
'
).
join
(
'
'
));
//model.setTextValue('data', session.getFile('content'));
model
.
setKeyValue
(
'
data
'
,
session
.
getFiles
(
'
content
'
));
model
.
render
(
function
(
err
)
{
logger
.
debug
(
'
Render callback
'
);
callback
(
err
,
model
);
...
...
wrapper/tokenizer.js
View file @
7e4228a1
...
...
@@ -97,12 +97,9 @@ function Tokenizer(){
this
.
getCommandModel
=
function
(
session
,
callback
)
{
var
model
=
new
CommandModel
();
logger
.
error
(
'
commandTemplate
'
);
logger
.
error
(
config
.
wrapper
);
model
.
serviceProperties
.
commandTemplate
=
config
.
wrapper
.
command
.
commandTemplate
;
model
.
init
(
session
);
model
.
set
Text
Value
(
'
data
'
,
session
.
reques
tFile
s
.
content
);
model
.
set
Key
Value
(
'
data
'
,
session
.
ge
tFile
(
'
content
'
)
);
model
.
addOutputPath
(
'
outputPath1
'
,
{
extension
:
'
txt
'
});
model
.
render
(
function
(
err
)
{
logger
.
debug
(
'
Render callback
'
);
...
...
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