示例#1
0
        private void EnsurePartialTemplate(string template)
        {
            List <string> partialTemplateCheck = new List <string>();

            partialTemplateCheck.Add(template);

            for (int i = 0; i < partialTemplateCheck.Count; i++)
            {
                var partials = PartialRegex.Matches(partialTemplateCheck[i]);
                foreach (Match partial in partials)
                {
                    var value = partial.Value;

                    var name = value.Substring(value.IndexOf("{{> ") + 4, value.IndexOf("}}") - value.IndexOf("{{> ") - 4);
                    if (name.IndexOf(' ') > -1)
                    {
                        name = name.Substring(0, name.IndexOf(' '));
                    }

                    if (!_engine.PartialExists(name))
                    {
                        var partialTemplate = _provider.GetTemplate(name);

                        if (string.IsNullOrEmpty(partialTemplate))
                        {
                            throw new Exception("Partial " + name + " is empty, found in: \n" + template);
                        }

                        partialTemplateCheck.Add(partialTemplate);
                        _engine.PartialCompile(name, partialTemplate);
                    }
                }
            }
        }
示例#2
0
        private void EnsurePartial(string template)
        {
            List <string> partialTemplateCheck = new List <string>();

            partialTemplateCheck.Add(template);
            for (int i = 0; i < partialTemplateCheck.Count; i++)
            {
                var partials = PartialRegex.Matches(partialTemplateCheck[i]);
                foreach (Match partial in partials)
                {
                    var value = partial.Value;

                    var name = value.Substring(value.IndexOf("{{> ") + 4, value.IndexOf("}}") - value.IndexOf("{{> ") - 4);
                    if (name.IndexOf(' ') > -1)
                    {
                        name = name.Substring(0, name.IndexOf(' '));
                    }

                    if (!_handlebars.PartialExists(name))
                    {
                        Console.WriteLine("Compiling parital \"" + name + "\"");
                        var path = Path.Combine(_root, name + ".handlebars");
                        if (!File.Exists(path))
                        {
                            path = Path.Combine(_root, name + ".hbs");
                        }

                        var partial_template = CompactTemplate(File.ReadAllText(path, System.Text.Encoding.UTF8));
                        _handlebars.PartialCompile(name, partial_template);
                    }
                }
            }
        }
        private void EnsurePartialAvailable(string template)
        {
            List <string> partialTemplateCheck = new List <string>();

            partialTemplateCheck.Add(template);
            for (int i = 0; i < partialTemplateCheck.Count; i++)
            {
                var partials = PartialRegex.Matches(partialTemplateCheck[i]);
                foreach (Match partial in partials)
                {
                    var value = partial.Value;

                    var name = value.Substring(value.IndexOf("{{> ") + 4, value.IndexOf("}}") - value.IndexOf("{{> ") - 4);
                    if (name.IndexOf(' ') > -1)
                    {
                        name = name.Substring(0, name.IndexOf(' '));
                    }

                    if (!_handlebars.PartialExists(name))
                    {
                        var partialPath = Path.Combine(HandlebarsProxyConfiguration.Instance.Directory +
                                                       "\\template",
                                                       name.Replace("/", "\\") + ".handlebars");

                        if (!File.Exists(partialPath))
                        {
                            partialPath = Path.Combine(HandlebarsProxyConfiguration.Instance.Directory +
                                                       "\\template",
                                                       name.Replace("/", "\\") + ".hbs");
                        }

                        var partialTemplate = File.ReadAllText(partialPath);

                        if (string.IsNullOrEmpty(partialTemplate))
                        {
                            throw new Exception("Partial " + name + " is empty, found in: \n" + template);
                        }

                        partialTemplateCheck.Add(partialTemplate);
                        _handlebars.PartialCompile(name, partialTemplate);
                    }
                }
            }
        }