Exemplo n.º 1
0
        public void CreateAttribute_using_late_bound_instancing()
        {
            var fac = new DomNodeFactory(
                new FDomNodeTypeProvider((name) => typeof(PAttribute))
                );

            Assert.IsInstanceOf <PAttribute>(fac.CreateAttribute("myname"));
        }
Exemplo n.º 2
0
        public void CreateAttribute_using_late_bound_instancing_has_name()
        {
            var fac = new DomNodeFactory(
                new FDomNodeTypeProvider((name) => typeof(PAttributeWithName))
                );

            Assert.IsInstanceOf <PAttributeWithName>(fac.CreateAttribute("expected"));
            Assert.Equal("expected", fac.CreateAttribute("expected").LocalName);
        }
Exemplo n.º 3
0
        // TODO These should probably be init from machine universal config

        static HxlCompilerSettings DefaultCompilerSettings()
        {
            var result = new HxlCompilerSettings(null);

            result.Assemblies.AddMany(HxlAssemblyCollection.System);
            result.Assemblies.AddMany(HxlAssemblyCollection.Hxl);

            var globalFactory = DomNodeFactory.Compose(
                HxlDomNodeFactory.Compiler,
                new ProviderDomNodeFactory());

            result.NodeFactories.AddNew("global", globalFactory);

            return(result);
        }
Exemplo n.º 4
0
        public ParsedTemplate(string text, string name, HxlCompilerSettings settings)
        {
            _metrics = Metrics.ForTemplateParsing();
            _metrics.StartParsing();
            _sourceDocument = HtmlDocumentFragment.Parse(text, new HtmlReaderSettings {
                Mode = HtmlTreeBuilderMode.Xml
            });
            _metrics.EndParsing(name, text.Length);

            _settings    = settings;
            _nodeFactory = DomNodeFactory.Compose(
                HxlDomNodeFactory.Compiler,
                _settings.NodeFactories,
                new InvalidFactory());

            Signature = string.Concat(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(text))
                                      .Take(8)
                                      .Select(b => b.ToString("x2"))
                                      );

            if (string.IsNullOrEmpty(name))
            {
                this.TemplateName = "Template" + this.Signature;
            }
            else
            {
                this.TemplateName = CodeUtility.Slug(name);
            }

            this.Namespace = "Generated";
            this.ClassName = this.TemplateName;

            using (UsingNamespaceResolver()) {
                this._preparedDocument = PrepareDocument();
            }
        }