SVN keyword substition gives is not pretty. E.g.,
SVN关键字替换给出的并不漂亮。例如。,
Last updated: $Date$ by $Author$
上次更新时间:$ Date $ by $ Author $
yields
Last updated: $Date: 2008-09-22 14:38:43 -0400 (Mon, 22 Sep 2008) $ by $Author: cconway $"
最近更新时间:$ Date:2008-09-22 14:38:43 -0400(2008年9月22日,星期一)$ by $作者:cconway $“
Does anybody have a Javascript snippet that prettifies things and outputs some HTML? The result should be more like:
有没有人有一个Javascript代码片段可以美化并输出一些HTML?结果应该更像是:
Last update: 22 Sep 2008 by cconway
最后更新:2008年9月22日,cconway
P.S. Is there a way to replace "cconway" with a display name?
附:有没有办法用显示名称替换“cconway”?
3 个解决方案
#1
2
Errr.. This feels a bit like me doing your job for you :), but here goes:
呃..这感觉有点像我为你做的工作:),但是这里有:
function formatSvnString(string){
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
var re = /\$Date: (\d{4})-(\d\d)-(\d\d).*?\$Author: (\S+) \$/
return string.replace(re, function(match, year, month, day, author){
var date = new Date([year, month, day].join('/'))
return date.getDate()
+ ' ' + months[date.getMonth()]
+ ' ' + date.getFullYear()
+ ' by ' + author
})
}
Usage:
formatSvnString("$Date: 2008-09-22 14:38:43 -0400 (Mon, 22 Sep 2008) $ by $Author: cconway $")
// returns: 22 Sep 2008 by cconway
I'll leave it up to you to work out how to find these SVN string and apply the above code automatically :)
我将由您决定如何找到这些SVN字符串并自动应用上述代码:)
To do the user's display name, you'll either have to convince SVN to insert it (I don't think it can do that, but I might be wrong), or somehow provide a means for JS to either fetch it, or to have access to a table full of usernames and associated display name (might be a bit too much like a security risk though. Hey kids, see if you can break into my server using one of these usernames!)
要做用户的显示名称,你要么必须说服SVN插入它(我不认为它可以做到这一点,但我可能是错的),或者以某种方式为JS提供获取它的方法,或者可以访问一个充满用户名和相关显示名称的表(虽然可能有点像安全风险。嘿孩子们,看看你是否可以使用其中一个用户名进入我的服务器!)
#2
0
Some JavaScript libraries provide templating functionality.
一些JavaScript库提供模板功能。
Prototype - http://www.prototypejs.org/api/template
Ext JS - http://extjs.com/deploy/dev/docs/?class=Ext.DomHelper
原型 - http://www.prototypejs.org/api/template Ext JS - http://extjs.com/deploy/dev/docs/?class=Ext.DomHelper
I'm sure you could find a plugin for JQuery.
我相信你可以找到一个JQuery插件。
#3
0
Here's a little jQuery code to do the job:
这里有一个jQuery代码来完成这项工作:
$(document).ready(function() { var date = "$Date: 2008-09-23 00:10:56 -0400 (Tue, 23 Sep 2008) $" .replace(/\$Date:.*\((.*)\)\s*\$/,"$1"); $(".timestamp").text( "Last updated: " + date ); });
where there is a <div class="timestamp" />
in the HTML wherever you want the timestamp text to appear.
HTML中任何地方都有
#1
2
Errr.. This feels a bit like me doing your job for you :), but here goes:
呃..这感觉有点像我为你做的工作:),但是这里有:
function formatSvnString(string){
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
var re = /\$Date: (\d{4})-(\d\d)-(\d\d).*?\$Author: (\S+) \$/
return string.replace(re, function(match, year, month, day, author){
var date = new Date([year, month, day].join('/'))
return date.getDate()
+ ' ' + months[date.getMonth()]
+ ' ' + date.getFullYear()
+ ' by ' + author
})
}
Usage:
formatSvnString("$Date: 2008-09-22 14:38:43 -0400 (Mon, 22 Sep 2008) $ by $Author: cconway $")
// returns: 22 Sep 2008 by cconway
I'll leave it up to you to work out how to find these SVN string and apply the above code automatically :)
我将由您决定如何找到这些SVN字符串并自动应用上述代码:)
To do the user's display name, you'll either have to convince SVN to insert it (I don't think it can do that, but I might be wrong), or somehow provide a means for JS to either fetch it, or to have access to a table full of usernames and associated display name (might be a bit too much like a security risk though. Hey kids, see if you can break into my server using one of these usernames!)
要做用户的显示名称,你要么必须说服SVN插入它(我不认为它可以做到这一点,但我可能是错的),或者以某种方式为JS提供获取它的方法,或者可以访问一个充满用户名和相关显示名称的表(虽然可能有点像安全风险。嘿孩子们,看看你是否可以使用其中一个用户名进入我的服务器!)
#2
0
Some JavaScript libraries provide templating functionality.
一些JavaScript库提供模板功能。
Prototype - http://www.prototypejs.org/api/template
Ext JS - http://extjs.com/deploy/dev/docs/?class=Ext.DomHelper
原型 - http://www.prototypejs.org/api/template Ext JS - http://extjs.com/deploy/dev/docs/?class=Ext.DomHelper
I'm sure you could find a plugin for JQuery.
我相信你可以找到一个JQuery插件。
#3
0
Here's a little jQuery code to do the job:
这里有一个jQuery代码来完成这项工作:
$(document).ready(function() { var date = "$Date: 2008-09-23 00:10:56 -0400 (Tue, 23 Sep 2008) $" .replace(/\$Date:.*\((.*)\)\s*\$/,"$1"); $(".timestamp").text( "Last updated: " + date ); });
where there is a <div class="timestamp" />
in the HTML wherever you want the timestamp text to appear.
HTML中任何地方都有