mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-08 00:14:31 +08:00
Compare commits
9 Commits
feature/as
...
feature/as
Author | SHA1 | Date | |
---|---|---|---|
![]() |
41e6daab43 | ||
![]() |
51d12ba178 | ||
![]() |
6243b98e6c | ||
![]() |
f947f75252 | ||
![]() |
6865a744ff | ||
![]() |
ed426496f8 | ||
![]() |
968ecdc959 | ||
![]() |
21de6d02b1 | ||
![]() |
d812f9e894 |
@@ -22,7 +22,7 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
private TestVirtualPathProvider _testVirtualPathProvider;
|
||||
|
||||
|
||||
protected override void Register(Autofac.ContainerBuilder builder) {
|
||||
protected override void Register(ContainerBuilder builder) {
|
||||
_descriptor = new ShellDescriptor { };
|
||||
_testViewEngine = new TestViewEngine();
|
||||
_testVirtualPathProvider = new TestVirtualPathProvider { TestViewEngine = _testViewEngine };
|
||||
|
91
src/Orchard.Web/Core/Async/BindingStrategies/RequireJS.cs
Normal file
91
src/Orchard.Web/Core/Async/BindingStrategies/RequireJS.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.UI.Resources;
|
||||
|
||||
namespace Orchard.Core.Async.BindingStrategies {
|
||||
[OrchardFeature("Async.RequireJS")]
|
||||
public class RequireJS : IShapeTableProvider {
|
||||
public void Discover(ShapeTableBuilder builder) {
|
||||
builder.Describe("AsyncScriptsResourceWriter").OnDisplaying(context => {
|
||||
context.ShapeMetadata.Type = "RequireJSAsyncScriptsWriter";
|
||||
});
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public void RequireJSAsyncScriptsWriter(dynamic Shape, dynamic Display, TextWriter Output) {
|
||||
var defaultSettings = (RequireSettings) Shape.DefaultSettings;
|
||||
var appPath = (string) Shape.AppPath;
|
||||
var resources = (IEnumerable<ResourceRequiredContext>) Shape.Resources;
|
||||
|
||||
if (!resources.Any())
|
||||
return;
|
||||
|
||||
var dictionary = resources.ToDictionary(x => x.Resource.Name);
|
||||
var resourcesWithDependencies = resources.Where(x => x.Resource.Dependencies != null && x.Resource.Dependencies.Any()).ToArray();
|
||||
var scriptBuilder = new StringBuilder();
|
||||
|
||||
// Configure dependencies
|
||||
if (resourcesWithDependencies.Any()) {
|
||||
scriptBuilder.AppendFormat(
|
||||
"requirejs.config({{" +
|
||||
"shim: {{\r\n");
|
||||
|
||||
var index = 0;
|
||||
foreach (var resource in resourcesWithDependencies) {
|
||||
var resourceName = GetModuleName(defaultSettings, appPath, resource);
|
||||
var dependencies = String.Join(",", resource.Resource.Dependencies.Select(x => String.Format("\"{0}\"", GetModuleName(defaultSettings, appPath, dictionary[x]))));
|
||||
scriptBuilder.AppendFormat("\"{0}\": [{1}]", resourceName, dependencies);
|
||||
|
||||
if (index++ < resourcesWithDependencies.Length - 1) {
|
||||
scriptBuilder.AppendLine(",");
|
||||
}
|
||||
}
|
||||
|
||||
scriptBuilder.AppendFormat("}}" +
|
||||
"}});\r\n");
|
||||
}
|
||||
|
||||
var scripts = resources.Select(x => String.Format("\"{0}\"", GetModuleName(defaultSettings, appPath, x)));
|
||||
scriptBuilder.AppendFormat("requirejs([{0}]);\r\n", String.Join("\r\n,", scripts));
|
||||
|
||||
var tagBuilder = new TagBuilder("script") {
|
||||
InnerHtml = scriptBuilder.ToString()
|
||||
};
|
||||
tagBuilder.Attributes["type"] = "text/javascript";
|
||||
Output.Write(tagBuilder.ToString(TagRenderMode.Normal));
|
||||
}
|
||||
|
||||
private static string GetModuleName(RequireSettings defaultSettings, string appPath, ResourceRequiredContext resource) {
|
||||
var url = resource.GetResourceUrl(defaultSettings, appPath);
|
||||
|
||||
if (IsAbsoluteUrl(url))
|
||||
return url;
|
||||
|
||||
var path = url.Substring(appPath.Length);
|
||||
var name = TrimStartingSlash(GetPathWithoutExtension(path).ToLowerInvariant());
|
||||
return name;
|
||||
}
|
||||
|
||||
private static string TrimStartingSlash(string path) {
|
||||
return path.StartsWith("/") ? path.Substring(1) : path;
|
||||
}
|
||||
|
||||
private static string GetPathWithoutExtension(string path) {
|
||||
var index = path.LastIndexOf('.');
|
||||
return index > 0 ? path.Substring(0, index) : path;
|
||||
}
|
||||
|
||||
private static bool IsAbsoluteUrl(string url) {
|
||||
var segments = new[] {"http", "https", "ftp", "ftps", "//"};
|
||||
return segments.Any(url.StartsWith);
|
||||
}
|
||||
}
|
||||
}
|
26
src/Orchard.Web/Core/Async/Filters/RequireJS.cs
Normal file
26
src/Orchard.Web/Core/Async/Filters/RequireJS.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Mvc.Filters;
|
||||
using Orchard.UI.Resources;
|
||||
|
||||
namespace Orchard.Core.Async.Filters {
|
||||
[OrchardFeature("Async.RequireJS")]
|
||||
public class RequireJS : FilterProvider, IResultFilter {
|
||||
public RequireJS(IResourceManager resourceManager) {
|
||||
_resourceManager = resourceManager;
|
||||
}
|
||||
|
||||
private readonly IResourceManager _resourceManager;
|
||||
|
||||
public void OnResultExecuting(ResultExecutingContext filterContext) {
|
||||
if (!(filterContext.Result is ViewResult)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_resourceManager.Include("script", "~/Core/Async/Scripts/require.js", null).AtHead();
|
||||
}
|
||||
|
||||
public void OnResultExecuted(ResultExecutedContext filterContext) {
|
||||
}
|
||||
}
|
||||
}
|
14
src/Orchard.Web/Core/Async/Module.txt
Normal file
14
src/Orchard.Web/Core/Async/Module.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
Name: Async Scripts
|
||||
AntiForgery: enabled
|
||||
Author: The Orchard Team
|
||||
Website: http://orchardproject.net
|
||||
Version: 1.8.1
|
||||
OrchardVersion: 1.8
|
||||
Description: Provides static file binding strategies and supporting scripts that implement the loading of scripts in an asynchronous fashion.
|
||||
Category: Async
|
||||
Features:
|
||||
Async.RequireJS:
|
||||
Name: RequireJS
|
||||
Description: Uses RequireJS to load scripts asynchronously.
|
||||
Category: Async
|
||||
Dependencies: Async
|
16
src/Orchard.Web/Core/Async/Scripts/Web.config
Normal file
16
src/Orchard.Web/Core/Async/Scripts/Web.config
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<system.webServer>
|
||||
<staticContent>
|
||||
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
|
||||
</staticContent>
|
||||
|
||||
<handlers accessPolicy="Script,Read">
|
||||
<!--
|
||||
iis7 - for any request to a file exists on disk, return it via native http module.
|
||||
accessPolicy 'Script' is to allow for a managed 404 page.
|
||||
-->
|
||||
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" />
|
||||
</handlers>
|
||||
</system.webServer>
|
||||
</configuration>
|
36
src/Orchard.Web/Core/Async/Scripts/require.js
Normal file
36
src/Orchard.Web/Core/Async/Scripts/require.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
RequireJS 2.1.14 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
|
||||
Available via the MIT or new BSD license.
|
||||
see: http://github.com/jrburke/requirejs for details
|
||||
*/
|
||||
var requirejs,require,define;
|
||||
(function(ba){function G(b){return"[object Function]"===K.call(b)}function H(b){return"[object Array]"===K.call(b)}function v(b,c){if(b){var d;for(d=0;d<b.length&&(!b[d]||!c(b[d],d,b));d+=1);}}function T(b,c){if(b){var d;for(d=b.length-1;-1<d&&(!b[d]||!c(b[d],d,b));d-=1);}}function t(b,c){return fa.call(b,c)}function m(b,c){return t(b,c)&&b[c]}function B(b,c){for(var d in b)if(t(b,d)&&c(b[d],d))break}function U(b,c,d,e){c&&B(c,function(c,g){if(d||!t(b,g))e&&"object"===typeof c&&c&&!H(c)&&!G(c)&&!(c instanceof
|
||||
RegExp)?(b[g]||(b[g]={}),U(b[g],c,d,e)):b[g]=c});return b}function u(b,c){return function(){return c.apply(b,arguments)}}function ca(b){throw b;}function da(b){if(!b)return b;var c=ba;v(b.split("."),function(b){c=c[b]});return c}function C(b,c,d,e){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.requireModules=e;d&&(c.originalError=d);return c}function ga(b){function c(a,k,b){var f,l,c,d,e,g,i,p,k=k&&k.split("/"),h=j.map,n=h&&h["*"];if(a){a=a.split("/");l=a.length-1;j.nodeIdCompat&&
|
||||
Q.test(a[l])&&(a[l]=a[l].replace(Q,""));"."===a[0].charAt(0)&&k&&(l=k.slice(0,k.length-1),a=l.concat(a));l=a;for(c=0;c<l.length;c++)if(d=l[c],"."===d)l.splice(c,1),c-=1;else if(".."===d&&!(0===c||1==c&&".."===l[2]||".."===l[c-1])&&0<c)l.splice(c-1,2),c-=2;a=a.join("/")}if(b&&h&&(k||n)){l=a.split("/");c=l.length;a:for(;0<c;c-=1){e=l.slice(0,c).join("/");if(k)for(d=k.length;0<d;d-=1)if(b=m(h,k.slice(0,d).join("/")))if(b=m(b,e)){f=b;g=c;break a}!i&&(n&&m(n,e))&&(i=m(n,e),p=c)}!f&&i&&(f=i,g=p);f&&(l.splice(0,
|
||||
g,f),a=l.join("/"))}return(f=m(j.pkgs,a))?f:a}function d(a){z&&v(document.getElementsByTagName("script"),function(k){if(k.getAttribute("data-requiremodule")===a&&k.getAttribute("data-requirecontext")===i.contextName)return k.parentNode.removeChild(k),!0})}function e(a){var k=m(j.paths,a);if(k&&H(k)&&1<k.length)return k.shift(),i.require.undef(a),i.makeRequire(null,{skipMap:!0})([a]),!0}function n(a){var k,c=a?a.indexOf("!"):-1;-1<c&&(k=a.substring(0,c),a=a.substring(c+1,a.length));return[k,a]}function p(a,
|
||||
k,b,f){var l,d,e=null,g=k?k.name:null,j=a,p=!0,h="";a||(p=!1,a="_@r"+(K+=1));a=n(a);e=a[0];a=a[1];e&&(e=c(e,g,f),d=m(r,e));a&&(e?h=d&&d.normalize?d.normalize(a,function(a){return c(a,g,f)}):-1===a.indexOf("!")?c(a,g,f):a:(h=c(a,g,f),a=n(h),e=a[0],h=a[1],b=!0,l=i.nameToUrl(h)));b=e&&!d&&!b?"_unnormalized"+(O+=1):"";return{prefix:e,name:h,parentMap:k,unnormalized:!!b,url:l,originalName:j,isDefine:p,id:(e?e+"!"+h:h)+b}}function s(a){var k=a.id,b=m(h,k);b||(b=h[k]=new i.Module(a));return b}function q(a,
|
||||
k,b){var f=a.id,c=m(h,f);if(t(r,f)&&(!c||c.defineEmitComplete))"defined"===k&&b(r[f]);else if(c=s(a),c.error&&"error"===k)b(c.error);else c.on(k,b)}function w(a,b){var c=a.requireModules,f=!1;if(b)b(a);else if(v(c,function(b){if(b=m(h,b))b.error=a,b.events.error&&(f=!0,b.emit("error",a))}),!f)g.onError(a)}function x(){R.length&&(ha.apply(A,[A.length,0].concat(R)),R=[])}function y(a){delete h[a];delete V[a]}function F(a,b,c){var f=a.map.id;a.error?a.emit("error",a.error):(b[f]=!0,v(a.depMaps,function(f,
|
||||
d){var e=f.id,g=m(h,e);g&&(!a.depMatched[d]&&!c[e])&&(m(b,e)?(a.defineDep(d,r[e]),a.check()):F(g,b,c))}),c[f]=!0)}function D(){var a,b,c=(a=1E3*j.waitSeconds)&&i.startTime+a<(new Date).getTime(),f=[],l=[],g=!1,h=!0;if(!W){W=!0;B(V,function(a){var i=a.map,j=i.id;if(a.enabled&&(i.isDefine||l.push(a),!a.error))if(!a.inited&&c)e(j)?g=b=!0:(f.push(j),d(j));else if(!a.inited&&(a.fetched&&i.isDefine)&&(g=!0,!i.prefix))return h=!1});if(c&&f.length)return a=C("timeout","Load timeout for modules: "+f,null,
|
||||
f),a.contextName=i.contextName,w(a);h&&v(l,function(a){F(a,{},{})});if((!c||b)&&g)if((z||ea)&&!X)X=setTimeout(function(){X=0;D()},50);W=!1}}function E(a){t(r,a[0])||s(p(a[0],null,!0)).init(a[1],a[2])}function I(a){var a=a.currentTarget||a.srcElement,b=i.onScriptLoad;a.detachEvent&&!Y?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1);b=i.onScriptError;(!a.detachEvent||Y)&&a.removeEventListener("error",b,!1);return{node:a,id:a&&a.getAttribute("data-requiremodule")}}function J(){var a;
|
||||
for(x();A.length;){a=A.shift();if(null===a[0])return w(C("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));E(a)}}var W,Z,i,L,X,j={waitSeconds:7,baseUrl:"./",paths:{},bundles:{},pkgs:{},shim:{},config:{}},h={},V={},$={},A=[],r={},S={},aa={},K=1,O=1;L={require:function(a){return a.require?a.require:a.require=i.makeRequire(a.map)},exports:function(a){a.usingExports=!0;if(a.map.isDefine)return a.exports?r[a.map.id]=a.exports:a.exports=r[a.map.id]={}},module:function(a){return a.module?
|
||||
a.module:a.module={id:a.map.id,uri:a.map.url,config:function(){return m(j.config,a.map.id)||{}},exports:a.exports||(a.exports={})}}};Z=function(a){this.events=m($,a.id)||{};this.map=a;this.shim=m(j.shim,a.id);this.depExports=[];this.depMaps=[];this.depMatched=[];this.pluginMaps={};this.depCount=0};Z.prototype={init:function(a,b,c,f){f=f||{};if(!this.inited){this.factory=b;if(c)this.on("error",c);else this.events.error&&(c=u(this,function(a){this.emit("error",a)}));this.depMaps=a&&a.slice(0);this.errback=
|
||||
c;this.inited=!0;this.ignore=f.ignore;f.enabled||this.enabled?this.enable():this.check()}},defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=!0,this.depCount-=1,this.depExports[a]=b)},fetch:function(){if(!this.fetched){this.fetched=!0;i.startTime=(new Date).getTime();var a=this.map;if(this.shim)i.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],u(this,function(){return a.prefix?this.callPlugin():this.load()}));else return a.prefix?this.callPlugin():this.load()}},load:function(){var a=
|
||||
this.map.url;S[a]||(S[a]=!0,i.load(this.map.id,a))},check:function(){if(this.enabled&&!this.enabling){var a,b,c=this.map.id;b=this.depExports;var f=this.exports,l=this.factory;if(this.inited)if(this.error)this.emit("error",this.error);else{if(!this.defining){this.defining=!0;if(1>this.depCount&&!this.defined){if(G(l)){if(this.events.error&&this.map.isDefine||g.onError!==ca)try{f=i.execCb(c,l,b,f)}catch(d){a=d}else f=i.execCb(c,l,b,f);this.map.isDefine&&void 0===f&&((b=this.module)?f=b.exports:this.usingExports&&
|
||||
(f=this.exports));if(a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",w(this.error=a)}else f=l;this.exports=f;if(this.map.isDefine&&!this.ignore&&(r[c]=f,g.onResourceLoad))g.onResourceLoad(i,this.map,this.depMaps);y(c);this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}else this.fetch()}},callPlugin:function(){var a=
|
||||
this.map,b=a.id,d=p(a.prefix);this.depMaps.push(d);q(d,"defined",u(this,function(f){var l,d;d=m(aa,this.map.id);var e=this.map.name,P=this.map.parentMap?this.map.parentMap.name:null,n=i.makeRequire(a.parentMap,{enableBuildCallback:!0});if(this.map.unnormalized){if(f.normalize&&(e=f.normalize(e,function(a){return c(a,P,!0)})||""),f=p(a.prefix+"!"+e,this.map.parentMap),q(f,"defined",u(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),d=m(h,f.id)){this.depMaps.push(f);
|
||||
if(this.events.error)d.on("error",u(this,function(a){this.emit("error",a)}));d.enable()}}else d?(this.map.url=i.nameToUrl(d),this.load()):(l=u(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),l.error=u(this,function(a){this.inited=!0;this.error=a;a.requireModules=[b];B(h,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&y(a.map.id)});w(a)}),l.fromText=u(this,function(f,c){var d=a.name,e=p(d),P=M;c&&(f=c);P&&(M=!1);s(e);t(j.config,b)&&(j.config[d]=j.config[b]);try{g.exec(f)}catch(h){return w(C("fromtexteval",
|
||||
"fromText eval for "+b+" failed: "+h,h,[b]))}P&&(M=!0);this.depMaps.push(e);i.completeLoad(d);n([d],l)}),f.load(a.name,n,l,j))}));i.enable(d,this);this.pluginMaps[d.id]=d},enable:function(){V[this.map.id]=this;this.enabling=this.enabled=!0;v(this.depMaps,u(this,function(a,b){var c,f;if("string"===typeof a){a=p(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=m(L,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;q(a,"defined",u(this,function(a){this.defineDep(b,
|
||||
a);this.check()}));this.errback&&q(a,"error",u(this,this.errback))}c=a.id;f=h[c];!t(L,c)&&(f&&!f.enabled)&&i.enable(a,this)}));B(this.pluginMaps,u(this,function(a){var b=m(h,a.id);b&&!b.enabled&&i.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){v(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}};i={config:j,contextName:b,registry:h,defined:r,urlFetched:S,defQueue:A,Module:Z,makeModuleMap:p,
|
||||
nextTick:g.nextTick,onError:w,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=j.shim,c={paths:!0,bundles:!0,config:!0,map:!0};B(a,function(a,b){c[b]?(j[b]||(j[b]={}),U(j[b],a,!0,!0)):j[b]=a});a.bundles&&B(a.bundles,function(a,b){v(a,function(a){a!==b&&(aa[a]=b)})});a.shim&&(B(a.shim,function(a,c){H(a)&&(a={deps:a});if((a.exports||a.init)&&!a.exportsFn)a.exportsFn=i.makeShimExports(a);b[c]=a}),j.shim=b);a.packages&&v(a.packages,function(a){var b,
|
||||
a="string"===typeof a?{name:a}:a;b=a.name;a.location&&(j.paths[b]=a.location);j.pkgs[b]=a.name+"/"+(a.main||"main").replace(ia,"").replace(Q,"")});B(h,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=p(b))});if(a.deps||a.callback)i.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(ba,arguments));return b||a.exports&&da(a.exports)}},makeRequire:function(a,e){function j(c,d,m){var n,q;e.enableBuildCallback&&(d&&G(d))&&(d.__requireJsBuild=
|
||||
!0);if("string"===typeof c){if(G(d))return w(C("requireargs","Invalid require call"),m);if(a&&t(L,c))return L[c](h[a.id]);if(g.get)return g.get(i,c,a,j);n=p(c,a,!1,!0);n=n.id;return!t(r,n)?w(C("notloaded",'Module name "'+n+'" has not been loaded yet for context: '+b+(a?"":". Use require([])"))):r[n]}J();i.nextTick(function(){J();q=s(p(null,a));q.skipMap=e.skipMap;q.init(c,d,m,{enabled:!0});D()});return j}e=e||{};U(j,{isBrowser:z,toUrl:function(b){var d,e=b.lastIndexOf("."),k=b.split("/")[0];if(-1!==
|
||||
e&&(!("."===k||".."===k)||1<e))d=b.substring(e,b.length),b=b.substring(0,e);return i.nameToUrl(c(b,a&&a.id,!0),d,!0)},defined:function(b){return t(r,p(b,a,!1,!0).id)},specified:function(b){b=p(b,a,!1,!0).id;return t(r,b)||t(h,b)}});a||(j.undef=function(b){x();var c=p(b,a,!0),e=m(h,b);d(b);delete r[b];delete S[c.url];delete $[b];T(A,function(a,c){a[0]===b&&A.splice(c,1)});e&&(e.events.defined&&($[b]=e.events),y(b))});return j},enable:function(a){m(h,a.id)&&s(a).enable()},completeLoad:function(a){var b,
|
||||
c,d=m(j.shim,a)||{},g=d.exports;for(x();A.length;){c=A.shift();if(null===c[0]){c[0]=a;if(b)break;b=!0}else c[0]===a&&(b=!0);E(c)}c=m(h,a);if(!b&&!t(r,a)&&c&&!c.inited){if(j.enforceDefine&&(!g||!da(g)))return e(a)?void 0:w(C("nodefine","No define call for "+a,null,[a]));E([a,d.deps||[],d.exportsFn])}D()},nameToUrl:function(a,b,c){var d,e,h;(d=m(j.pkgs,a))&&(a=d);if(d=m(aa,a))return i.nameToUrl(d,b,c);if(g.jsExtRegExp.test(a))d=a+(b||"");else{d=j.paths;a=a.split("/");for(e=a.length;0<e;e-=1)if(h=a.slice(0,
|
||||
e).join("/"),h=m(d,h)){H(h)&&(h=h[0]);a.splice(0,e,h);break}d=a.join("/");d+=b||(/^data\:|\?/.test(d)||c?"":".js");d=("/"===d.charAt(0)||d.match(/^[\w\+\.\-]+:/)?"":j.baseUrl)+d}return j.urlArgs?d+((-1===d.indexOf("?")?"?":"&")+j.urlArgs):d},load:function(a,b){g.load(i,a,b)},execCb:function(a,b,c,d){return b.apply(d,c)},onScriptLoad:function(a){if("load"===a.type||ja.test((a.currentTarget||a.srcElement).readyState))N=null,a=I(a),i.completeLoad(a.id)},onScriptError:function(a){var b=I(a);if(!e(b.id))return w(C("scripterror",
|
||||
"Script error for: "+b.id,a,[b.id]))}};i.require=i.makeRequire();return i}var g,x,y,D,I,E,N,J,s,O,ka=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,la=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,Q=/\.js$/,ia=/^\.\//;x=Object.prototype;var K=x.toString,fa=x.hasOwnProperty,ha=Array.prototype.splice,z=!!("undefined"!==typeof window&&"undefined"!==typeof navigator&&window.document),ea=!z&&"undefined"!==typeof importScripts,ja=z&&"PLAYSTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/,
|
||||
Y="undefined"!==typeof opera&&"[object Opera]"===opera.toString(),F={},q={},R=[],M=!1;if("undefined"===typeof define){if("undefined"!==typeof requirejs){if(G(requirejs))return;q=requirejs;requirejs=void 0}"undefined"!==typeof require&&!G(require)&&(q=require,require=void 0);g=requirejs=function(b,c,d,e){var n,p="_";!H(b)&&"string"!==typeof b&&(n=b,H(c)?(b=c,c=d,d=e):b=[]);n&&n.context&&(p=n.context);(e=m(F,p))||(e=F[p]=g.s.newContext(p));n&&e.configure(n);return e.require(b,c,d)};g.config=function(b){return g(b)};
|
||||
g.nextTick="undefined"!==typeof setTimeout?function(b){setTimeout(b,4)}:function(b){b()};require||(require=g);g.version="2.1.14";g.jsExtRegExp=/^\/|:|\?|\.js$/;g.isBrowser=z;x=g.s={contexts:F,newContext:ga};g({});v(["toUrl","undef","defined","specified"],function(b){g[b]=function(){var c=F._;return c.require[b].apply(c,arguments)}});if(z&&(y=x.head=document.getElementsByTagName("head")[0],D=document.getElementsByTagName("base")[0]))y=x.head=D.parentNode;g.onError=ca;g.createNode=function(b){var c=
|
||||
b.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script");c.type=b.scriptType||"text/javascript";c.charset="utf-8";c.async=!0;return c};g.load=function(b,c,d){var e=b&&b.config||{};if(z)return e=g.createNode(e,c,d),e.setAttribute("data-requirecontext",b.contextName),e.setAttribute("data-requiremodule",c),e.attachEvent&&!(e.attachEvent.toString&&0>e.attachEvent.toString().indexOf("[native code"))&&!Y?(M=!0,e.attachEvent("onreadystatechange",b.onScriptLoad)):
|
||||
(e.addEventListener("load",b.onScriptLoad,!1),e.addEventListener("error",b.onScriptError,!1)),e.src=d,J=e,D?y.insertBefore(e,D):y.appendChild(e),J=null,e;if(ea)try{importScripts(d),b.completeLoad(c)}catch(m){b.onError(C("importscripts","importScripts failed for "+c+" at "+d,m,[c]))}};z&&!q.skipDataMain&&T(document.getElementsByTagName("script"),function(b){y||(y=b.parentNode);if(I=b.getAttribute("data-main"))return s=I,q.baseUrl||(E=s.split("/"),s=E.pop(),O=E.length?E.join("/")+"/":"./",q.baseUrl=
|
||||
O),s=s.replace(Q,""),g.jsExtRegExp.test(s)&&(s=I),q.deps=q.deps?q.deps.concat(s):[s],!0});define=function(b,c,d){var e,g;"string"!==typeof b&&(d=c,c=b,b=null);H(c)||(d=c,c=null);!c&&G(d)&&(c=[],d.length&&(d.toString().replace(ka,"").replace(la,function(b,d){c.push(d)}),c=(1===d.length?["require"]:["require","exports","module"]).concat(c)));if(M){if(!(e=J))N&&"interactive"===N.readyState||T(document.getElementsByTagName("script"),function(b){if("interactive"===b.readyState)return N=b}),e=N;e&&(b||
|
||||
(b=e.getAttribute("data-requiremodule")),g=F[e.getAttribute("data-requirecontext")])}(g?g.defQueue:R).push([b,c,d])};define.amd={jQuery:!0};g.exec=function(b){return eval(b)};g(q)}})(this);
|
@@ -73,6 +73,8 @@
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Async\BindingStrategies\RequireJS.cs" />
|
||||
<Compile Include="Async\Filters\RequireJS.cs" />
|
||||
<Compile Include="Common\Controllers\ErrorController.cs" />
|
||||
<Compile Include="Common\DateEditor\DateEditorSettings.cs" />
|
||||
<Compile Include="Common\OwnerEditor\OwnerEditorSettings.cs" />
|
||||
@@ -277,6 +279,8 @@
|
||||
<Compile Include="XmlRpc\XmlRpcContext.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Async\Module.txt" />
|
||||
<Content Include="Async\Scripts\require.js" />
|
||||
<Content Include="Common\Module.txt" />
|
||||
<Content Include="Common\Styles\datetime-editor.css" />
|
||||
<Content Include="Common\Views\DefinitionTemplates\BodyTypePartSettings.cshtml" />
|
||||
@@ -367,7 +371,6 @@
|
||||
<Content Include="Common\Views\Parts.Common.Body.Summary.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
<Folder Include="Views\Gamma\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -559,6 +562,11 @@
|
||||
<Content Include="Containers\Views\EditorTemplates\ContainerWidget.cshtml" />
|
||||
<Content Include="Containers\Views\Parts.ContainerWidget.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Async\Scripts\Web.config">
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
@@ -30,7 +30,7 @@ namespace Orchard.Core.Shapes {
|
||||
private readonly Work<IShapeFactory> _shapeFactory;
|
||||
|
||||
public CoreShapes(
|
||||
Work<WorkContext> workContext,
|
||||
Work<WorkContext> workContext,
|
||||
Work<IResourceManager> resourceManager,
|
||||
Work<IHttpContextAccessor> httpContextAccessor,
|
||||
Work<IShapeFactory> shapeFactory
|
||||
@@ -44,7 +44,7 @@ namespace Orchard.Core.Shapes {
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public dynamic New { get { return _shapeFactory.Value; } }
|
||||
public dynamic New { get { return _shapeFactory.Value; } }
|
||||
|
||||
public void Discover(ShapeTableBuilder builder) {
|
||||
// the root page shape named 'Layout' is wrapped with 'Document'
|
||||
@@ -54,7 +54,7 @@ namespace Orchard.Core.Shapes {
|
||||
.OnCreating(creating => creating.Create = () => new ZoneHolding(() => creating.New.Zone()))
|
||||
.OnCreated(created => {
|
||||
var layout = created.Shape;
|
||||
|
||||
|
||||
layout.Head = created.New.DocumentZone(ZoneName: "Head");
|
||||
layout.Body = created.New.DocumentZone(ZoneName: "Body");
|
||||
layout.Tail = created.New.DocumentZone(ZoneName: "Tail");
|
||||
@@ -104,7 +104,7 @@ namespace Orchard.Core.Shapes {
|
||||
string menuName = menuItem.Menu.MenuName;
|
||||
string contentType = null;
|
||||
if (menuItem.Content != null) {
|
||||
contentType = ((IContent) menuItem.Content).ContentItem.ContentType;
|
||||
contentType = ((IContent)menuItem.Content).ContentItem.ContentType;
|
||||
}
|
||||
|
||||
// MenuItemLink__[ContentType] e.g. MenuItemLink-HtmlMenuItem
|
||||
@@ -119,7 +119,7 @@ namespace Orchard.Core.Shapes {
|
||||
if (contentType != null) {
|
||||
menuItem.Metadata.Alternates.Add("MenuItemLink__" + EncodeAlternateElement(menuName) + "__" + EncodeAlternateElement(contentType));
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
builder.Describe("LocalMenu")
|
||||
@@ -130,7 +130,7 @@ namespace Orchard.Core.Shapes {
|
||||
menu.Classes.Add("localmenu");
|
||||
menu.Metadata.Alternates.Add("LocalMenu__" + EncodeAlternateElement(menuName));
|
||||
});
|
||||
|
||||
|
||||
builder.Describe("LocalMenuItem")
|
||||
.OnDisplaying(displaying => {
|
||||
var menuItem = displaying.Shape;
|
||||
@@ -218,8 +218,8 @@ namespace Orchard.Core.Shapes {
|
||||
.OnDisplaying(displaying => {
|
||||
var resource = displaying.Shape;
|
||||
string url = resource.Url;
|
||||
string fileName = StaticFileBindingStrategy.GetAlternateShapeNameFromFileName(url);
|
||||
if (!string.IsNullOrEmpty(fileName)) {
|
||||
var fileName = StaticFileBindingStrategy.GetAlternateShapeNameFromFileName(url);
|
||||
if (!String.IsNullOrEmpty(fileName)) {
|
||||
resource.Metadata.Alternates.Add("Style__" + fileName);
|
||||
}
|
||||
});
|
||||
@@ -228,7 +228,7 @@ namespace Orchard.Core.Shapes {
|
||||
.OnDisplaying(displaying => {
|
||||
var resource = displaying.Shape;
|
||||
string url = resource.Url;
|
||||
string fileName = StaticFileBindingStrategy.GetAlternateShapeNameFromFileName(url);
|
||||
var fileName = StaticFileBindingStrategy.GetAlternateShapeNameFromFileName(url);
|
||||
if (!string.IsNullOrEmpty(fileName)) {
|
||||
resource.Metadata.Alternates.Add("Script__" + fileName);
|
||||
}
|
||||
@@ -238,7 +238,7 @@ namespace Orchard.Core.Shapes {
|
||||
.OnDisplaying(displaying => {
|
||||
var resource = displaying.Shape;
|
||||
string url = resource.Url;
|
||||
string fileName = StaticFileBindingStrategy.GetAlternateShapeNameFromFileName(url);
|
||||
var fileName = StaticFileBindingStrategy.GetAlternateShapeNameFromFileName(url);
|
||||
if (!string.IsNullOrEmpty(fileName)) {
|
||||
resource.Metadata.Alternates.Add("Resource__" + fileName);
|
||||
}
|
||||
@@ -329,14 +329,14 @@ namespace Orchard.Core.Shapes {
|
||||
|
||||
[Shape]
|
||||
public void Metas(TextWriter Output) {
|
||||
foreach (var meta in _resourceManager.Value.GetRegisteredMetas() ) {
|
||||
foreach (var meta in _resourceManager.Value.GetRegisteredMetas()) {
|
||||
Output.WriteLine(meta.GetTag());
|
||||
}
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public void HeadLinks(TextWriter Output) {
|
||||
foreach (var link in _resourceManager.Value.GetRegisteredLinks() ) {
|
||||
foreach (var link in _resourceManager.Value.GetRegisteredLinks()) {
|
||||
Output.WriteLine(link.GetTag());
|
||||
}
|
||||
}
|
||||
@@ -354,7 +354,7 @@ namespace Orchard.Core.Shapes {
|
||||
|
||||
[Shape]
|
||||
public void Script(HtmlHelper Html, TextWriter Output, ResourceDefinition Resource, string Url, string Condition, Dictionary<string, string> TagAttributes) {
|
||||
// do not write to Output directly as Styles are rendered in Zones
|
||||
// do not write to Output directly as Scripts are rendered in Zones
|
||||
ResourceManager.WriteResource(Html.ViewContext.Writer, Resource, Url, Condition, TagAttributes);
|
||||
}
|
||||
|
||||
@@ -393,27 +393,80 @@ namespace Orchard.Core.Shapes {
|
||||
};
|
||||
var requiredResources = _resourceManager.Value.BuildRequiredResources(resourceType);
|
||||
var appPath = _httpContextAccessor.Value.Current().Request.ApplicationPath;
|
||||
foreach (var context in requiredResources.Where(r =>
|
||||
var requiredResourcesQuery = requiredResources.Where(r =>
|
||||
(includeLocation.HasValue ? r.Settings.Location == includeLocation.Value : true) &&
|
||||
(excludeLocation.HasValue ? r.Settings.Location != excludeLocation.Value : true))) {
|
||||
(excludeLocation.HasValue ? r.Settings.Location != excludeLocation.Value : true));
|
||||
var filteredResources = requiredResourcesQuery.ToArray();
|
||||
|
||||
var path = context.GetResourceUrl(defaultSettings, appPath);
|
||||
var resourceWriter = New.ResourceWriter(DefaultSettings: defaultSettings, AppPath: appPath, Resources: filteredResources);
|
||||
|
||||
switch (resourceType) {
|
||||
case "stylesheet":
|
||||
resourceWriter.Metadata.Type = "StyleSheetsResourceWriter";
|
||||
break;
|
||||
case "script":
|
||||
var scripts = filteredResources.Where(x => !x.Settings.LoadAsync);
|
||||
var asyncScripts = filteredResources.Where(x => x.Settings.LoadAsync);
|
||||
|
||||
resourceWriter.Metadata.Type = "ScriptsResourceWriter";
|
||||
resourceWriter.Add(New.SyncScriptsResourceWriter(DefaultSettings: defaultSettings, AppPath: appPath, Resources: scripts));
|
||||
resourceWriter.Add(New.AsyncScriptsResourceWriter(DefaultSettings: defaultSettings, AppPath: appPath, Resources: asyncScripts));
|
||||
break;
|
||||
default:
|
||||
resourceWriter.Metadata.Type = "DefaultResourceWriter";
|
||||
break;
|
||||
}
|
||||
|
||||
Output.Write(Display(resourceWriter));
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public void DefaultResourceWriter(dynamic Display, TextWriter Output, RequireSettings DefaultSettings, string AppPath, IEnumerable<ResourceRequiredContext> Resources) {
|
||||
foreach (var context in Resources) {
|
||||
var path = context.GetResourceUrl(DefaultSettings, AppPath);
|
||||
var condition = context.Settings.Condition;
|
||||
var attributes = context.Settings.HasAttributes ? context.Settings.Attributes : null;
|
||||
IHtmlString result;
|
||||
if (resourceType == "stylesheet") {
|
||||
result = Display.Style(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes);
|
||||
}
|
||||
else if (resourceType == "script") {
|
||||
result = Display.Script(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes);
|
||||
}
|
||||
else {
|
||||
result = Display.Resource(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes);
|
||||
}
|
||||
IHtmlString result = Display.Resource(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes, Settings: context.Settings);
|
||||
Output.Write(result);
|
||||
}
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public void StyleSheetsResourceWriter(dynamic Display, TextWriter Output, RequireSettings DefaultSettings, string AppPath, IEnumerable<ResourceRequiredContext> Resources) {
|
||||
foreach (var context in Resources) {
|
||||
var path = context.GetResourceUrl(DefaultSettings, AppPath);
|
||||
var condition = context.Settings.Condition;
|
||||
var attributes = context.Settings.HasAttributes ? context.Settings.Attributes : null;
|
||||
IHtmlString result = Display.Style(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes, Settings: context.Settings);
|
||||
Output.Write(result);
|
||||
}
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public void ScriptsResourceWriter(dynamic Shape, dynamic Display, TextWriter Output, RequireSettings DefaultSettings, string AppPath, IEnumerable<ResourceRequiredContext> Resources) {
|
||||
foreach (var child in Shape) {
|
||||
Output.Write(Display(child));
|
||||
}
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public void SyncScriptsResourceWriter(dynamic Display, TextWriter Output, RequireSettings DefaultSettings, string AppPath, IEnumerable<ResourceRequiredContext> Resources) {
|
||||
foreach (var context in Resources) {
|
||||
var path = context.GetResourceUrl(DefaultSettings, AppPath);
|
||||
var condition = context.Settings.Condition;
|
||||
var attributes = context.Settings.HasAttributes ? context.Settings.Attributes : null;
|
||||
IHtmlString result = Display.Script(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes, Settings: context.Settings);
|
||||
Output.Write(result);
|
||||
}
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public void AsyncScriptsResourceWriter(dynamic Shape, dynamic Display, TextWriter Output, RequireSettings DefaultSettings, string AppPath, IEnumerable<ResourceRequiredContext> Resources) {
|
||||
// The default implementation is the same as the synchronous scripts resource writer.
|
||||
Shape.Metadata.Type = "SyncScriptsResourceWriter";
|
||||
Output.Write(Display(Shape));
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public IHtmlString Pager_Links(dynamic Shape, dynamic Display,
|
||||
HtmlHelper Html,
|
||||
@@ -442,7 +495,7 @@ namespace Orchard.Core.Shapes {
|
||||
var numberOfPagesToShow = Quantity ?? 0;
|
||||
if (Quantity == null || Quantity < 0)
|
||||
numberOfPagesToShow = 7;
|
||||
|
||||
|
||||
var totalPageCount = (int)Math.Ceiling(TotalItemCount / pageSize);
|
||||
|
||||
var firstText = FirstText ?? T("<<");
|
||||
@@ -467,7 +520,7 @@ namespace Orchard.Core.Shapes {
|
||||
if (shapeRouteData == null) {
|
||||
var route = shapeRoute as RouteData;
|
||||
if (route != null) {
|
||||
shapeRouteData = (route).Values;
|
||||
shapeRouteData = (route).Values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -535,7 +588,7 @@ namespace Orchard.Core.Shapes {
|
||||
if (lastPage < totalPageCount && numberOfPagesToShow > 0) {
|
||||
Shape.Add(New.Pager_Gap(Value: gapText, Pager: Shape));
|
||||
}
|
||||
|
||||
|
||||
// next and last pages
|
||||
if (Page < totalPageCount) {
|
||||
// next
|
||||
@@ -551,47 +604,47 @@ namespace Orchard.Core.Shapes {
|
||||
|
||||
[Shape]
|
||||
public IHtmlString Pager(dynamic Shape, dynamic Display) {
|
||||
Shape.Metadata.Alternates.Clear();
|
||||
Shape.Metadata.Alternates.Clear();
|
||||
Shape.Metadata.Type = "Pager_Links";
|
||||
return Display(Shape);
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public IHtmlString Pager_First(dynamic Shape, dynamic Display) {
|
||||
Shape.Metadata.Alternates.Clear();
|
||||
Shape.Metadata.Alternates.Clear();
|
||||
Shape.Metadata.Type = "Pager_Link";
|
||||
return Display(Shape);
|
||||
}
|
||||
|
||||
|
||||
[Shape]
|
||||
public IHtmlString Pager_Previous(dynamic Shape, dynamic Display) {
|
||||
Shape.Metadata.Alternates.Clear();
|
||||
Shape.Metadata.Alternates.Clear();
|
||||
Shape.Metadata.Type = "Pager_Link";
|
||||
return Display(Shape);
|
||||
}
|
||||
|
||||
|
||||
[Shape]
|
||||
public IHtmlString Pager_CurrentPage(HtmlHelper Html, dynamic Display, object Value) {
|
||||
var tagBuilder = new TagBuilder("span");
|
||||
tagBuilder.InnerHtml = EncodeOrDisplay(Value, Display, Html).ToString();
|
||||
|
||||
|
||||
return MvcHtmlString.Create(tagBuilder.ToString());
|
||||
}
|
||||
|
||||
|
||||
[Shape]
|
||||
public IHtmlString Pager_Next(dynamic Shape, dynamic Display) {
|
||||
Shape.Metadata.Alternates.Clear();
|
||||
Shape.Metadata.Alternates.Clear();
|
||||
Shape.Metadata.Type = "Pager_Link";
|
||||
return Display(Shape);
|
||||
}
|
||||
|
||||
|
||||
[Shape]
|
||||
public IHtmlString Pager_Last(dynamic Shape, dynamic Display) {
|
||||
Shape.Metadata.Alternates.Clear();
|
||||
Shape.Metadata.Alternates.Clear();
|
||||
Shape.Metadata.Type = "Pager_Link";
|
||||
return Display(Shape);
|
||||
}
|
||||
|
||||
|
||||
[Shape]
|
||||
public IHtmlString Pager_Link(HtmlHelper Html, dynamic Shape, dynamic Display, object Value) {
|
||||
Shape.Metadata.Alternates.Clear();
|
||||
@@ -645,7 +698,7 @@ namespace Orchard.Core.Shapes {
|
||||
|
||||
if (Items == null)
|
||||
return;
|
||||
|
||||
|
||||
// prevent multiple enumerations
|
||||
var items = Items.ToList();
|
||||
|
||||
@@ -655,7 +708,7 @@ namespace Orchard.Core.Shapes {
|
||||
return;
|
||||
|
||||
string listTagName = null;
|
||||
|
||||
|
||||
if (Tag != "-") {
|
||||
listTagName = string.IsNullOrEmpty(Tag) ? "ul" : Tag;
|
||||
}
|
||||
@@ -664,7 +717,7 @@ namespace Orchard.Core.Shapes {
|
||||
|
||||
string itemTagName = null;
|
||||
if (ItemTag != "-") {
|
||||
itemTagName = string.IsNullOrEmpty(ItemTag) ? "li" : ItemTag;
|
||||
itemTagName = string.IsNullOrEmpty(ItemTag) ? "li" : ItemTag;
|
||||
}
|
||||
|
||||
if (listTag != null) {
|
||||
@@ -677,7 +730,7 @@ namespace Orchard.Core.Shapes {
|
||||
// give the item shape the possibility to alter its container tag
|
||||
var index = 0;
|
||||
foreach (var item in items) {
|
||||
|
||||
|
||||
var itemTag = String.IsNullOrEmpty(itemTagName) ? null : GetTagBuilder(itemTagName, null, ItemClasses, ItemAttributes);
|
||||
|
||||
if (item is IShape) {
|
||||
@@ -698,7 +751,7 @@ namespace Orchard.Core.Shapes {
|
||||
}
|
||||
|
||||
index = 0;
|
||||
foreach(var itemOutput in itemOutputs) {
|
||||
foreach (var itemOutput in itemOutputs) {
|
||||
var itemTag = itemTags[index];
|
||||
|
||||
if (itemTag != null) {
|
||||
@@ -792,7 +845,7 @@ namespace Orchard.Core.Shapes {
|
||||
if (Value is IShape) {
|
||||
return Display(Value).ToString();
|
||||
}
|
||||
|
||||
|
||||
return Html.Raw(Html.Encode(Value.ToString()));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.FileSystems.VirtualPath;
|
||||
using Orchard.UI.Resources;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors.ResourceBindingStrategy {
|
||||
/// <summary>
|
||||
/// Discovers .js files and turns them into Script__<filename> shapes.
|
||||
/// </summary>
|
||||
public class ScriptBindingStrategy : StaticFileBindingStrategy, IShapeTableProvider {
|
||||
public ScriptBindingStrategy(IExtensionManager extensionManager, ShellDescriptor shellDescriptor, IVirtualPathProvider virtualPathProvider)
|
||||
: base(extensionManager, shellDescriptor, virtualPathProvider) {
|
||||
}
|
||||
|
||||
public override string GetFileExtension() {
|
||||
return ".js";
|
||||
}
|
||||
|
||||
public override string GetFolder() {
|
||||
return "Scripts";
|
||||
}
|
||||
|
||||
public override string GetShapePrefix() {
|
||||
return "Script__";
|
||||
}
|
||||
|
||||
public virtual string GetShapeName() {
|
||||
return "Script";
|
||||
}
|
||||
|
||||
public override void Discover(ShapeTableBuilder builder) {
|
||||
base.Discover(builder);
|
||||
|
||||
builder.Describe("Script")
|
||||
.OnDisplaying(displaying => {
|
||||
var resourceShape = displaying.Shape;
|
||||
var url = (string)resourceShape.Url;
|
||||
var settings = (RequireSettings)resourceShape.Settings;
|
||||
if (settings.LoadAsync) {
|
||||
displaying.ShapeMetadata.Alternates.Clear();
|
||||
displaying.ShapeMetadata.Type = GetShapeName();
|
||||
|
||||
var fileName = GetAlternateShapeNameFromFileName(url);
|
||||
if (!String.IsNullOrEmpty(fileName)) {
|
||||
resourceShape.Metadata.Alternates.Add(GetShapePrefix() + fileName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.FileSystems.VirtualPath;
|
||||
using Orchard.UI.Resources;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors.ResourceBindingStrategy {
|
||||
/// <summary>
|
||||
/// Discovers static files and turns them into shapes.
|
||||
/// </summary>
|
||||
public abstract class StaticFileBindingStrategy {
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly ShellDescriptor _shellDescriptor;
|
||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||
private static readonly char[] unsafeCharList = "/:?#[]@!&'()*+,;=\r\n\t\f\" <>.-_".ToCharArray();
|
||||
|
||||
protected StaticFileBindingStrategy(IExtensionManager extensionManager, ShellDescriptor shellDescriptor, IVirtualPathProvider virtualPathProvider) {
|
||||
_extensionManager = extensionManager;
|
||||
_shellDescriptor = shellDescriptor;
|
||||
_virtualPathProvider = virtualPathProvider;
|
||||
}
|
||||
|
||||
public abstract string GetFileExtension();
|
||||
public abstract string GetFolder();
|
||||
public abstract string GetShapePrefix();
|
||||
|
||||
public virtual void WriteResource(dynamic display, TextWriter output, ResourceDefinition resource, string url, string condition, Dictionary<string, string> attributes) {
|
||||
ResourceManager.WriteResource(output, resource, display.Url, condition, attributes);
|
||||
}
|
||||
|
||||
private static string SafeName(string name) {
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return String.Empty;
|
||||
|
||||
return name.Strip(unsafeCharList).ToLowerInvariant();
|
||||
}
|
||||
|
||||
public static string GetAlternateShapeNameFromFileName(string fileName) {
|
||||
if (fileName == null) {
|
||||
throw new ArgumentNullException("fileName");
|
||||
}
|
||||
string shapeName;
|
||||
if (Uri.IsWellFormedUriString(fileName, UriKind.Absolute)) {
|
||||
var uri = new Uri(fileName);
|
||||
shapeName = uri.Authority + "$" + uri.AbsolutePath + "$" + uri.Query;
|
||||
}
|
||||
else {
|
||||
shapeName = Path.GetFileNameWithoutExtension(fileName);
|
||||
}
|
||||
return SafeName(shapeName);
|
||||
}
|
||||
|
||||
private static IEnumerable<ExtensionDescriptor> Once(IEnumerable<FeatureDescriptor> featureDescriptors) {
|
||||
var once = new ConcurrentDictionary<string, object>();
|
||||
return featureDescriptors.Select(fd => fd.Extension).Where(ed => once.TryAdd(ed.Id, null)).ToList();
|
||||
}
|
||||
|
||||
public virtual void Discover(ShapeTableBuilder builder) {
|
||||
var availableFeatures = _extensionManager.AvailableFeatures();
|
||||
var activeFeatures = availableFeatures.Where(FeatureIsEnabled);
|
||||
var activeExtensions = Once(activeFeatures);
|
||||
|
||||
var hits = activeExtensions.SelectMany(extensionDescriptor => {
|
||||
var basePath = Path.Combine(extensionDescriptor.Location, extensionDescriptor.Id).Replace(Path.DirectorySeparatorChar, '/');
|
||||
var virtualPath = Path.Combine(basePath, GetFolder()).Replace(Path.DirectorySeparatorChar, '/');
|
||||
var shapes = _virtualPathProvider.ListFiles(virtualPath)
|
||||
.Select(Path.GetFileName)
|
||||
.Where(fileName => string.Equals(Path.GetExtension(fileName), GetFileExtension(), StringComparison.OrdinalIgnoreCase))
|
||||
.Select(fileName => new {
|
||||
fileName = Path.GetFileNameWithoutExtension(fileName),
|
||||
fileVirtualPath = Path.Combine(virtualPath, fileName).Replace(Path.DirectorySeparatorChar, '/'),
|
||||
shapeType = GetShapePrefix() + GetAlternateShapeNameFromFileName(fileName),
|
||||
extensionDescriptor
|
||||
});
|
||||
return shapes;
|
||||
});
|
||||
|
||||
foreach (var iter in hits) {
|
||||
var hit = iter;
|
||||
var featureDescriptors = hit.extensionDescriptor.Features.Where(fd => fd.Id == hit.extensionDescriptor.Id);
|
||||
foreach (var featureDescriptor in featureDescriptors) {
|
||||
builder.Describe(iter.shapeType)
|
||||
.From(new Feature { Descriptor = featureDescriptor })
|
||||
.BoundAs(
|
||||
hit.fileVirtualPath,
|
||||
shapeDescriptor => displayContext => {
|
||||
var shape = ((dynamic)displayContext.Value);
|
||||
var output = displayContext.ViewContext.Writer;
|
||||
ResourceDefinition resource = shape.Resource;
|
||||
string condition = shape.Condition;
|
||||
Dictionary<string, string> attributes = shape.TagAttributes;
|
||||
WriteResource(shape, output, resource, hit.fileVirtualPath, condition, attributes);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool FeatureIsEnabled(FeatureDescriptor fd) {
|
||||
return (DefaultExtensionTypes.IsTheme(fd.Extension.ExtensionType) && (fd.Id == "TheAdmin" || fd.Id == "SafeMode")) ||
|
||||
_shellDescriptor.Features.Any(sf => sf.Name == fd.Id);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,110 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.FileSystems.VirtualPath;
|
||||
using Orchard.UI.Resources;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors.ResourceBindingStrategy {
|
||||
// discovers static files and turns them into shapes.
|
||||
public abstract class StaticFileBindingStrategy {
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly ShellDescriptor _shellDescriptor;
|
||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||
private static readonly char[] unsafeCharList = "/:?#[]@!&'()*+,;=\r\n\t\f\" <>.-_".ToCharArray();
|
||||
|
||||
protected StaticFileBindingStrategy(IExtensionManager extensionManager, ShellDescriptor shellDescriptor, IVirtualPathProvider virtualPathProvider) {
|
||||
_extensionManager = extensionManager;
|
||||
_shellDescriptor = shellDescriptor;
|
||||
_virtualPathProvider = virtualPathProvider;
|
||||
}
|
||||
|
||||
public abstract string GetFileExtension();
|
||||
public abstract string GetFolder();
|
||||
public abstract string GetShapePrefix();
|
||||
|
||||
private static string SafeName(string name) {
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return String.Empty;
|
||||
|
||||
return name.Strip(unsafeCharList).ToLowerInvariant();
|
||||
}
|
||||
|
||||
public static string GetAlternateShapeNameFromFileName(string fileName) {
|
||||
if (fileName == null) {
|
||||
throw new ArgumentNullException("fileName");
|
||||
}
|
||||
string shapeName;
|
||||
if (Uri.IsWellFormedUriString(fileName, UriKind.Absolute)) {
|
||||
var uri = new Uri(fileName);
|
||||
shapeName = uri.Authority + "$" + uri.AbsolutePath + "$" + uri.Query;
|
||||
}
|
||||
else {
|
||||
shapeName = Path.GetFileNameWithoutExtension(fileName);
|
||||
}
|
||||
return SafeName(shapeName);
|
||||
}
|
||||
|
||||
private static IEnumerable<ExtensionDescriptor> Once(IEnumerable<FeatureDescriptor> featureDescriptors) {
|
||||
var once = new ConcurrentDictionary<string, object>();
|
||||
return featureDescriptors.Select(fd => fd.Extension).Where(ed => once.TryAdd(ed.Id, null)).ToList();
|
||||
}
|
||||
|
||||
public void Discover(ShapeTableBuilder builder) {
|
||||
var availableFeatures = _extensionManager.AvailableFeatures();
|
||||
var activeFeatures = availableFeatures.Where(FeatureIsEnabled);
|
||||
var activeExtensions = Once(activeFeatures);
|
||||
|
||||
var hits = activeExtensions.SelectMany(extensionDescriptor => {
|
||||
var basePath = Path.Combine(extensionDescriptor.Location, extensionDescriptor.Id).Replace(Path.DirectorySeparatorChar, '/');
|
||||
var virtualPath = Path.Combine(basePath, GetFolder()).Replace(Path.DirectorySeparatorChar, '/');
|
||||
var shapes = _virtualPathProvider.ListFiles(virtualPath)
|
||||
.Select(Path.GetFileName)
|
||||
.Where(fileName => string.Equals(Path.GetExtension(fileName), GetFileExtension(), StringComparison.OrdinalIgnoreCase))
|
||||
.Select(cssFileName => new {
|
||||
fileName = Path.GetFileNameWithoutExtension(cssFileName),
|
||||
fileVirtualPath = Path.Combine(virtualPath, cssFileName).Replace(Path.DirectorySeparatorChar, '/'),
|
||||
shapeType = GetShapePrefix() + GetAlternateShapeNameFromFileName(cssFileName),
|
||||
extensionDescriptor
|
||||
});
|
||||
return shapes;
|
||||
});
|
||||
|
||||
foreach (var iter in hits) {
|
||||
var hit = iter;
|
||||
var featureDescriptors = hit.extensionDescriptor.Features.Where(fd => fd.Id == hit.extensionDescriptor.Id);
|
||||
foreach (var featureDescriptor in featureDescriptors) {
|
||||
builder.Describe(iter.shapeType)
|
||||
.From(new Feature {Descriptor = featureDescriptor})
|
||||
.BoundAs(
|
||||
hit.fileVirtualPath,
|
||||
shapeDescriptor => displayContext => {
|
||||
var shape = ((dynamic) displayContext.Value);
|
||||
var output = displayContext.ViewContext.Writer;
|
||||
ResourceDefinition resource = shape.Resource;
|
||||
string condition = shape.Condition;
|
||||
Dictionary<string, string> attributes = shape.TagAttributes;
|
||||
ResourceManager.WriteResource(output, resource, hit.fileVirtualPath, condition, attributes);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool FeatureIsEnabled(FeatureDescriptor fd) {
|
||||
return (DefaultExtensionTypes.IsTheme(fd.Extension.ExtensionType) && (fd.Id == "TheAdmin" || fd.Id == "SafeMode")) ||
|
||||
_shellDescriptor.Features.Any(sf => sf.Name == fd.Id);
|
||||
}
|
||||
}
|
||||
|
||||
// discovers .css files and turns them into Style__<filename> shapes.
|
||||
/// <summary>
|
||||
/// Discovers .css files and turns them into Style__<filename> shapes.
|
||||
/// </summary>
|
||||
public class StylesheetBindingStrategy : StaticFileBindingStrategy, IShapeTableProvider {
|
||||
public StylesheetBindingStrategy(IExtensionManager extensionManager, ShellDescriptor shellDescriptor, IVirtualPathProvider virtualPathProvider) : base(extensionManager, shellDescriptor, virtualPathProvider) {
|
||||
public StylesheetBindingStrategy(IExtensionManager extensionManager, ShellDescriptor shellDescriptor, IVirtualPathProvider virtualPathProvider)
|
||||
: base(extensionManager, shellDescriptor, virtualPathProvider) {
|
||||
}
|
||||
|
||||
public override string GetFileExtension() {
|
||||
|
@@ -198,6 +198,8 @@
|
||||
<Compile Include="Data\ISessionConfigurationEvents.cs" />
|
||||
<Compile Include="Data\ISessionInterceptor.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\PlacementInfo.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ResourceBindingStrategy\ScriptBindingStrategy.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ResourceBindingStrategy\StaticFileBindingStrategy.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ResourceBindingStrategy\StylesheetBindingStrategy.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeDescriptor.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeAlteration.cs" />
|
||||
@@ -337,6 +339,7 @@
|
||||
<Compile Include="UI\Navigation\PagerParameters.cs" />
|
||||
<Compile Include="UI\Resources\IResourceManifestProvider.cs" />
|
||||
<Compile Include="UI\Resources\ResourceManifestBuilder.cs" />
|
||||
<Compile Include="UI\Resources\ResourceSynchronicity.cs" />
|
||||
<Compile Include="UI\Zones\LayoutWorkContext.cs" />
|
||||
<Compile Include="UI\Zones\ZoneHoldingBehavior.cs" />
|
||||
<Compile Include="Mvc\ViewEngines\ThemeAwareness\ConfiguredEnginesCache.cs" />
|
||||
|
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Orchard.UI.Resources {
|
||||
public class RequireSettings {
|
||||
@@ -14,6 +13,7 @@ namespace Orchard.UI.Resources {
|
||||
public bool DebugMode { get; set; }
|
||||
public bool CdnMode { get; set; }
|
||||
public ResourceLocation Location { get; set; }
|
||||
public ResourceSynchronicity Synchronicity { get; set; }
|
||||
public string Condition { get; set; }
|
||||
public Action<ResourceDefinition> InlineDefinition { get; set; }
|
||||
public Dictionary<string, string> Attributes {
|
||||
@@ -49,6 +49,19 @@ namespace Orchard.UI.Resources {
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequireSettings Async(bool async = true) {
|
||||
return UseSynchronicity(async ? ResourceSynchronicity.Asynchronous : ResourceSynchronicity.Synchronous);
|
||||
}
|
||||
|
||||
public RequireSettings UseSynchronicity(ResourceSynchronicity synchronicity) {
|
||||
Synchronicity = (ResourceSynchronicity)Math.Max((int)Synchronicity, (int)synchronicity);
|
||||
return this;
|
||||
}
|
||||
|
||||
public bool LoadAsync {
|
||||
get { return Synchronicity == ResourceSynchronicity.Asynchronous && Location == ResourceLocation.Unspecified; }
|
||||
}
|
||||
|
||||
public RequireSettings UseCulture(string cultureName) {
|
||||
if (!String.IsNullOrEmpty(cultureName)) {
|
||||
Culture = cultureName;
|
||||
@@ -129,6 +142,7 @@ namespace Orchard.UI.Resources {
|
||||
Name = Name,
|
||||
Type = Type
|
||||
}).AtLocation(Location).AtLocation(other.Location)
|
||||
.UseSynchronicity(Synchronicity).UseSynchronicity(other.Synchronicity)
|
||||
.WithBasePath(BasePath).WithBasePath(other.BasePath)
|
||||
.UseCdn(CdnMode).UseCdn(other.CdnMode)
|
||||
.UseDebugMode(DebugMode).UseDebugMode(other.DebugMode)
|
||||
|
7
src/Orchard/UI/Resources/ResourceSynchronicity.cs
Normal file
7
src/Orchard/UI/Resources/ResourceSynchronicity.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Orchard.UI.Resources {
|
||||
public enum ResourceSynchronicity {
|
||||
Unspecified,
|
||||
Asynchronous,
|
||||
Synchronous,
|
||||
}
|
||||
}
|
@@ -85,7 +85,7 @@ namespace Orchard.Utility.Extensions {
|
||||
return true;
|
||||
}
|
||||
|
||||
// at this point, check for an fully qualified url
|
||||
// at this point, check for a fully qualified url
|
||||
try {
|
||||
var uri = new Uri(url);
|
||||
if (uri.Authority.Equals(request.Headers["Host"], StringComparison.OrdinalIgnoreCase)) {
|
||||
@@ -106,7 +106,7 @@ namespace Orchard.Utility.Extensions {
|
||||
return false;
|
||||
}
|
||||
catch {
|
||||
// mall-formed url e.g, "abcdef"
|
||||
// malformed url e.g, "abcdef"
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -324,5 +324,9 @@ namespace Orchard.Utility.Extensions {
|
||||
var pattern = String.Format("({0})", String.Join("|", replacements.Keys.ToArray()));
|
||||
return Regex.Replace(original, pattern, (match) => replacements[match.Value]);
|
||||
}
|
||||
|
||||
public static bool IsAbsoluteUrl(this string url) {
|
||||
return url.StartsWith("http://") || url.StartsWith("https://") || url.StartsWith("//");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user