public override void Process(TagHelperContext context, TagHelperOutput output) { if (String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Src)) { // Include custom script var setting = _resourceManager.RegisterUrl("stylesheet", Src, DebugSrc); if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } else { setting.AtLocation(ResourceLocation.Head); } if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } if (AppendVersion.HasValue == true) { setting.ShouldAppendVersion(AppendVersion); } if (Debug != null) { setting.UseDebugMode(Debug.Value); } if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } } else if (!String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Src)) { // Resource required var setting = _resourceManager.RegisterResource("stylesheet", Name); if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } else { setting.AtLocation(ResourceLocation.Head); } if (UseCdn != null) { setting.UseCdn(UseCdn.Value); } if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } if (Debug != null) { setting.UseDebugMode(Debug.Value); } if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } if (AppendVersion.HasValue == true) { setting.ShouldAppendVersion(AppendVersion); } if (!String.IsNullOrEmpty(Version)) { setting.UseVersion(Version); } // This allows additions to the pre registered scripts dependencies. if (!String.IsNullOrEmpty(DependsOn)) { setting.SetDependencies(DependsOn.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } } else if (!String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Src)) { // Inline declaration var definition = _resourceManager.InlineManifest.DefineStyle(Name); definition.SetUrl(Src, DebugSrc); if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } if (!String.IsNullOrEmpty(CdnSrc)) { definition.SetCdn(CdnSrc, DebugCdnSrc); } if (!String.IsNullOrEmpty(Culture)) { definition.SetCultures(Culture.Split(',', StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(DependsOn)) { definition.SetDependencies(DependsOn.Split(',', StringSplitOptions.RemoveEmptyEntries)); } // Also include the style var setting = _resourceManager.RegisterResource("stylesheet", Name); if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } else { setting.AtLocation(ResourceLocation.Head); } if (UseCdn != null) { setting.UseCdn(UseCdn.Value); } if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } if (Debug != null) { setting.UseDebugMode(Debug.Value); } if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } } output.TagName = null; }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { output.SuppressOutput(); if (String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Source)) { RequireSettings setting; if (String.IsNullOrEmpty(DependsOn)) { // Include custom script url setting = _resourceManager.Include("script", Source, DebugSrc); } else { // Anonymous declaration with dependencies, then display // Using the source as the name to prevent duplicate references to the same file var name = Source.ToLowerInvariant(); var definition = _resourceManager.InlineManifest.DefineScript(name); definition.SetUrl(Source, DebugSrc); if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } if (!String.IsNullOrEmpty(CdnSrc)) { definition.SetCdn(CdnSrc, DebugCdnSrc); } if (!String.IsNullOrEmpty(Culture)) { definition.SetCultures(Culture.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(DependsOn)) { definition.SetDependencies(DependsOn.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } setting = _resourceManager.RegisterResource("script", name); } if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } setting.UseDebugMode(Debug); if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } foreach (var attribute in output.Attributes) { setting.SetAttribute(attribute.Name, attribute.Value.ToString()); } } else if (!String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Source)) { // Resource required var setting = _resourceManager.RegisterResource("script", Name); if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } setting.UseCdn(UseCdn); if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } setting.UseDebugMode(Debug); if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } if (!String.IsNullOrEmpty(Version)) { setting.UseVersion(Version); } } else if (!String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Source)) { // Inline declaration var definition = _resourceManager.InlineManifest.DefineScript(Name); definition.SetUrl(Source, DebugSrc); if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } if (!String.IsNullOrEmpty(CdnSrc)) { definition.SetCdn(CdnSrc, DebugCdnSrc); } if (!String.IsNullOrEmpty(Culture)) { definition.SetCultures(Culture.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(DependsOn)) { definition.SetDependencies(DependsOn.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } // If At is specified then we also render it if (At != ResourceLocation.Unspecified) { var setting = _resourceManager.RegisterResource("script", Name); setting.AtLocation(At); if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } setting.UseDebugMode(Debug); if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } foreach (var attribute in output.Attributes) { setting.SetAttribute(attribute.Name, attribute.Value.ToString()); } } } else if (String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Source)) { // Custom script content var childContent = await output.GetChildContentAsync(); var builder = new TagBuilder("script"); builder.InnerHtml.AppendHtml(childContent); builder.TagRenderMode = TagRenderMode.Normal; foreach (var attribute in output.Attributes) { builder.Attributes.Add(attribute.Name, attribute.Value.ToString()); } // If no type was specified, define a default one if (!builder.Attributes.ContainsKey("type")) { builder.Attributes.Add("type", "text/javascript"); } if (At == ResourceLocation.Head) { _resourceManager.RegisterHeadScript(builder); } else { _resourceManager.RegisterFootScript(builder); } } }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { output.SuppressOutput(); if (String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Src)) { // Include custom script var setting = _resourceManager.RegisterUrl("stylesheet", Src, DebugSrc); foreach (var attribute in output.Attributes) { setting.SetAttribute(attribute.Name, attribute.Value.ToString()); } if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } else { setting.AtLocation(ResourceLocation.Head); } if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } if (AppendVersion.HasValue == true) { setting.ShouldAppendVersion(AppendVersion); } if (Debug != null) { setting.UseDebugMode(Debug.Value); } if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } } else if (!String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Src)) { // Resource required var setting = _resourceManager.RegisterResource("stylesheet", Name); foreach (var attribute in output.Attributes) { setting.SetAttribute(attribute.Name, attribute.Value.ToString()); } if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } else { setting.AtLocation(ResourceLocation.Head); } if (UseCdn != null) { setting.UseCdn(UseCdn.Value); } if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } if (Debug != null) { setting.UseDebugMode(Debug.Value); } if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } if (AppendVersion.HasValue == true) { setting.ShouldAppendVersion(AppendVersion); } if (!String.IsNullOrEmpty(Version)) { setting.UseVersion(Version); } // This allows additions to the pre registered scripts dependencies. if (!String.IsNullOrEmpty(DependsOn)) { setting.SetDependencies(DependsOn.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } var childContent = await output.GetChildContentAsync(); if (!childContent.IsEmptyOrWhiteSpace) { // Inline content definition _resourceManager.InlineManifest.DefineStyle(Name) .SetInnerContent(childContent.GetContent()); } } else if (!String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Src)) { // Inline declaration var definition = _resourceManager.InlineManifest.DefineStyle(Name); definition.SetUrl(Src, DebugSrc); foreach (var attribute in output.Attributes) { definition.SetAttribute(attribute.Name, attribute.Value.ToString()); } if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } if (!String.IsNullOrEmpty(CdnSrc)) { definition.SetCdn(CdnSrc, DebugCdnSrc); } if (!String.IsNullOrEmpty(Culture)) { definition.SetCultures(Culture.Split(',', StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(DependsOn)) { definition.SetDependencies(DependsOn.Split(',', StringSplitOptions.RemoveEmptyEntries)); } // Also include the style var setting = _resourceManager.RegisterResource("stylesheet", Name); if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } else { setting.AtLocation(ResourceLocation.Head); } if (UseCdn != null) { setting.UseCdn(UseCdn.Value); } if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } if (Debug != null) { setting.UseDebugMode(Debug.Value); } if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } } else if (String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Src)) { // Custom style content var childContent = await output.GetChildContentAsync(); var builder = new TagBuilder("style"); builder.InnerHtml.AppendHtml(childContent); builder.TagRenderMode = TagRenderMode.Normal; foreach (var attribute in output.Attributes) { builder.Attributes.Add(attribute.Name, attribute.Value.ToString()); } // If no type was specified, define a default one if (!builder.Attributes.ContainsKey("type")) { builder.Attributes.Add("type", "text/css"); } _resourceManager.RegisterStyle(builder); } }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { output.SuppressOutput(); if (String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Src)) { // <script asp-src="~/TheBlogTheme/js/clean-blog.min.js"></script> RequireSettings setting; if (String.IsNullOrEmpty(DependsOn)) { // Include custom script url setting = _resourceManager.RegisterUrl("script", Src, DebugSrc); } else { // Anonymous declaration with dependencies, then display // Using the source as the name to prevent duplicate references to the same file var name = Src.ToLowerInvariant(); var definition = _resourceManager.InlineManifest.DefineScript(name); definition.SetUrl(Src, DebugSrc); if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } if (!String.IsNullOrEmpty(CdnSrc)) { definition.SetCdn(CdnSrc, DebugCdnSrc); } if (!String.IsNullOrEmpty(Culture)) { definition.SetCultures(Culture.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(DependsOn)) { definition.SetDependencies(DependsOn.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (AppendVersion.HasValue) { definition.ShouldAppendVersion(AppendVersion); } if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } setting = _resourceManager.RegisterResource("script", name); } if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } if (Debug != null) { setting.UseDebugMode(Debug.Value); } if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } if (AppendVersion.HasValue) { setting.ShouldAppendVersion(AppendVersion); } foreach (var attribute in output.Attributes) { setting.SetAttribute(attribute.Name, attribute.Value.ToString()); } if (At == ResourceLocation.Unspecified || At == ResourceLocation.Inline) { using var sw = new StringWriter(); _resourceManager.RenderLocalScript(setting, sw); output.Content.AppendHtml(sw.ToString()); } } else if (!String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Src)) { // Resource required // <script asp-name="bootstrap"></script> var setting = _resourceManager.RegisterResource("script", Name); if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } if (UseCdn != null) { setting.UseCdn(UseCdn.Value); } if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } if (Debug != null) { setting.UseDebugMode(Debug.Value); } if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } if (AppendVersion.HasValue) { setting.ShouldAppendVersion(AppendVersion); } if (!String.IsNullOrEmpty(Version)) { setting.UseVersion(Version); } // This allows additions to the pre registered scripts dependencies. if (!String.IsNullOrEmpty(DependsOn)) { setting.SetDependencies(DependsOn.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } foreach (var attribute in output.Attributes) { setting.SetAttribute(attribute.Name, attribute.Value.ToString()); } // Allow Inline to work with both named scripts, and named inline scripts. if (At != ResourceLocation.Unspecified) { // Named inline declaration. var childContent = await output.GetChildContentAsync(); if (!childContent.IsEmptyOrWhiteSpace) { // Inline content definition _resourceManager.InlineManifest.DefineScript(Name) .SetInnerContent(childContent.GetContent()); } if (At == ResourceLocation.Inline) { using var sw = new StringWriter(); _resourceManager.RenderLocalScript(setting, sw); output.Content.AppendHtml(sw.ToString()); } } else { using var sw = new StringWriter(); _resourceManager.RenderLocalScript(setting, sw); output.Content.AppendHtml(sw.ToString()); } } else if (!String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Src)) { // Inline declaration var definition = _resourceManager.InlineManifest.DefineScript(Name); definition.SetUrl(Src, DebugSrc); if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } if (!String.IsNullOrEmpty(CdnSrc)) { definition.SetCdn(CdnSrc, DebugCdnSrc); } if (!String.IsNullOrEmpty(Culture)) { definition.SetCultures(Culture.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(DependsOn)) { definition.SetDependencies(DependsOn.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (AppendVersion.HasValue) { definition.ShouldAppendVersion(AppendVersion); } if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } // If At is specified then we also render it if (At != ResourceLocation.Unspecified) { var setting = _resourceManager.RegisterResource("script", Name); setting.AtLocation(At); if (UseCdn != null) { setting.UseCdn(UseCdn.Value); } if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } if (Debug != null) { setting.UseDebugMode(Debug.Value); } if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } foreach (var attribute in output.Attributes) { setting.SetAttribute(attribute.Name, attribute.Value.ToString()); } if (At == ResourceLocation.Inline) { using var sw = new StringWriter(); _resourceManager.RenderLocalScript(setting, sw); output.Content.AppendHtml(sw.ToString()); } } } else if (String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Src)) { // Custom script content var childContent = await output.GetChildContentAsync(); var builder = new TagBuilder("script"); builder.InnerHtml.AppendHtml(childContent); builder.TagRenderMode = TagRenderMode.Normal; foreach (var attribute in output.Attributes) { builder.Attributes.Add(attribute.Name, attribute.Value.ToString()); } if (At == ResourceLocation.Head) { _resourceManager.RegisterHeadScript(builder); } else if (At == ResourceLocation.Inline) { output.Content.SetHtmlContent(builder); } else { _resourceManager.RegisterFootScript(builder); } } }
public override void Process(TagHelperContext context, TagHelperOutput output) { output.SuppressOutput(); if (String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Src)) { // Include custom script url var setting = _resourceManager.Include("script", Src, DebugSrc); if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } setting.UseDebugMode(Debug); if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } foreach (var attribute in output.Attributes) { setting.SetAttribute(attribute.Name, attribute.Value.ToString()); } } else if (!String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Src)) { // Resource required var setting = _resourceManager.RegisterResource("script", Name); if (At != ResourceLocation.Unspecified) { setting.AtLocation(At); } setting.UseCdn(UseCdn); if (!String.IsNullOrEmpty(Condition)) { setting.UseCondition(Condition); } setting.UseDebugMode(Debug); if (!String.IsNullOrEmpty(Culture)) { setting.UseCulture(Culture); } if (!String.IsNullOrEmpty(Version)) { setting.UseVersion(Version); } } else if (!String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Src)) { // Inline declaration var definition = _resourceManager.InlineManifest.DefineScript(Name); definition.SetUrl(Src, DebugSrc); if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } if (!String.IsNullOrEmpty(CdnSrc)) { definition.SetCdn(CdnSrc, DebugCdnSrc); } if (!String.IsNullOrEmpty(Culture)) { definition.SetCultures(Culture.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(DependsOn)) { definition.SetDependencies(DependsOn.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(Version)) { definition.SetVersion(Version); } } else if (String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Src)) { // Custom script content var childContent = output.GetChildContentAsync().Result; var builder = new TagBuilder("script"); builder.InnerHtml.AppendHtml(childContent); builder.TagRenderMode = TagRenderMode.Normal; foreach (var attribute in output.Attributes) { builder.Attributes.Add(attribute.Name, attribute.Value.ToString()); } // If no type was specified, define a default one if (!builder.Attributes.ContainsKey("type")) { builder.Attributes.Add("type", "text/javascript"); } if (At == ResourceLocation.Head) { _resourceManager.RegisterHeadScript(builder); } else { _resourceManager.RegisterFootScript(builder); } } }