Skip to content

Instantly share code, notes, and snippets.

# Node.js
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
internal static class ResourceGroupExtensions
{
/// <summary>
/// Converts the source data to a Javascript variable
/// </summary>
/// <param name="resources">The record to convert</param>
/// <returns>A valid Javascript object</returns>
internal static string ToJavascript(this IEnumerable<ResourceGroup> resources)
{
StringBuilder sb = new StringBuilder();
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Localization;
using System.Linq;
using System.Reflection;
namespace InjectJavascriptToWebApp
{
<environment include="Development">
<resources names='new[] { "Labels" }'></resources>
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"></script>
</environment>
public class ResourcesHelper
{
private readonly IStringLocalizerFactory _stringLocalizerFactory;
public ResourcesHelper(IStringLocalizerFactory stringLocalizerFactory)
{
_stringLocalizerFactory = stringLocalizerFactory;
}
public IEnumerable<LocalizedString> GetResources(string name)
internal class ResourceGroup
{
public string Name { get; set; }
public IEnumerable<LocalizedString> Entries { get; set; }
}
services.AddLocalization(options => options.ResourcesPath = "Resources");
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddLocalization(options => options.ResourcesPath = "Resources");
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
internal class ResourceJavaScriptService
{
/// <summary>
/// Converts the source data to a Javascript variable
/// </summary>
/// <param name="fields">The record to convert</param>
/// <returns>A valid Javascript object</returns>
public string ToJavascript(IEnumerable<ResourceGroup> fields)
{
StringBuilder sb = new StringBuilder();