importing more stuff from Belle proj

This commit is contained in:
Shannon Deminick
2013-05-26 19:54:50 -10:00
parent 8b841e19eb
commit faae0b85cb
17 changed files with 741 additions and 298 deletions

View File

@@ -0,0 +1,13 @@
require.config("##RequireJsConfig##");
require("##RequireJsInitialize##", function (angular, myApp) {
//This function will be called when all the dependencies
//listed above are loaded. Note that this function could
//be called before the page is loaded.
//This callback is optional.
jQuery(document).ready(function() {
angular.bootstrap(document, ['myApp']);
});
});

View File

@@ -0,0 +1,33 @@
{
/*NOTE: This is actually /Belle/js because we are loading in requireJs from /Belle already*/
baseUrl: 'js',
waitSeconds: 120,
paths: {
jquery: '../lib/jquery/jquery-1.8.2.min',
jqueryCookie: '../lib/jquery/jquery.cookie',
bootstrap: '../lib/bootstrap/js/bootstrap',
underscore: '../lib/underscore/underscore',
angular: '../lib/angular/angular',
angularResource: '../lib/angular/angular-resource',
statemanager: '../lib/angular/statemanager',
text: '../lib/require/text',
async: '../lib/require/async',
namespaceMgr: '../lib/Umbraco/NamespaceManager',
myApp: '../../../Content/JavaScript/myApp'
},
shim: {
'angular' : {'exports' : 'angular'},
'angular-resource': { deps: ['angular'] },
'statemanager': { deps: ['angular'] },
'bootstrap': { deps: ['jquery'] },
'jqueryCookie': { deps: ['jquery'] },
'angular-statemanager' : {deps:['angular']},
'underscore': {exports: '_'}
},
priority: [
"angular"
],
urlArgs: 'v=1.1'
}

View File

@@ -0,0 +1,79 @@
using System.IO;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Umbraco.Core.Manifest;
namespace Umbraco.Web.UI.JavaScript
{
/// <summary>
/// Reads from all defined manifests and ensures that any of their initialization is output with the
/// main Umbraco initialization output.
/// </summary>
internal class RequireJsInit
{
private readonly DirectoryInfo _pluginsDir;
private readonly ManifestParser _parser;
public RequireJsInit(DirectoryInfo pluginsDir)
{
_pluginsDir = pluginsDir;
_parser = new ManifestParser(_pluginsDir);
}
private static readonly Regex Token = new Regex("(\"##\\w+?##\")", RegexOptions.Compiled);
/// <summary>
/// Processes all found manifest files and outputs the main.js file containing all plugin manifests
/// </summary>
public string GetJavascriptInitialization(JObject umbracoConfig, JArray umbracoInit)
{
foreach (var m in _parser.GetManifests())
{
ManifestParser.MergeJObjects(umbracoConfig, m.JavaScriptConfig, true);
ManifestParser.MergeJArrays(umbracoInit, m.JavaScriptInitialize);
}
return ParseMain(umbracoConfig.ToString(), umbracoInit.ToString());
}
/// <summary>
/// Returns the default config as a JObject
/// </summary>
/// <returns></returns>
internal static JObject GetDefaultConfig()
{
var config = Resources.RequireJsConfig;
var jObj = JsonConvert.DeserializeObject<JObject>(config);
return jObj;
}
/// <summary>
/// Returns the default config as a JArray
/// </summary>
/// <returns></returns>
internal static JArray GetDefaultInitialization()
{
var init = Resources.RequireJsInitialize;
var jArr = JsonConvert.DeserializeObject<JArray>(init);
return jArr;
}
/// <summary>
/// Parses the JsResources.Main and replaces the replacement tokens accordingly.
/// </summary>
/// <param name="replacements"></param>
/// <returns></returns>
internal static string ParseMain(params string[] replacements)
{
var count = 0;
return Token.Replace(Resources.Main, match =>
{
var replaced = replacements[count];
count++;
return replaced;
});
}
}
}

View File

@@ -0,0 +1,7 @@
[
'angular',
'jquery',
'underscore',
'namespaceMgr',
'myApp'
]

View File

@@ -0,0 +1,138 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18034
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Umbraco.Web.UI.JavaScript {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Umbraco.Web.UI.JavaScript.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to require.config(&quot;##RequireJsConfig##&quot;);
///
///require(&quot;##RequireJsInitialize##&quot;, function (angular, myApp) {
///
/// //This function will be called when all the dependencies
/// //listed above are loaded. Note that this function could
/// //be called before the page is loaded.
/// //This callback is optional.
///
/// jQuery(document).ready(function() {
/// angular.bootstrap(document, [&apos;myApp&apos;]);
/// });
///});.
/// </summary>
internal static string Main {
get {
return ResourceManager.GetString("Main", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {
///
/// /*NOTE: This is actually /Belle/js because we are loading in requireJs from /Belle already*/
/// baseUrl: &apos;js&apos;,
///
/// waitSeconds: 120,
/// paths: {
/// jquery: &apos;../lib/jquery/jquery-1.8.2.min&apos;,
/// jqueryCookie: &apos;../lib/jquery/jquery.cookie&apos;,
/// bootstrap: &apos;../lib/bootstrap/js/bootstrap&apos;,
/// underscore: &apos;../lib/underscore/underscore&apos;,
/// angular: &apos;../lib/angular/angular&apos;,
/// angularResource: &apos;../lib/angular/angular-resource&apos;,
/// statemanager: &apos;../ [rest of string was truncated]&quot;;.
/// </summary>
internal static string RequireJsConfig {
get {
return ResourceManager.GetString("RequireJsConfig", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to [
/// &apos;angular&apos;,
/// &apos;jquery&apos;,
/// &apos;underscore&apos;,
/// &apos;namespaceMgr&apos;,
/// &apos;myApp&apos;
///].
/// </summary>
internal static string RequireJsInitialize {
get {
return ResourceManager.GetString("RequireJsInitialize", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to //TODO: This would be nicer as an angular module so it can be injected into stuff... that&apos;d be heaps nicer, but
///// how to do that when this is not a regular JS file, it is a server side JS file and RequireJS seems to only want
///// to force load JS files ?
///
/////create the namespace (NOTE: This loads before any dependencies so we don&apos;t have a namespace mgr so we just create it manually)
///var Umbraco = {};
///Umbraco.Sys = {};
/////define a global static object
///Umbraco.Sys.ServerVariables = ##Variables## ;.
/// </summary>
internal static string ServerVariables {
get {
return ResourceManager.GetString("ServerVariables", resourceCulture);
}
}
}
}

View File

@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Main" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Main.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="RequireJsConfig" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>requirejsconfig.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="RequireJsInitialize" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>requirejsinitialize.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="ServerVariables" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>servervariables.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
</root>

View File

@@ -0,0 +1,9 @@
//TODO: This would be nicer as an angular module so it can be injected into stuff... that'd be heaps nicer, but
// how to do that when this is not a regular JS file, it is a server side JS file and RequireJS seems to only want
// to force load JS files ?
//create the namespace (NOTE: This loads before any dependencies so we don't have a namespace mgr so we just create it manually)
var Umbraco = {};
Umbraco.Sys = {};
//define a global static object
Umbraco.Sys.ServerVariables = ##Variables## ;

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace Umbraco.Web.UI.JavaScript
{
internal class ServerVariablesParser
{
/// <summary>
/// Can allow developers to add custom variables on startup
/// </summary>
internal static EventHandler<Dictionary<string, object>> Parsing;
internal const string Token = "##Variables##";
internal static string Parse(Dictionary<string, object> items)
{
var vars = JsResources.ServerVariables;
if (Parsing != null)
{
Parsing(null, items);
}
var json = JObject.FromObject(items);
return vars.Replace(Token, json.ToString());
}
}
}