mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Removed unnecessary YamlService.
Instead we can use the NuGet package directly.
This commit is contained in:
parent
010b1884bd
commit
fef3fbfbe7
@ -320,7 +320,6 @@
|
|||||||
<Compile Include="Localization\DateTimePartsTests.cs" />
|
<Compile Include="Localization\DateTimePartsTests.cs" />
|
||||||
<Compile Include="Localization\DefaultDateLocalizationServicesTests.cs" />
|
<Compile Include="Localization\DefaultDateLocalizationServicesTests.cs" />
|
||||||
<Compile Include="Localization\DefaultDateFormatterTests.cs" />
|
<Compile Include="Localization\DefaultDateFormatterTests.cs" />
|
||||||
<Compile Include="Services\YamlParserTests.cs" />
|
|
||||||
<Compile Include="Stubs\StubApplicationEnvironment.cs" />
|
<Compile Include="Stubs\StubApplicationEnvironment.cs" />
|
||||||
<Compile Include="Stubs\StubCultureSelector.cs" />
|
<Compile Include="Stubs\StubCultureSelector.cs" />
|
||||||
<Compile Include="Localization\TestHelpers.cs" />
|
<Compile Include="Localization\TestHelpers.cs" />
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Orchard.Services;
|
|
||||||
|
|
||||||
namespace Orchard.Tests.Services {
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
public class YamlParserTests {
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ShouldConvertYamlToWellknowType() {
|
|
||||||
var parser = new YamlParser();
|
|
||||||
var yaml = SampleYamlDocument;
|
|
||||||
|
|
||||||
var order = parser.Deserialize<Order>(yaml);
|
|
||||||
|
|
||||||
Assert.AreEqual("Nikola", order.Customer.FirstName);
|
|
||||||
Assert.AreEqual(2, order.Items.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ShouldConvertYamlToDynamic()
|
|
||||||
{
|
|
||||||
var parser = new YamlParser();
|
|
||||||
var yaml = SampleYamlDocument;
|
|
||||||
|
|
||||||
var order = parser.Deserialize(yaml);
|
|
||||||
|
|
||||||
Assert.AreEqual("Nikola", (string)order.Customer.FirstName);
|
|
||||||
Assert.AreEqual(2, (int)order.Items.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Order {
|
|
||||||
public DateTime Date { get; set; }
|
|
||||||
public Customer Customer { get; set; }
|
|
||||||
public IList<OrderItem> Items { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class OrderItem {
|
|
||||||
public string Product { get; set; }
|
|
||||||
public int Quantity { get; set; }
|
|
||||||
public decimal Price { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Customer {
|
|
||||||
public string FirstName { get; set; }
|
|
||||||
public string LastName { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private const string SampleYamlDocument =
|
|
||||||
@"
|
|
||||||
Date: 1916-04-01
|
|
||||||
Customer:
|
|
||||||
FirstName: Nikola
|
|
||||||
LastName: Tesla
|
|
||||||
Items:
|
|
||||||
- Product: Bulb
|
|
||||||
Quantity: 1
|
|
||||||
Price: 1.46
|
|
||||||
|
|
||||||
- Product: Wire
|
|
||||||
Quantity: 1
|
|
||||||
Price: 0.32
|
|
||||||
";
|
|
||||||
}
|
|
||||||
}
|
|
@ -102,6 +102,14 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="YamlDotNet, Version=3.8.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\..\packages\YamlDotNet.3.8.0\lib\net35\YamlDotNet.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="YamlDotNet.Dynamic, Version=3.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\..\packages\YamlDotNet.Dynamic.3.2.3\lib\net40\YamlDotNet.Dynamic.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Assets\JavaScript\Models\RecycleBin.js" />
|
<Content Include="Assets\JavaScript\Models\RecycleBin.js" />
|
||||||
|
@ -17,10 +17,10 @@ using Orchard.Layouts.Services;
|
|||||||
using Orchard.Layouts.Shapes;
|
using Orchard.Layouts.Shapes;
|
||||||
using Orchard.Layouts.ViewModels;
|
using Orchard.Layouts.ViewModels;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Services;
|
|
||||||
using Orchard.Themes.Services;
|
using Orchard.Themes.Services;
|
||||||
using Orchard.Tokens;
|
using Orchard.Tokens;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
using YamlDotNet.Dynamic;
|
||||||
|
|
||||||
namespace Orchard.Layouts.Providers {
|
namespace Orchard.Layouts.Providers {
|
||||||
[OrchardFeature("Orchard.Layouts.Snippets")]
|
[OrchardFeature("Orchard.Layouts.Snippets")]
|
||||||
@ -34,7 +34,6 @@ namespace Orchard.Layouts.Providers {
|
|||||||
private readonly Work<ICurrentThemeShapeBindingResolver> _currentThemeShapeBindingResolver;
|
private readonly Work<ICurrentThemeShapeBindingResolver> _currentThemeShapeBindingResolver;
|
||||||
private readonly Work<ITokenizer> _tokenizer;
|
private readonly Work<ITokenizer> _tokenizer;
|
||||||
private readonly IWorkContextAccessor _wca;
|
private readonly IWorkContextAccessor _wca;
|
||||||
private readonly Work<IYamlParser> _yamlParser;
|
|
||||||
|
|
||||||
public SnippetElementHarvester(
|
public SnippetElementHarvester(
|
||||||
IWorkContextAccessor workContextAccessor,
|
IWorkContextAccessor workContextAccessor,
|
||||||
@ -44,8 +43,7 @@ namespace Orchard.Layouts.Providers {
|
|||||||
Work<IElementFactory> elementFactory,
|
Work<IElementFactory> elementFactory,
|
||||||
Work<IShapeDisplay> shapeDisplay,
|
Work<IShapeDisplay> shapeDisplay,
|
||||||
Work<ITokenizer> tokenizer,
|
Work<ITokenizer> tokenizer,
|
||||||
Work<ICurrentThemeShapeBindingResolver> currentThemeShapeBindingResolver,
|
Work<ICurrentThemeShapeBindingResolver> currentThemeShapeBindingResolver) {
|
||||||
Work<IYamlParser> yamlParser) {
|
|
||||||
|
|
||||||
_shapeFactory = shapeFactory;
|
_shapeFactory = shapeFactory;
|
||||||
_siteThemeService = siteThemeService;
|
_siteThemeService = siteThemeService;
|
||||||
@ -54,7 +52,6 @@ namespace Orchard.Layouts.Providers {
|
|||||||
_shapeDisplay = shapeDisplay;
|
_shapeDisplay = shapeDisplay;
|
||||||
_tokenizer = tokenizer;
|
_tokenizer = tokenizer;
|
||||||
_currentThemeShapeBindingResolver = currentThemeShapeBindingResolver;
|
_currentThemeShapeBindingResolver = currentThemeShapeBindingResolver;
|
||||||
_yamlParser = yamlParser;
|
|
||||||
_wca = workContextAccessor;
|
_wca = workContextAccessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +146,7 @@ namespace Orchard.Layouts.Providers {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
var yaml = File.ReadAllText(paramsFileName);
|
var yaml = File.ReadAllText(paramsFileName);
|
||||||
var snippetConfig = _yamlParser.Value.Deserialize(yaml);
|
var snippetConfig = Deserialize(yaml);
|
||||||
var fieldsConfig = snippetConfig.Fields != null ? snippetConfig.Fields.Children : new dynamic[0];
|
var fieldsConfig = snippetConfig.Fields != null ? snippetConfig.Fields.Children : new dynamic[0];
|
||||||
var descriptor = new SnippetDescriptor();
|
var descriptor = new SnippetDescriptor();
|
||||||
|
|
||||||
@ -202,5 +199,9 @@ namespace Orchard.Layouts.Providers {
|
|||||||
var markup = File.ReadAllText(localFileName);
|
var markup = File.ReadAllText(localFileName);
|
||||||
return markup.Contains("@Html.SnippetField");
|
return markup.Contains("@Html.SnippetField");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private dynamic Deserialize(string yaml) {
|
||||||
|
return new DynamicYaml(yaml);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,4 +7,6 @@
|
|||||||
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net452" />
|
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net452" />
|
||||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
|
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
|
||||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
|
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
|
||||||
|
<package id="YamlDotNet" version="3.8.0" targetFramework="net452" />
|
||||||
|
<package id="YamlDotNet.Dynamic" version="3.2.3" targetFramework="net452" />
|
||||||
</packages>
|
</packages>
|
@ -170,10 +170,6 @@
|
|||||||
<HintPath>..\packages\YamlDotNet.3.8.0\lib\net35\YamlDotNet.dll</HintPath>
|
<HintPath>..\packages\YamlDotNet.3.8.0\lib\net35\YamlDotNet.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="YamlDotNet.Dynamic, Version=3.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\packages\YamlDotNet.Dynamic.3.2.3\lib\net40\YamlDotNet.Dynamic.dll</HintPath>
|
|
||||||
<Private>True</Private>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ContentManagement\Extensions\DriverResultExtensions.cs" />
|
<Compile Include="ContentManagement\Extensions\DriverResultExtensions.cs" />
|
||||||
@ -427,9 +423,7 @@
|
|||||||
<Compile Include="Services\ClientHostAddressAccessor.cs" />
|
<Compile Include="Services\ClientHostAddressAccessor.cs" />
|
||||||
<Compile Include="Services\DefaultJsonConverter.cs" />
|
<Compile Include="Services\DefaultJsonConverter.cs" />
|
||||||
<Compile Include="Services\IClientHostAddressAccessor.cs" />
|
<Compile Include="Services\IClientHostAddressAccessor.cs" />
|
||||||
<Compile Include="Services\IYamlParser.cs" />
|
|
||||||
<Compile Include="Services\IJsonConverter.cs" />
|
<Compile Include="Services\IJsonConverter.cs" />
|
||||||
<Compile Include="Services\YamlParser.cs" />
|
|
||||||
<Compile Include="Settings\CurrentSiteWorkContext.cs" />
|
<Compile Include="Settings\CurrentSiteWorkContext.cs" />
|
||||||
<Compile Include="Settings\ResourceDebugMode.cs" />
|
<Compile Include="Settings\ResourceDebugMode.cs" />
|
||||||
<Compile Include="Tasks\Locking\Services\DistributedLockSchemaBuilder.cs" />
|
<Compile Include="Tasks\Locking\Services\DistributedLockSchemaBuilder.cs" />
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
namespace Orchard.Services {
|
|
||||||
/// <summary>
|
|
||||||
/// Provides methods to deserialize objects from YAML documents.
|
|
||||||
/// </summary>
|
|
||||||
public interface IYamlParser : IDependency {
|
|
||||||
/// <summary>
|
|
||||||
/// Deserializes a YAML document to a dynamic object.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="yaml">The YAML document to deserialize.</param>
|
|
||||||
/// <returns>The deserialized object.</returns>
|
|
||||||
dynamic Deserialize(string yaml);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deserializes a YAML document to a specific object.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The type of the object to deserialize.</typeparam>
|
|
||||||
/// <param name="yaml">The YAML document to deserialize.</param>
|
|
||||||
/// <returns>The deserialized object.</returns>
|
|
||||||
T Deserialize<T>(string yaml);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
using System.IO;
|
|
||||||
using YamlDotNet.Dynamic;
|
|
||||||
using YamlDotNet.Serialization;
|
|
||||||
using YamlDotNet.Serialization.NamingConventions;
|
|
||||||
|
|
||||||
namespace Orchard.Services {
|
|
||||||
public class YamlParser : IYamlParser {
|
|
||||||
public dynamic Deserialize(string yaml) {
|
|
||||||
return new DynamicYaml(yaml);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Deserialize<T>(string yaml) {
|
|
||||||
var deserializer = new Deserializer(namingConvention: new PascalCaseNamingConvention(), ignoreUnmatched: true);
|
|
||||||
using (var reader = new StringReader(yaml)) {
|
|
||||||
return deserializer.Deserialize<T>(reader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,5 +18,4 @@
|
|||||||
<package id="NHibernate" version="4.0.1.4000" targetFramework="net452" />
|
<package id="NHibernate" version="4.0.1.4000" targetFramework="net452" />
|
||||||
<package id="Owin" version="1.0" targetFramework="net452" />
|
<package id="Owin" version="1.0" targetFramework="net452" />
|
||||||
<package id="YamlDotNet" version="3.8.0" targetFramework="net452" />
|
<package id="YamlDotNet" version="3.8.0" targetFramework="net452" />
|
||||||
<package id="YamlDotNet.Dynamic" version="3.2.3" targetFramework="net452" />
|
|
||||||
</packages>
|
</packages>
|
Loading…
Reference in New Issue
Block a user