示例#1
0
        internal static void GenerateOneSourceFile(HxlCompilerSession session,
                                                   HxlTemplate template,
                                                   TextWriter outputWriter)
        {
            // TODO Soft check here instead of casting
            IHxlEmittableTemplate t = (IHxlEmittableTemplate)template;

            t.GenerateSource(session, outputWriter);
        }
示例#2
0
        internal static void NameOrDefault(HxlTemplate template, out string name, out string type)
        {
            var builder = template as IHxlTemplateBuilder;

            NameOrDefault(template.GetType(), out name, out type);

            if (builder != null && !string.IsNullOrEmpty(builder.TemplateName))
            {
                name = builder.TemplateName;
            }
        }
示例#3
0
        internal static HxlTemplateContext WithData(HxlTemplate owner, IEnumerable <KeyValuePair <string, object> > variables)
        {
            var tc = new HxlTemplateContext(owner);

            if (variables != null)
            {
                foreach (var e in variables)
                {
                    tc.Data.Add(e.Key, e.Value);
                }
            }
            return(tc);
        }
        public HxlTemplate CreateTemplate(string templateName, string templateType, IServiceProvider serviceProvider)
        {
            if (templateName == null)
            {
                throw new ArgumentNullException("templateName");
            }
            if (string.IsNullOrEmpty(templateName))
            {
                throw Failure.EmptyString("templateName");
            }

            var         info   = RequireMap().FindTemplate(templateName, templateType);
            HxlTemplate result = null;
            Type        type   = null;

            if (info != null)
            {
                type = info.CompiledType;

                try {
                    result = (HxlTemplate)Activator.CreateInstance(type);
                } catch (Exception ex) {
                    Traceables.ReflectedTemplateFactoryCreateTemplateError(
                        assembly,
                        type,
                        templateName,
                        ex);

                    throw;
                }
            }

            Traceables.ReflectedTemplateFactoryCreateTemplate(
                assembly,
                type,
                templateName,
                result != null);
            return(result);
        }
示例#5
0
        public static void Render(string inputFile, string outputFile, IEnumerable <KeyValuePair <string, object> > variables = null)
        {
            HxlTemplate template = HxlTemplate.FromFile(inputFile);

            template.Transform(outputFile, variables);
        }
示例#6
0
        public static string RenderText(string inputFile, IEnumerable <KeyValuePair <string, object> > variables = null)
        {
            HxlTemplate template = HxlTemplate.FromFile(inputFile);

            return(template.TransformText(variables));
        }
示例#7
0
 public static bool TryParse(string text, out HxlTemplate result)
 {
     result = Parse(text);
     return(true);
 }