Initial state

This commit is contained in:
SteveSandersonMS
2015-11-02 10:30:36 -08:00
parent 0e1fa2e09d
commit f693bd60e3
110 changed files with 6722 additions and 0 deletions

View File

@@ -0,0 +1 @@
/bin/

View File

@@ -0,0 +1,50 @@
using System.Threading.Tasks;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.NodeServices;
using Microsoft.AspNet.Http.Extensions;
namespace Microsoft.AspNet.NodeServices.Angular
{
[HtmlTargetElement(Attributes = PrerenderModuleAttributeName)]
public class AngularRunAtServerTagHelper : TagHelper
{
static StringAsTempFile nodeScript;
static AngularRunAtServerTagHelper() {
// Consider populating this lazily
var script = EmbeddedResourceReader.Read(typeof (AngularRunAtServerTagHelper), "/Content/Node/angular-rendering.js");
nodeScript = new StringAsTempFile(script); // Will be cleaned up on process exit
}
const string PrerenderModuleAttributeName = "aspnet-ng2-prerender-module";
const string PrerenderExportAttributeName = "aspnet-ng2-prerender-export";
private static NodeInstance nodeInstance = new NodeInstance();
[HtmlAttributeName(PrerenderModuleAttributeName)]
public string ModuleName { get; set; }
[HtmlAttributeName(PrerenderExportAttributeName)]
public string ExportName { get; set; }
private IHttpContextAccessor contextAccessor;
public AngularRunAtServerTagHelper(IHttpContextAccessor contextAccessor)
{
this.contextAccessor = contextAccessor;
}
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var result = await nodeInstance.InvokeExport(nodeScript.FileName, "renderComponent", new {
componentModule = this.ModuleName,
componentExport = this.ExportName,
tagName = output.TagName,
baseUrl = UriHelper.GetEncodedUrl(this.contextAccessor.HttpContext.Request)
});
output.SuppressOutput();
output.PostElement.AppendEncoded(result);
}
}
}

View File

@@ -0,0 +1,28 @@
var path = require('path');
var ngUniversal = require('angular2-universal-patched');
var ng = require('angular2/angular2');
var ngRouter = require('angular2/router');
module.exports = {
renderComponent: function(callback, options) {
// Find the component class. Use options.componentExport if specified, otherwise convert tag-name to PascalCase.
var loadedModule = require(path.resolve(process.cwd(), options.componentModule));
var componentExport = options.componentExport || options.tagName.replace(/(-|^)([a-z])/g, function (m1, m2, char) { return char.toUpperCase(); });
var component = loadedModule[componentExport];
if (!component) {
throw new Error('The module "' + options.componentModule + '" has no export named "' + componentExport + '"');
}
var serverBindings = [
ngRouter.ROUTER_BINDINGS,
ngUniversal.HTTP_PROVIDERS,
ng.provide(ngUniversal.BASE_URL, { useValue: options.baseUrl }),
ngUniversal.SERVER_LOCATION_PROVIDERS
];
return ngUniversal.renderToString(component, serverBindings).then(
function(successValue) { callback(null, successValue); },
function(errorValue) { callback(errorValue); }
);
}
};

View File

@@ -0,0 +1,34 @@
{
"version": "1.0.0-alpha1",
"description": "Microsoft.AspNet.NodeServices.Angular Class Library",
"authors": [
"Microsoft"
],
"tags": [
""
],
"projectUrl": "",
"licenseUrl": "",
"tooling": {
"defaultNamespace": "Microsoft.AspNet.NodeServices.Angular"
},
"frameworks": {
"dnx451": {},
"dnxcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-*",
"System.Collections": "4.0.11-beta-*",
"System.Linq": "4.0.1-beta-*",
"System.Runtime": "4.0.21-beta-*",
"System.Threading": "4.0.11-beta-*"
}
}
},
"dependencies": {
"Microsoft.AspNet.NodeServices": "1.0.0-alpha1",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8"
},
"resource": [
"Content/**/*"
]
}