Commit b97a3522 authored by Marco Mancini's avatar Marco Mancini
Browse files

Merge branch 'using_mustache2' into 'master'

Using mustache2

See merge request groupe-calcul/website!21
parents 38c205b3 92e211f2
......@@ -3,8 +3,8 @@
clear: both;
}
.indico_1{margin-left: 0px;}
.indico_2{margin-left: 110px;}
.indico_1{margin-left: 0px; border-top: 1px solid grey;}
.indico_2{margin-left: 90px; border-top: 1px solid grey;}
.indico_date{
width: 100%;
......@@ -15,34 +15,37 @@
}
.indico_header{
width: 100%;
padding-left:10px;
border-top: 1px solid grey;
/* width: 100%; */
/* padding-left:10px; */
/* border-top: 1px solid grey; */
}
.indico_contain{
display: inline-flex;
}
.indico_time{
width: 100px;
display: table;
/* display: inline; */
}
.indico_title{
/* display: inline; */
padding-left: 20px;
font-weight: bold;
}
.indico_desc{
padding-left: 100px;
margin: 0;
padding-left: 20px;
/* margin: 0; */
font-style: italic;
max-width: 800px;
}
.indico_2 .indico_desc{
padding-left: 60px;
}
.indico_conveners, .indico_loc, .indico_doc{
padding-left: 10px;
/* padding-left: 20px; */
margin: 0;
}
......@@ -8,6 +8,27 @@ Script to parse JSON arriving from indico "timetable" and to insert
(function(exports){
function create_authors_str(collab){
let result = collab.name;
if(collab.affiliation !==''){ result += ' ('+collab.affiliation+')';}
return result;
};
function create_time_str(t_start, t_end){
let start = t_start.time.split(':');
start.pop(); start = start.join(':');
let result = start;
if(t_end){
let end = t_end.time.split(':');
end.pop(); end = end.join(':');
result += '-' + end;
}
return result;
}
function serialize_Indico(base, level, obj)
{
// convert object into array
......@@ -17,6 +38,18 @@ Script to parse JSON arriving from indico "timetable" and to insert
if(obj[key].hasOwnProperty('startDate')){
let newkey = base + ':' + obj[key]['startDate']['time'];
obj[key].level = level;
if(obj[key].hasOwnProperty('presenters')){
obj[key].orators_str = obj[key].presenters.map(create_authors_str).join(', ') + '';
}
if(level === 1){
obj[key].times_str = create_time_str(obj[key].startDate,obj[key].endDate);
}
else{
obj[key].times_str = create_time_str(obj[key].startDate);
}
sortable.push([newkey, obj[key]]); // each item is an array in format [key, value]
}
if(obj[key].hasOwnProperty('entries')){
......@@ -29,12 +62,46 @@ Script to parse JSON arriving from indico "timetable" and to insert
y=b[0].toLowerCase();
return x<y ? -1 : x>y ? 1 : 0;
});
return sortable; // array in format [ [ key1, val1 ], [ key2, val2 ], ... ]
return sortable.map(function(d){return d[1];}); // array
}
function MakeUp_Indico(key,data,where){
var element = document.getElementById(where);
var template = ''+
'{{#data}}'+
'<div class="indico_1">' +
' <div class="indico_contain">'+
' <div class="indico_time">{{times_str}}</div>' +
' <div class="indico_header">' +
' <div class="indico_title">{{title}}</div>' +
' <div class="indico_desc">{{description}}</div>' +
' </div>' +
' </div>' +
' {{#entries}}'+
' <div class="indico_2">'+
' <div class="indico_contain">'+
' <div class="indico_time">{{times_str}}</div>'+
' <div class="indico_header">'+
' <div class="indico_title">{{title}}</div>'+
' <div class="indico_desc">{{description}}</div>'+
' </div>'+
' </div>'+
' {{#orators_str}}'+
' <div class="indico_conveners">Contributeurs : {{orators_str}}</div>'+
' {{/orators_str}}'+
' {{#material}}'+
' <div class="indico_doc"> Document : '+
' <a href="{{resources.0.url}}">{{title}}</a>'+
' </div>'+
' {{/material}}'+
' </div>'+
' {{/entries}}'+
' <div class="indico_loc">Lieu : {{room}}</div>' +
'</div>'+
'{{/data}}';
function MakeUp_Indico(key,data){
// day level
moment.locale('fr');
let m = moment(key, ['YYYYMMDD']).format('dddd DD MMMM YYYY');
......@@ -42,7 +109,7 @@ Script to parse JSON arriving from indico "timetable" and to insert
//date
let newele = document.createElement('div');
newele.className = 'indico_event';
element.appendChild(newele);
let date = document.createElement('div');
date.className = 'indico_date';
......@@ -50,152 +117,31 @@ Script to parse JSON arriving from indico "timetable" and to insert
newele.appendChild(date);
for( let hh in data){
let session = data[hh][1];
let sessionDiv = document.createElement('div');
sessionDiv.className = 'indico_1';
newele.appendChild(sessionDiv);
//header
let header = document.createElement('div');
header.className = 'indico_header';
//time
let time = document.createElement('span');
time.className = 'indico_time';
time.innerHTML = (function(d){
let start = d.startDate.time.split(':');
start.pop(); start = start.join(':');
let end = d.endDate.time.split(':');
end.pop(); end = end.join(':');
newele.appendChild(header);
return start + '-' + end;
})(session);
header.appendChild(time);
newele.innerHTML += Mustache.to_html(template,{ data : data});
//title
let title = document.createElement('span');
title.className = 'indico_title';
title.innerHTML = session.title;
header.appendChild(title);
sessionDiv.appendChild(header);
let desc = document.createElement('div');
desc.className = 'indico_desc';
desc.innerHTML = session.description;
//
sessionDiv.appendChild(desc);
if(session.entryType == 'Session'){
if(session.conveners.length >0){
let conv = document.createElement('div');
conv.className = 'indico_conveners';
conv.innerHTML = 'Contributeurs : '+session.conveners.map(
function(a) {return a.name;}).join(', ') + '';
sessionDiv.appendChild(conv);
}
if(Object.keys(session.entries).length >0){
for(let ii in session.entries){
let sub = session.entries[ii][1];
let subDiv = document.createElement('div');
subDiv.className = 'indico_2';
//subelement
let header = document.createElement('div');
header.className = 'indico_header';
//time
let time = document.createElement('span');
time.className = 'indico_time';
time.innerHTML = (function(d){
let start = d.startDate.time.split(':');
start.pop(); start = start.join(':');
return start;
})(sub);
header.appendChild(time);
//title
let title = document.createElement('span');
title.className = 'indico_title';
title.innerHTML = sub.title;
header.appendChild(title);
subDiv.appendChild(header);
let desc = document.createElement('div');
desc.className = 'indico_desc';
desc.innerHTML = sub.description;
//
subDiv.appendChild(desc);
if(sub.presenters.length >0){
let conv = document.createElement('div');
conv.className = 'indico_conveners';
conv.innerHTML = 'Contributeurs : '+sub.presenters.map(
function(a) {return a.name;}).join(', ') + '';
subDiv.appendChild(conv);
}
if(sub.material.length > 0) {
let material = sub.material[0];
let doc = document.createElement('div');
doc.className = 'indico_doc';
doc.innerHTML = 'Document : <a href="' + material.resources[0].pdf +'">'+material.title+'</a>';
subDiv.appendChild(doc);
}
sessionDiv.appendChild(subDiv);
}
}
let loc = document.createElement('div');
loc.className = 'indico_loc';
loc.innerHTML = 'Lieu : ' + session.room;
//
sessionDiv.appendChild(loc);
if(session.material.length > 0) {
let material = session.material[0];
let doc = document.createElement('div');
doc.className = 'indico_doc';
doc.innerHTML = 'Document : <a href="' + material.resources[0].pdf +'">'+material.title+'</a>';
sessionDiv.appendChild(doc);
}
}
}
return newele;
console.log(data);
}
function parse_indico_json(data, nb_event, where){
let event = data.results[nb_event];
let event = data.results[nb_event],
element = document.getElementById(where),
newdiv = document.createElement('div');
// loop on days
for (let key in event){
// any day is serialized
let day_event = serialize_Indico(key, 1, event[key]);
let day_event = serialize_Indico(key,1,event[key]);
// for any day the div is created and appended in where element
MakeUp_Indico(key,day_event,where);
newdiv.appendChild( MakeUp_Indico(key,day_event));
}
element.appendChild(newdiv);
}
/* Exported fuctions */
......
(function defineMustache(global,factory){if(typeof exports==="object"&&exports&&typeof exports.nodeName!=="string"){factory(exports)}else if(typeof define==="function"&&define.amd){define(["exports"],factory)}else{global.Mustache={};factory(global.Mustache)}})(this,function mustacheFactory(mustache){var objectToString=Object.prototype.toString;var isArray=Array.isArray||function isArrayPolyfill(object){return objectToString.call(object)==="[object Array]"};function isFunction(object){return typeof object==="function"}function typeStr(obj){return isArray(obj)?"array":typeof obj}function escapeRegExp(string){return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function hasProperty(obj,propName){return obj!=null&&typeof obj==="object"&&propName in obj}var regExpTest=RegExp.prototype.test;function testRegExp(re,string){return regExpTest.call(re,string)}var nonSpaceRe=/\S/;function isWhitespace(string){return!testRegExp(nonSpaceRe,string)}var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};function escapeHtml(string){return String(string).replace(/[&<>"'`=\/]/g,function fromEntityMap(s){return entityMap[s]})}var whiteRe=/\s*/;var spaceRe=/\s+/;var equalsRe=/\s*=/;var curlyRe=/\s*\}/;var tagRe=/#|\^|\/|>|\{|&|=|!/;function parseTemplate(template,tags){if(!template)return[];var sections=[];var tokens=[];var spaces=[];var hasTag=false;var nonSpace=false;function stripSpace(){if(hasTag&&!nonSpace){while(spaces.length)delete tokens[spaces.pop()]}else{spaces=[]}hasTag=false;nonSpace=false}var openingTagRe,closingTagRe,closingCurlyRe;function compileTags(tagsToCompile){if(typeof tagsToCompile==="string")tagsToCompile=tagsToCompile.split(spaceRe,2);if(!isArray(tagsToCompile)||tagsToCompile.length!==2)throw new Error("Invalid tags: "+tagsToCompile);openingTagRe=new RegExp(escapeRegExp(tagsToCompile[0])+"\\s*");closingTagRe=new RegExp("\\s*"+escapeRegExp(tagsToCompile[1]));closingCurlyRe=new RegExp("\\s*"+escapeRegExp("}"+tagsToCompile[1]))}compileTags(tags||mustache.tags);var scanner=new Scanner(template);var start,type,value,chr,token,openSection;while(!scanner.eos()){start=scanner.pos;value=scanner.scanUntil(openingTagRe);if(value){for(var i=0,valueLength=value.length;i<valueLength;++i){chr=value.charAt(i);if(isWhitespace(chr)){spaces.push(tokens.length)}else{nonSpace=true}tokens.push(["text",chr,start,start+1]);start+=1;if(chr==="\n")stripSpace()}}if(!scanner.scan(openingTagRe))break;hasTag=true;type=scanner.scan(tagRe)||"name";scanner.scan(whiteRe);if(type==="="){value=scanner.scanUntil(equalsRe);scanner.scan(equalsRe);scanner.scanUntil(closingTagRe)}else if(type==="{"){value=scanner.scanUntil(closingCurlyRe);scanner.scan(curlyRe);scanner.scanUntil(closingTagRe);type="&"}else{value=scanner.scanUntil(closingTagRe)}if(!scanner.scan(closingTagRe))throw new Error("Unclosed tag at "+scanner.pos);token=[type,value,start,scanner.pos];tokens.push(token);if(type==="#"||type==="^"){sections.push(token)}else if(type==="/"){openSection=sections.pop();if(!openSection)throw new Error('Unopened section "'+value+'" at '+start);if(openSection[1]!==value)throw new Error('Unclosed section "'+openSection[1]+'" at '+start)}else if(type==="name"||type==="{"||type==="&"){nonSpace=true}else if(type==="="){compileTags(value)}}openSection=sections.pop();if(openSection)throw new Error('Unclosed section "'+openSection[1]+'" at '+scanner.pos);return nestTokens(squashTokens(tokens))}function squashTokens(tokens){var squashedTokens=[];var token,lastToken;for(var i=0,numTokens=tokens.length;i<numTokens;++i){token=tokens[i];if(token){if(token[0]==="text"&&lastToken&&lastToken[0]==="text"){lastToken[1]+=token[1];lastToken[3]=token[3]}else{squashedTokens.push(token);lastToken=token}}}return squashedTokens}function nestTokens(tokens){var nestedTokens=[];var collector=nestedTokens;var sections=[];var token,section;for(var i=0,numTokens=tokens.length;i<numTokens;++i){token=tokens[i];switch(token[0]){case"#":case"^":collector.push(token);sections.push(token);collector=token[4]=[];break;case"/":section=sections.pop();section[5]=token[2];collector=sections.length>0?sections[sections.length-1][4]:nestedTokens;break;default:collector.push(token)}}return nestedTokens}function Scanner(string){this.string=string;this.tail=string;this.pos=0}Scanner.prototype.eos=function eos(){return this.tail===""};Scanner.prototype.scan=function scan(re){var match=this.tail.match(re);if(!match||match.index!==0)return"";var string=match[0];this.tail=this.tail.substring(string.length);this.pos+=string.length;return string};Scanner.prototype.scanUntil=function scanUntil(re){var index=this.tail.search(re),match;switch(index){case-1:match=this.tail;this.tail="";break;case 0:match="";break;default:match=this.tail.substring(0,index);this.tail=this.tail.substring(index)}this.pos+=match.length;return match};function Context(view,parentContext){this.view=view;this.cache={".":this.view};this.parent=parentContext}Context.prototype.push=function push(view){return new Context(view,this)};Context.prototype.lookup=function lookup(name){var cache=this.cache;var value;if(cache.hasOwnProperty(name)){value=cache[name]}else{var context=this,names,index,lookupHit=false;while(context){if(name.indexOf(".")>0){value=context.view;names=name.split(".");index=0;while(value!=null&&index<names.length){if(index===names.length-1)lookupHit=hasProperty(value,names[index]);value=value[names[index++]]}}else{value=context.view[name];lookupHit=hasProperty(context.view,name)}if(lookupHit)break;context=context.parent}cache[name]=value}if(isFunction(value))value=value.call(this.view);return value};function Writer(){this.cache={}}Writer.prototype.clearCache=function clearCache(){this.cache={}};Writer.prototype.parse=function parse(template,tags){var cache=this.cache;var tokens=cache[template];if(tokens==null)tokens=cache[template]=parseTemplate(template,tags);return tokens};Writer.prototype.render=function render(template,view,partials){var tokens=this.parse(template);var context=view instanceof Context?view:new Context(view);return this.renderTokens(tokens,context,partials,template)};Writer.prototype.renderTokens=function renderTokens(tokens,context,partials,originalTemplate){var buffer="";var token,symbol,value;for(var i=0,numTokens=tokens.length;i<numTokens;++i){value=undefined;token=tokens[i];symbol=token[0];if(symbol==="#")value=this.renderSection(token,context,partials,originalTemplate);else if(symbol==="^")value=this.renderInverted(token,context,partials,originalTemplate);else if(symbol===">")value=this.renderPartial(token,context,partials,originalTemplate);else if(symbol==="&")value=this.unescapedValue(token,context);else if(symbol==="name")value=this.escapedValue(token,context);else if(symbol==="text")value=this.rawValue(token);if(value!==undefined)buffer+=value}return buffer};Writer.prototype.renderSection=function renderSection(token,context,partials,originalTemplate){var self=this;var buffer="";var value=context.lookup(token[1]);function subRender(template){return self.render(template,context,partials)}if(!value)return;if(isArray(value)){for(var j=0,valueLength=value.length;j<valueLength;++j){buffer+=this.renderTokens(token[4],context.push(value[j]),partials,originalTemplate)}}else if(typeof value==="object"||typeof value==="string"||typeof value==="number"){buffer+=this.renderTokens(token[4],context.push(value),partials,originalTemplate)}else if(isFunction(value)){if(typeof originalTemplate!=="string")throw new Error("Cannot use higher-order sections without the original template");value=value.call(context.view,originalTemplate.slice(token[3],token[5]),subRender);if(value!=null)buffer+=value}else{buffer+=this.renderTokens(token[4],context,partials,originalTemplate)}return buffer};Writer.prototype.renderInverted=function renderInverted(token,context,partials,originalTemplate){var value=context.lookup(token[1]);if(!value||isArray(value)&&value.length===0)return this.renderTokens(token[4],context,partials,originalTemplate)};Writer.prototype.renderPartial=function renderPartial(token,context,partials){if(!partials)return;var value=isFunction(partials)?partials(token[1]):partials[token[1]];if(value!=null)return this.renderTokens(this.parse(value),context,partials,value)};Writer.prototype.unescapedValue=function unescapedValue(token,context){var value=context.lookup(token[1]);if(value!=null)return value};Writer.prototype.escapedValue=function escapedValue(token,context){var value=context.lookup(token[1]);if(value!=null)return mustache.escape(value)};Writer.prototype.rawValue=function rawValue(token){return token[1]};mustache.name="mustache.js";mustache.version="2.3.0";mustache.tags=["{{","}}"];var defaultWriter=new Writer;mustache.clearCache=function clearCache(){return defaultWriter.clearCache()};mustache.parse=function parse(template,tags){return defaultWriter.parse(template,tags)};mustache.render=function render(template,view,partials){if(typeof template!=="string"){throw new TypeError('Invalid template! Template should be a "string" '+'but "'+typeStr(template)+'" was given as the first '+"argument for mustache#render(template, view, partials)")}return defaultWriter.render(template,view,partials)};mustache.to_html=function to_html(template,view,partials,send){var result=mustache.render(template,view,partials);if(isFunction(send)){send(result)}else{return result}};mustache.escape=escapeHtml;mustache.Scanner=Scanner;mustache.Context=Context;mustache.Writer=Writer;return mustache});
......@@ -261,6 +261,7 @@
{% if article.indico %}
<script src="/js/mustache.min.js"></script>
<script src="/js/indico_planning.js"></script>
<script src="/js/indico.js"></script>
{% endif %}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment