Default IViewSourceLoader implementation that uses the file system and assembly source as source of view templates
Inheritance: IViewSourceLoader, IServiceEnabledComponent
        /// <summary>
        /// Deze functie geeft maakt HTML van een brail template
        /// </summary>
        /// <param name="templateDirectory">Directory waar de brail template zich bevind</param>
        /// <param name="templateName">naam van de brail file</param>
        /// <param name="propertyBag">Eventueele propertybag's</param>
        /// <returns>een string met HTML</returns>
        public string Parse(string templateDirectory, string templateName, Dictionary<string, object> propertyBag)
        {
            if (string.IsNullOrEmpty(viewDirectory))
            {
                throw new Exception("Geen absoluut pad opgegeven voor de viewDirectory in de Windsor configuratie file");
            }

            if (string.IsNullOrEmpty(templateName))
            {
                throw new Exception("Template naam is niet opgegeven");
            }

            try
            {
                //als er een templatedirectory is, combineer die met de opgegeven viewDirectory
                string viewTemplateDirectory = viewDirectory;
                if (!string.IsNullOrEmpty(templateDirectory))
                    viewTemplateDirectory = Path.Combine(viewDirectory, templateDirectory);
                //maak een viewsource loader voor het laden van brail templates
                FileAssemblyViewSourceLoader viewSourceLoader = new FileAssemblyViewSourceLoader(viewTemplateDirectory);
                StandaloneBooViewEngine standaloneBooViewEngine = new StandaloneBooViewEngine(viewSourceLoader, null);
                StringWriter writer = new StringWriter();
                standaloneBooViewEngine.Process(templateName, writer, propertyBag);
                return writer.GetStringBuilder().ToString();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Example #2
0
        public void Init()
        {
            mocks = new MockRepository();
            serviceProvider = new StubMonoRailServices();

            var viewSourceLoader = new FileAssemblyViewSourceLoader("MonoRail.Tests.Views");
            viewSourceLoader.Service(this.serviceProvider);
            serviceProvider.ViewSourceLoader = viewSourceLoader;
            serviceProvider.AddService(typeof(IViewSourceLoader), viewSourceLoader);

            Configure();

            controllerContext = new ControllerContext();
            propertyBag = controllerContext.PropertyBag;

            controllerContext.LayoutNames = new []{"default"};
            output = new StringWriter();

            server = new StubServerUtility();
            routingEngine = MockRepository.GenerateMock<IRoutingEngine>();
            var urlBuilder = new DefaultUrlBuilder(server, routingEngine);
            serviceProvider.UrlBuilder = urlBuilder;
            serviceProvider.AddService(typeof(IUrlBuilder), urlBuilder);

            InitUrlInfo("", "home", "index");

            response = engineContext.Response;
        }
		public object GetService(Type serviceType)
		{
			if (typeof(IViewSourceLoader) == serviceType)
			{
				FileAssemblyViewSourceLoader loader = new FileAssemblyViewSourceLoader();
				loader.ViewRootDir = viewRootDir;
				return loader;
			}
			return null;
		}
Example #4
0
        public virtual void SetUp()
        {

            PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
            Helpers = new HelperDictionary();
            var services = new StubMonoRailServices
                               {
                                   UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), new StubRoutingEngine()),
                                   UrlTokenizer = new DefaultUrlTokenizer()
                               };
            var urlInfo = new UrlInfo(
                "example.org", "test", "/TestBrail", "http", 80,
                "http://test.example.org/test_area/test_controller/test_action.tdd",
                Area, ControllerName, Action, "tdd", "no.idea");
            StubEngineContext = new StubEngineContext(new StubRequest(), new StubResponse(), services, urlInfo);
            StubEngineContext.AddService<IUrlBuilder>(services.UrlBuilder);
            StubEngineContext.AddService<IUrlTokenizer>(services.UrlTokenizer);

            ViewComponentFactory = new DefaultViewComponentFactory();
            ViewComponentFactory.Service(StubEngineContext);
            ViewComponentFactory.Initialize();

            StubEngineContext.AddService<IViewComponentFactory>(ViewComponentFactory);
            ControllerContext = new ControllerContext
                                    {
                                        Helpers = Helpers, 
                                        PropertyBag = PropertyBag
                                    };
            StubEngineContext.CurrentControllerContext = ControllerContext;


            Helpers["urlhelper"] = Helpers["url"] = new UrlHelper(StubEngineContext);
            Helpers["formhelper"] = Helpers["form"] = new FormHelper(StubEngineContext);
            Helpers["dicthelper"] = Helpers["dict"] = new DictHelper(StubEngineContext);
            Helpers["DateFormatHelper"] = Helpers["DateFormat"] = new DateFormatHelper(StubEngineContext);



            var loader = new FileAssemblyViewSourceLoader("Views");
            _monoRailViewEngine = new NHamlMonoRailViewEngine();
            _monoRailViewEngine.TemplateEngine.Options.TemplateCompiler = new CSharp3TemplateCompiler();
            _monoRailViewEngine.SetViewSourceLoader(loader);
            _templateEngine = _monoRailViewEngine.TemplateEngine;
            _templateEngine.Options.TemplateBaseType = typeof( NHamlMonoRailView );
            


            ViewComponentFactory.Inspect(GetType().Assembly);

        }
        protected BooViewEngine getBrail(Controller controller){
            if (null == Engine){
                var eng = new BooViewEngine(); eng.Initialize();
                eng.Options.SaveToDisk = false;
				eng.Options.BaseType = typeof(BrailBase).FullName;
                eng.Options.CommonScriptsDirectory = "CommonScripts";
                eng.Options.SaveDirectory = controller.Context.Server.MapPath("~/tmp/ioc.getreport");
                eng.ViewFactory = new MONORAILBrailTypeFactory(new BrailSourceResolver {Identity = "reportpreparator"},eng.Options);

                var source = new FileAssemblyViewSourceLoader(controller.Context.Server.MapPath("~/usr/views"));

                source.AddPathSource(controller.Context.Server.MapPath("~/mod/views"));
                source.AddPathSource(controller.Context.Server.MapPath("~/sys/views"));


                eng.SetViewSourceLoader(source);
                eng.Initialize();

                source.ViewChanged += _ViewChanged;
                Engine = eng;
            }
            return Engine;
        }
Example #6
0
 public TemplateParserService(string templateDirectory)
 {
     viewSourceLoader = new FileAssemblyViewSourceLoader(templateDirectory);
     standaloneBooViewEngine = new StandaloneBooViewEngine(viewSourceLoader, null);
 }
        public void Init()
        {
            mocks = new MockRepository();
            factory = new SparkViewFactory();
            engineContext = mocks.CreateMock<IEngineContext>();
            server = new MockServerUtility();
            request = mocks.CreateMock<IRequest>();
            response = mocks.CreateMock<IResponse>();

            controller = mocks.CreateMock<IController>();
            controllerContext = mocks.CreateMock<IControllerContext>();
            routingEngine = mocks.CreateMock<IRoutingEngine>();
            output = new StringWriter();
            helpers = new HelperDictionary();

            propertyBag = new Dictionary<string, object>();
            flash = new Flash();
            session = new Dictionary<string, object>();
            requestParams = new NameValueCollection();
            contextItems = new Dictionary<string, object>();


            SetupResult.For(engineContext.Server).Return(server);
            SetupResult.For(engineContext.Request).Return(request);
            SetupResult.For(engineContext.Response).Return(response);
            SetupResult.For(engineContext.CurrentController).Return(controller);
            SetupResult.For(engineContext.CurrentControllerContext).Return(controllerContext);
            SetupResult.For(engineContext.Flash).Return(flash);
            SetupResult.For(engineContext.Session).Return(session);
            SetupResult.For(engineContext.Items).Return(contextItems);

            SetupResult.For(request.Params).Return(requestParams);

            SetupResult.For(controllerContext.LayoutNames).Return(new[] { "default" });
            SetupResult.For(controllerContext.Helpers).Return(helpers);
            SetupResult.For(controllerContext.PropertyBag).Return(propertyBag);

            SetupResult.For(routingEngine.IsEmpty).Return(true);

            var urlBuilder = new DefaultUrlBuilder(server, routingEngine);

            var serviceProvider = mocks.CreateMock<IServiceProvider>();
            var viewSourceLoader = new FileAssemblyViewSourceLoader("Views");
            SetupResult.For(serviceProvider.GetService(typeof(IViewSourceLoader))).Return(viewSourceLoader);
            SetupResult.For(serviceProvider.GetService(typeof(ILoggerFactory))).Return(new NullLogFactory());
            SetupResult.For(serviceProvider.GetService(typeof(ISparkViewEngine))).Return(null);
            SetupResult.For(serviceProvider.GetService(typeof(IUrlBuilder))).Return(urlBuilder);
            SetupResult.For(serviceProvider.GetService(typeof(IViewComponentFactory))).Return(null);
            mocks.Replay(serviceProvider);

            SetupResult.For(engineContext.GetService(null)).IgnoreArguments().Do(
                new Func<Type, object>(serviceProvider.GetService));

            factory.Service(serviceProvider);


            manager = new DefaultViewEngineManager();
            manager.RegisterEngineForExtesionLookup(factory);
            manager.RegisterEngineForView(factory);
        }