Ejemplo n.º 1
0
        public string GenerateSource(HxlCompilerSettings settings = null)
        {
            StringWriter sw = new StringWriter();

            GenerateSource(sw, settings);
            return(sw.ToString());
        }
Ejemplo n.º 2
0
        public HxlCompilerSession(HxlCompilerSettings settings)
        {
            var sessionID = Utility.RandomID();

            this.TemporaryDirectory = Path.Combine(WorkDirectory, sessionID);
            this.SessionID          = sessionID;
            this.Settings           = settings;
        }
Ejemplo n.º 3
0
        public void GenerateSource(TextWriter outputWriter, HxlCompilerSettings settings = null)
        {
            if (outputWriter == null)
            {
                throw new ArgumentNullException("outputWriter");
            }

            HxlCompiler.Create(settings).GenerateSource(outputWriter, this);
        }
Ejemplo n.º 4
0
        public static HxlCompiler Create(HxlCompilerSettings settings = null)
        {
            if (settings == null)
            {
                settings = HxlCompilerSettings.Default;
            }

            return(new HxlCompiler(settings));
        }
Ejemplo n.º 5
0
 private HxlCompiler(HxlCompilerSettings settings)
 {
     settings = settings ?? HxlCompilerSettings.Default;
     if (settings.IsReadOnly)
     {
         this.settings = settings;
     }
     else
     {
         this.settings = settings.Clone();
         this.settings.MakeReadOnly();
     }
 }
Ejemplo n.º 6
0
        public HxlCompilerSettings(HxlCompilerSettings settings)
        {
            if (settings == null)
            {
                return;
            }

            this.debug = settings.Debug;
            this.emitTemplateFactory = settings.emitTemplateFactory;
            this.namespaces.AddMany(settings.namespaces);
            this.factories.AddMany(settings.factories);
            this._assemblies.AddMany(settings._assemblies);
            this._defaultBaseClass = settings.TemplateBaseClass;
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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();
            }
        }
Ejemplo n.º 9
0
 public string GenerateSource(HxlCompilerSettings settings = null)
 {
     return(CreateInstance().GenerateSource(settings));
 }
Ejemplo n.º 10
0
 public void GenerateSource(TextWriter outputWriter, HxlCompilerSettings settings = null)
 {
     // TODO Generate source attachment
     throw new NotImplementedException();
 }