private static string WorkaroundTemplateName(string fixtureFileName, string key) { string input = fixtureFileName + "#" + key; // Take last segment of the name by default Match m = Regex.Match(input, "[^/]+$"); if (m.Success) { input = m.Value; } return(CodeUtility.Slug(input)); }
string GenerateSourceTempFile(HxlCompilerSession session, HxlTemplate template) { string name, type; HxlTemplateAttribute.NameOrDefault(template, out name, out type); string tempFile = CodeUtility.Slug(name) + "-" + ((ParsedTemplate)template).Signature + ".cs"; using (var sw = session.CreateText(tempFile)) { HxlCompiler.GenerateOneSourceFile(session, template, sw); } return(session.GetFileName(tempFile)); }
private string GenerateSlug(HxlRenderWorkElement pre) { var line = pre.PreLines.FirstOrDefault(t => !string.IsNullOrEmpty(t)) ?? string.Empty; string result = CodeUtility.Slug("work_" + line.Replace("__self.Write", string.Empty)); if (_slugCache.Add(result)) { return(result); } result += Utility.RandomID(); _slugCache.Add(result); return(result); }
private string SafeNewVariable(string suffix, bool isAttr = false) { string result; suffix = CodeUtility.Slug(suffix); if (stack.Count <= 1) { CurrentOutput.WriteLine(); result = NewVariable("root_" + suffix, isAttr); } else { string variable = stack.Peek(); result = NewVariable(string.Format("{0}_{1}", variable, suffix), isAttr); } return(result); }
private int RunCore() { // TODO Validate options var collectedReferences = LoadReferences(); var settings = new HxlCompilerSettings(); foreach (var reference in collectedReferences) { settings.Assemblies.AddNew(reference.Key, new Uri(reference.Value, UriKind.RelativeOrAbsolute)); } // TODO Support output assembly name // Path.GetFileNameWithoutExtension(Options.OutputFile); foreach (var kvp in Options.Namespaces) { settings.Namespaces.AddNew(kvp.Key, new Uri(kvp.Value)); } var compiler = HxlCompiler.Create(settings); var templates = new List <HxlTemplate>(); foreach (var item in Options.Inputs.EnumerateFiles()) { string file = item.File; _logger.ParsingTemplate(file); // TODO Get access to template builder another way var template = compiler.LoadTemplate(file); var builder = (IHxlTemplateBuilder)template; var viewType = Options.BaseType ?? TypeReference.Parse("Carbonfrost.Commons.Hxl.HxlViewTemplate"); // TODO Drop this- should be using the type selector // TODO Allow type selector to be configurable builder.BaseClass = viewType; if (builder.ModelType == null) { builder.BaseClass = viewType; } else { string text = viewType.OriginalString + "<" + builder.ModelType + ">"; builder.BaseClass = TypeReference.Parse(text); } builder.TemplateName = PathHelper.UnixPath(PathHelper.MakeRelative(item.OriginalGlob, file)); builder.ClassName = CodeUtility.Slug(builder.TemplateName); templates.Add(template); } if (templates.Count == 0) { _logger.NoSourceFilesSpecified(); return(1); } if (Options.NoCompile) { return(GenerateSource(compiler, templates)); } else { return(CompileSource(compiler, templates)); } }
public void Slug_should_escape_leading_digits() { Assert.Equal("_404_hxl", CodeUtility.Slug("404.hxl")); }