Exemplo n.º 1
0
        public void Render(string templateName)
        {
            var template = new Template(templateName, CodeTemplateManager.Read(templateName));
            var assembly = Template.Emit(new [] { template });
            var content  = template.Render(assembly, ctx =>
            {
                ctx.Registry   = _registry !;
                ctx.ScriptCode = _scriptCode !;
            });

            Console.WriteLine(content);
        }
Exemplo n.º 2
0
        static void RunOptions(Options opts)
        {
            var inputPath  = opts.InputPath !;
            var outputPath = opts.OutputPath !;

            if (!Path.IsPathRooted(inputPath))
            {
                inputPath = Path.Combine(Environment.CurrentDirectory, inputPath);
            }

            if (!Path.IsPathRooted(outputPath))
            {
                outputPath = Path.Combine(Environment.CurrentDirectory, outputPath);
            }

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            //TODO cleanup old *.cs files

            var registryFilePath = Path.Combine(inputPath, "language-subtag-registry");

            if (opts.UpdateRegistry)
            {
                UpdateRegistry(registryFilePath);
            }

            var registry     = Registry.Read(File.OpenRead(registryFilePath));
            var languageCode = new CodeMap(Path.Combine(inputPath, "LanguageCodes.csv"));
            var regionCode   = new CodeMap(Path.Combine(inputPath, "RegionCodes.csv"));
            var scriptCode   = new CodeMap(Path.Combine(inputPath, "ScriptCodes.csv"));
            var variantCode  = new CodeMap(Path.Combine(inputPath, "VariantCodes.csv"));

            var templates = new []
            {
                "Grandfathered",
                "Language.byCode",
                "Language.extLang",
                "Language.list",
                "Language.parsing",
                "LanguageCode",
                "Region.byCode",
                "Region.list",
                "Region.parsing",
                "RegionCode",
                "Script.byCode",
                "Script.list",
                "Script.parsing",
                "ScriptCode",
                "Variant.byCode",
                "Variant.list",
                "Variant.parsing",
                "VariantCode",

                "LanguageTag.Summary",
                "LanguageTag.Ctors",
                "LanguageTag.Take",
            }
            .Select(x => new Template(x, CodeTemplateManager.Read(x)))
            .ToList();

            AddTxt(templates, "Subtag.Summary");

            if (opts.NewCodes)
            {
                languageCode.Update(registry.PrimaryLanguages.Select(x => x.Subtag));
                regionCode.Update(registry.Regions.Select(x => x.Subtag));
                scriptCode.Update(registry.Scripts.Select(x => x.Subtag));
                variantCode.Update(registry.Variants.Select(x => x.Subtag));
            }

            var assembly = Template.Emit(templates);

            foreach (var template in templates)
            {
                var fileName = Path.Combine(outputPath, template.FileName);
                var content  = template.Render(assembly, ctx =>
                {
                    ctx.Registry     = registry;
                    ctx.LanguageCode = languageCode;
                    ctx.RegionCode   = regionCode;
                    ctx.ScriptCode   = scriptCode;
                    ctx.VariantCode  = variantCode;
                });
                File.WriteAllText(fileName, content);
            }
        }
Exemplo n.º 3
0
        private static void AddTxt(List <Template> templates, string name)
        {
            var content = CodeTemplateManager.Read(name);

            templates.Add(new Template(name, content, "txt"));
        }