public void LoadTemplates(params Assembly[] assemblies)
        {
            var pattern = new Regex(@"^.*\.Templates\.(.+)\.hbs$", RegexOptions.IgnoreCase);

            foreach (var assembly in assemblies)
            {
                foreach (var resourceName in assembly.GetManifestResourceNames())
                {
                    var match = pattern.Match(resourceName);

                    if (!match.Success)
                    {
                        continue;
                    }

                    var contents = default(string);

                    using (var stream = assembly.GetManifestResourceStream(resourceName))
                        using (var reader = new StreamReader(stream, Encoding.UTF8))
                        {
                            contents = reader.ReadToEnd();
                        }

                    var templateName = match.Groups[1].Value.Replace('.', '/');
                    var template     = new Template(templateName, this.Instance, TemplateSource.CreateForText(contents));

                    this.RegisterTemplate(template, true);
                }
            }
        }
示例#2
0
        public void LoadTemplates(Assembly assembly, string templatePath, string templateNamePrefix)
        {
            var pattern = new Regex($@"^{Regex.Escape(templatePath)}\.(.+)\.hbs$", RegexOptions.IgnoreCase);

            foreach (var resourceName in assembly.GetManifestResourceNames())
            {
                var match = pattern.Match(resourceName);

                if (!match.Success)
                {
                    continue;
                }

                var contents = default(string);

                using (var stream = assembly.GetManifestResourceStream(resourceName))
                    using (var reader = new StreamReader(stream, Encoding.UTF8))
                    {
                        contents = reader.ReadToEnd();
                    }

                var templateName = templateNamePrefix + "/" + match.Groups[1].Value.Replace('.', '/');
                var template     = new Template(templateName, Instance, TemplateSource.CreateForText(contents));

                RegisterTemplate(template, true);
            }
        }
        public void AddTemplate(string name, string templateText, bool overrideExisting = false)
        {
            var template = new Template(name, this.Instance, TemplateSource.CreateForText(templateText));

            this.RegisterTemplate(template, overrideExisting);
        }