예제 #1
0
        public static void RenderCssFile <TModel>(this HtmlHelper <TModel> htmlHelper, string path, string releasePath) where TModel : EcardModel
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

#if DEBUG
#else
            if (!string.IsNullOrEmpty(releasePath))
            {
                path = releasePath;
            }
#endif

            if (!(path.StartsWith("http://") || path.StartsWith("https://")))
            {
                var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

                path = !path.StartsWith("/")
                           ? urlHelper.CssPath(path, htmlHelper.ViewData.Model)
                           : urlHelper.AppPath(path);
            }

            htmlHelper.ViewContext.HttpContext.Response.Write(
                htmlHelper.HeadLink("stylesheet", path, "text/css", "")
                );
        }
예제 #2
0
        public static void RenderScriptTag <TModel>(this HtmlHelper <TModel> htmlHelper, string path, string releasePath) where TModel : OxiteModel
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

#if DEBUG
#else
            if (!string.IsNullOrEmpty(releasePath))
            {
                path = releasePath;
            }
#endif

            if (!(path.StartsWith("http://") || path.StartsWith("https://")))
            {
                UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

                path = !path.StartsWith("/")
                    ? urlHelper.ScriptPath(path, htmlHelper.ViewData.Model)
                    : urlHelper.AppPath(path);
            }

            htmlHelper.ViewContext.HttpContext.Response.Write(htmlHelper.ScriptBlock("text/javascript", path));
        }
예제 #3
0
        public static string ScriptPath(this UrlHelper urlHelper, string relativePath, ViewModels.OxiteModel model)
        {
            if (!string.IsNullOrEmpty(relativePath) && !relativePath.StartsWith("/"))
            {
                relativePath = "/" + relativePath;
            }

            return(string.Format(urlHelper.AppPath(model.Site.ScriptsPath), model.SkinName) + relativePath);
        }
예제 #4
0
        public static string PluginTemplatesPath(this UrlHelper urlHelper, Plugin plugin, string path)
        {
            if (!string.IsNullOrEmpty(path) && !path.StartsWith("/"))
            {
                path = "/" + path;
            }

            return(urlHelper.AppPath(plugin.Container.GetTemplatesPath() + path));
        }
예제 #5
0
        internal static void FilePath(this UrlHelper urlHelper, ViewContext viewContext, Func <IOxiteViewEngine, string, FileEngineResult> findFile, ref string path)
        {
            List <string> searchedLocations = new List <string>(50);

            foreach (IOxiteViewEngine viewEngine in (IEnumerable <IOxiteViewEngine>)viewContext.ViewData["OxiteViewEngines"])
            {
                FileEngineResult result = findFile(viewEngine, path);

                if (result.SearchedLocations.Count() > 0)
                {
                    searchedLocations.AddRange(result.SearchedLocations);
                }
                else
                {
                    path = urlHelper.AppPath(result.FilePath);
                    searchedLocations.Clear();

                    break;
                }
            }

            if (searchedLocations.Count > 0)
            {
                if ((bool)viewContext.ViewData["Debug"])
                {
                    StringBuilder locationsText = new StringBuilder();

                    foreach (string location in searchedLocations)
                    {
                        locationsText.AppendLine();
                        locationsText.Append(location);
                    }

                    throw new InvalidOperationException(string.Format("The file '{0}' could not be found. The following locations were searched:{1}", path, locationsText));
                }
                else
                {
                    path = urlHelper.AppPath(searchedLocations.ElementAt(0));
                }
            }
        }
예제 #6
0
 /// <summary>
 /// 加载js文件
 /// </summary>
 /// <param name="jsFilePath"></param>
 /// <param name="isInHead"></param>
 public static void IncludeJsFile(string jsFilePath, bool isInHead)
 {
     if (isInHead)
     {
         Page currentHandler      = HttpContext.Current.CurrentHandler as Page;
         HtmlGenericControl child = new HtmlGenericControl("script");
         child.Attributes.Add("type", "text/javascript");
         child.Attributes.Add("language", "javascript");
         child.Attributes.Add("src", UrlHelper.AppPath() + jsFilePath);
         currentHandler.Header.Controls.Add(child);
     }
     else
     {
         string str = string.Format("\n<script  type=\"text/javascript\" src=\"{0}\">\n</script>\n", jsFilePath);
         ((Page)HttpContext.Current.Handler).ClientScript.RegisterStartupScript(Type.GetType("System.String"), Guid.NewGuid().ToString(), str);
     }
 }
예제 #7
0
        public static void RenderLiveWriterManifest(this HtmlHelper htmlHelper)
        {
            UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

            htmlHelper.RenderLiveWriterManifest(urlHelper.AppPath("~/LiveWriterManifest.xml"));
        }
예제 #8
0
        public static void RenderFavIcon <TModel>(this HtmlHelper <TModel> htmlHelper) where TModel : OxiteModel
        {
            OxiteModel model = htmlHelper.ViewData.Model;

            if (!string.IsNullOrEmpty(model.Site.FavIconUrl))
            {
                UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

                htmlHelper.ViewContext.HttpContext.Response.Write(htmlHelper.HeadLink("shortcut icon", urlHelper.AppPath(model.Site.FavIconUrl), null, null));
            }
        }
예제 #9
0
        public static string OpenSearchOSDXLink <TModel>(this HtmlHelper <TModel> htmlHelper) where TModel : OxiteModel
        {
            OxiteModel model = htmlHelper.ViewData.Model;

            if (model.Site.IncludeOpenSearch && htmlHelper.ViewContext.HttpContext.Request.UserAgent.Contains("Windows NT 6.1"))
            {
                UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

                return(htmlHelper.Link(string.Format(model.Localize("Search.WindowsSearch", "Search {0} in Windows"), model.Site.DisplayName), urlHelper.AppPath(urlHelper.OpenSearchOSDX()), new { @class = "windowsSearch" }));
            }

            return("");
        }
예제 #10
0
 public static string MetaWeblogApi(this UrlHelper urlHelper)
 {
     return(urlHelper.AppPath("~/MetaWeblog.svc"));
 }
예제 #11
0
 public static string Pingback(this UrlHelper urlHelper, Post post)
 {
     return(urlHelper.AppPath("~/Pingback.svc"));
 }
예제 #12
0
 public static string MetaWeblog(this UrlHelper urlHelper)
 {
     return(urlHelper.AppPath("/MetaWeblog"));
 }
예제 #13
0
 public static string Home(this UrlHelper urlHelper)
 {
     return(urlHelper.AppPath("~/"));
 }