Ejemplo n.º 1
0
 public override void Process(GetPageRenderingArgs args)
 {
     AssetRepository.Current.AddScriptFile("/Scripts/Commerce/knockout-2.3.0.js", ScriptLocation.Head, true);
     AssetRepository.Current.AddScriptFile("/Scripts/Commerce/knockout.validation-2.0.0.js", ScriptLocation.Head, true);
     AssetRepository.Current.AddScriptFile("/Scripts/Commerce/debug-knockout.js", ScriptLocation.Head, true);
     AssetRepository.Current.AddScriptFile("/Scripts/Commerce/ajax-helpers.js", ScriptLocation.Head, true);
 }
        public override void Process(GetPageRenderingArgs args)
        {
            this.AddRenderingAssets(args.PageContext.PageDefinition.Renderings);

            var bundleName = ReactSettingsProvider.Current.BundleName;

            if (string.IsNullOrWhiteSpace(bundleName))
            {
                bundleName = "~/bundles/react";
            }

            var bundle = new BabelBundle(bundleName);

            foreach (var jsxFile in JsxRepository.Current.Items)
            {
                bundle.Include(jsxFile);

                if (!ReactSiteConfiguration.Configuration.Scripts.Any(s => s.Equals(jsxFile)))
                {
                    ReactSiteConfiguration.Configuration.AddScript(jsxFile);
                }
            }

            BundleTable.Bundles.Add(bundle);
        }
Ejemplo n.º 3
0
 public override void Process(GetPageRenderingArgs args)
 {
     foreach (Asset asset in SiteAssets)
     {
         AssetRepository.Current.Add(asset, true);
     }
 }
Ejemplo n.º 4
0
        public override void Process(GetPageRenderingArgs args)
        {
            // Safety check - if the config is set to webpack, don't run this pipeline or it will fail.
            if (ReactSettingsProvider.Current.BundleType == Settings.BundleTypes.Webpack)
            {
                return;
            }

            AddRenderingAssets(args.PageContext.PageDefinition.Renderings);

            // Create the bundle for the render
            var bundle = new BabelBundle(ReactSettingsProvider.Current.BundleName);

            foreach (var jsxFile in JsxRepository.Current.Items)
            {
                bundle.Include(jsxFile);

                if (!ReactSiteConfiguration.Configuration.Scripts.Any(script => script.Equals(jsxFile)))
                {
                    ReactSiteConfiguration.Configuration.AddScript(jsxFile);
                }
            }

            BundleTable.Bundles.Add(bundle);
        }
Ejemplo n.º 5
0
 public override void Process(GetPageRenderingArgs args)
 {
     if (Settings.CheckSCBEnabledSite())
     {
         scripts = (!string.IsNullOrEmpty(Settings.GetSitecoreSettings("scb_script_assets"))) ? Settings.GetSitecoreSettings("scb_script_assets").Split(',') : null;
         System.Web.HttpContext.Current.Response.Filter = new ScriptStream(System.Web.HttpContext.Current.Response.Filter, this.scripts);
     }
 }
Ejemplo n.º 6
0
    public override void Process(GetPageRenderingArgs args)
    {
      this.AddDefaultAssetsFromConfiguration();

      this.AddPageAssets(PageContext.Current.Item);

      this.AddRenderingAssets(args.PageContext.PageDefinition.Renderings);
    }
Ejemplo n.º 7
0
        public override void Process(GetPageRenderingArgs args)
        {
            this.AddDefaultAssetsFromConfiguration();

            this.AddPageAssets(PageContext.Current.Item);

            this.AddRenderingAssets(args.PageContext.PageDefinition.Renderings);
        }
        public override void Process(GetPageRenderingArgs args)
        {
            var item     = args.PageContext.Item;
            var ancestor = item.DescendsFrom(RenderingAssets.TemplateId)
                                ? item
                                : item.Axes.GetAncestors().LastOrDefault(i => i.DescendsFrom(RenderingAssets.TemplateId));

            AddAsset(ancestor);
        }
Ejemplo n.º 9
0
 public override void Process(GetPageRenderingArgs args)
 {
     if (Sitecore.Context.Device.ID == _pdfRenderingId &&
         !(Sitecore.Context.PageMode.IsPreview || Sitecore.Context.PageMode.IsExperienceEditor))
     {
         Trace.WriteLine("Creating PDF rendering...");
         args.Result = new PdfRendering(args.Result);
     }
 }
        public override void Process(GetPageRenderingArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (args.PageContext == null ||
                args.PageContext.RequestContext == null ||
                args.PageContext.RequestContext.HttpContext == null ||
                args.PageContext.RequestContext.HttpContext.Response == null)
            {
                return;
            }

            SetCacheHeaders(args.PageContext.RequestContext.HttpContext.Response);
            if (Context.Item != null)
            {
                SetUpdateHeaders(Context.Item, args.PageContext.RequestContext.HttpContext.Response);
            }
        }
Ejemplo n.º 11
0
        public override void Process(GetPageRenderingArgs args)
        {
            this.AddRenderingAssets(args.PageContext.PageDefinition.Renderings);

            // Create the bundle for the render
            var bundle = new BabelBundle("~/bundles/react");

            foreach (var jsxFile in JsxRepository.Current.Items)
            {
                bundle.Include(jsxFile);

                if (!ReactSiteConfiguration.Configuration.Scripts.Any(s => s.Equals(jsxFile)))
                {
                    ReactSiteConfiguration.Configuration.AddScript(jsxFile);
                }
            }

            BundleTable.Bundles.Add(bundle);
        }
		/// <summary>
		/// Applies the rendering specific references to Cassette bundles.
		/// </summary>
		/// <param name="args">The args.</param>
		protected void ApplyRenderingSpecificReferences(GetPageRenderingArgs args)
		{
			foreach (Rendering rendering in args.PageContext.PageDefinition.Renderings)
			{
				switch (rendering.RenderingItem.ID.ToString())
				{
					/* Example of adding Bundle references based on the current item having a specific reference
					 * ItemReference is just a static class to reference ID's of specific items in Sitecore.
					 * 
					case ItemReference.SliderPanelRendering:
						Bundles.Reference("js/vendor/jquery.flexslider.js", "footer");
						Bundles.AddInlineScript("$(document).ready(function() { $('.home-slider').flexslider({ pauseOnHover: true, slideshow: false }); });", "footer");
						break;
					*/
					default:
						break;
				}
			}
		}
 /// <summary>
 /// Applies the rendering specific references to Cassette bundles.
 /// </summary>
 /// <param name="args">The args.</param>
 protected void ApplyRenderingSpecificReferences(GetPageRenderingArgs args)
 {
     foreach (Rendering rendering in args.PageContext.PageDefinition.Renderings)
     {
         switch (rendering.RenderingItem.ID.ToString())
         {
         /* Example of adding Bundle references based on the current item having a specific reference
          * ItemReference is just a static class to reference ID's of specific items in Sitecore.
          *
          * case ItemReference.SliderPanelRendering:
          *      Bundles.Reference("js/vendor/jquery.flexslider.js", "footer");
          *      Bundles.AddInlineScript("$(document).ready(function() { $('.home-slider').flexslider({ pauseOnHover: true, slideshow: false }); });", "footer");
          *      break;
          */
         default:
             break;
         }
     }
 }
Ejemplo n.º 14
0
        public override void Process(GetPageRenderingArgs args)
        {
            // Loop through all the renderings which are cacheable and might not have had their code executed
            foreach (var rendering in args.PageContext.PageDefinition.Renderings)
            {
                // Only run in "normal" page mode, otherwise we assume renderings are always executed.
                if (Sitecore.Context.PageMode.IsNormal && rendering.Caching.Cacheable)
                {
                    MyContext.AssetRequirementService.AddFromRenderingCache(rendering.RenderingItem.ID);
                }

                var renderingItem = rendering.RenderingItem.InnerItem;

                var javaScriptAssets = renderingItem["JavaScript assets"];
                foreach (var javaScriptAsset in javaScriptAssets.Split(';', ',', '\n'))
                {
                    MyContext.AssetRequirementService.AddJavaScriptFile(javaScriptAsset, true);
                }

                var javaScriptInline = renderingItem["JavaScript inline"];
                if (!string.IsNullOrEmpty(javaScriptInline))
                {
                    MyContext.AssetRequirementService.AddJavaScriptInline(javaScriptInline, renderingItem.ID.ToString(), true);
                }

                var cssAssets = renderingItem["Css assets"];
                foreach (var cssAsset in cssAssets.Split(';', ',', '\n'))
                {
                    MyContext.AssetRequirementService.AddCssFile(cssAsset, true);
                }

                var cssInline = renderingItem["Css inline"];
                if (!string.IsNullOrEmpty(cssInline))
                {
                    MyContext.AssetRequirementService.AddCssInline(cssInline, renderingItem.ID.ToString(), true);
                }
            }
        }
Ejemplo n.º 15
0
        public override void Process(GetPageRenderingArgs args)
        {
            // Loop through all the renderings which are cacheable and might not have had their code executed
            foreach (var rendering in args.PageContext.PageDefinition.Renderings)
            {
                // Only run in "normal" page mode, otherwise we assume renderings are always executed.
                if (Sitecore.Context.PageMode.IsNormal && rendering.Caching.Cacheable)
                {
                    MyContext.AssetRequirementService.AddFromRenderingCache(rendering.RenderingItem.ID);
                }

                var renderingItem = rendering.RenderingItem.InnerItem;

                var javaScriptAssets = renderingItem["JavaScript assets"];
                foreach (var javaScriptAsset in javaScriptAssets.Split(';', ',', '\n'))
                {
                    MyContext.AssetRequirementService.AddJavaScriptFile(javaScriptAsset, true);
                }

                var javaScriptInline = renderingItem["JavaScript inline"];
                if (!string.IsNullOrEmpty(javaScriptInline))
                {
                    MyContext.AssetRequirementService.AddJavaScriptInline(javaScriptInline, renderingItem.ID.ToString(), true);
                }

                var cssAssets = renderingItem["Css assets"];
                foreach (var cssAsset in cssAssets.Split(';', ',', '\n'))
                {
                    MyContext.AssetRequirementService.AddCssFile(cssAsset, true);
                }

                var cssInline = renderingItem["Css inline"];
                if (!string.IsNullOrEmpty(cssInline))
                {
                    MyContext.AssetRequirementService.AddCssInline(cssInline, renderingItem.ID.ToString(), true);
                }
            }
        }
		public override void Process(GetPageRenderingArgs args)
		{
			ApplyDefaultReferences();
			ApplyRenderingSpecificReferences(args);
		}
 public override void Process(GetPageRenderingArgs args)
 {
     ApplyDefaultReferences();
     ApplyRenderingSpecificReferences(args);
 }
Ejemplo n.º 18
0
 public override void Process(GetPageRenderingArgs args) => AddAssets(args.PageContext.PageDefinition.Renderings);
Ejemplo n.º 19
0
        /// <summary>
        /// Renders an item with a layout defined to a string for MVC
        /// </summary>
        /// <returns>HTML of item</returns>
        public virtual void Render(TextWriter writer)
        {
            var originalDisplayMode = Context.Site.DisplayMode;

            // keep a copy of the renderings we start with.
            // running the renderPlaceholder pipeline (which runs renderRendering) will overwrite these
            // and we need to set them back how they were when we're done rendering the xBlock
            var originalRenderingDefinitionContext = RenderingContext.CurrentOrNull?.PageContext?.PageDefinition;

            try
            {
                // prevents editing the snippet in context, so you cannot mistakenly change something shared by mistake
                if (Context.PageMode.IsExperienceEditorEditing)
                {
                    Context.Site.SetDisplayMode(DisplayMode.Preview, DisplayModeDuration.Temporary);
                }

                var pageDef = new PageDefinition
                {
                    Renderings = new List <Rendering>()
                };

                //Extracts the item's layout XML, then parses all of the renderings out of it.
                pageDef.Renderings.AddRange(GetRenderings(GetLayoutFromItem()));

                // Uncovers the main layout rendering
                var pageRenderingArgs = new GetPageRenderingArgs(pageDef);
                PipelineService.Get().RunPipeline("mvc.getPageRendering", pageRenderingArgs);

                //Renders all placeholders for the layout rendering, which would be the entire page
                var renderPlaceholderArgs = new RenderPlaceholderArgs(PerformItemRendering.ItemRenderingKey, writer, pageRenderingArgs.Result)
                {
                    PageContext = new PageContext
                    {
                        PageDefinition = pageDef
                    }
                };

                using (PageRenderItemDefinitionContext.Enter(new PageRenderItemDefinitionContext(pageDef, Item, originalDisplayMode)))
                {
                    PipelineService.Get().RunPipeline("mvc.renderPlaceholder", renderPlaceholderArgs);
                }
            }
            catch (Exception e)
            {
                Log.Error("There was a problem rendering an item to string", e, this);
                if (originalDisplayMode == DisplayMode.Edit || originalDisplayMode == DisplayMode.Preview)
                {
                    writer.Write($"<p class=\"edit-only\">Error occurred while rendering {Item.Paths.FullPath}: {e.Message}<br>For error details, <a href=\"{LinkManager.GetItemUrl(Item)}\" onclick=\"window.open(this.href); return false;\">visit the target page</a></p>");
                }
            }
            finally
            {
                // replace the renderings in the current context with the ones that existed before we ran our sideline renderPlaceholder
                // because they have been overwritten with the xBlock's renderings at this point
                if (originalRenderingDefinitionContext != null)
                {
                    RenderingContext.CurrentOrNull.PageContext.PageDefinition = originalRenderingDefinitionContext;
                }

                Context.Site.SetDisplayMode(originalDisplayMode, DisplayModeDuration.Temporary);
            }
        }
Ejemplo n.º 20
0
 public override void Process(GetPageRenderingArgs args)
 {
     AssetRepository.Current.Clear();
 }
Ejemplo n.º 21
0
 public override void Process(GetPageRenderingArgs args)
 {
     this.AddSiteAssetsFromConfiguration();
 }
Ejemplo n.º 22
0
 public override void Process(GetPageRenderingArgs args)
 {
     this.AddAssets();
 }
Ejemplo n.º 23
0
 public override void Process(GetPageRenderingArgs args)
 {
     this.AddAssets(PageContext.Current.Item);
 }