我已经尝试了 squshit 和 rejuicer 来尝试从视图中组合和缩小一些 css 和 js。到目前为止还没有运气。我所做的是在我放置的过滤器中
#region using
using System;
using Castle.MonoRail.Framework;
using campusMap.Models;
using MonoRailHelper;
using Rejuicer;
#endregion
namespace campusMap.Filters
{
public class scriptFilter : IFilter
{
public bool Perform(ExecuteWhen exec, IEngineContext context, IController controller, IControllerContext controllerContext)
{
controllerContext.PropertyBag["adminRejuicer_css"] = OnRequest.ForCss("~/Content/css/min/Combined.css").Compact;
controllerContext.PropertyBag["adminRejuicer_js"] = OnRequest.ForJs("~/Content/js/min/Combined.js");
//controllerContext.PropertyBag["JavaScriptBundle"] = new JavaScriptBundle();
return true;
}
}
}
然后在基本控制器上
#region Directives
using Castle.MonoRail.Framework;
using campusMap.Services;
using System.Text.RegularExpressions;
using System;
using campusMap.Models;
using Castle.ActiveRecord;
using MonoRailHelper;
using campusMap.Filters;
using log4net;
using log4net.Config;
using System.Text;
#endregion
namespace campusMap.Controllers
{
[Filter(ExecuteWhen.BeforeAction, typeof(scriptFilter))]
[Layout("default"), Rescue("generalerror")]
public abstract class BaseController : MonoRailHelper.HelperBaseController
{
}
然后最后从视图中
$adminRejuicer_css.File("~/Content/css/admin_styles.css").File("~/Content/js/colorpicker/css/jpicker-1.1.6.min.css")
但什么都没有。如果我对 ssushit 做基本相同的事情,但在过滤器中
controllerContext.PropertyBag["cssBundle"] = Bundle.Css();
并且在视图中
$cssBundle.Add("~/Content/css/admin_styles.css").Add("~/Content/js/colorpicker/css/jpicker-1.1.6.min.css").Render("~/Content/css/min/admin.css")
这次它至少只输出两个脚本的标签,没有缩小或捆绑,但至少它在做一些事情。
关于如何做到这一点的任何想法?谢谢你-杰里米