GSoC 2015 Week9
The restructuring work continues, this weeks I’ve mainly done some ending works of this, including:
Refactoring modules related with
email-verification
. Email templates now share a common layout,actionId
andverifyId
are replaced by a singleuuid
, few variable names are updated and some packages as well.Reorganizing admin page related things, rearrage the middlewares so other user-modules won’t bother privilege problems which makes things neat.
- Updated modules to coform to new Dashboard.
- More…
While I was doing the EJS 2 JADE works, I once again encountered a problem. Elliott had written this code below,
1
<script type="text/javascript">
$(function() {
var paramRow = function(){
return '<tr><% for (var j = 0; j < columns.length; j++) { %><td>'
+'<input type="text" class="<%=columns[j].type%>" placeholder="<%=columns[j].value%>" name="'+($('#params tbody tr').length-1)+'-<%=columns[j].name%>"></td><% } %></tr>';
};
/// more
};
</script>
Basically it utilizes some code to generate the Javascript code that will be used in our pages, this section of Javascript would be a plain text block in JADE syntax. However, I can’t figure out how to iterate within a plain text block, which seems not to be a good idea.
Having tried lots of ways and considered the concept of static compiling, my solution are,
1
-
//- if only I could use jade.render in templates
var rowAdded = '<tr>';
for (var j = 0; j < settings.columns.length; ++j) {
var col = settings.columns[j];
rowAdded += '<td>';
rowAdded += '<input type="text" class="'+ col.type + '" ' +
'placeholder="' + col.value + '" ' +
'name="{{index}}-' + col.name + '">';
rowAdded += '</td>';
}
rowAdded += '</tr>';
//- script start
script(type='text/javascript').
$(function() {
var paramRow = function(){
var index = $('#params tr').length-1;
//- unescaped
return '!{rowAdded}'.replace(/{{index}}/g, index);
};
};
/// more
This is quiet ugly… but it’s the best solution I could get.