Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved ITextResource and DefaultTextResource into Nancy to look for re…

…sx files by default
  • Loading branch information...
commit 0aa9beded23aca812ffa44efd8cffe48109f77bb 1 parent 664ca78
@jchannon jchannon authored
View
45 src/Nancy.Demo.Localization/DefaultTextResource.cs
@@ -1,45 +0,0 @@
-namespace Nancy.Demo.Localization
-{
-
- using Nancy.ViewEngines.Razor;
- using System.Collections;
- using System.Collections.Generic;
-
- public class DefaultTextResource : ITextResource
- {
- private readonly IDictionary<string, IDictionary<string, string>> dictionary;
-
- public DefaultTextResource()
- {
- this.dictionary = new Dictionary<string, IDictionary<string, string>>();
- this.dictionary.Add("Greeting", new Dictionary<string, string>() { { "en-GB", "Hello Sir" }, { "de-DE", "Guten Tag" }, { "en-US", "Howdy" } });
- }
-
- public IEnumerator<KeyValuePair<string, IDictionary<string,string>>> GetEnumerator()
- {
- return dictionary.GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- public string this[string key, NancyContext context]
- {
- get
- {
- if (!dictionary.ContainsKey(key))
- {
- return null;
-
- }
-
- return dictionary[key].ContainsKey(context.Culture.Name) ? dictionary[key][context.Culture.Name] : null;
- }
-
- set { dictionary[key][context.Culture.Name] = value; }
- }
-
- }
-}
View
14 src/Nancy.Demo.Localization/Nancy.Demo.Localization.csproj
@@ -60,9 +60,13 @@
<Content Include="Web.config" />
</ItemGroup>
<ItemGroup>
- <Compile Include="DefaultTextResource.cs" />
<Compile Include="Modules\HomeModule.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Resources\Text.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>Text.resx</DependentUpon>
+ </Compile>
</ItemGroup>
<ItemGroup>
<Content Include="Views\Index.cshtml" />
@@ -77,6 +81,13 @@
</None>
</ItemGroup>
<ItemGroup>
+ <EmbeddedResource Include="Resources\Text.de-DE.resx" />
+ <EmbeddedResource Include="Resources\Text.resx">
+ <Generator>PublicResXFileCodeGenerator</Generator>
+ <LastGenOutput>Text.Designer.cs</LastGenOutput>
+ </EmbeddedResource>
+ </ItemGroup>
+ <ItemGroup>
<ProjectReference Include="..\Nancy.Hosting.Aspnet\Nancy.Hosting.Aspnet.csproj">
<Project>{15b7f794-0bb2-4b66-ad78-4a951f1209b2}</Project>
<Name>Nancy.Hosting.Aspnet</Name>
@@ -90,7 +101,6 @@
<Name>Nancy</Name>
</ProjectReference>
</ItemGroup>
- <ItemGroup />
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
View
3  src/Nancy.ViewEngines.Razor/HtmlHelpers.cs
@@ -95,6 +95,9 @@ public IHtmlString AntiForgeryToken()
return new NonEncodedHtmlString(String.Format("<input type=\"hidden\" name=\"{0}\" value=\"{1}\"/>", tokenKeyValue.Key, tokenKeyValue.Value));
}
+ /// <summary>
+ /// Returns current culture name
+ /// </summary>
public string CurrentLocale
{
get { return this.RenderContext.Context.Culture.Name; }
View
9 src/Nancy.ViewEngines.Razor/ITextResource.cs
@@ -1,9 +0,0 @@
-namespace Nancy.ViewEngines.Razor
-{
- using System.Collections.Generic;
-
- public interface ITextResource : IEnumerable<KeyValuePair<string, IDictionary<string, string>>>
- {
- string this[string key, NancyContext context] { get; set; }
- }
-}
View
1  src/Nancy.ViewEngines.Razor/Nancy.ViewEngines.Razor.csproj
@@ -113,7 +113,6 @@
<Compile Include="HelperResult.cs" />
<Compile Include="HtmlHelpers.cs" />
<Compile Include="IHtmlString.cs" />
- <Compile Include="ITextResource.cs" />
<Compile Include="IRazorConfiguration.cs" />
<Compile Include="IRazorViewRenderer.cs" />
<Compile Include="ModelFinder.cs" />
View
6 src/Nancy.ViewEngines.Razor/TextResourceFinder.cs
@@ -1,12 +1,6 @@
namespace Nancy.ViewEngines.Razor
{
- using System;
- using System.Collections;
- using System.Collections.Generic;
using System.Dynamic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
/// <summary>
/// Returns text from an implemented ITextResource
View
4 src/Nancy/Bootstrapper/NancyInternalConfiguration.cs
@@ -90,6 +90,7 @@ public static NancyInternalConfiguration Default
RouteSegmentExtractor = typeof(DefaultRouteSegmentExtractor),
RouteDescriptionProvider = typeof(DefaultRouteDescriptionProvider),
CultureService = typeof(DefaultCultureService),
+ DefaultTextResource = typeof(DefaultTextResource),
};
}
}
@@ -162,6 +163,8 @@ public static NancyInternalConfiguration Default
public Type CultureService { get; set; }
+ public Type DefaultTextResource { get; set; }
+
public IEnumerable<Func<Assembly, bool>> IgnoredAssemblies
{
get
@@ -256,6 +259,7 @@ public IEnumerable<TypeRegistration> GetTypeRegistations()
new TypeRegistration(typeof(IRouteSegmentExtractor), this.RouteSegmentExtractor),
new TypeRegistration(typeof(IRouteDescriptionProvider), this.RouteDescriptionProvider),
new TypeRegistration(typeof(ICultureService), this.CultureService),
+ new TypeRegistration(typeof(ITextResource), this.DefaultTextResource),
};
}
View
2  src/Nancy/Nancy.csproj
@@ -271,6 +271,7 @@
<Compile Include="ViewEngines\DefaultRenderContextFactory.cs" />
<Compile Include="ViewEngines\DefaultResourceAssemblyProvider.cs" />
<Compile Include="ViewEngines\DefaultResourceReader.cs" />
+ <Compile Include="ViewEngines\DefaultTextResource.cs" />
<Compile Include="ViewEngines\DefaultViewCache.cs" />
<Compile Include="ViewEngines\DefaultViewLocationCache.cs" />
<Compile Include="ViewEngines\DefaultViewRenderer.cs" />
@@ -373,6 +374,7 @@
<Compile Include="ViewEngines\IRenderContextFactory.cs" />
<Compile Include="ViewEngines\IResourceAssemblyProvider.cs" />
<Compile Include="ViewEngines\IResourceReader.cs" />
+ <Compile Include="ViewEngines\ITextResource.cs" />
<Compile Include="ViewEngines\IViewCache.cs" />
<Compile Include="ViewEngines\IViewEngine.cs" />
<Compile Include="ViewEngines\IViewLocationCache.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.