Skip to content

Commit

Permalink
Restructure certain locals when passed to settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmerfield committed Nov 16, 2018
1 parent 7b77964 commit b890bd7
Showing 1 changed file with 75 additions and 20 deletions.
95 changes: 75 additions & 20 deletions app/dashboard/routes/editor/loadTemplate.js
Original file line number Original file line Diff line number Diff line change
@@ -1,10 +1,9 @@
var Template = require("template"); var Template = require("template");
var config = require('config'); var config = require("config");
var helper = require('helper'); var helper = require("helper");
var arrayify = helper.arrayify; var arrayify = helper.arrayify;


module.exports = function (req, res, next) { module.exports = function(req, res, next) {

var blogID = req.blog.id; var blogID = req.blog.id;


// makeSlug is called twice (stupidly, accidentally) // makeSlug is called twice (stupidly, accidentally)
Expand All @@ -15,36 +14,92 @@ module.exports = function (req, res, next) {
// to call it once ourselves. // to call it once ourselves.
var name = helper.makeSlug(req.params.template); var name = helper.makeSlug(req.params.template);


if (!name) return res.redirect('/settings/design'); if (!name) return res.redirect("/settings/design");


var templateID = Template.makeID(blogID, name); var templateID = Template.makeID(blogID, name);


// This should probably be Template.owns(blogID, templateid) // This should probably be Template.owns(blogID, templateid)
Template.isOwner(blogID, templateID, function(err, isOwner){ Template.isOwner(blogID, templateID, function(err, isOwner) {

// Check the blog owns the template // Check the blog owns the template
if (err || !isOwner) return res.redirect('/settings/design'); if (err || !isOwner) return res.redirect("/settings/design");

Template.getMetadata(templateID, function(err, template){


if (template.localEditing && req.path !== '/template/' + req.params.template + '/local-editing') { Template.getMetadata(templateID, function(err, template) {
return res.redirect('/template/' + req.params.template +'/local-editing'); if (
template.localEditing &&
req.path !== "/template/" + req.params.template + "/local-editing"
) {
return res.redirect(
"/template/" + req.params.template + "/local-editing"
);
} }


template.locals = arrayify(template.locals); // Determine which HTML input we should show for each local
// on the settings page.
template.locals = arrayify(template.locals).map(function(local) {
if (local.name.indexOf("size") > -1 || local.name.indexOf("height") > -1) {
// show the number picker component for this local
local.label = local.name.split('_').join(' ');
local.label = local.label[0].toUpperCase() + local.label.slice(1);

if (local.label === 'Page size') local.label = 'Number of posts per page';

local.range = true;
} else if (local.name.indexOf("color") > -1) {
local.label = local.name.split('_').join(' ');
local.label = local.label[0].toUpperCase() + local.label.slice(1);
// show the color picker component for this local
local.color = true;
} else if (local.name.indexOf("font") > -1) {
// show the font picker component for this local
local.font = true;
local.label = local.name.split('_').join(' ');
local.label = local.label[0].toUpperCase() + local.label.slice(1);
local.fonts = [
{
label: "Charter",
value: "charter",
selected: local.content === "charter" ? "selected" : ""
},
{
label: "Helvetica",
value: "Helvetica",
selected: local.content === "Helvetica" ? "selected" : ""
},
{
label: "Times New Roman",
value: "times",
selected: local.content === "times" ? "selected" : ""
}
];
} else {
// use default template
local.default = true;
}

return local;
});


req.template = template; req.template = template;


template.baseUrl = "/template/" + encodeURIComponent(template.slug); template.baseUrl = "/template/" + encodeURIComponent(template.slug);
template.preview = ['http://preview.my', template.slug, req.blog.handle, config.host].join('.'); template.preview = [
"http://preview.my",
template.slug,
req.blog.handle,
config.host
].join(".");


res.locals.template = template; res.locals.template = template;
res.locals.partials.head = 'partials/head'; res.locals.partials.head = "partials/head";
res.locals.partials.footer = 'partials/footer'; res.locals.partials.footer = "partials/footer";
res.locals.partials.local = 'template/_local'; res.locals.partials.locals = "template/_locals";
res.locals.partials.locals = 'template/_locals'; res.locals.partials.partial = "template/_partial";
res.locals.partials.partial = 'template/_partial'; res.locals.partials.partials = "template/_partials";
res.locals.partials.partials = 'template/_partials';
res.locals.partials.default = "template/_local-default";
res.locals.partials.color = "template/_local-color";
res.locals.partials.font = "template/_local-font";
res.locals.partials.range = "template/_local-range";


return next(); return next();
}); });
Expand Down

0 comments on commit b890bd7

Please sign in to comment.