public static string Html(Func <int, int> random, int paragraphs, bool includeHeading, bool includeHeadAndBody) { var builder = new StringBuilder(); var innerEngine = new InnerEngine(random); var waffleContent = innerEngine.GetContent(paragraphs, includeHeading); if (waffleContent.Heading != null) { if (includeHeadAndBody) { builder.AppendLine(@$ "<html> <head> <title>{waffleContent.Heading.Title}</title>
public static string Html(Func <int, int> random, int paragraphs, bool includeHeading, bool includeHeadAndBody) { var builder = new StringBuilder(); var innerEngine = new InnerEngine(random); var waffleContent = innerEngine.GetContent(paragraphs, includeHeading); if (includeHeading) { if (includeHeadAndBody) { builder.AppendLine("<html>"); builder.AppendLine("<head>"); builder.AppendFormat("<title>{0}</title>", waffleContent.Heading.Title); builder.AppendLine(); builder.AppendLine("</head>"); builder.AppendLine("<body>"); } builder.AppendFormat(@"<h1>{0}</h1>", waffleContent.Heading.Title); builder.AppendLine(); builder.AppendLine($"<blockquote>\"{waffleContent.Heading.Quote}\"<br>"); builder.AppendLine($"<cite>{waffleContent.Heading.Cite}</cite></blockquote>"); builder.AppendLine($"<h2>{waffleContent.Heading.Buzz}</h2>"); } foreach (var paragraph in waffleContent.Paragraphs) { builder.AppendLine("<p>"); if (paragraph.Heading != null) { builder.AppendLine($"<h2>{paragraph.Heading}</h2>"); } builder.AppendLine(paragraph.Body); builder.AppendLine("</p>"); } if (includeHeadAndBody) { builder.AppendLine("</body>"); builder.Append("</html>"); } return(builder.ToString()); }
public static string Text(Func <int, int> random, int paragraphs, bool includeHeading) { var builder = new StringBuilder(); var innerEngine = new InnerEngine(random); var waffleContent = innerEngine.GetContent(paragraphs, includeHeading); if (includeHeading) { builder.AppendLine(waffleContent.Heading.Title); builder.AppendLine(); builder.AppendLine($"\"{waffleContent.Heading.Quote}\""); builder.AppendLine(); builder.AppendLine($" - {waffleContent.Heading.Cite}"); builder.AppendLine(); builder.AppendLine(waffleContent.Heading.Buzz); builder.AppendLine(); } var lastIndex = waffleContent.Paragraphs.Count - 1; for (var index = 0; index < waffleContent.Paragraphs.Count; index++) { var paragraph = waffleContent.Paragraphs[index]; if (paragraph.Heading != null) { builder.AppendLine(paragraph.Heading); builder.AppendLine(); } builder.AppendLine(paragraph.Body); if (index != lastIndex) { builder.AppendLine(); } } return(builder.ToString()); }
/// <summary> /// Creates a pre-compiled script from embedded JS resource /// </summary> /// <param name="resourceName">The case-sensitive resource name without the namespace of the specified type</param> /// <param name="type">The type, that determines the assembly and whose namespace is used to scope /// the resource name</param> /// <returns>A pre-compiled script that can be executed by different instances of JS engine</returns> public virtual IPrecompiledScript PrecompileResource(string resourceName, Type type) { return(InnerEngine.PrecompileResource(resourceName, type)); }
/// <summary> /// Creates a pre-compiled script from JS code /// </summary> /// <param name="code">JS code</param> /// <param name="documentName">Document name</param> /// <returns>A pre-compiled script that can be executed by different instances of JS engine</returns> public virtual IPrecompiledScript Precompile(string code, string documentName) { return(InnerEngine.Precompile(code, documentName)); }
/// <summary> /// Collects the garbage /// </summary> public virtual void CollectGarbage() { InnerEngine.CollectGarbage(); }
/// <summary> /// Embeds a .NET type in the JS engine /// </summary> /// <param name="itemName">Name of the type</param> /// <param name="type">The type</param> /// <remarks> /// .NET types are exposed to script code in the form of objects whose properties and /// methods are bound to the type's static members. /// </remarks> public virtual void EmbedHostType(string itemName, Type type) { InnerEngine.EmbedHostType(itemName, type); }
/// <summary> /// Removes a variable /// </summary> /// <param name="variableName">Variable name</param> public virtual void RemoveVariable(string variableName) { InnerEngine.RemoveVariable(variableName); }
/// <summary> /// Gets a value of variable /// </summary> /// <typeparam name="T">Type of variable</typeparam> /// <param name="variableName">Variable name</param> /// <returns>Value of variable</returns> public virtual T GetVariableValue <T>(string variableName) { return(InnerEngine.GetVariableValue <T>(variableName)); }
/// <summary> /// Evaluates an expression /// </summary> /// <typeparam name="T">Type of result</typeparam> /// <param name="expression">JS expression</param> /// <param name="documentName">Document name</param> /// <returns>Result of the expression</returns> public virtual T Evaluate <T>(string expression, string documentName) { return(InnerEngine.Evaluate <T>(expression, documentName)); }
/// <summary> /// Evaluates an expression /// </summary> /// <typeparam name="T">Type of result</typeparam> /// <param name="expression">JS expression</param> /// <returns>Result of the expression</returns> public virtual T Evaluate <T>(string expression) { return(InnerEngine.Evaluate <T>(expression)); }
/// <summary> /// Evaluates an expression /// </summary> /// <param name="expression">JS expression</param> /// <param name="documentName">Document name</param> /// <returns>Result of the expression</returns> public virtual object Evaluate(string expression, string documentName) { return(InnerEngine.Evaluate(expression, documentName)); }
/// <summary> /// Evaluates an expression /// </summary> /// <param name="expression">JS expression</param> /// <returns>Result of the expression</returns> public virtual object Evaluate(string expression) { return(InnerEngine.Evaluate(expression)); }
public static string Title(Func <int, int> random) { var innerEngine = new InnerEngine(random); return(innerEngine.BuildTitle()); }
/// <summary> /// Сhecks for the existence of a variable /// </summary> /// <param name="variableName">Variable name</param> /// <returns>Result of check (true - exists; false - not exists</returns> public virtual bool HasVariable(string variableName) { return(InnerEngine.HasVariable(variableName)); }
/// <summary> /// Gets a value of variable /// </summary> /// <param name="variableName">Variable name</param> /// <returns>Value of variable</returns> public virtual object GetVariableValue(string variableName) { return(InnerEngine.GetVariableValue(variableName)); }
/// <summary> /// Executes a code /// </summary> /// <param name="code">JS code</param> public virtual void Execute(string code) { InnerEngine.Execute(code); }
/// <summary> /// Sets a value of variable /// </summary> /// <param name="variableName">Variable name</param> /// <param name="value">Value of variable</param> public virtual void SetVariableValue(string variableName, object value) { InnerEngine.SetVariableValue(variableName, value); }
/// <summary> /// Executes a code /// </summary> /// <param name="code">JS code</param> /// <param name="documentName">Document name</param> public virtual void Execute(string code, string documentName) { InnerEngine.Execute(code, documentName); }
/// <summary> /// Embeds a .NET object in the JS engine /// </summary> /// <param name="itemName">Name of the item</param> /// <param name="value">Value of the item</param> /// <remarks>Allows to embed instances of simple classes (or structures) and delegates.</remarks> public virtual void EmbedHostObject(string itemName, object value) { InnerEngine.EmbedHostObject(itemName, value); }
/// <summary> /// Executes a pre-compiled script /// </summary> /// <param name="precompiledScript">A pre-compiled script that can be executed by different /// instances of JS engine</param> public virtual void Execute(IPrecompiledScript precompiledScript) { InnerEngine.Execute(precompiledScript); }
/// <summary> /// Interrupts script execution and causes the JS engine to throw an exception /// </summary> public virtual void Interrupt() { InnerEngine.Interrupt(); }
/// <summary> /// Executes a code from JS file /// </summary> /// <param name="path">Path to the JS file</param> /// <param name="encoding">Text encoding</param> public virtual void ExecuteFile(string path, Encoding encoding = null) { InnerEngine.ExecuteFile(path, encoding); }
/// <summary> /// Creates a pre-compiled script from JS code /// </summary> /// <param name="code">JS code</param> /// <returns>A pre-compiled script that can be executed by different instances of JS engine</returns> public virtual IPrecompiledScript Precompile(string code) { return(InnerEngine.Precompile(code)); }
/// <summary> /// Executes a code from embedded JS resource /// </summary> /// <param name="resourceName">The case-sensitive resource name without the namespace of the specified type</param> /// <param name="type">The type, that determines the assembly and whose namespace is used to scope /// the resource name</param> public virtual void ExecuteResource(string resourceName, Type type) { InnerEngine.ExecuteResource(resourceName, type); }
/// <summary> /// Creates a pre-compiled script from JS file /// </summary> /// <param name="path">Path to the JS file</param> /// <param name="encoding">Text encoding</param> /// <returns>A pre-compiled script that can be executed by different instances of JS engine</returns> public virtual IPrecompiledScript PrecompileFile(string path, Encoding encoding = null) { return(InnerEngine.PrecompileFile(path, encoding)); }
/// <summary> /// Executes a code from embedded JS resource /// </summary> /// <param name="resourceName">The case-sensitive resource name</param> /// <param name="assembly">The assembly, which contains the embedded resource</param> public virtual void ExecuteResource(string resourceName, Assembly assembly) { InnerEngine.ExecuteResource(resourceName, assembly); }
/// <summary> /// Creates a pre-compiled script from embedded JS resource /// </summary> /// <param name="resourceName">The case-sensitive resource name</param> /// <param name="assembly">The assembly, which contains the embedded resource</param> /// <returns>A pre-compiled script that can be executed by different instances of JS engine</returns> public virtual IPrecompiledScript PrecompileResource(string resourceName, Assembly assembly) { return(InnerEngine.PrecompileResource(resourceName, assembly)); }
/// <summary> /// Calls a function /// </summary> /// <typeparam name="T">Type of function result</typeparam> /// <param name="functionName">Function name</param> /// <param name="args">Function arguments</param> /// <returns>Result of the function execution</returns> public virtual T CallFunction <T>(string functionName, params object[] args) { return(InnerEngine.CallFunction <T>(functionName, args)); }