public string GenerateSource(HxlCompilerSettings settings = null) { StringWriter sw = new StringWriter(); GenerateSource(sw, settings); return(sw.ToString()); }
public HxlCompilerSession(HxlCompilerSettings settings) { var sessionID = Utility.RandomID(); this.TemporaryDirectory = Path.Combine(WorkDirectory, sessionID); this.SessionID = sessionID; this.Settings = settings; }
public void GenerateSource(TextWriter outputWriter, HxlCompilerSettings settings = null) { if (outputWriter == null) { throw new ArgumentNullException("outputWriter"); } HxlCompiler.Create(settings).GenerateSource(outputWriter, this); }
public static HxlCompiler Create(HxlCompilerSettings settings = null) { if (settings == null) { settings = HxlCompilerSettings.Default; } return(new HxlCompiler(settings)); }
private HxlCompiler(HxlCompilerSettings settings) { settings = settings ?? HxlCompilerSettings.Default; if (settings.IsReadOnly) { this.settings = settings; } else { this.settings = settings.Clone(); this.settings.MakeReadOnly(); } }
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; }
// 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); }
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(); } }
public string GenerateSource(HxlCompilerSettings settings = null) { return(CreateInstance().GenerateSource(settings)); }
public void GenerateSource(TextWriter outputWriter, HxlCompilerSettings settings = null) { // TODO Generate source attachment throw new NotImplementedException(); }