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 and verifyId are replaced by a single uuid, 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,

<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

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,

  //- 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}}-' + + '">';
    rowAdded += '</td>';
  rowAdded += '</tr>';
//- script start
  $(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.