Skip to content

Commit

Permalink
Compile filesummary handlebars
Browse files Browse the repository at this point in the history
Fixes #11030
For https://github.com/orgs/nextcloud/projects/18

This template is now compiled so this no longer has to happen in the
browser. Another step towards a stricter CSP.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed Sep 27, 2018
1 parent d984231 commit ae1250f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
7 changes: 7 additions & 0 deletions apps/files/js/filesummary.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<span class="info">
<span class="dirinfo"></span>
<span class="connector">{{connectorLabel}}</span>
<span class="fileinfo"></span>
<span class="hiddeninfo"></span>
<span class="filter"></span>
</span>
19 changes: 6 additions & 13 deletions apps/files/js/filesummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
*/

(function() {
var INFO_TEMPLATE =
'<span class="info">' +
'<span class="dirinfo"></span>' +
'<span class="connector">{{connectorLabel}}</span>' +
'<span class="fileinfo"></span>' +
'<span class="hiddeninfo"></span>' +
'<span class="filter"></span>' +
'</span>';

/**
* The FileSummary class encapsulates the file summary values and
* the logic to render it in the given container
Expand Down Expand Up @@ -200,10 +191,12 @@
},

_infoTemplate: function(data) {
if (!this._infoTemplateCompiled) {
this._infoTemplateCompiled = Handlebars.compile(INFO_TEMPLATE);
}
return this._infoTemplateCompiled(_.extend({
/* NOTE: To update the template make changes in filesummary.handlebars
* and run:
*
* handlebars -n OCA.Files.FileSummary.Templates filesummary.handlebars -f filesummary_template.js
*/
return OCA.Files.FileSummary.Templates['filesummary'](_.extend({
connectorLabel: t('files', '{dirs} and {files}', {dirs: '', files: ''})
}, data));
},
Expand Down
10 changes: 10 additions & 0 deletions apps/files/js/filesummary_template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(function() {
var template = Handlebars.template, templates = OCA.Files.FileSummary.Templates = OCA.Files.FileSummary.Templates || {};
templates['filesummary'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var helper;

return "<span class=\"info\">\n <span class=\"dirinfo\"></span>\n <span class=\"connector\">"
+ container.escapeExpression(((helper = (helper = helpers.connectorLabel || (depth0 != null ? depth0.connectorLabel : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0,{"name":"connectorLabel","hash":{},"data":data}) : helper)))
+ "</span>\n <span class=\"fileinfo\"></span>\n <span class=\"hiddeninfo\"></span>\n <span class=\"filter\"></span>\n</span>\n";
},"useData":true});
})();
1 change: 1 addition & 0 deletions apps/files/js/merged-index.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"jquery-visibility.js",
"fileinfomodel.js",
"filesummary.js",
"filesummary_template.js",
"filemultiselectmenu.js",
"breadcrumb.js",
"filelist.js",
Expand Down
2 changes: 2 additions & 0 deletions apps/files_sharing/lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\IRootFolder;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Util;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use OCP\Share\IManager as ShareManager;
Expand Down Expand Up @@ -396,6 +397,7 @@ public function showShare($path = ''): TemplateResponse {
// JS required for folders
\OCP\Util::addStyle('files', 'merged');
\OCP\Util::addScript('files', 'filesummary');
\OCP\Util::addScript('files', 'filesummary_template');
\OCP\Util::addScript('files', 'breadcrumb');
\OCP\Util::addScript('files', 'fileinfomodel');
\OCP\Util::addScript('files', 'newfilemenu');
Expand Down

0 comments on commit ae1250f

Please sign in to comment.