Beispiel #1
0
        // NOT thread-safe over a request because it modifies the
        // global UmbracoContext.Current.InPreviewMode status. So it
        // should never execute in // over the same UmbracoContext with
        // different preview modes.
        static string RenderRteMacros(string source, bool preview)
        {
            // save and set for macro rendering
            var inPreviewMode = UmbracoContext.Current.InPreviewMode;

            UmbracoContext.Current.InPreviewMode = preview;

            var sb = new StringBuilder();

            try
            {
                var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
                MacroTagParser.ParseMacros(
                    source,
                    //callback for when text block is found
                    textBlock => sb.Append(textBlock),
                    //callback for when macro syntax is found
                    (macroAlias, macroAttributes) => sb.Append(umbracoHelper.RenderMacro(
                                                                   macroAlias,
                                                                   //needs to be explicitly casted to Dictionary<string, object>
                                                                   macroAttributes.ConvertTo(x => (string)x, x => x)).ToString()));
            }
            finally
            {
                // restore
                UmbracoContext.Current.InPreviewMode = inPreviewMode;
            }

            return(sb.ToString());
        }
        public bool Init(int CurrentNodeId, string PropertyData, out object instance)
        {
			//we're going to send the string through the macro parser and create the output string.
			if (UmbracoContext.Current != null)
			{
				var sb = new StringBuilder();
				var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
				MacroTagParser.ParseMacros(
					PropertyData,
					//callback for when text block is found
					textBlock => sb.Append(textBlock),
					//callback for when macro syntax is found
					(macroAlias, macroAttributes) => sb.Append(umbracoHelper.RenderMacro(
						macroAlias,
						//needs to be explicitly casted to Dictionary<string, object>
						macroAttributes.ConvertTo(x => (string)x, x => (object)x)).ToString()));
				instance = new HtmlString(sb.ToString());
			}			
			else
			{
				//we have no umbraco context, so best we can do is convert to html string
				instance = new HtmlString(PropertyData);
			}			
            return true;
        }
 public bool Init(int CurrentNodeId, string PropertyData, out object instance)
 {
     //we're going to send the string through the macro parser and create the output string.
     if (UmbracoContext.Current != null)
     {
         var sb            = new StringBuilder();
         var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
         MacroTagParser.ParseMacros(
             PropertyData,
             //callback for when text block is found
             textBlock => sb.Append(textBlock),
             //callback for when macro syntax is found
             (macroAlias, macroAttributes) => sb.Append(umbracoHelper.RenderMacro(
                                                            macroAlias,
                                                            //needs to be explicitly casted to Dictionary<string, object>
                                                            macroAttributes.ConvertTo(x => (string)x, x => (object)x)).ToString()));
         instance = new HtmlString(sb.ToString());
     }
     else
     {
         //we have no umbraco context, so best we can do is convert to html string
         instance = new HtmlString(PropertyData);
     }
     return(true);
 }
		/// <summary>
		/// Return IHtmlString so devs doesn't need to decode html
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public override Attempt<object> ConvertPropertyValue(object value)
		{
			//we're going to send the string through the macro parser and create the output string.
			var sb = new StringBuilder();
			var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
			MacroTagParser.ParseMacros(
				value.ToString(),
				//callback for when text block is found
				textBlock => sb.Append(textBlock),
				//callback for when macro syntax is found
				(macroAlias, macroAttributes) => sb.Append(umbracoHelper.RenderMacro(
					macroAlias, 
					//needs to be explicitly casted to Dictionary<string, object>
					macroAttributes.ConvertTo(x => (string)x, x => (object)x)).ToString()));

			return new Attempt<object>(true, new HtmlString(sb.ToString()));
		}
Beispiel #5
0
        /// <summary>
        /// Return IHtmlString so devs doesn't need to decode html
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override Attempt <object> ConvertPropertyValue(object value)
        {
            //we're going to send the string through the macro parser and create the output string.
            var sb            = new StringBuilder();
            var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);

            MacroTagParser.ParseMacros(
                value.ToString(),
                //callback for when text block is found
                textBlock => sb.Append(textBlock),
                //callback for when macro syntax is found
                (macroAlias, macroAttributes) => sb.Append(umbracoHelper.RenderMacro(
                                                               macroAlias,
                                                               //needs to be explicitly casted to Dictionary<string, object>
                                                               macroAttributes.ConvertTo(x => (string)x, x => (object)x)).ToString()));

            return(new Attempt <object>(true, new HtmlString(sb.ToString())));
        }
        // NOT thread-safe over a request because it modifies the
        // global UmbracoContext.Current.InPreviewMode status. So it
        // should never execute in // over the same UmbracoContext with
        // different preview modes.
        string RenderMacros(string source, bool preview)
        {
            var umbracoContext = _umbracoContextAccessor.UmbracoContext;

            using (umbracoContext.ForcedPreview(preview)) // force for macro rendering
            {
                var sb = new StringBuilder();

                var umbracoHelper = new UmbracoHelper(umbracoContext, _services);
                MacroTagParser.ParseMacros(
                    source,
                    //callback for when text block is found
                    textBlock => sb.Append(textBlock),
                    //callback for when macro syntax is found
                    (macroAlias, macroAttributes) => sb.Append(umbracoHelper.RenderMacro(
                                                                   macroAlias,
                                                                   //needs to be explicitly casted to Dictionary<string, object>
                                                                   macroAttributes.ConvertTo(x => (string)x, x => x)).ToString()));

                return(sb.ToString());
            }
        }