Commit 535abaf8 authored by Tebjan Halm's avatar Tebjan Halm
Browse files

Merge pull request #90 from erdomke/master

Initial Work on W3C Test Compliance
parents 4b1ff3d4 bd05ecbc
using ExCSS.Model;
using ExCSS.Model.Extensions;
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public class FontFaceRule : RuleSet, ISupportsDeclarations
{
private readonly StyleDeclaration _declarations;
public FontFaceRule()
{
_declarations = new StyleDeclaration();
RuleType = RuleType.FontFace;
}
internal FontFaceRule AppendRule(Property rule)
{
_declarations.Properties.Add(rule);
return this;
}
public StyleDeclaration Declarations
{
get { return _declarations; }
}
public string FontFamily
{
get { return _declarations.GetPropertyValue("font-family"); }
set { _declarations.SetProperty("font-family", value); }
}
public string Src
{
get { return _declarations.GetPropertyValue("src"); }
set { _declarations.SetProperty("src", value); }
}
public string FontStyle
{
get { return _declarations.GetPropertyValue("font-style"); }
set { _declarations.SetProperty("font-style", value); }
}
public string FontWeight
{
get { return _declarations.GetPropertyValue("font-weight"); }
set { _declarations.SetProperty("font-weight", value); }
}
public string Stretch
{
get { return _declarations.GetPropertyValue("stretch"); }
set { _declarations.SetProperty("stretch", value); }
}
public string UnicodeRange
{
get { return _declarations.GetPropertyValue("unicode-range"); }
set { _declarations.SetProperty("unicode-range", value); }
}
public string FontVariant
{
get { return _declarations.GetPropertyValue("font-variant"); }
set { _declarations.SetProperty("font-variant", value); }
}
public string FeatureSettings
{
get { return _declarations.GetPropertyValue("font-feature-settings"); }
set { _declarations.SetProperty("font-feature-settings", value); }
}
public override string ToString()
{
return ToString(false);
}
public override string ToString(bool friendlyFormat, int indentation = 0)
{
return "@font-face{".NewLineIndent(friendlyFormat, indentation) +
_declarations.ToString(friendlyFormat, indentation) +
"}".NewLineIndent(friendlyFormat, indentation);
}
}
}
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public class GenericRule : AggregateRule
{
private string _text;
private bool _stopped;
internal void SetInstruction(string text)
{
_text = text;
_stopped = true;
}
internal void SetCondition(string text)
{
_text = text;
_stopped = false;
}
public override string ToString()
{
return ToString(false);
}
public override string ToString(bool friendlyFormat, int indentation = 0)
{
if (_stopped)
{
return _text + ";";
}
return _text + "{" + RuleSets + "}";
}
}
}
using System.Collections.Generic;
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public interface IRuleContainer
{
List<RuleSet> Declarations { get; }
}
}
\ No newline at end of file
using ExCSS.Model;
using ExCSS.Model.Extensions;
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public class ImportRule : RuleSet, ISupportsMedia
{
private string _href;
private readonly MediaTypeList _media;
public ImportRule()
{
_media = new MediaTypeList();
RuleType = RuleType.Import;
}
public string Href
{
get { return _href; }
set { _href = value; }
}
public MediaTypeList Media
{
get { return _media; }
}
public override string ToString()
{
return ToString(false);
}
public override string ToString(bool friendlyFormat, int indentation = 0)
{
return _media.Count > 0
? string.Format("@import url({0}) {1};", _href, _media).NewLineIndent(friendlyFormat, indentation)
: string.Format("@import url({0});", _href).NewLineIndent(friendlyFormat, indentation);
}
}
}
using ExCSS.Model;
using ExCSS.Model.Extensions;
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public class KeyframeRule : RuleSet, ISupportsDeclarations
{
private string _value;
public KeyframeRule()
{
Declarations = new StyleDeclaration();
RuleType = RuleType.Keyframe;
}
public string Value
{
get { return _value; }
set { _value = value; }
}
public StyleDeclaration Declarations { get; private set; }
public override string ToString()
{
return ToString(false);
}
public override string ToString(bool friendlyFormat, int indentation = 0)
{
return string.Empty.Indent(friendlyFormat, indentation) +
_value +
"{" +
Declarations.ToString(friendlyFormat, indentation) +
"}".NewLineIndent(friendlyFormat, indentation);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using ExCSS.Model.Extensions;
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public class KeyframesRule : RuleSet, IRuleContainer
{
private readonly List<RuleSet> _ruleSets;
private string _identifier;
public KeyframesRule()
{
_ruleSets = new List<RuleSet>();
RuleType = RuleType.Keyframes;
}
public string Identifier
{
get { return _identifier; }
set { _identifier = value; }
}
//TODO change to "keyframes"
public List<RuleSet> Declarations
{
get { return _ruleSets; }
}
public override string ToString()
{
return ToString(false);
}
public override string ToString(bool friendlyFormat, int indentation = 0)
{
var join = friendlyFormat ? "".NewLineIndent(true, indentation) : "";
var declarationList = _ruleSets.Select(d => d.ToString(friendlyFormat, indentation + 1));
var declarations = string.Join(join, declarationList.ToArray());
return ("@keyframes " + _identifier + "{").NewLineIndent(friendlyFormat, indentation) +
declarations.NewLineIndent(friendlyFormat, indentation) +
"}".NewLineIndent(friendlyFormat, indentation);
}
}
}
using System;
using System.Linq;
using ExCSS.Model;
using ExCSS.Model.Extensions;
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public class MediaRule : ConditionalRule, ISupportsMedia
{
private readonly MediaTypeList _media;
public MediaRule()
{
_media = new MediaTypeList();
RuleType = RuleType.Media;
}
public override string Condition
{
get { return _media.MediaType; }
set { _media.MediaType = value; }
}
public MediaTypeList Media
{
get { return _media; }
}
public override string ToString()
{
return ToString(false);
}
public override string ToString(bool friendlyFormat, int indentation = 0)
{
var join = friendlyFormat ? "".NewLineIndent(true, indentation + 1) : "";
var declarationList = RuleSets.Select(d => d.ToString(friendlyFormat, indentation + 1).TrimFirstLine());
var declarations = string.Join(join, declarationList.ToArray());
return ("@media " + _media.MediaType + "{").NewLineIndent(friendlyFormat, indentation) +
declarations.TrimFirstLine().NewLineIndent(friendlyFormat, indentation + 1) +
"}".NewLineIndent(friendlyFormat, indentation);
}
}
}
using ExCSS.Model.Extensions;
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public class NamespaceRule : RuleSet
{
public NamespaceRule()
{
RuleType = RuleType.Namespace;
}
public string Uri { get; set; }
public string Prefix { get; set; }
public override string ToString()
{
return ToString(false);
}
public override string ToString(bool friendlyFormat, int indentation = 0)
{
return string.IsNullOrEmpty(Prefix)
? string.Format("@namespace '{0}';", Uri).NewLineIndent(friendlyFormat, indentation)
: string.Format("@namespace {0} '{1}';", Prefix, Uri).NewLineIndent(friendlyFormat, indentation);
}
}
}
using ExCSS.Model;
using ExCSS.Model.Extensions;
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public class PageRule : RuleSet, ISupportsSelector, ISupportsDeclarations
{
private readonly StyleDeclaration _declarations;
private BaseSelector _selector;
private string _selectorText;
public PageRule()
{
_declarations = new StyleDeclaration();
RuleType = RuleType.Page;
}
internal PageRule AppendRule(Property rule)
{
_declarations.Properties.Add(rule);
return this;
}
public BaseSelector Selector
{
get { return _selector; }
set
{
_selector = value;
_selectorText = value.ToString();
}
}
public StyleDeclaration Declarations
{
get { return _declarations; }
}
public override string ToString()
{
return ToString(false);
}
public override string ToString(bool friendlyFormat, int indentation = 0)
{
var pseudo = string.IsNullOrEmpty(_selectorText)
? ""
: ":" + _selectorText;
var declarations = _declarations.ToString(friendlyFormat, indentation);//.TrimFirstLine();
return ("@page " + pseudo + "{").NewLineIndent(friendlyFormat, indentation) +
declarations +
"}".NewLineIndent(friendlyFormat, indentation);
}
}
}
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public abstract class RuleSet
{
internal RuleSet()
{
RuleType = RuleType.Unknown;
}
public RuleType RuleType { get; set; }
public abstract string ToString(bool friendlyFormat, int indentation = 0);
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public class StyleDeclaration : IList<Property>
{
private readonly List<Property> _properties;
private readonly Func<string> _getter;
private readonly Action<string> _setter;
private bool _blocking;
public StyleDeclaration()
{
var text = string.Empty;
_getter = () => text;
_setter = value => text = value;
_properties = new List<Property>();
}
public string Value
{
get { return _getter(); }
set
{
Update(value);
_setter(value);
}
}
public RuleSet ParentRule { get; set; }
public void Add(Property item)
{
_properties.Add(item);
}
public void Clear()
{
_properties.Clear();
}
public bool Contains(Property item)
{
return _properties.Contains(item);
}
public void CopyTo(Property[] array, int arrayIndex)
{
_properties.CopyTo(array, arrayIndex);
}
public bool Remove(Property item)
{
return _properties.Remove(item);
}
public int IndexOf(Property item)
{
return _properties.IndexOf(item);
}
public void Insert(int index, Property item)
{
_properties.Insert(index, item);
}
public void RemoveAt(int index)
{
_properties.RemoveAt(index);
}
public override string ToString()
{
return ToString(false);
}
public string ToString(bool friendlyFormat, int indentation = 0)
{
var builder = new StringBuilder();
foreach (var property in _properties)
{
if (friendlyFormat)
{
builder.Append(Environment.NewLine);
}
builder.Append(property.ToString(friendlyFormat, indentation+1)).Append(';');
}
return builder.ToString();
}
internal string RemoveProperty(string propertyName)
{
for (var i = 0; i < _properties.Count; i++)
{
if (!_properties[i].Name.Equals(propertyName))
{
continue;
}
var value = _properties[i].Term;
_properties.RemoveAt(i);
Propagate();
return value.ToString();
}
return null;
}
internal string GetPropertyValue(string propertyName)
{
for (var i = 0; i < _properties.Count; i++)
{
if (_properties[i].Name.Equals(propertyName))
{
return _properties[i].Term.ToString();
}
}
return null;
}
public IEnumerator<Property> GetEnumerator()
{
return _properties.GetEnumerator();
}
public Property this[int index]
{
get { return _properties[index]; }
set { _properties[index] = value; }
}
public List<Property> Properties
{
get { return _properties; }
}
public int Count { get { return _properties.Count; } }
public bool IsReadOnly { get { return false; } }
internal StyleDeclaration SetProperty(string propertyName, string propertyValue)
{
//_properties.Add(Parser.ParseDeclaration(propertyName + ":" + propertyValue));
//TODO
Propagate();
return this;
}
internal void Update(string value)
{
if (_blocking)
{
return;
}
var rules = Parser.ParseDeclarations(value ?? string.Empty).Properties;
_properties.Clear();
_properties.AddRange(rules);
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)_properties).GetEnumerator();
}
private void Propagate()
{
_blocking = true;
_setter(ToString());
_blocking = false;
}
}
}
\ No newline at end of file
using System;
using ExCSS.Model;
using ExCSS.Model.Extensions;
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public class StyleRule : RuleSet, ISupportsSelector, ISupportsDeclarations
{
private string _value;
private BaseSelector _selector;
private readonly StyleDeclaration _declarations;
public StyleRule() : this( new StyleDeclaration())
{}
public StyleRule(StyleDeclaration declarations)
{
RuleType = RuleType.Style;
_declarations = declarations;
}
public BaseSelector Selector
{
get { return _selector; }
set
{
_selector = value;
_value = value.ToString();
}
}
public string Value
{
get { return _value; }
set
{
_selector = Parser.ParseSelector(value);
_value = value;
}
}
public StyleDeclaration Declarations
{
get { return _declarations; }
}
public override string ToString()
{
return ToString(false);
}
public override string ToString(bool friendlyFormat, int indentation = 0)
{
return _value.NewLineIndent(friendlyFormat, indentation) +
"{" +
_declarations.ToString(friendlyFormat, indentation) +
"}".NewLineIndent(friendlyFormat, indentation);
}
}
}
using System.Linq;
using ExCSS.Model.Extensions;
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public class SupportsRule : ConditionalRule
{
private string _condition;
public SupportsRule()
{
RuleType = RuleType.Supports;
_condition = string.Empty;
}
public override string Condition
{
get { return _condition; }
set { _condition = value; }
}
public bool IsSupported{ get; set; }
public override string ToString()
{
return ToString(false);
}
public override string ToString(bool friendlyFormat, int indentation = 0)
{
var join = friendlyFormat ? "".NewLineIndent(true, indentation + 1) : "";
var declarationList = RuleSets.Select(d => d.ToString(friendlyFormat, indentation + 1).TrimFirstLine());
var declarations = string.Join(join, declarationList.ToArray());
return ("@supports" + _condition + "{").NewLineIndent(friendlyFormat, indentation) +
declarations.TrimFirstLine().NewLineIndent(friendlyFormat, indentation + 1) +
"}".NewLineIndent(friendlyFormat, indentation);
}
}
}
This diff is collapsed.

// ReSharper disable once CheckNamespace
namespace ExCSS
{
public abstract class BaseSelector
{
public sealed override string ToString()
{
return ToString(false);
}
public abstract string ToString(bool friendlyFormat, int indentation = 0);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment