Example #1
0
        public TemplateOptions()
        {
            Usings = new Set<string>(new[] { "System", "System.IO", "System.Web", "NHaml", "NHaml.Utils", "System.Collections.Generic" });
            References = new Set<string>(new[]
            {
                typeof(TemplateEngine).Assembly.Location, // NHaml
                typeof(INotifyPropertyChanged).Assembly.Location, // System
                typeof(HttpUtility).Assembly.Location // System.Web
            });
            AutoClosingTags = new Set<string>(new[] { "META", "IMG", "LINK", "BR", "HR", "INPUT" });
            ReferencedTypeHandles = new List<RuntimeTypeHandle>();
            MarkupRules = new List<MarkupRule>();
            _indentSize = 2;
            _templateBaseType = typeof(Template);
            _templateCompiler = new CSharp3TemplateCompiler();
            TemplateContentProvider = new FileTemplateContentProvider();

            AddRule(new EofMarkupRule());
            AddRule(new MetaMarkupRule());
            AddRule(new DocTypeMarkupRule());
            AddRule(new TagMarkupRule());
            AddRule(new ClassMarkupRule());
            AddRule(new IdMarkupRule());
            AddRule(new EvalMarkupRule());
            AddRule(new EncodedEvalMarkupRule());
            AddRule(new SilentEvalMarkupRule());
            AddRule(new PreambleMarkupRule());
            AddRule(new CommentMarkupRule());
            AddRule(new EscapeMarkupRule());
            AddRule(new PartialMarkupRule());
            AddRule(new NotEncodedEvalMarkupRule());
        }
        public HamlTemplateFactory(string baseTemplatePath)
        {
            var templateOptions = new TemplateOptions();
            templateOptions.EncodeHtml = false;
            templateOptions.AutoRecompile = true;
            templateOptions.IndentSize = 2;
            templateOptions.TemplateBaseType = typeof(HamlTemplate);

            var fileTemplateResolver = new FileTemplateContentProvider();
            fileTemplateResolver.PathSources = new [] { baseTemplatePath }.ToList();

            this.templateEngine = new TemplateEngine(templateOptions) { TemplateContentProvider = fileTemplateResolver };
        }
Example #3
0
        private TemplateOptions buildTemplateOptions(IComponentContext c)
        {
            var settings = c.Resolve<ToastSettings>();

              // setup template content provider
              var tmplProvider = new FileTemplateContentProvider();

              tmplProvider.PathSources.Clear();
              tmplProvider.PathSources.Add("Content/haml");

              // build the template options
              var opts = new TemplateOptions {
            AutoRecompile = true,
            UseTabs = false,
            IndentSize = 2,
            TemplateContentProvider = tmplProvider,
            OutputDebugFiles = settings.DebugMode,
              };

              // add all assemblies required to be referenced by the template code
              var refs = new[] {
            typeof(ToastTemplate).Assembly,
            typeof(ToastSettings).Assembly,
            typeof(System.Web.HttpContext).Assembly
              };

              opts.References.Clear();
              Array.ForEach(refs, opts.AddReference);

              opts.AddReference("Toast.exe");

              // add Toast-specific usings
              var usings = new[] {
            "Toast",
            "Toast.Web",
            "Toast.Web.Tokens"
              };

              Array.ForEach(usings, opts.AddUsing);

              return opts;
        }