public void DoReplace(ElementNode node, IList<Node> body) { string propertyExpression = node.GetAttributeValue("for"); Node checkedSnippet = propertyExpression.GetCheckedSnippet(); node.RemoveAttributesByName("checked"); node.Attributes.Add(new AttributeNode("checked", new List<Node>(){checkedSnippet})); }
public ISparkExtension CreateExtension(VisitorContext context, ElementNode node) { if (node.Name == "unittest") return new TestExtension(); return null; }
public ISparkExtension CreateExtension(VisitorContext context, ElementNode node) { if(_serviceProvider==null) { return null; } var componentFactory = (IViewComponentFactory)_serviceProvider.GetService(typeof(IViewComponentFactory)); if (componentFactory == null || componentFactory.Registry == null) return null; ViewComponentInfo viewComponentInfo; lock (_cachedViewComponent) { if (!_cachedViewComponent.TryGetValue(node.Name, out viewComponentInfo)) { if (componentFactory.Registry.HasViewComponent(node.Name)) { viewComponentInfo = new ViewComponentInfo(componentFactory.Create(node.Name)); _cachedViewComponent.Add(node.Name, viewComponentInfo); } else { _cachedViewComponent.Add(node.Name, null); } } } if (viewComponentInfo != null) { return new ViewComponentExtension(node, viewComponentInfo); } return null; }
private static IEnumerable<IReplacement> GetApplicableReplacements(ElementNode node) { var result = new List<IReplacement>(); result.AddRange(UriReplacementSpecifications.GetMatching(node)); result.AddRange(FormReplacementSpecifications.GetMatching(node)); return result; }
protected void Transform(ElementNode elementNode, IList<Node> body) { foreach (IReplacement replacement in replacements) { replacement.DoReplace(elementNode); } }
protected static void AddAttribute(ElementNode elementNode, string attributeName, Node childNode) { elementNode.RemoveAttributesByName(attributeName); elementNode.Attributes.Add(new AttributeNode(attributeName, new List<Node> { childNode })); }
private Node RemoteAndEvalUriSnippet(ElementNode elementNode) { string attribValue = elementNode.GetAttributeValue(replacementSpecification.OriginalAttributeName); elementNode.RemoveAttributesByName(replacementSpecification.OriginalAttributeName); return attribValue.GetCreateUriSnippet( IsTypeReplacement()); }
public void NonVoidElementDoesNotSelfClose() { var elt = new ElementNode("span", new AttributeNode[]{ }, true); var visitor = new ChunkBuilderVisitor(new VisitorContext()); visitor.Accept(elt); Assert.AreEqual(1, visitor.Chunks.Count()); Assert.AreEqual("<span></span>", ((SendLiteralChunk)visitor.Chunks[0]).Text); }
public ISparkElementTransformer CreateElementTransformer(ElementNode elementNode) { var tag = new Tag(elementNode.Name, elementNode.Attributes.Select(x=>new TagAttribute(x.Name, x.Value)).ToArray()); if(!_elementTransformerService.IsTransformable(tag)) { return new NullSparkElementTransformer(); } return new SparkElementTransformer(_elementTransformerService.GetTransformerFor(tag)); }
public ISparkElementTransformer CreateElementTransformer(ElementNode elementNode) { var sparkElementWrapper = new SparkElementWrapper(elementNode); if(!_elementTransformerService.IsTransformable(sparkElementWrapper)) { return new NullSparkElementTransformer(); } return new SparkElementTransformer(_elementTransformerService.GetTransformerFor(sparkElementWrapper)); }
private static IEnumerable<IReplacement> GetMiscReplacements(ElementNode node) { IEnumerable<IReplacement> result = TextAreaSpecs.Where(x => x.IsMatch(node)).Select(x => new TextAreaValueReplacement(x)).Cast<IReplacement>(); result = result.Union( SelectSpecs.Where(x => x.IsMatch(node)).Select(x => new SelectSelectedValueReplacement(x)).Cast<IReplacement>()); return result; }
public ISparkExtension CreateExtension(VisitorContext context, ElementNode node) { ISparkElementTransformer elementTransformer = _sparkElementTransformerService.CreateElementTransformer(node); if(elementTransformer is NullSparkElementTransformer) { return null; } return new SparkOverrideExtension(node, elementTransformer); }
public ISparkExtension CreateExtension(VisitorContext context, ElementNode node) { IEnumerable<IReplacement> replacements = GetApplicableReplacements(node); if (replacements.Any()) { return new SparkExtension(node, replacements); } return null; }
private AttributeNode ExtractFakeAttribute(ElementNode node, string name, string fakeName) { var attribute = node.Attributes.SingleOrDefault(x => AttrName(x) == name); if (attribute == null) return null; node.Attributes.Remove(attribute); return new AttributeNode(fakeName, '"', attribute.Nodes); }
public static IEnumerable<IReplacement> GetMatching(ElementNode node) { // should create the urireplacements on static construction var result = new List<IReplacement>(); result.AddRange(GetNameReplacements(node)); result.AddRange(GetValueReplacements(node)); result.AddRange(GetMiscReplacements(node)); result.AddRange(GetTidyReplacements(node)); return result; }
public void DoReplace(ElementNode node) { RemoveReplacedAttribute(node); Node uriSnippet = RemoteAndEvalUriSnippet(node); node.Attributes.Add(new AttributeNode(replacementSpecification.NewAttributeName, new List<Node>() { uriSnippet })); }
public TargetExtension(VisitorContext context, ElementNode targetElement, int targetExtensionCount) { _context = context; _targetElement = targetElement; _targetExtensionCount = targetExtensionCount; _idAttribute = _targetElement.Attributes.SingleOrDefault(attr => attr.Name == "id"); _classAttribute = _targetElement.Attributes.SingleOrDefault(attr => attr.Name == "class"); _descriptionAttribute = _targetElement.Attributes.SingleOrDefault(attr => attr.Name == "description"); _targetAttribute = _targetElement.Attributes.SingleOrDefault(attr => attr.Name == "target"); }
public ISparkExtension CreateExtension(VisitorContext context, ElementNode node) { if (string.Equals(node.Name, "div", StringComparison.OrdinalIgnoreCase)) { return new TargetExtension(context, node, ++_TargetExtensionCount); } if (string.Equals(node.Name, "functions", StringComparison.OrdinalIgnoreCase)) { return new FunctionsExtension(context, node); } return null; }
public void NodeShouldBeTakenFromTransformer() { var elementTransformer = MockRepository.GenerateStub<ISparkElementTransformer>(); Node transformedNode = new ElementNode("transformed", new List<AttributeNode>(), false); IList<Node> body = new List<Node>(); var extension = new SparkOverrideExtension(elementTransformer); extension.VisitNode(new StubNodeVisitor(), body, null); elementTransformer.AssertWasCalled(x => x.Transform(body)); }
public void ShouldAppendEndElementIfNodeIsNotEmpty() { var elementTransformer = MockRepository.GenerateStub<ISparkElementTransformer>(); Node transformedNode = new ElementNode("transformed", new List<AttributeNode>(), false); elementTransformer.Stub(x => x.Transform(null)).IgnoreArguments().Return(transformedNode); var extension = new SparkOverrideExtension(elementTransformer); var stubNodeVisitor = new StubNodeVisitor(); extension.VisitNode(stubNodeVisitor, new List<Node>(), null); stubNodeVisitor.Nodes.LastOrDefault().As<EndElementNode>().Name.ShouldEqual("transformed"); }
public override void DoReplace(ElementNode node, IList<Node> body) { IEnumerable<ElementNode> options = GetOptions(body); foreach (ElementNode option in options) { string currentSelectedValue = option.GetAttributeValue("selected"); string propertyValue = option.GetAttributeValue("value"); string propertyExpression = node.GetAttributeValue(ReplacementSpecification.OriginalAttributeName); Node selectedNode = propertyExpression.GetSelectedSnippet(currentSelectedValue, propertyValue); option.RemoveAttributesByName("selected"); AddAttribute(option, "selected", selectedNode); } }
protected override void Visit(ElementNode element) { var binding = MatchElementBinding(element); if (binding == null) { base.Visit(element); return; } var snippets = binding.Nodes.SelectMany(bindingNode => BuildSnippetsForNode(binding, bindingNode, element)); var expression = new ExpressionNode(snippets); Accept(expression); }
private static IEnumerable<Snippet> BuildSnippets(BindingNameReference reference, ElementNode element) { var attrs = element.Attributes.Where(attr => attr.Name == reference.Name); if (reference.AssumeStringValue) { var builder = new ExpressionBuilder(); PopulateBuilder(attrs.SelectMany(attr => attr.Nodes), builder); return new[] { new Snippet { Value = builder.ToCode() } }; } return attrs.SelectMany(attr => attr.AsCode()); }
public void ShouldNotRet() { var elementTransformer = MockRepository.GenerateStub<ISparkElementTransformer>(); var nodeVisitor = MockRepository.GenerateStub<INodeVisitor>(); IList<Node> body = new List<Node>(); Node transformedNode = new ElementNode("transformed", new List<AttributeNode>(), false); elementTransformer.Stub(x => x.Transform(body)).Return(transformedNode); var extension = new SparkOverrideExtension(elementTransformer); extension.VisitNode(nodeVisitor, body, null); nodeVisitor.AssertWasCalled(x => x.Accept(transformedNode)); nodeVisitor.AssertWasCalled(x => x.Accept(body)); }
protected override bool IsSpecialAttribute(ElementNode element, AttributeNode attribute) { var eltName = NameUtility.GetName(element.Name); if (eltName == "for") return false; if (Context.Namespaces == NamespacesType.Unqualified) return attribute.Name == "each"; if (attribute.Namespace != Constants.Namespace) return false; return NameUtility.GetName(attribute.Name) == "each"; }
public void ShouldVisitTransformedNodeBodyIfNotEmpty() { var elementTransformer = MockRepository.GenerateStub<ISparkElementTransformer>(); Node transformedNode = new ElementNode("transformed", new List<AttributeNode>(), false); elementTransformer.Stub(x => x.Transform(null)).IgnoreArguments().Return(transformedNode); var extension = new SparkOverrideExtension(elementTransformer); var stubNodeVisitor = new StubNodeVisitor(); List<Node> body = new List<Node>() {new TextNode("Body text"), new TextNode("Another one")}; List<Node> expectedNodes = new List<Node> { transformedNode }; expectedNodes.AddRange(body); extension.VisitNode(stubNodeVisitor, body, null); stubNodeVisitor.Nodes.ShouldStartWith(expectedNodes); }
protected override bool IsSpecialAttribute(ElementNode element, AttributeNode attr) { var eltName = NameUtility.GetName(element.Name); if (eltName == "test" || eltName == "if" || eltName == "elseif" || eltName == "else") return false; if (Context.Namespaces == NamespacesType.Unqualified) return attr.Name == "once"; if (attr.Namespace != Constants.Namespace) return false; var nqName = NameUtility.GetName(attr.Name); return nqName == "once"; }
private static IEnumerable<IReplacement> GetApplicableReplacements(ElementNode node) { var result = new List<IReplacement>(); // rf this crap if ((node.Name == "input") && (node.HasAttribute("type") && (node.HasAttribute("for")))) { if (node.Attributes.Where(x => (x.Name == "type") && (x.Value == "checkbox")).Any()) { result.Add(new CheckBoxCheckedReplacement()); } } result.AddRange(UriReplacementSpecifications.GetMatching(node)); result.AddRange(FormReplacementSpecifications.GetMatching(node)); return result; }
protected override SpecialNode CreateWrappingNode(AttributeNode attr, ElementNode node) { var attrKey = ExtractFakeAttribute(node, "cache", "key") ?? ExtractFakeAttribute(node, "cache.key", "key"); var attrExpires = ExtractFakeAttribute(node, "cache.expires", "expires"); var attrSignal = ExtractFakeAttribute(node, "cache.signal", "signal"); var attrNodes = new[] { attrKey, attrExpires, attrSignal }.Where(x => x != null).ToList(); var fakeElement = new ElementNode("cache", attrNodes, false) { OriginalNode = attr }; return new SpecialNode(fakeElement); }
private void AddCheckedAttribute(ElementNode elementNode, AttributeNode valueNode) { if (valueNode != null) { string entity = valueNode.Value.Split('.').First(); string code = string.Format("({0}!= null)&&({1})", entity, valueNode.Value); ConditionNode conditionNode = new ConditionNode(code) { Nodes = new List<Node>() { new TextNode("true") } }; elementNode.Attributes.Add(new AttributeNode("checked", new List<Node>{conditionNode} )); } }
public SpecialNode(ElementNode element) { this.Element = element; }
public ExtensionNode(ElementNode element, ISparkExtension extension) { Element = element; Extension = extension; OriginalNode = element; }
public ExtensionNode(ElementNode element, ISparkExtension extension) { this.Element = element; this.Extension = extension; base.OriginalNode = element; }
public SpecialNode(ElementNode element) { Element = element; }