Skip to content

Commit

Permalink
using throw new Error(string) instead of throw string
Browse files Browse the repository at this point in the history
  • Loading branch information
edi9999 committed May 27, 2014
1 parent 8c65033 commit b8110b0
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 51 deletions.
8 changes: 4 additions & 4 deletions coffee/docUtils.coffee
Expand Up @@ -39,7 +39,7 @@ DocUtils.loadDoc= (path,options={}) ->
intelligentTagging=if options.intelligentTagging? then options.intelligentTagging else false
callback=if options.callback? then options.callback else null
basePath=""
throw 'path not defined' unless path?
if !path? then throw new Error('path not defined')
if path.indexOf('/')!=-1
totalPath= path
fileName= totalPath
Expand Down Expand Up @@ -86,7 +86,7 @@ DocUtils.loadDoc= (path,options={}) ->
rejectUnauthorized:false

errorCallback= (e) ->
throw "Error on HTTPS Call"
throw new Error("Error on HTTPS Call")

reqCallback= (res)->
res.setEncoding('binary')
Expand Down Expand Up @@ -144,7 +144,7 @@ DocUtils.clone = (obj) ->

DocUtils.xml2Str = (xmlNode) ->
if xmlNode==undefined
throw "xmlNode undefined!"
throw new Error("xmlNode undefined!")
try
if global?
a= new XMLSerializer()
Expand Down Expand Up @@ -183,7 +183,7 @@ DocUtils.decode_utf8= (s) ->
console.log s
console.log 'could not decode'
debugger
throw 'end'
throw new Error('end')

DocUtils.base64encode= (b) ->
btoa(unescape(encodeURIComponent(b)))
Expand Down
2 changes: 1 addition & 1 deletion coffee/docxQrCode.coffee
Expand Up @@ -4,7 +4,7 @@ env= if global? then 'node' else 'browser'
DocxQrCode = class DocxQrCode
constructor:(imageData, @xmlTemplater,@imgName="",@num,@callback)->
@data=imageData
if @data==undefined then throw "data of qrcode can't be undefined"
if @data==undefined then throw new Error("data of qrcode can't be undefined")
if env=='browser'
@base64Data=JSZip.base64.encode(@data)
@ready=false
Expand Down
2 changes: 1 addition & 1 deletion coffee/docxTemplater.coffee
Expand Up @@ -7,7 +7,7 @@ root.DocXTemplater = class DocXTemplater extends XmlTemplater
super("",options)
@currentClass=root.DocXTemplater
@tagXml='w:t'
if typeof content=="string" then @load content else throw "content must be string!"
if typeof content=="string" then @load content else throw new Error("content must be string!")
calcIntellegentlyDashElement:()->
{content,start,end}= @templaterState.findOuterTagsContent(@content)
scopeContent= xmlUtil.getListXmlElements @content, start,end-start
Expand Down
2 changes: 1 addition & 1 deletion coffee/imgManager.coffee
Expand Up @@ -45,7 +45,7 @@ ImgManager = class ImgManager
@setImage "[Content_Types].xml",DocUtils.encode_utf8 DocUtils.xml2Str xmlDoc
addImageRels: (imageName,imageData) -> #Adding an image and returns it's Rid
if @zip.files["word/media/#{imageName}"]?
throw 'file already exists'
throw new Error('file already exists')
return false
@maxRid++
file=
Expand Down
8 changes: 4 additions & 4 deletions coffee/imgReplacer.coffee
Expand Up @@ -24,13 +24,13 @@ ImgReplacer = class ImgReplacer
xmlImg= DocUtils.Str2xml '<?xml version="1.0" ?><w:document mc:Ignorable="w14 wp14" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">'+match[0]+'</w:document>'
if env=='browser' then tagrId= xmlImg.getElementsByTagNameNS('*','blip')[0]
if env=='node' then tagrId= xmlImg.getElementsByTagName("a:blip")[0]
if tagrId==undefined then throw 'tagRiD undefined !'
if tagrId==undefined then throw new Error('tagRiD undefined !')
rId = tagrId.getAttribute('r:embed')
oldFile= @xmlTemplater.DocxGen.imgManager.getImageByRid(rId)
if oldFile==null then throw 'oldFile undefined'
if oldFile==null then throw new Error('oldFile undefined')
if env=='browser' then tag= xmlImg.getElementsByTagNameNS('*','docPr')[0]
if env=='node' then tag= xmlImg.getElementsByTagName("wp:docPr")[0]
if tag==undefined then throw 'tag undefined'
if tag==undefined then throw new Error('tag undefined')
if tag.getAttribute("name").substr(0,6)=="Copie_" then return #if image is already a replacement then do nothing
imgName= ("Copie_"+@xmlTemplater.imageId+".png").replace(/\x20/,"")
@xmlTemplater.DocxGen.qrCodeNumCallBack++
Expand All @@ -42,7 +42,7 @@ ImgReplacer = class ImgReplacer
tagrId.setAttribute('r:embed',"rId#{newId}")
if env=='browser' then imageTag= xmlImg.getElementsByTagNameNS('*','drawing')[0]
if env=='node' then imageTag=xmlImg.getElementsByTagName('w:drawing')[0]
if imageTag==undefined then throw 'imageTag undefined'
if imageTag==undefined then throw new Error('imageTag undefined')
replacement= DocUtils.xml2Str imageTag
@xmlTemplater.content= @xmlTemplater.content.replace(match[0], replacement)
@xmlTemplater.numQrCode++
Expand Down
2 changes: 1 addition & 1 deletion coffee/scopeManager.coffee
Expand Up @@ -24,7 +24,7 @@ root.ScopeManager = class ScopeManager
@useTag(tag)
value= result
if value.indexOf('{')!=-1 or value.indexOf('}')!=-1
throw "You can't enter { or } inside the content of a variable"
throw new Error("You can't enter { or } inside the content of a variable")
else if typeof result=="number"
value=String(result)
else value= result
Expand Down
4 changes: 2 additions & 2 deletions coffee/subContent.coffee
Expand Up @@ -17,10 +17,10 @@ root.SubContent = class SubContent
this
getOuterXml:(xmlTag)->
@end= @fullText.indexOf('</'+xmlTag+'>',@end)
if @end==-1 then throw "can't find endTag #{@end}"
if @end==-1 then throw new Error("can't find endTag #{@end}")
@end+=('</'+xmlTag+'>').length
@start = Math.max @fullText.lastIndexOf('<'+xmlTag+'>',@start), @fullText.lastIndexOf('<'+xmlTag+' ',@start)
if @start==-1 then throw "can't find startTag"
if @start==-1 then throw new Error("can't find startTag")
@refreshText()
replace:(newText)->
@fullText=@fullText.substr(0,@start)+newText+@fullText.substr(@end)
Expand Down
4 changes: 2 additions & 2 deletions coffee/templaterState.coffee
Expand Up @@ -30,7 +30,7 @@ root.TemplaterState= class TemplaterState
@rawXmlTag=false
@textInsideTag= ""
startTag:(char)->
if @inTag is true then throw "Tag already open with text: #{@textInsideTag}"
if @inTag is true then throw new Error("Tag already open with text: #{@textInsideTag}")
@inTag= true
@rawXmlTag=false
@textInsideTag= ""
Expand All @@ -43,7 +43,7 @@ root.TemplaterState= class TemplaterState
isLoopClosingTag:()->
@textInsideTag[0]=='/' and ('/'+@loopOpen.tag == @textInsideTag)
endTag:()->
if @inTag is false then throw "Tag already closed"
if @inTag is false then throw new Error("Tag already closed")
@inTag= false
@tagEnd=@currentStep
if @textInsideTag[0]=='@' and @loopType()=='simple'
Expand Down
10 changes: 5 additions & 5 deletions coffee/xmlTemplater.coffee
Expand Up @@ -110,13 +110,13 @@ root.XmlTemplater = class XmlTemplater #abstract class !!
startTag= @templaterState.calcXmlTagPosition(xmlTagNumber)#where the open tag starts: <w:t>
#calculate the replacer according to the params
@templaterState.moveCharacters(xmlTagNumber+1,replacer,@templaterState.matches[xmlTagNumber][0])
if content.indexOf(@templaterState.matches[xmlTagNumber][0])==-1 then throw "content #{@templaterState.matches[xmlTagNumber][0]} not found in content"
if content.indexOf(@templaterState.matches[xmlTagNumber][0])==-1 then throw new Error("content #{@templaterState.matches[xmlTagNumber][0]} not found in content")
content = DocUtils.replaceFirstFrom content,@templaterState.matches[xmlTagNumber][0], replacer, startTag
@templaterState.matches[xmlTagNumber][0]=replacer
content
replaceTagByValue: (newValue,content=@content) ->
if (@templaterState.matches[@templaterState.tagEnd.numXmlTag][2].indexOf ('}'))==-1 then throw "no closing tag at @templaterState.tagEnd.numXmlTag #{@templaterState.matches[@templaterState.tagEnd.numXmlTag][2]}"
if (@templaterState.matches[@templaterState.tagStart.numXmlTag][2].indexOf ('{'))==-1 then throw "no opening tag at @templaterState.tagStart.numXmlTag #{@templaterState.matches[@templaterState.tagStart.numXmlTag][2]}"
if (@templaterState.matches[@templaterState.tagEnd.numXmlTag][2].indexOf ('}'))==-1 then throw new Error("no closing tag at @templaterState.tagEnd.numXmlTag #{@templaterState.matches[@templaterState.tagEnd.numXmlTag][2]}")
if (@templaterState.matches[@templaterState.tagStart.numXmlTag][2].indexOf ('{'))==-1 then throw new Error("no opening tag at @templaterState.tagStart.numXmlTag #{@templaterState.matches[@templaterState.tagStart.numXmlTag][2]}")

if @templaterState.tagEnd.numXmlTag==@templaterState.tagStart.numXmlTag #<w>{aaaaa}</w>

Expand Down Expand Up @@ -181,10 +181,10 @@ root.XmlTemplater = class XmlTemplater #abstract class !!
subsubfile
getOuterXml: (text,start,end,xmlTag) -> #tag: w:t
endTag= text.indexOf('</'+xmlTag+'>',end)
if endTag==-1 then throw "can't find endTag #{endTag}"
if endTag==-1 then throw new Error("can't find endTag #{endTag}")
endTag+=('</'+xmlTag+'>').length
startTag = Math.max text.lastIndexOf('<'+xmlTag+'>',start), text.lastIndexOf('<'+xmlTag+' ',start)
if startTag==-1 then throw "can't find startTag"
if startTag==-1 then throw new Error("can't find startTag")
{"text":text.substr(startTag,endTag-startTag),startTag,endTag}
forLoop: (innerTagsContent=@templaterState.findInnerTagsContent(@content).content,outerTagsContent=@templaterState.findOuterTagsContent(@content).content)->
###
Expand Down
42 changes: 21 additions & 21 deletions js/docxgen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b8110b0

Please sign in to comment.