/// <summary> /// Initializes a new instance of the <see cref="TemplateEngineLanguageGenerator"/> class. /// </summary> /// <param name="lgText">lg template text.</param> /// <param name="id">optional label for the source of the templates (used for labeling source of template errors).</param> /// <param name="resourceMapping">template resource loader delegate (locale) -> <see cref="ImportResolverDelegate"/>.</param> public TemplateEngineLanguageGenerator(string lgText, string id, Dictionary <string, IList <IResource> > resourceMapping) { this.Id = id ?? DEFAULTLABEL; var(_, locale) = LGResourceLoader.ParseLGFileName(id); var importResolver = LanguageGeneratorManager.ResourceExplorerResolver(locale, resourceMapping); this.lg = LanguageGeneration.Templates.ParseText(lgText ?? string.Empty, Id, importResolver); }
/// <summary> /// Initializes a new instance of the <see cref="TemplateEngineLanguageGenerator"/> class. /// </summary> /// <param name="filePath">lg template file absolute path.</param> /// <param name="resourceMapping">template resource loader delegate (locale) -> <see cref="ImportResolverDelegate"/>.</param> public TemplateEngineLanguageGenerator(string filePath, Dictionary <string, IList <IResource> > resourceMapping) { filePath = PathUtils.NormalizePath(filePath); this.Id = Path.GetFileName(filePath); var(_, locale) = LGResourceLoader.ParseLGFileName(Id); var importResolver = LanguageGeneratorManager.ResourceExplorerResolver(locale, resourceMapping); this.lg = LanguageGeneration.Templates.ParseFile(filePath, importResolver); }
private static void RegisterSourcemap(LanguageGeneration.Templates templates, Resource resource) { foreach (var template in templates.AllTemplates) { RegisterSourcemap(template, template.SourceRange, template.SourceRange.Source); foreach (var expressionRef in template.Expressions) { RegisterSourcemap(expressionRef, expressionRef.SourceRange, resource.FullName); } } }
/// <summary> /// Initializes a new instance of the <see cref="TemplateEngineLanguageGenerator"/> class. /// </summary> /// <param name="resource">Resource.</param> /// <param name="resourceMapping">template resource loader delegate (locale) -> <see cref="ImportResolverDelegate"/>.</param> public TemplateEngineLanguageGenerator(Resource resource, Dictionary <string, IList <Resource> > resourceMapping) { this.Id = resource.Id; var(_, locale) = LGResourceLoader.ParseLGFileName(Id); var importResolver = LanguageGeneratorManager.ResourceExplorerResolver(locale, resourceMapping); var content = resource.ReadTextAsync().GetAwaiter().GetResult(); var lgResource = new LGResource(Id, resource.FullName, content); this.lg = LanguageGeneration.Templates.ParseResource(lgResource, importResolver); }
/// <summary> /// Initializes a new instance of the <see cref="TemplateEngineLanguageGenerator"/> class. /// </summary> /// <param name="engine">template engine.</param> public TemplateEngineLanguageGenerator(LanguageGeneration.Templates engine = null) { this.lg = engine ?? new LanguageGeneration.Templates(); }
/// <summary> /// Initializes a new instance of the <see cref="TemplateEngineLanguageGenerator"/> class. /// </summary> public TemplateEngineLanguageGenerator() { this.lg = new LanguageGeneration.Templates(); }
/// <summary> /// Initializes a new instance of the <see cref="TemplateEngineLanguageGenerator"/> class. /// </summary> /// <param name="engine">template engine.</param> public TemplateEngineLanguageGenerator(LanguageGeneration.Templates engine = null) { _lg = new Lazy <Task <LanguageGeneration.Templates> >(() => Task.FromResult(engine ?? new LanguageGeneration.Templates())); }