mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 19:34:40 +08:00
Recipe parser and related unit tests.
Metadata for blog,cms and minimal recipes in Setup. --HG-- branch : recipe
This commit is contained in:
@@ -1,16 +1,64 @@
|
||||
using Orchard.Localization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Recipes.Models;
|
||||
|
||||
namespace Orchard.Recipes.Services {
|
||||
public class RecipeParser : IRecipeParser {
|
||||
public RecipeParser() {
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
ILogger Logger { get; set; }
|
||||
|
||||
public Recipe ParseRecipe(string recipeText) {
|
||||
return new Recipe();
|
||||
var recipe = new Recipe();
|
||||
|
||||
try {
|
||||
var recipeSteps = new List<RecipeStep>();
|
||||
TextReader textReader = new StringReader(recipeText);
|
||||
var recipeTree = XElement.Load(textReader, LoadOptions.PreserveWhitespace);
|
||||
textReader.Close();
|
||||
|
||||
foreach (var element in recipeTree.Elements()) {
|
||||
switch(element.Name.ToString()) {
|
||||
case "Name":
|
||||
recipe.Name = element.Value;
|
||||
break;
|
||||
case "Description":
|
||||
recipe.Description = element.Value;
|
||||
break;
|
||||
case "Author":
|
||||
recipe.Author = element.Value;
|
||||
break;
|
||||
case "WebSite":
|
||||
recipe.WebSite = element.Value;
|
||||
break;
|
||||
case "Version":
|
||||
recipe.Version = element.Value;
|
||||
break;
|
||||
case "Tags":
|
||||
recipe.Tags = element.Value;
|
||||
break;
|
||||
default:
|
||||
var recipeStep = new RecipeStep {Name = element.Name.ToString(), Step = element};
|
||||
recipeSteps.Add(recipeStep);
|
||||
break;
|
||||
}
|
||||
}
|
||||
recipe.RecipeSteps = recipeSteps;
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Logger.Error(exception, "Parsing recipe failed. Recipe text was: {0}.", recipeText);
|
||||
throw;
|
||||
}
|
||||
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0"?>
|
||||
<Recipe>
|
||||
<Name>blog</Name>
|
||||
<Description>Orchard Blog Recipe</Description>
|
||||
<Author>The Orchard Team</Author>
|
||||
<WebSite>http://orchardproject.net</WebSite>
|
||||
<Tags></Tags>
|
||||
<Version>1.0</Version>
|
||||
</Recipe>
|
||||
|
@@ -1 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0"?>
|
||||
<Recipe>
|
||||
<Name>cms</Name>
|
||||
<Description>Orchard CMS Recipe</Description>
|
||||
<Author>The Orchard Team</Author>
|
||||
<WebSite>http://orchardproject.net</WebSite>
|
||||
<Tags></Tags>
|
||||
<Version>1.0</Version>
|
||||
</Recipe>
|
||||
|
@@ -1 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0"?>
|
||||
<Recipe>
|
||||
<Name>minimal</Name>
|
||||
<Description>A minimal recipe for Orchard devs</Description>
|
||||
<Author>The Orchard Team</Author>
|
||||
<WebSite>http://orchardproject.net</WebSite>
|
||||
<Tags>developer</Tags>
|
||||
<Version>1.0</Version>
|
||||
</Recipe>
|
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Web;
|
||||
@@ -24,7 +23,6 @@ using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Indexing;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Localization.Services;
|
||||
using Orchard.Recipes.Models;
|
||||
using Orchard.Recipes.Services;
|
||||
using Orchard.Reports.Services;
|
||||
using Orchard.Security;
|
||||
|
Reference in New Issue
Block a user