Last active
November 10, 2016 17:59
-
-
Save NTaylorMullen/b16b4ec9bac1bfd72b6db9c54da05203 to your computer and use it in GitHub Desktop.
TagHelper Hackathon Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Index | |
- YouTubeEmbed | |
- About | |
- Shared/_Layout.cshtml | |
INDEX.cshtml | |
<youtube-embed ..../> | |
<script src="youtubeembedjs.js" /> | |
<script src="foo.js" head-only order="123" /> | |
FOO.js | |
/// <link href="../../BAR.js" /> | |
// METADATA | |
STARTUP.cs | |
public void Configure(services) | |
{ | |
services.AddScriptManager(options => | |
{ | |
options.SetOrder("Foo.js", 123); | |
options.SetLocation("Foo.js", "head"); | |
}); | |
} | |
[HtmlTargetElement("script")] | |
public class ScriptManagerTagHelper : TagHelper | |
{ | |
public string Src { get; set; } | |
ctor(IScriptManager manager) | |
{ | |
_manager = manager; | |
} | |
Process(output, context) | |
{ | |
_manager.AddScript(Src); | |
output.SuppressOutput(); | |
} | |
} | |
public class YoutubeEmbed : TagHelper | |
{ | |
ctor(IScriptManager manager) | |
{ | |
_manager = manager; | |
} | |
Process(output, context) | |
{ | |
_manager.AddScript("myyoutubeembedscript.js"); | |
} | |
} | |
<youtube-embed /> | |
public class ScriptManagerOptionsSetup : IConfigureOptions<ScriptManagerOptions> | |
{ | |
private readonly IHostingEnvironment _hostingEnvironment; | |
public ScriptManagerOptionsSetup(IHostingEnvironment hostingEnv) | |
{ | |
_hostingEnvironment = hostingEnv; | |
} | |
public void Configure(ScriptManagerOptions options) | |
{ | |
if (_hostingEnvironment.IsProduction()) | |
{ | |
options.Minimized = true; | |
options.Cdn = "foo.cdn.com" | |
options.CombinedSrc = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment