public void Can_parse_rule_to_ast() { var mapping = new Dictionary <string, List <string> > { { "http://schemas.microsoft.com/winfx/2006/xaml/presentation", new List <string> { typeof(System.Windows.Data.Binding).AssemblyQualifiedName.Replace(".Binding,", ","), typeof(System.Windows.Navigation.NavigationWindow).AssemblyQualifiedName.Replace(".NavigationWindow,", ","), typeof(System.Windows.Shapes.Rectangle).AssemblyQualifiedName.Replace(".Rectangle,", ","), typeof(System.Windows.Controls.Button).AssemblyQualifiedName.Replace(".Button,", ","), typeof(System.Windows.FrameworkElement).AssemblyQualifiedName.Replace(".FrameworkElement,", ","), typeof(System.Windows.Documents.Run).AssemblyQualifiedName.Replace(".Run,", ",") } } }; TypeHelpers.Initialze(mapping); CssParser.Initialize(typeof(System.Windows.Controls.Button).AssemblyQualifiedName.Replace(".Button,", ","), null); var stylesheetBase = new StyleSheet(); stylesheetBase.Content = @"@namespace ""http://schemas.microsoft.com/winfx/2006/xaml/presentation"";"; stylesheetBase.GetNamespaceUri("", "FlowDocument").Should().Be("System.Windows.Documents, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); var dependent = new StyleSheet(); dependent.SingleBaseStyleSheet = stylesheetBase; // inherits defaultnamespace from stylesheetBase dependent.GetNamespaceUri("", "FlowDocument").Should().Be("System.Windows.Documents, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); var dependent2 = new StyleSheet(); dependent2.SingleBaseStyleSheet = stylesheetBase; // overwrite inherited defaultnamespace from stylesheetBase dependent2.Content = $@"@namespace ""{typeof(System.Windows.Controls.Button).AssemblyQualifiedName.Replace(".Button,", ",")}"";"; dependent.GetNamespaceUri("", "FlowDocument").Should().Be("System.Windows.Documents, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); dependent2.GetNamespaceUri("", "FlowDocument").Should().Be("System.Windows.Controls, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); stylesheetBase.Content = @""; dependent.GetNamespaceUri("", "FlowDocument").Should().Be("System.Windows.Controls, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); dependent2.GetNamespaceUri("", "FlowDocument").Should().Be("System.Windows.Controls, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); stylesheetBase.Content = @"@namespace ""http://schemas.microsoft.com/winfx/2006/xaml/presentation"";"; // inherited namespace matter because it is not overwritten in dependent stylesheets dependent.GetNamespaceUri("", "FlowDocument").Should().Be("System.Windows.Documents, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); dependent2.GetNamespaceUri("", "FlowDocument").Should().Be("System.Windows.Controls, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); }
public void Can_parse_slash_in_comment() { CssParser.Initialize(null, new TestCssFileProvider()); var css = @" .fa { /*/asdfasdfsd*/ } "; var styleSheet = CssParser.Parse(css); styleSheet.Rules.Count.Should().Be(1); styleSheet.Errors.Count.Should().Be(0); }
public BaseCss(IDependencyPropertyService <TDependencyObject, TUIElement, TStyle, TDependencyProperty> dependencyPropertyService, ITreeNodeProvider <TDependencyObject> treeNodeProvider, IStyleResourcesService applicationResourcesService, INativeStyleService <TStyle, TDependencyObject, TDependencyProperty> nativeStyleService, string defaultCssNamespace, IMarkupExtensionParser markupExpressionParser, Action <Action> uiInvoker) { this.dependencyPropertyService = dependencyPropertyService; this.treeNodeProvider = treeNodeProvider; this.applicationResourcesService = applicationResourcesService; this.nativeStyleService = nativeStyleService; this.markupExpressionParser = markupExpressionParser; this.uiInvoker = uiInvoker; CssParser.Initialize(defaultCssNamespace); }
public BaseCss(IDependencyPropertyService <TDependencyObject, TUIElement, TStyle, TDependencyProperty> dependencyPropertyService, ITreeNodeProvider <TDependencyObject> treeNodeProvider, IStyleResourcesService applicationResourcesService, INativeStyleService <TStyle, TDependencyObject, TDependencyProperty> nativeStyleService, string defaultCssNamespace, IMarkupExtensionParser markupExpressionParser, Action <Action> uiInvoker, ICssFileProvider fileProvider) { this.dependencyPropertyService = dependencyPropertyService; this.treeNodeProvider = treeNodeProvider; this.applicationResourcesService = applicationResourcesService; this.nativeStyleService = nativeStyleService; this.markupExpressionParser = markupExpressionParser; this.uiInvoker = uiInvoker; this.cssTypeHelper = new CssTypeHelper <TDependencyObject, TUIElement, TDependencyProperty, TStyle>(markupExpressionParser, dependencyPropertyService); CssParser.Initialize(defaultCssNamespace, fileProvider); StyleSheet.GetParent = parent => treeNodeProvider.GetParent((TDependencyObject)parent); StyleSheet.GetStyleSheet = treeNode => dependencyPropertyService.GetStyleSheet((TDependencyObject)treeNode); }
public void Can_import_css_file() { CssParser.Initialize(null, new TestCssFileProvider()); var css = @" @import 'CssParsing\\TestData\\ImportCss.scss'; SomeElement { @include InputElement(); TextColor: $textColor; } "; var styleSheet = CssParser.Parse(css); styleSheet.Rules.Count.Should().Be(2); styleSheet.Rules[0].DeclarationBlock[0].Property.Should().Be("Grid.Column"); styleSheet.Rules[0].DeclarationBlock[0].Value.Should().Be("1"); styleSheet.Rules[0].DeclarationBlock[1].Property.Should().Be("TextColor"); styleSheet.Rules[0].DeclarationBlock[1].Value.Should().Be("Red"); }
public void Dont_hang_on_first_char_of_comment() { CssParser.Initialize(null, new TestCssFileProvider()); var css = @" .fa { FontFamily: ""test""; / &.fa-css3 { Text: ""\f13c""; } } "; var styleSheet = CssParser.Parse(css); styleSheet.Rules.Count.Should().Be(1); styleSheet.Errors.Count.Should().Be(1); styleSheet.Rules[0].SelectorString.Should().Be(".fa"); styleSheet.Rules[0].DeclarationBlock[0].Property.Should().Be("FontFamily"); styleSheet.Rules[0].DeclarationBlock[0].Value.Should().Be("test"); }
public void Can_override_imported_css_file() { CssParser.Initialize(null, new TestCssFileProvider()); var css = @" @import 'CssParsing\\TestData\\ImportCss.scss'; $textColor: Pink; @mixin InputElement() { Background: Orange; } SomeElement { @include InputElement(); TextColor: $textColor; } "; var styleSheet = CssParser.Parse(css); styleSheet.Rules.Count.Should().Be(2); styleSheet.Rules[0].SelectorString.Should().Be("SomeElement"); styleSheet.Rules[0].DeclarationBlock[0].Property.Should().Be("Background"); styleSheet.Rules[0].DeclarationBlock[0].Value.Should().Be("Orange"); styleSheet.Rules[0].DeclarationBlock[1].Property.Should().Be("TextColor"); styleSheet.Rules[0].DeclarationBlock[1].Value.Should().Be("Pink"); styleSheet.Rules[1].SelectorString.Should().Be(".header"); styleSheet.Rules[1].DeclarationBlock[0].Property.Should().Be("TextColor"); styleSheet.Rules[1].DeclarationBlock[0].Value.Should().Be("Red"); styleSheet.Rules[1].DeclarationBlock[1].Property.Should().Be("BackgroundColor"); styleSheet.Rules[1].DeclarationBlock[1].Value.Should().Be("White"); }