changed underscore templating to be standard syntax thoughout fixing main.tex name inserting bug, added tests to catch it in future

This commit is contained in:
Henry Oswald 2014-03-06 12:28:07 +00:00
parent 92928c35ab
commit 38d3bbb556
4 changed files with 41 additions and 15 deletions

View file

@ -1,6 +1,4 @@
_ = require('underscore') _ = require('underscore')
_.templateSettings =
interpolate: /\{\{(.+?)\}\}/g
PersonalEmailLayout = require("./Layouts/PersonalEmailLayout") PersonalEmailLayout = require("./Layouts/PersonalEmailLayout")
NotificationEmailLayout = require("./Layouts/NotificationEmailLayout") NotificationEmailLayout = require("./Layouts/NotificationEmailLayout")
@ -12,7 +10,7 @@ templates.welcome =
layout: PersonalEmailLayout layout: PersonalEmailLayout
type:"lifecycle" type:"lifecycle"
compiledTemplate: _.template ''' compiledTemplate: _.template '''
Hi {{first_name}}, thanks for signing up to ShareLaTeX. If you ever get lost, you can log in again <a href="https://www.sharelatex.com/login">here</a>. Hi <%= first_name %>, thanks for signing up to ShareLaTeX. If you ever get lost, you can log in again <a href="https://www.sharelatex.com/login">here</a>.
<p> <p>
Im the co-founder of ShareLaTeX and I love talking to our users about our service. Please feel free to get in touch by replying to this email and I will get back to you within a day. Im the co-founder of ShareLaTeX and I love talking to our users about our service. Please feel free to get in touch by replying to this email and I will get back to you within a day.
@ -28,7 +26,7 @@ templates.canceledSubscription =
layout: PersonalEmailLayout layout: PersonalEmailLayout
type:"lifecycle" type:"lifecycle"
compiledTemplate: _.template ''' compiledTemplate: _.template '''
Hi {{first_name}}, Hi <%= first_name %>,
I am sorry to see you cancelled your premium account. I wondered if you would mind giving me some advice on what the site is lacking at the moment? Criticism from our users about what is missing is the best thing for us to help improve the tool. I am sorry to see you cancelled your premium account. I wondered if you would mind giving me some advice on what the site is lacking at the moment? Criticism from our users about what is missing is the best thing for us to help improve the tool.
@ -46,7 +44,7 @@ templates.passwordReset =
compiledTemplate: _.template ''' compiledTemplate: _.template '''
<h1 class="h1">Password Reset</h1> <h1 class="h1">Password Reset</h1>
<p> <p>
Your password has been reset, the new password is <p> {{newPassword}} Your password has been reset, the new password is <p> <%= newPassword %>
<p> <p>
please <a href="https://www.sharelatex.com/login">login here</a> and then change your password <a href=#{Settings.siteUrl}/user/settings> in your user settings</a> please <a href="https://www.sharelatex.com/login">login here</a> and then change your password <a href=#{Settings.siteUrl}/user/settings> in your user settings</a>
@ -56,16 +54,16 @@ please <a href="https://www.sharelatex.com/login">login here</a> and then change
''' '''
templates.projectSharedWithYou = templates.projectSharedWithYou =
subject: _.template "{{owner.email}} wants to share {{project.name}} with you" subject: _.template "<%= owner.email %> wants to share <%= project.name %> with you"
layout: NotificationEmailLayout layout: NotificationEmailLayout
type:"notification" type:"notification"
compiledTemplate: _.template ''' compiledTemplate: _.template '''
<h1 class="h1">{{owner.email}} wants to share <a href="{{project.url}}">'{{project.name}}'</a> with you</h1> <h1 class="h1"><%= owner.email %> wants to share <a href="<%= project.url %>">'<%= project.name %>'</a> with you</h1>
<p>&nbsp;</p> <p>&nbsp;</p>
<center> <center>
<div style="width:200px;background-color:#0069CC;border:1px solid #02A9D6;border-radius:4px;padding:15px; margin:10px 5px"> <div style="width:200px;background-color:#0069CC;border:1px solid #02A9D6;border-radius:4px;padding:15px; margin:10px 5px">
<div style="padding-right:10px;padding-left:10px"> <div style="padding-right:10px;padding-left:10px">
<a href="{{project.url}}" style="text-decoration:none" target="_blank"> <a href="<%= project.url %>" style="text-decoration:none" target="_blank">
<span style= "font-size:16px;font-family:Arial;font-weight:bold;color:#fff;white-space:nowrap;display:block; text-align:center"> <span style= "font-size:16px;font-family:Arial;font-weight:bold;color:#fff;white-space:nowrap;display:block; text-align:center">
View Project View Project
</span> </span>

View file

@ -1,6 +1,4 @@
_ = require("underscore") _ = require("underscore")
_.templateSettings =
interpolate: /\{\{(.+?)\}\}/g
module.exports = _.template ''' module.exports = _.template '''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@ -334,7 +332,7 @@ module.exports = _.template '''
<tr> <tr>
<td valign="top"> <td valign="top">
<div> <div>
{{body}} <%= body %>
</div> </div>
</td> </td>
</tr> </tr>

View file

@ -1,6 +1,5 @@
_ = require("underscore") _ = require("underscore")
_.templateSettings =
interpolate: /\{\{(.+?)\}\}/g
module.exports = _.template ''' module.exports = _.template '''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@ -12,7 +11,7 @@ module.exports = _.template '''
</head> </head>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0"> <body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">
{{body}} <%= body %>
</body> </body>
</html> </html>

View file

@ -6,10 +6,11 @@ modulePath = "../../../../app/js/Features/Project/ProjectCreationHandler.js"
SandboxedModule = require('sandboxed-module') SandboxedModule = require('sandboxed-module')
Settings = require('settings-sharelatex') Settings = require('settings-sharelatex')
Path = require "path" Path = require "path"
_ = require("underscore")
describe 'ProjectCreationHandler', -> describe 'ProjectCreationHandler', ->
ownerId = '4eecb1c1bffa66588e0000a1' ownerId = '4eecb1c1bffa66588e0000a1'
projectName = 'project name' projectName = 'project name goes here'
project_id = "4eecaffcbffa66588e000008" project_id = "4eecaffcbffa66588e000008"
docId = '4eecb17ebffa66588e00003f' docId = '4eecb17ebffa66588e00003f'
rootFolderId = "234adfa3r2afe" rootFolderId = "234adfa3r2afe"
@ -166,3 +167,33 @@ describe 'ProjectCreationHandler', ->
@handler._buildTemplate @handler._buildTemplate
.calledWith("references.bib", ownerId, projectName) .calledWith("references.bib", ownerId, projectName)
.should.equal true .should.equal true
describe "_buildTemplate", ->
beforeEach (done)->
@handler._buildTemplate "main.tex", @user_id, projectName, (err, templateLines)=>
@template = templateLines.reduce (singleLine, line)-> "#{singleLine}\n#{line}"
done()
it "should insert the project name into the template", (done)->
@template.indexOf(projectName).should.not.equal -1
done()
it "should insert the users name into the template", (done)->
@template.indexOf(@user.first_name).should.not.equal -1
@template.indexOf(@user.last_name).should.not.equal -1
done()
it "should not have undefined in the template", (done)->
@template.indexOf("undefined").should.equal -1
done()
it "should not have any underscore brackets in the output", (done)->
@template.indexOf("{{").should.equal -1
@template.indexOf("<%=").should.equal -1
done()
it "should put the year in", (done)->
@template.indexOf(new Date().getUTCFullYear()).should.not.equal -1
done()