PageRenderTime 74ms CodeModel.GetById 70ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Manos/Manos.Template/TemplateLibrary.cs

http://github.com/jacksonh/manos
C# | 89 lines | 46 code | 20 blank | 23 comment | 1 complexity | 8c57d3b3f057d519085ff986b4cf283c MD5 | raw file
 1//
 2// Copyright (C) 2010 Jackson Harper (jackson@manosdemono.com)
 3//
 4// Permission is hereby granted, free of charge, to any person obtaining
 5// a copy of this software and associated documentation files (the
 6// "Software"), to deal in the Software without restriction, including
 7// without limitation the rights to use, copy, modify, merge, publish,
 8// distribute, sublicense, and/or sell copies of the Software, and to
 9// permit persons to whom the Software is furnished to do so, subject to
10// the following conditions:
11// 
12// The above copyright notice and this permission notice shall be
13// included in all copies or substantial portions of the Software.
14// 
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22//
23//
24
25
26using System;
27using System.IO;
28using System.Text;
29using System.Reflection;
30using System.Collections.Generic;
31
32
33namespace Manos.Templates {
34
35	public static class BuiltinFilters {
36
37		public static string __upper (string input)
38		{
39			return input.ToUpper ();
40		}
41
42		public static string __lower (string input)
43		{
44			return input.ToLower ();
45		}
46
47		public static string __default (string input, string default_value)
48		{
49			if (String.IsNullOrEmpty (input))
50				return default_value;
51
52			return input;
53		}
54
55		public static string __filename (string input)
56		{
57			return Path.GetFileName (input);
58		}
59
60		public static string __filename_noextension (string input)
61		{
62			return Path.GetFileName (input);
63		}
64
65		public static string __remove_extension (string input)
66		{
67			return Path.GetFileNameWithoutExtension (input);
68		}
69	}
70
71	public static class TemplateFilterManager {
72
73		public static MethodInfo GetFilter (string filter)
74		{
75			Type bin = typeof (BuiltinFilters);
76
77			MethodInfo res = bin.GetMethod (String.Concat ("__", filter), BindingFlags.Static | BindingFlags.Public);
78
79			return res;
80		}
81	}
82
83	public interface ITemplatePage {
84
85		void Render (IManosContext context, Stream stream, object the_arg);
86	}
87}
88
89