// public static By CreateBy(string scssSelector, params object[] args) // { // scssSelector = string.Format(scssSelector, args); // return Create(scssSelector).By; // } public static Scss Create(string scssSelector) { if (string.IsNullOrWhiteSpace(scssSelector)) { return(null); } var combineWithRoot = false; if (scssSelector.StartsWith(ROOT_PREFIX)) { combineWithRoot = true; scssSelector = scssSelector.Remove(0, ROOT_PREFIX.Length).Trim(); } var xpath = string.Empty; string css = null; try { var isTrueCss = true; var parts = SplitIgnoringConditions(scssSelector, true, ','); foreach (var partScssSelector in parts) { bool partScssIsTrueCss; var xpathPart = ScssPartToXpath(partScssSelector, out partScssIsTrueCss); xpath += "//" + RemoveDescendantAxis(xpathPart) + "|"; isTrueCss &= partScssIsTrueCss; } xpath = xpath.Substring(0, xpath.Length - 1); if (isTrueCss) { css = scssSelector; } } catch (InvalidScssException e) { // Это не scss, возможно это xpath if (XPathBuilder.IsXPath(scssSelector)) { xpath = scssSelector; } else { throw new InvalidScssException($"Invalid scss: {scssSelector}.", e); } } return(new Scss(xpath, css, combineWithRoot)); }
private static Scss CreateFromXpath(string scssSelector, bool combineWithRoot) { string xpath; // Это не scss, возможно это xpath if (XPathBuilder.IsXPath(scssSelector)) { xpath = scssSelector; } else { // TODO: what should we do in this case? throw new InvalidScssException($"Invalid scss: {scssSelector}."); } return(new Scss(xpath, null, combineWithRoot)); }
public static Scss Create(string scssSelector) { if (string.IsNullOrEmpty(scssSelector)) { return(new Scss(string.Empty, string.Empty)); } var xpath = string.Empty; string css = null; try { var isTrueCss = true; var parts = SplitIgnoringConditions(scssSelector, true, ','); foreach (var partScssSelector in parts) { bool partScssIsTrueCss; var xpathPart = ScssPartToXpath(partScssSelector, out partScssIsTrueCss); xpath += "//" + RemoveDescendantAxis(xpathPart) + "|"; isTrueCss &= partScssIsTrueCss; } xpath = xpath.Substring(0, xpath.Length - 1); if (isTrueCss) { css = scssSelector; } } catch (InvalidScssException e) { // Это не scss, возможно это xpath if (XPathBuilder.IsXPath(scssSelector)) { xpath = scssSelector; } else { throw e; } } return(new Scss(xpath, css)); }