move HTML escape to global as E

This commit is contained in:
ccd0 2014-06-28 21:58:14 -07:00
parent 79ef398b32
commit b6739cc45d
4 changed files with 15 additions and 16 deletions

View File

@ -1,9 +1,6 @@
Build = Build =
initPixelRatio: window.devicePixelRatio initPixelRatio: window.devicePixelRatio
spoilerRange: {} spoilerRange: {}
h_escape: (text) ->
(text+'').replace /[&"'<>]/g, (c) ->
{'&': '&amp;', "'": '&#039;', '"': '&quot;', '<': '&lt;', '>': '&gt;'}[c]
unescape: (text) -> unescape: (text) ->
return text unless text? return text unless text?
text.replace /&(amp|#039|quot|lt|gt);/g, (c) -> text.replace /&(amp|#039|quot|lt|gt);/g, (c) ->
@ -74,7 +71,6 @@ Build =
This function contains code from 4chan-JS (https://github.com/4chan/4chan-JS). This function contains code from 4chan-JS (https://github.com/4chan/4chan-JS).
@license: https://github.com/4chan/4chan-JS/blob/master/LICENSE @license: https://github.com/4chan/4chan-JS/blob/master/LICENSE
### ###
E = Build.h_escape
{ {
postID, threadID, boardID postID, threadID, boardID
name, capcode, tripcode, uniqueID, email, subject, flagCode, flagName, date, dateUTC name, capcode, tripcode, uniqueID, email, subject, flagCode, flagName, date, dateUTC

View File

@ -160,7 +160,7 @@ Get =
return return
# convert comment to html # convert comment to html
h_comment = Build.h_escape (data.comment or '') h_comment = E (data.comment or '')
# https://github.com/eksopl/fuuka/blob/master/Board/Yotsuba.pm#L413-452 # https://github.com/eksopl/fuuka/blob/master/Board/Yotsuba.pm#L413-452
# https://github.com/eksopl/asagi/blob/master/src/main/java/net/easymodo/asagi/Yotsuba.java#L109-138 # https://github.com/eksopl/asagi/blob/master/src/main/java/net/easymodo/asagi/Yotsuba.java#L109-138
h_comment = h_comment.replace /// h_comment = h_comment.replace ///

View File

@ -6,3 +6,6 @@ g =
VERSION: '<%= version %>' VERSION: '<%= version %>'
NAMESPACE: '<%= meta.name %>.' NAMESPACE: '<%= meta.name %>.'
boards: {} boards: {}
E = (text) ->
(text+'').replace /[&"'<>]/g, (x) ->
{'&': '&amp;', "'": '&#039;', '"': '&quot;', '<': '&lt;', '>': '&gt;'}[x]

View File

@ -13,23 +13,23 @@ FileInfo =
if c of FileInfo.h_formatters if c of FileInfo.h_formatters
FileInfo.h_formatters[c].call(post) FileInfo.h_formatters[c].call(post)
else else
Build.h_escape s E s
h_formatters: h_formatters:
t: -> Build.h_escape @file.URL.match(/\d+\..+$/)[0] t: -> E @file.URL.match(/\d+\..+$/)[0]
T: -> "<a href='#{Build.h_escape @file.URL}' target='_blank'>#{FileInfo.h_formatters.t.call @}</a>" T: -> "<a href='#{E @file.URL}' target='_blank'>#{FileInfo.h_formatters.t.call @}</a>"
l: -> "<a href='#{Build.h_escape @file.URL}' target='_blank'>#{FileInfo.h_formatters.n.call @}</a>" l: -> "<a href='#{E @file.URL}' target='_blank'>#{FileInfo.h_formatters.n.call @}</a>"
L: -> "<a href='#{Build.h_escape @file.URL}' target='_blank'>#{FileInfo.h_formatters.N.call @}</a>" L: -> "<a href='#{E @file.URL}' target='_blank'>#{FileInfo.h_formatters.N.call @}</a>"
n: -> n: ->
fullname = @file.name fullname = @file.name
shortname = Build.shortFilename @file.name, @isReply shortname = Build.shortFilename @file.name, @isReply
if fullname is shortname if fullname is shortname
Build.h_escape fullname E fullname
else else
"<span class='fntrunc'>#{Build.h_escape shortname}</span><span class='fnfull'>#{Build.h_escape fullname}</span>" "<span class='fntrunc'>#{E shortname}</span><span class='fnfull'>#{E fullname}</span>"
N: -> Build.h_escape @file.name N: -> E @file.name
p: -> if @file.isSpoiler then 'Spoiler, ' else '' p: -> if @file.isSpoiler then 'Spoiler, ' else ''
s: -> Build.h_escape @file.size s: -> E @file.size
B: -> return "#{+@file.sizeInBytes} Bytes" B: -> return "#{+@file.sizeInBytes} Bytes"
K: -> "#{+Math.round(@file.sizeInBytes/1024)} KB" K: -> "#{+Math.round(@file.sizeInBytes/1024)} KB"
M: -> "#{+Math.round(@file.sizeInBytes/1048576*100)/100} MB" M: -> "#{+Math.round(@file.sizeInBytes/1048576*100)/100} MB"
r: -> Build.h_escape (@file.dimensions or 'PDF') r: -> E (@file.dimensions or 'PDF')