Esempio n. 1
0
            public override string ToString()
            {
                var sb = new StringBuilder();

                sb.Append("{");
                sb.AppendFormat("\"name\":\"{0}\", \"location\":\"{1}\", \"html\":\"", Name, "-");

                string rawHtml = GetBaseHtmlWO();

                sb.Append(CodeUtility.Escape(rawHtml));
                sb.Append("\" }");
                return(sb.ToString());
            }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
 public static string AppendDomText(string text)
 {
     return(string.Format("__self.Write(\"{0}\");",
                          CodeUtility.Escape(text)));
 }
Esempio n. 4
0
 public static string RandomID()
 {
     byte[] array = new byte[8];
     RandomNumberGenerator.Create().GetBytes(array);
     return(CodeUtility.Slug(Convert.ToBase64String(array)));
 }