/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. using System;
  25. using System.IO;
  26. using System.Text;
  27. using System.Reflection;
  28. using System.Collections.Generic;
  29. namespace Manos.Templates {
  30. public static class BuiltinFilters {
  31. public static string __upper (string input)
  32. {
  33. return input.ToUpper ();
  34. }
  35. public static string __lower (string input)
  36. {
  37. return input.ToLower ();
  38. }
  39. public static string __default (string input, string default_value)
  40. {
  41. if (String.IsNullOrEmpty (input))
  42. return default_value;
  43. return input;
  44. }
  45. public static string __filename (string input)
  46. {
  47. return Path.GetFileName (input);
  48. }
  49. public static string __filename_noextension (string input)
  50. {
  51. return Path.GetFileName (input);
  52. }
  53. public static string __remove_extension (string input)
  54. {
  55. return Path.GetFileNameWithoutExtension (input);
  56. }
  57. }
  58. public static class TemplateFilterManager {
  59. public static MethodInfo GetFilter (string filter)
  60. {
  61. Type bin = typeof (BuiltinFilters);
  62. MethodInfo res = bin.GetMethod (String.Concat ("__", filter), BindingFlags.Static | BindingFlags.Public);
  63. return res;
  64. }
  65. }
  66. public interface ITemplatePage {
  67. void Render (IManosContext context, Stream stream, object the_arg);
  68. }
  69. }