Beispiel #1
0
        public void CommandParameters_WhenSpecifyingCommandExtension_ExtensionParameterIsParsed()
        {
            var extension = Substitute.For <IHaveCommandLineArgs>();

            extension.When(e => e.UpdateOptions(Arg.Any <OptionSet>()))
            .Do(c =>
            {
                var options = c.Arg <OptionSet>();

                options.Add <string>("newOption=", "description", v => NewOption = v);
            });

            var subject = new CommandParameters(new List <IHaveCommandLineArgs> {
                extension
            }, new MockFileSystem())
            {
                Path = ExpectedPath
            };
            var args = new List <string> {
                "-newOption=test"
            };

            subject.Parse(args);

            Assert.Equal("test", NewOption);
        }
Beispiel #2
0
#pragma warning restore 649

        public void Execute(IEnumerable <string> arguments)
        {
            Tracing.Info("bake - transforming content into a website");

            parameters.Parse(arguments);

            var siteContext = Generator.BuildContext(parameters.Path);

            if (string.IsNullOrWhiteSpace(parameters.Template))
            {
                parameters.DetectFromDirectory(templateEngines.Engines, siteContext);
            }

            var engine = templateEngines[parameters.Template];

            if (engine != null)
            {
                var watch = new Stopwatch();
                watch.Start();
                engine.Initialize();
                engine.Process(siteContext);
                foreach (var t in transforms)
                {
                    t.Transform(siteContext);
                }
                watch.Stop();
                Tracing.Info(string.Format("done - took {0}ms", watch.ElapsedMilliseconds));
            }
            else
            {
                Tracing.Info(String.Format("Cannot find engine for input: '{0}'", parameters.Template));
            }
        }
Beispiel #3
0
#pragma warning restore 649

        public void Execute(IEnumerable <string> arguments)
        {
            Tracing.Info("import - import posts from external source");

            parameters.Parse(arguments);

            if (!Importers.Any(e => String.Equals(e, parameters.ImportType, StringComparison.InvariantCultureIgnoreCase)))
            {
                Tracing.Info("Requested import type not found: {0}", parameters.ImportType);
                return;
            }

            if (string.Equals("wordpress", parameters.ImportType, StringComparison.InvariantCultureIgnoreCase))
            {
                var wordpressImporter = new WordpressImport(fileSystem, parameters.Path, parameters.ImportPath);
                wordpressImporter.Import();
            }
            else if (string.Equals("blogger", parameters.ImportType, StringComparison.InvariantCultureIgnoreCase))
            {
                var bloggerImporter = new BloggerImport(fileSystem, parameters.Path, parameters.ImportPath);
                bloggerImporter.Import();
            }

            Tracing.Info("Import complete");
        }
Beispiel #4
0
#pragma warning restore 649

        public void Execute(IEnumerable <string> arguments)
        {
            Tracing.Info("ingredient - create a new post");

            parameters.Parse(arguments);

            var ingredient = new Ingredient(fileSystem, parameters.NewPostTitle, parameters.Path, parameters.IncludeDrafts);

            ingredient.Create();
        }
Beispiel #5
0
#pragma warning restore 649

        public void Execute(IEnumerable <string> arguments)
        {
            Tracing.Info("bake - transforming content into a website");

            parameters.Parse(arguments);

            var siteContext = Generator.BuildContext(parameters.Path, parameters.DestinationPath, parameters.IncludeDrafts);

            if (parameters.CleanTarget && FileSystem.Directory.Exists(siteContext.OutputFolder))
            {
                FileSystem.Directory.Delete(siteContext.OutputFolder, true);
            }

            if (string.IsNullOrWhiteSpace(parameters.Template))
            {
                parameters.DetectFromDirectory(templateEngines.Engines, siteContext);
            }

            var engine = templateEngines[parameters.Template];

            if (engine != null)
            {
                var watch = new Stopwatch();
                watch.Start();
                engine.Initialize();
                engine.Process(siteContext);
                foreach (var t in transforms)
                {
                    t.Transform(siteContext);
                }

                engine.CompressSitemap(siteContext, FileSystem);

                watch.Stop();
                Tracing.Info(string.Format("done - took {0}ms", watch.ElapsedMilliseconds));
            }
            else
            {
                Tracing.Info(String.Format("Cannot find engine for input: '{0}'", parameters.Template));
            }
        }
Beispiel #6
0
#pragma warning restore 649

        public void Execute(IEnumerable <string> arguments)
        {
            Tracing.Info("create - configure a new site");

            parameters.Parse(arguments);

            var engine = String.IsNullOrWhiteSpace(parameters.Template)
                             ? TemplateEngines.First()
                             : parameters.Template;

            if (!TemplateEngines.Any(e => String.Equals(e, engine, StringComparison.InvariantCultureIgnoreCase)))
            {
                Tracing.Info(String.Format("Requested templating engine not found: {0}", engine));
                return;
            }

            Tracing.Info(string.Format("Using {0} Engine", engine));

            var recipe = new Recipe(fileSystem, engine, parameters.Path, additionalIngredients, parameters.WithProject, parameters.Wiki, parameters.IncludeDrafts);

            recipe.Create();
        }
Beispiel #7
0
        public void Parse_WhenNoParametersSet_MapsPathToCurrentDirectory()
        {
            var args = new List <string>();

            subject.Parse(args);
            Assert.Equal(Directory.GetCurrentDirectory(), subject.Path);
        }
Beispiel #8
0
        public void Parse_WhenSpecifyingTemplateUsingShortParameter_MapsToPath()
        {
            var args = new List <string> {
                "--t", ExpectedTemplate
            };

            subject.Parse(args);
            Assert.Equal(ExpectedTemplate, subject.Template);
        }
 /// <summary>
 /// Convert parameter
 /// </summary>
 /// <param name="originalParameter">Original parameter</param>
 /// <returns></returns>
 public static CommandParameters ConvertParameter(object originalParameter)
 {
     return(CommandParameters.Parse(originalParameter));
 }
Beispiel #10
0
#pragma warning restore 649

        public void Execute(IEnumerable <string> arguments)
        {
            Tracing.Info("taste - testing a site locally");

            parameters.Parse(arguments);

            var context = Generator.BuildContext(parameters.Path, parameters.IncludeDrafts);

            if (string.IsNullOrWhiteSpace(parameters.Template))
            {
                parameters.DetectFromDirectory(templateEngines.Engines, context);
            }

            engine = templateEngines[parameters.Template];

            if (engine == null)
            {
                Tracing.Info(string.Format("template engine {0} not found - (engines: {1})", parameters.Template,
                                           string.Join(", ", templateEngines.Engines.Keys)));

                return;
            }

            engine.Initialize();
            engine.Process(context, skipFileOnError: true);
            foreach (var t in transforms)
            {
                t.Transform(context);
            }
            var watcher = new SimpleFileSystemWatcher();

            watcher.OnChange(parameters.Path, WatcherOnChanged);

            var w = new WebHost(engine.GetOutputDirectory(parameters.Path), new FileContentProvider(), Convert.ToInt32(parameters.Port));

            w.Start();

            var url = string.Format("http://localhost:{0}/", parameters.Port);

            if (parameters.LaunchBrowser)
            {
                Tracing.Info(string.Format("Opening {0} in default browser...", url));
                try
                {
                    Process.Start(url);
                }
                catch (Exception)
                {
                    Tracing.Info(string.Format("Failed to launch {0}.", url));
                }
            }
            else
            {
                Tracing.Info(string.Format("Browse to {0} to view the site.", url));
            }

            Tracing.Info("Press 'Q' to stop the web host...");
            ConsoleKeyInfo key;

            do
            {
                key = Console.ReadKey();
            }while (key.Key != ConsoleKey.Q);
            Console.WriteLine();
        }
Beispiel #11
0
        public void Parse_WhenNoParametersSet_MapsPathToCurrentDirectory()
        {
            var args = new List <string>();

            subject.Parse(args);
            Assert.Equal(FileSystem.Directory.GetCurrentDirectory(), subject.Path);
            Assert.Equal(FileSystem.Path.Combine(subject.Path, "_site"), subject.DestinationPath);
        }