Permalink
Browse files

Big code layout reorganization with a bit of refactoring.

  • Loading branch information...
1 parent c4d1580 commit 7c9cf61f7d5de5a3acd0dd605c8a530c2cf01561 @nrk committed Jul 17, 2010
@@ -1 +1 @@
-..\..\..\..\..\Main\bin\Debug\ClassInitGenerator.exe ..\..\..\..\..\Main\bin\Debug\IronRuby.Libraries.Hpricot.dll -libraries:IronRuby.Libraries.Hpricot -out:Initializers.Generated.cs
+..\deps\ClassInitGenerator.exe ..\bin\Debug\IronRuby.Hpricot.dll -libraries:IronRuby.Hpricot -out:Initializers.Generated.cs
View
@@ -0,0 +1,19 @@
+using System;
+using IronRuby.Builtins;
+
+namespace IronRuby.Hpricot {
+ public class AttributeData : BasicData {
+ // TODO: Hash or MutableString?
+ private Object _attr;
+
+ public Object Attr {
+ get { return _attr; }
+ set { _attr = value; }
+ }
+
+ // TODO: this smells, will fix later
+ public bool AttrIsNull {
+ get { return _attr == null; }
+ }
+ }
+}
View
@@ -0,0 +1,19 @@
+using System;
+using IronRuby.Builtins;
+
+namespace IronRuby.Hpricot {
+ public class BasicData {
+ private Object _tag;
+ private Object _parent;
+
+ public Object Tag {
+ get { return _tag; }
+ set { _tag = value; }
+ }
+
+ public Object Parent {
+ get { return _parent; }
+ set { _parent = value; }
+ }
+ }
+}
View
@@ -0,0 +1,38 @@
+using System;
+using IronRuby.Builtins;
+
+namespace IronRuby.Hpricot {
+ public class ElementData : AttributeData {
+ // TODO: RubyArray
+ private Object _children;
+ private Object _etag;
+ private Object _raw;
+ private Object _ec;
+ private Int32 _name;
+
+ public Object Children {
+ get { return _children; }
+ set { _children = value; }
+ }
+
+ public Object ETag {
+ get { return _etag; }
+ set { _etag = value; }
+ }
+
+ public Object Raw {
+ get { return _raw; }
+ set { _raw = value; }
+ }
+
+ public Object EC {
+ get { return _ec; }
+ set { _ec = value; }
+ }
+
+ public Int32 Name {
+ get { return _name; }
+ set { _name = value; }
+ }
+ }
+}
View
@@ -0,0 +1,56 @@
+using System;
+using System.Text;
+using IronRuby.Builtins;
+using IronRuby.Runtime;
+using Microsoft.Scripting;
+using Microsoft.Scripting.Runtime;
+
+namespace IronRuby.Hpricot {
+ [RubyClass("BaseEle", DefineIn=typeof(Hpricot))]
+ public abstract class BaseElement : IHpricotDataContainer {
+ protected RubyContext _context;
+ protected BasicData _data;
+
+ public BaseElement(ScannerState state)
+ : this(state.Context, new BasicData()) {
+ }
+
+ public BaseElement(ScannerState state, BasicData data)
+ : this(state.Context, data) {
+ }
+
+ public BaseElement(RubyContext context)
+ : this(context, new BasicData()) {
+ }
+
+ public BaseElement(RubyContext context, BasicData data) {
+ _context = context;
+ _data = data;
+ }
+
+ public T GetData<T>() where T : BasicData {
+ return _data as T;
+ }
+
+ protected virtual MutableString RawString {
+ get {
+ return _data.Tag != null ? _data.Tag as MutableString : MutableString.CreateEmpty();
+ }
+ }
+
+ [RubyMethod("raw_string")]
+ public static MutableString GetRawString(BaseElement/*!*/ self) {
+ return self.RawString;
+ }
+
+ [RubyMethod("parent")]
+ public static Object GetParent(BaseElement/*!*/ self) {
+ return self._data.Parent;
+ }
+
+ [RubyMethod("parent=")]
+ public static void SetParent(BaseElement/*!*/ self, Object/*!*/ parent) {
+ self._data.Parent = parent;
+ }
+ }
+}
View
@@ -0,0 +1,25 @@
+using System;
+using System.Text;
+using System.Diagnostics;
+using IronRuby.Builtins;
+using IronRuby.Runtime;
+using Microsoft.Scripting;
+using Microsoft.Scripting.Runtime;
+
+namespace IronRuby.Hpricot {
+ [RubyClass("BogusETag", Inherits = typeof(ETag), DefineIn = typeof(Hpricot))]
+ public class BogusETag : ETag {
+ public BogusETag(ScannerState state)
+ : this(state.Context) {
+ }
+
+ public BogusETag(RubyContext context)
+ : base(context) {
+ }
+
+ [RubyConstructor]
+ public static new BogusETag Allocator(RubyClass/*!*/ self) {
+ return new BogusETag(self.Context);
+ }
+ }
+}
View
@@ -0,0 +1,40 @@
+using System;
+using System.Text;
+using IronRuby.Builtins;
+using IronRuby.Runtime;
+using Microsoft.Scripting;
+using Microsoft.Scripting.Runtime;
+
+namespace IronRuby.Hpricot {
+ [RubyClass("CData", Inherits = typeof(BaseElement), DefineIn = typeof(Hpricot))]
+ public class CData : BaseElement {
+ public CData(ScannerState state)
+ : this(state.Context) {
+ }
+
+ public CData(RubyContext context)
+ : base(context) {
+ }
+
+ [RubyConstructor]
+ public static CData Allocator(RubyClass/*!*/ self) {
+ return new CData(self.Context);
+ }
+
+ protected override MutableString RawString {
+ get {
+ return MutableString.CreateAscii(String.Format("<![CDATA[{0}]]>", GetContent(this)));
+ }
+ }
+
+ [RubyMethod("content")]
+ public static MutableString GetContent(CData/*!*/ self) {
+ return self._data.Tag as MutableString;
+ }
+
+ [RubyMethod("content=")]
+ public static void SetContent(CData/*!*/ self, Object/*!*/ content) {
+ self._data.Tag = content;
+ }
+ }
+}
View
@@ -0,0 +1,40 @@
+using System;
+using System.Text;
+using IronRuby.Builtins;
+using IronRuby.Runtime;
+using Microsoft.Scripting;
+using Microsoft.Scripting.Runtime;
+
+namespace IronRuby.Hpricot {
+ [RubyClass("Comment", Inherits = typeof(BaseElement), DefineIn = typeof(Hpricot))]
+ public class Comment : BaseElement {
+ public Comment(ScannerState state)
+ : this(state.Context) {
+ }
+
+ public Comment(RubyContext context)
+ : base(context) {
+ }
+
+ [RubyConstructor]
+ public static Comment Allocator(RubyClass/*!*/ self) {
+ return new Comment(self.Context);
+ }
+
+ protected override MutableString RawString {
+ get {
+ return MutableString.CreateAscii(String.Format("<!--{0}-->", GetContent(this)));
+ }
+ }
+
+ [RubyMethod("content")]
+ public static MutableString GetContent(Comment/*!*/ self) {
+ return self._data.Tag as MutableString;
+ }
+
+ [RubyMethod("content=")]
+ public static void SetContent(Comment/*!*/ self, Object/*!*/ content) {
+ self._data.Tag = content;
+ }
+ }
+}
View
@@ -0,0 +1,46 @@
+using System;
+using System.Text;
+using IronRuby.Builtins;
+using IronRuby.Runtime;
+using Microsoft.Scripting;
+using Microsoft.Scripting.Runtime;
+
+namespace IronRuby.Hpricot {
+ [RubyClass("Doc", DefineIn = typeof(Hpricot))]
+ public class Document : IHpricotDataContainer {
+ private RubyContext _context;
+ private ElementData _data;
+
+ public Document(ScannerState state)
+ : this(state.Context) {
+ }
+
+ public Document(RubyContext context)
+ : this(context, new ElementData()) {
+ }
+
+ public Document(RubyContext context, ElementData data) {
+ _context = context;
+ _data = data;
+ }
+
+ public T GetData<T>() where T : BasicData {
+ return _data as T;
+ }
+
+ [RubyConstructor]
+ public static Document Allocator(RubyClass/*!*/ self) {
+ return new Document(self.Context);
+ }
+
+ [RubyMethod("children")]
+ public static Object GetChildren(Document/*!*/ self) {
+ return self._data.Children;
+ }
+
+ [RubyMethod("children=")]
+ public static void SetChildren(Document/*!*/ self, Object/*!*/ children) {
+ self._data.Children = children;
+ }
+ }
+}
@@ -0,0 +1,103 @@
+using System;
+using System.Text;
+using IronRuby.Builtins;
+using IronRuby.Runtime;
+using Microsoft.Scripting;
+using Microsoft.Scripting.Runtime;
+
+namespace IronRuby.Hpricot {
+ [RubyClass("DocType", Inherits = typeof(BaseElement), DefineIn=typeof(Hpricot))]
+ public class DocumentType : BaseElement {
+ private RubySymbol _systemId;
+ private RubySymbol _publicId;
+
+ public DocumentType(ScannerState state)
+ : this(state.Context) {
+ }
+
+ public DocumentType(RubyContext context)
+ : base(context, new AttributeData()) {
+
+ _systemId = context.CreateAsciiSymbol("system_id");
+ _publicId = context.CreateAsciiSymbol("public_id");
+ }
+
+ [RubyConstructor]
+ public static DocumentType Allocator(RubyClass/*!*/ self) {
+ return new DocumentType(self.Context);
+ }
+
+ protected override MutableString RawString {
+ get {
+ MutableString doctype = MutableString.CreateEmpty();
+ doctype.AppendFormat("<!DOCTYPE {0} ", GetTarget(this));
+
+ AttributeData data = _data as AttributeData;
+ if (!data.AttrIsNull) {
+ object publicId = GetPublicId(this);
+ doctype.Append(publicId != null ? String.Format("PUBLIC \"{0}\"", publicId) : "SYSTEM");
+
+ object systemId = GetSystemId(this);
+ if (systemId != null) {
+ doctype.AppendFormat(" \"{0}\"", systemId.ToString().Replace("\"", "\\\""));
+ }
+ }
+
+ doctype.Append(">");
+ return doctype;
+ }
+ }
+
+ [RubyMethod("target")]
+ public static Object GetTarget(DocumentType/*!*/ self) {
+ return self._data.Tag;
+ }
+
+ [RubyMethod("target=")]
+ public static void SetTarget(DocumentType/*!*/ self, Object/*!*/ target) {
+ self._data.Tag = target;
+ }
+
+ [RubyMethod("public_id")]
+ public static Object GetPublicId(DocumentType/*!*/ self) {
+ AttributeData data = self._data as AttributeData;
+ if (data.AttrIsNull) {
+ return null;
+ }
+
+ Object value;
+ (data.Attr as Hash).TryGetValue(self._publicId, out value);
+ return value;
+ }
+
+ [RubyMethod("public_id=")]
+ public static void SetPublicId(RubyContext context/*!*/, DocumentType/*!*/ self, Object/*!*/ publicId) {
+ AttributeData data = self._data as AttributeData;
+ if (data.AttrIsNull) {
+ data.Attr = new Hash(context);
+ }
+ (data.Attr as Hash)[self._publicId] = publicId;
+ }
+
+ [RubyMethod("system_id")]
+ public static Object GetSystemId(DocumentType/*!*/ self) {
+ AttributeData data = self._data as AttributeData;
+ if (data.AttrIsNull) {
+ return null;
+ }
+
+ Object value;
+ (data.Attr as Hash).TryGetValue(self._systemId, out value);
+ return value;
+ }
+
+ [RubyMethod("system_id=")]
+ public static void SetSystemId(RubyContext context/*!*/, DocumentType/*!*/ self, Object/*!*/ systemId) {
+ AttributeData data = self._data as AttributeData;
+ if (data.AttrIsNull) {
+ data.Attr = new Hash(context);
+ }
+ (data.Attr as Hash)[self._systemId] = systemId;
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 7c9cf61

Please sign in to comment.