Ejemplo n.º 1
0
 public IBindingsBuilder <M> Attr <F>(
     string attrName,
     Expression <Func <M, F> > expression,
     string format = null,
     params LambdaExpression[] otherExpressions)
 {
     if (expression == null)
     {
         throw (new ArgumentNullException("expression"));
     }
     if (string.IsNullOrWhiteSpace(attrName))
     {
         throw (new ArgumentNullException("attrName"));
     }
     if (writer == null)
     {
         return(this);
     }
     if (attrStringBuilder == null)
     {
         attrStringBuilder = new StringBuilder();
     }
     attrStringBuilder.Append(BindingsExtensions.standardString <M, F>(this, attrName, expression, format, otherExpressions));
     return(this);
 }
Ejemplo n.º 2
0
 public IBindingsBuilder <M> Event <F>(
     string eventName,
     Expression <Func <M, F> > expression,
     bool bubble   = true,
     string format = null,
     params LambdaExpression[] otherExpressions)
 {
     if (expression == null)
     {
         throw (new ArgumentNullException("expression"));
     }
     if (string.IsNullOrWhiteSpace(eventName))
     {
         throw (new ArgumentNullException("eventName"));
     }
     if (writer == null)
     {
         return(this);
     }
     if (eventStringBuilder == null)
     {
         eventStringBuilder = new StringBuilder();
     }
     eventStringBuilder.Append(BindingsExtensions.standardString <M, F>(this, eventName, expression, format, otherExpressions));
     if (!bubble)
     {
         this.Add(eventName + "Bubble: false");
     }
     return(this);
 }
Ejemplo n.º 3
0
        private string TagMatchEvaluator(Match match)
        {
            string result   = match.ToString();
            var    tagInfos = match.Groups["tagName"];
            string otag     = tagInfos.Value;
            string tag      = otag.ToLower();

            if (tag.StartsWith("!"))
            {
                return(result);
            }
            if (tag == "script")
            {
                Group bodyMatch = match.Groups["scriptbody"];
                if (bodyMatch.Success)
                {
                    scriptCount++;
                    return(string.Format("<{0} {1}>", namePrefix == null ? ClientTemplateHelper.scriptSymbol : "script", bodyMatch.Value));
                }
                else
                {
                    scriptCount--;
                    return(string.Format("</{0}>", namePrefix == null ? ClientTemplateHelper.scriptSymbol : "script"));
                }
            }
            if (scriptCount != 0)
            {
                return(result);
            }
            string toAdd = null;

            Group  nameGroup = match.Groups["name"];
            string name      = null;

            if (nameGroup.Success)
            {
                name = nameGroup.Captures[0].Value;
                int index = name.IndexOf(".");
                if (index >= 0)
                {
                    name = name.Substring(index + 1);
                }
                else
                {
                    return(result);
                }
            }
            else
            {
                return(result);
            }
            string oldName = null;

            if (name.Length >= 7 && name.Substring(name.Length - 7) == "_hidden")
            {
                oldName = name;
                name    = name.Substring(0, name.Length - 7);
            }
            dynamic currBindings = bindings;
            Group   indexGroup   = match.Groups["index"];

            if (indexGroup.Success)
            {
                string key = "_TemplateLevel_" + indexGroup.Value;
                if (HttpContext.Current.Items.Contains(key))
                {
                    currBindings = HttpContext.Current.Items[key];
                }
            }
            dynamic expression = currBindings.BuildExpression(name);

            if (expression == null)
            {
                if (oldName != null)
                {
                    expression = currBindings.BuildExpression(oldName);
                }
                if (expression == null)
                {
                    return(result);
                }
            }
            bool tryMultiselect = false;
            bool tryCheckBox    = false;

            if (tag == "select")
            {
                tryMultiselect = true;
            }
            else if (tag == "input")
            {
                tryCheckBox = true;
            }
            MatchCollection attributes    = suitableAttribute.Matches(result);
            bool            look          = true;
            bool            elementispart = false;
            bool            element_type  = false;
            string          dataBind      = null;
            Match           dataBindMatch = null;

            foreach (Match m in attributes)
            {
                Group g = m.Groups["attributeName"];
                Group v = m.Groups["attributeValue"];
                if (g.Success && g.Value == "data-bind")
                {
                    dataBind      = v.Value;
                    dataBindMatch = m;
                }
                if (g.Success && g.Value == "data-nobinding")
                {
                    return(result);
                }
                if (g.Success && (g.Value == "data-elementispart"))
                {
                    elementispart = true;
                }
                if (g.Success && (g.Value == "data-element-type"))
                {
                    element_type = true;
                }
                if (look && tryMultiselect)
                {
                    if (g.Success && g.Value.ToLower() == "multiple" && v.Success && v.Value.ToLower() == "multiple")
                    {
                        toAdd = BindingsExtensions.SelectedOptions(currBindings, expression).Get().ToString();
                        look  = false;
                    }
                }
                else if (look && tryCheckBox)
                {
                    if (g.Success && g.Value.ToLower() == "type" && v.Success && (v.Value.ToLower() == "checkbox" || v.Value.ToLower() == "radio"))
                    {
                        toAdd = BindingsExtensions.Checked(currBindings, expression).Get().ToString();
                        look  = false;
                    }
                }
            }
            if (tag != "input" && tag != "select" && tag != "textarea" && !element_type)
            {
                return(result);
            }
            if (toAdd == null && (element_type || !elementispart))
            {
                toAdd = BindingsExtensions.Value(currBindings, expression).Get().ToString();
            }

            int    start  = result.IndexOf(otag) + otag.Length;
            string ending = result.Substring(start);

            if (!string.IsNullOrWhiteSpace(dataBind))
            {
                string header = ending.Substring(0, dataBindMatch.Index - start);
                string footer = ending.Substring(dataBindMatch.Index + dataBindMatch.Length - start);

                result = string.Format("<{0} data-nobinding='true' data-bind=\"{1}, {2}\" {3} {4}", otag, dataBind, toAdd, header, footer);
            }
            else
            {
                result = string.Format("<{0} data-nobinding='true' data-bind=\"{1}\" {2}", otag, toAdd, ending);
            }
            return(result);
        }