string RenderEvalScripts(ITemplate template, TwitterStatus status)
{
// search is there any eval scripts
var tempHtml = PersistTemplate(template);
var r1 = new Regex(@"(<%#) ?.*eval?.*%>", RegexOptions.IgnoreCase);
var matches = r1.Matches(tempHtml);
_valCounter = 0;
_values = new List<string>();
// manualy extract eval scripts if any
if(matches.Count > 0) {
var r2 = new Regex(@"""(.*?)""");
foreach(var match in matches) {
var evalData = r2.Match(match.ToString()).ToString();
evalData = evalData.Substring(1, evalData.Length - 2);
object value = null;
if(evalData.Contains(".")) {
var props = evalData.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
var propVal1 = typeof(TwitterStatus).GetProperty(props[0]).GetValue(status, null);
if(propVal1 != null)
value = propVal1.GetType().GetProperty(props[1]).GetValue(propVal1, null);
}
else {
value = typeof(TwitterStatus).GetProperty(evalData).GetValue(status, null);
}
if(value == null)
value = "[" + evalData + "]";
_values.Add(value.ToString());
}
var evaluator = new MatchEvaluator(FillStatusValue);
return r1.Replace(tempHtml, evaluator);
}
return null;
}