Updated server side stuff to work with new yepnope which makes things much simpler.
This commit is contained in:
+80
-92
@@ -1,92 +1,80 @@
|
||||
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 ManifestParser _parser;
|
||||
|
||||
public RequireJsInit(ManifestParser parser)
|
||||
{
|
||||
_parser = parser;
|
||||
}
|
||||
|
||||
//used to strip comments
|
||||
internal static readonly Regex Comments = new Regex("(/\\*.*\\*/)", RegexOptions.Compiled);
|
||||
//used for dealing with js functions inside of json (which is not a supported json syntax)
|
||||
private const string PrefixJavaScriptObject = "@@@@";
|
||||
private static readonly Regex JsFunctionParser = new Regex(string.Format("(\"{0}(.*?)\")+", PrefixJavaScriptObject),
|
||||
RegexOptions.Multiline
|
||||
| RegexOptions.CultureInvariant
|
||||
| RegexOptions.Compiled);
|
||||
//used to replace the tokens in the js main
|
||||
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];
|
||||
|
||||
//we need to cater for the special syntax when we have js function() objects contained in the json
|
||||
var jsFunctionParsed = JsFunctionParser.Replace(replaced, "$2");
|
||||
|
||||
count++;
|
||||
|
||||
return jsFunctionParsed;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
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 JsInitialization
|
||||
{
|
||||
private readonly ManifestParser _parser;
|
||||
|
||||
public JsInitialization(ManifestParser parser)
|
||||
{
|
||||
_parser = parser;
|
||||
}
|
||||
|
||||
//used to strip comments
|
||||
internal static readonly Regex Comments = new Regex("(/\\*.*\\*/)", RegexOptions.Compiled);
|
||||
//used for dealing with js functions inside of json (which is not a supported json syntax)
|
||||
private const string PrefixJavaScriptObject = "@@@@";
|
||||
private static readonly Regex JsFunctionParser = new Regex(string.Format("(\"{0}(.*?)\")+", PrefixJavaScriptObject),
|
||||
RegexOptions.Multiline
|
||||
| RegexOptions.CultureInvariant
|
||||
| RegexOptions.Compiled);
|
||||
//used to replace the tokens in the js main
|
||||
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(JArray umbracoInit)
|
||||
{
|
||||
foreach (var m in _parser.GetManifests())
|
||||
{
|
||||
ManifestParser.MergeJArrays(umbracoInit, m.JavaScriptInitialize);
|
||||
}
|
||||
|
||||
return ParseMain(umbracoInit.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the default config as a JArray
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static JArray GetDefaultInitialization()
|
||||
{
|
||||
var init = Resources.JsInitialize;
|
||||
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];
|
||||
|
||||
//we need to cater for the special syntax when we have js function() objects contained in the json
|
||||
var jsFunctionParsed = JsFunctionParser.Replace(replaced, "$2");
|
||||
|
||||
count++;
|
||||
|
||||
return jsFunctionParsed;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
[
|
||||
'lib/jquery/jquery-1.8.2.min.js',
|
||||
'lib/jquery/jquery.cookie.js',
|
||||
'lib/angular/angular.min.js',
|
||||
'lib/bootstrap/js/bootstrap.js',
|
||||
'lib/underscore/underscore.js',
|
||||
'lib/umbraco/Extensions.js',
|
||||
|
||||
'js/app.js',
|
||||
|
||||
'js/umbraco.resources.js',
|
||||
'js/umbraco.directives.js',
|
||||
'js/umbraco.filters.js',
|
||||
'js/umbraco.services.js',
|
||||
'js/umbraco.security.js',
|
||||
'js/umbraco.controllers.js',
|
||||
'js/routes.js'
|
||||
]
|
||||
@@ -1,13 +1,11 @@
|
||||
require.config("##RequireJsConfig##");
|
||||
yepnope({
|
||||
|
||||
require("##RequireJsInitialize##", function (angular, app, jQuery) {
|
||||
load: "##JsInitialize##",
|
||||
|
||||
//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.
|
||||
complete: function () {
|
||||
jQuery(document).ready(function () {
|
||||
angular.bootstrap(document, ['umbraco']);
|
||||
});
|
||||
|
||||
jQuery(document).ready(function () {
|
||||
angular.bootstrap(document, ['umbraco']);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,45 +0,0 @@
|
||||
{
|
||||
baseUrl: "js",
|
||||
waitSeconds: 120,
|
||||
paths: {
|
||||
jquery: '../lib/jquery/jquery-1.8.2.min',
|
||||
jqueryCookie: '../lib/jquery/jquery.cookie',
|
||||
umbracoExtensions: '../lib/umbraco/extensions',
|
||||
bootstrap: '../lib/bootstrap/js/bootstrap',
|
||||
underscore: '../lib/underscore/underscore',
|
||||
angular: '../lib/angular/angular.min',
|
||||
angularResource: '../lib/angular/angular-resource',
|
||||
|
||||
codemirror: '../lib/codemirror/js/lib/codemirror',
|
||||
codemirrorJs: '../lib/codemirror/js/mode/javascript/javascript',
|
||||
codemirrorCss: '../lib/codemirror/js/mode/css/css',
|
||||
codemirrorXml: '../lib/codemirror/js/mode/xml/xml',
|
||||
codemirrorHtml: '../lib/codemirror/js/mode/htmlmixed/htmlmixed',
|
||||
|
||||
tinymce: '../lib/tinymce/tinymce.min',
|
||||
text: '../lib/require/text',
|
||||
async: '../lib/require/async',
|
||||
css: '../lib/require/css',
|
||||
namespaceMgr: '../lib/Umbraco/NamespaceManager',
|
||||
},
|
||||
shim: {
|
||||
'umbracoExtensions' : {'exports' : 'umbracoExtensions'},
|
||||
'angular' : {'exports' : 'angular'},
|
||||
'angular-resource': { deps: ['angular'] },
|
||||
'bootstrap': { deps: ['jquery'] },
|
||||
'jqueryCookie': { deps: ['jquery'] },
|
||||
'underscore': {exports: '_'},
|
||||
'codemirror': {exports: 'CodeMirror'},
|
||||
'codemirrorJs':{deps:['codemirror']},
|
||||
'codemirrorCss':{deps:['codemirror']},
|
||||
'codemirrorXml':{deps:['codemirror']},
|
||||
'codemirrorHtml':{deps:['codemirrorXml','codemirrorCss','codemirrorJs'], exports: 'mixedMode'},
|
||||
/* THIS IS SPECIAL SYNTAX BECAUSE JS functions ARE NOT STANDARD JSON SO THEY CANNOT BE SERIALIZED */
|
||||
/* SO BEFORE WE RENDER WE'LL ENSURE THAT IT'S FORM */
|
||||
'tinymce': "@@@@{exports: 'tinyMCE', init: function () { this.tinymce.DOM.events.domLoaded = true; return this.tinymce; } }"
|
||||
},
|
||||
priority: [
|
||||
"angular"
|
||||
],
|
||||
urlArgs: 'v=1.1'
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
[
|
||||
'angular',
|
||||
'app',
|
||||
'jquery',
|
||||
'jqueryCookie',
|
||||
'umbracoExtensions',
|
||||
'bootstrap',
|
||||
'umbraco.resources',
|
||||
'umbraco.directives',
|
||||
'umbraco.filters',
|
||||
'umbraco.services',
|
||||
'umbraco.controllers',
|
||||
'sample.propertyeditor.controller',
|
||||
'sampletwo.propertyeditor.controller',
|
||||
'routes',
|
||||
'namespaceMgr'
|
||||
]
|
||||
+34
-47
@@ -1,7 +1,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.18034
|
||||
// Runtime Version:4.0.30319.18046
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
@@ -61,18 +61,42 @@ namespace Umbraco.Web.UI.JavaScript {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to require.config("##RequireJsConfig##");
|
||||
/// Looks up a localized string similar to [
|
||||
/// 'lib/jquery/jquery-1.8.2.min.js',
|
||||
/// 'lib/jquery/jquery.cookie.js',
|
||||
/// 'lib/angular/angular.min.js',
|
||||
/// 'lib/bootstrap/js/bootstrap.js',
|
||||
/// 'lib/underscore/underscore.js',
|
||||
/// 'lib/umbraco/Extensions.js',
|
||||
///
|
||||
///require("##RequireJsInitialize##", function (angular, myApp) {
|
||||
/// 'js/app.js',
|
||||
///
|
||||
/// //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.
|
||||
/// 'js/umbraco.resources.js',
|
||||
/// 'js/umbraco.directives.js',
|
||||
/// 'js/umbraco.filters.js',
|
||||
/// 'js/umbraco.services.js',
|
||||
/// 'js/umbraco.security.js',
|
||||
/// 'js/umbraco.controllers.js',
|
||||
/// 'js/routes.js'
|
||||
///].
|
||||
/// </summary>
|
||||
internal static string JsInitialize {
|
||||
get {
|
||||
return ResourceManager.GetString("JsInitialize", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to yepnope({
|
||||
///
|
||||
/// jQuery(document).ready(function() {
|
||||
/// angular.bootstrap(document, ['myApp']);
|
||||
/// });
|
||||
/// load: "##JsInitialize##",
|
||||
///
|
||||
/// complete: function () {
|
||||
/// jQuery(document).ready(function () {
|
||||
/// angular.bootstrap(document, ['umbraco']);
|
||||
/// });
|
||||
///
|
||||
/// }
|
||||
///});.
|
||||
/// </summary>
|
||||
internal static string Main {
|
||||
@@ -81,43 +105,6 @@ namespace Umbraco.Web.UI.JavaScript {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {
|
||||
///
|
||||
/// /*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: '../ [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string RequireJsConfig {
|
||||
get {
|
||||
return ResourceManager.GetString("RequireJsConfig", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to [
|
||||
/// 'angular',
|
||||
/// 'jquery',
|
||||
/// 'underscore',
|
||||
/// 'namespaceMgr',
|
||||
/// 'myApp'
|
||||
///].
|
||||
/// </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'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
|
||||
|
||||
@@ -118,15 +118,12 @@
|
||||
<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="JsInitialize" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>jsinitialize.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
|
||||
</data>
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user