The settings to be used when Rendering a Mustache Template
Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Context"/> class.
 /// </summary>
 /// <param name="view">The data view to create the context with</param>
 /// <param name="registry">A reference to the a registry instance</param>
 /// <param name="parentContext">The parent context for the new context</param>
 /// <param name="settings">The render settings </param>
 public Context(object view, Registry registry, Context parentContext, RenderSettings settings)
 {
     this.view = view;
     View = this.view;
     ParentContext = parentContext;
     Registry = registry;
     RenderSettings = settings;
     Cache = new Dictionary<string, object>()
     {
         { ".", TryEnumerationConversionIfRequired(this.view) }
     };
 }
Example #2
0
 /// <summary>
 /// Takes a template, view object, partials and render settings and Renders them
 /// using default tags
 /// </summary>
 /// <param name="template">The template to parse and render</param>
 /// <param name="view">The view object to use to render</param>
 /// <param name="partials">The partials available to the template</param>
 /// <param name="settings">The settings to use for rendering</param>
 /// <returns>The template rendered with the view object</returns>
 public string Render(string template, object view, IDictionary<string, string> partials, RenderSettings settings)
     => Render(template, new Context(view, Registry, settings), partials, null);
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Context"/> class.
 /// </summary>
 /// <param name="view">The data view to create the context with</param>
 /// <param name="registry">A reference to the a registry instance</param>
 /// <param name="settings">The render settings </param>
 public Context(object view, Registry registry, RenderSettings settings)
     : this(view, registry, null, settings)
 {
 }
 /// <summary>
 /// Renders the template with the given view and partials using
 /// the writer and the given Render Settings
 /// </summary>
 /// <param name="template">The mustache teplate to render</param>
 /// <param name="view">The data to use for rendering</param>
 /// <param name="partials">A hash of Partials</param>
 /// <param name="settings">Any settings you wish to override the defaults with</param>
 /// <returns>A mustache rendered string</returns>
 public static string Render(string template, object view, IDictionary<string, string> partials, RenderSettings settings)
 {
     return Instance.Render(template, view, partials, settings);
 }
 /// <summary>
 /// Renders the template with the given view using the writer
 /// and the given render settings.
 /// </summary>
 /// <param name="template">The mustache teplate to render</param>
 /// <param name="view">The data to use for rendering</param>
 /// <param name="settings">Any settings you wish to override the defaults with</param>
 /// <returns>A mustache rendered string</returns>
 public static string Render(string template, object view, RenderSettings settings)
 {
     return Instance.Render(template, view, settings);
 }
Example #6
0
        /// <summary>
        /// Renders the template with the given view and partials using
        /// the writer and the given Render Settings
        /// </summary>
        /// <param name="template">The mustache teplate to render</param>
        /// <param name="view">The data to use for rendering</param>
        /// <param name="partials">A hash of Partials</param>
        /// <param name="settings">Any settings you wish to override the defaults with</param>
        /// <returns>A mustache rendered string</returns>
        public string Render(string template, object view, IDictionary<string, string> partials, RenderSettings settings)
        {
            var loadedTemplate = Registry.TemplateLoader.Load(template);
            if (loadedTemplate == null)
            {
                throw new UnknownTemplateException("No template was found with the name '" + template + "'");
            }

            return Writer.Render(loadedTemplate, view, partials, settings ?? Registry.RenderSettings);
        }
Example #7
0
 /// <summary>
 /// Renders the template with the given view using the writer
 /// and the given render settings.
 /// </summary>
 /// <param name="template">The mustache teplate to render</param>
 /// <param name="view">The data to use for rendering</param>
 /// <param name="settings">Any settings you wish to override the defaults with</param>
 /// <returns>A mustache rendered string</returns>
 public string Render(string template, object view, RenderSettings settings)
 {
     return Render(template, view, null, settings);
 }