Minor changes to improve testability of helpers
[castle.git] / MonoRail / Castle.MonoRail.ActiveRecordScaffold / Helpers / PresentationHelper.cs
blobc2f95c206506f1178acecf31527a4fa12b144cc9
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.ActiveRecordScaffold.Helpers
17 using System;
18 using System.Collections;
19 using Castle.ActiveRecord.Framework.Internal;
20 using Castle.MonoRail.Framework.Helpers;
22 public class PresentationHelper : AbstractHelper
24 public String StartAlternateTR(int index, String styleClass, String altStyleClass)
26 return String.Format("<tr class=\"{0}\">", index % 2 == 0 ? styleClass : altStyleClass);
29 public String BestAlignFor(Type type)
31 if (type == typeof(String))
33 return "left";
36 return "center";
39 public String LinkToBack(String text, IDictionary attributes)
41 return String.Format( "<a href=\"javascript:history.go(-1);\" {1}>{0}</a>",
42 text, GetAttributes(attributes) );
45 public String LinkToList(ActiveRecordModel model, bool useModelName, String text, IDictionary attributes)
47 if (useModelName)
49 return String.Format("<a href=\"list{0}.{1}\" {3}>{2}</a>", model.Type.Name,
50 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes));
52 else
54 return String.Format("<a href=\"list.{0}\" {2}>{1}</a>",
55 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes));
59 public String LinkToNew(ActiveRecordModel model, bool useModelName, String text, IDictionary attributes)
61 if (useModelName)
63 return String.Format("<a href=\"new{0}.{1}\" {3}>{2}</a>", model.Type.Name,
64 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes));
66 else
68 return String.Format("<a href=\"new.{0}\" {2}>{1}</a>",
69 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes));
73 public String LinkToEdit(ActiveRecordModel model, bool useModelName,
74 String text, object key, IDictionary attributes)
76 if (useModelName)
78 return String.Format("<a href=\"edit{0}.{1}?id={4}\" {3}>{2}</a>", model.Type.Name,
79 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes), key);
81 else
83 return String.Format("<a href=\"edit.{0}?id={3}\" {2}>{1}</a>",
84 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes), key);
88 public String LinkToConfirm(ActiveRecordModel model, bool useModelName, String text, object key, IDictionary attributes)
90 if (useModelName)
92 return String.Format("<a href=\"confirm{0}.{1}?id={4}\" {3}>{2}</a>", model.Type.Name,
93 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes), key);
95 else
97 return String.Format("<a href=\"confirm.{0}?id={3}\" {2}>{1}</a>",
98 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes), key);
102 public String LinkToRemove(ActiveRecordModel model, bool useModelName, String text, object key, IDictionary attributes)
104 if (useModelName)
106 return String.Format("<a href=\"remove{0}.{1}?id={4}\" {3}>{2}</a>", model.Type.Name,
107 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes), key);
109 else
111 return String.Format("<a href=\"remove.{0}?id={3}\" {2}>{1}</a>",
112 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes), key);