Пример #1
0
        public override void TransformHtml(Generator generator, Drawable element, HtmlNode node)
        {
            var document = node.OwnerDocument;
            var gridContainer = document.CreateElement("div");
            var style = element.Style;

            // TODO: Move this to GeneratorBlock
            if (style != null)
                gridContainer.Attributes.Add(document.CreateAttribute("class", style));

            // Add our created element to the parent.
            node.AppendChild(gridContainer);

            // IMPORTANT: Unless you know better, always call this at the end. Otherwise the Content of this
            // node will NOT be turned into HTML.
            base.TransformHtml(generator, element, gridContainer);
        }
Пример #2
0
        public override void TransformHtml(Generator generator, Drawable element, HtmlNode node)
        {
            var document = node.OwnerDocument;
            var buttonContainer = document.CreateElement("a");
            var style = element.Style;

            // TODO: Move this to GeneratorBlock
            if (style != null)
                buttonContainer.Attributes.Add(document.CreateAttribute("class", style));

            // Add our created element to the parent.
            node.AppendChild(buttonContainer);

            // For now we'll just add "Hello world" if a Button contains no content.
            if (((Button)element).Text == null)
                buttonContainer.AppendChild(document.CreateTextNode("Browse"));

            // IMPORTANT: Unless you know better, always call this at the end. Otherwise the Content of this
            // node will NOT be turned into HTML.
            base.TransformHtml(generator, element, buttonContainer);
        }
        public override void TransformHtml(Generator generator, Drawable element, HtmlNode node)
        {
            // TODO: Flesh this out. Rather bare bones at the moment.
            var document = node.OwnerDocument;
            var newElement = document.CreateElement("div");
            var style = element.Style;

            // TODO: Move this to GeneratorBlock, or not, at least not for this GeneratorBlock impl.
            // Reason being is that I do some ContentProperty voodoo, which isnt appropriate for us here.
            if (style != null)
                newElement.Attributes.Add(document.CreateAttribute("class", style));

            // Add our created element to the parent.
            node.AppendChild(newElement);

            // This is where special handling of Content comes in. I simply loop through the StackPanel and call generate.
            // TODO: Try to generalize this and move it to GeneratorBlock. Will clean things up a bit.
            foreach (var child in ((StackPanel)element).Children)
            {
                generator.Generate(newElement, child);
            }
        }
Пример #4
0
        /// <summary>
        /// Given a Pantheon Drawable, produces a node of HTML.
        /// </summary>
        /// <param name="generator">The current Generator.</param>
        /// <param name="element">The current Pantheon Drawable.</param>
        /// <param name="node">The current node. NOTE: If you're calling base.TransformHtml(..) be sure to call it
        /// with a child node you create using the HTMLAgility document. See: ButtonGeneratorBlock.</param>
        public virtual void TransformHtml(Generator generator, Drawable element, HtmlNode node)
        {
            // Do some reflection to get the [ContentProperty] from a Drawable and call Generator.Generate(..) on it.
            var axtt = element.GetType().CustomAttributes.Where(a => a.AttributeType == typeof(ContentPropertyAttribute)).SingleOrDefault();
            if (axtt.ConstructorArguments.Count > 0)
            {
                // Get the Property name by scanning the Attribute for a Constuctor arg.
                var propName = (string)axtt.ConstructorArguments[0].Value;

                // Make sure our element actually contains the Property.
                // TODO: Does ContentPropertyAttribute make this check redundant?
                if (element.GetType().GetProperty(propName) != null)
                {
                    // TODO: Cache to reduce the double check on GetProperty(..)
                    var returnedType = element.GetType().GetProperty(propName).GetValue(element);

                    // If the type is a Drawable call generate.
                    // There will be cases where its an IList<...> but that's up to the implementer to deal with
                    // See StackPanelGeneratorBlock
                    if (returnedType is Drawable)
                        generator.Generate(node, (Drawable)returnedType);
                }
            }
        }