mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 02:44:52 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -221,13 +221,13 @@ namespace Orchard.Core.Shapes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Shape]
|
[Shape]
|
||||||
public void Style(TextWriter Output, ResourceDefinition Resource, string Url, string Condition) {
|
public void Style(TextWriter Output, ResourceDefinition Resource, string Url, string Condition, Dictionary<string, string> TagAttributes) {
|
||||||
UI.Resources.ResourceManager.WriteResource(Output, Resource, Url, Condition);
|
UI.Resources.ResourceManager.WriteResource(Output, Resource, Url, Condition, TagAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Shape]
|
[Shape]
|
||||||
public void Resource(TextWriter Output, ResourceDefinition Resource, string Url, string Condition) {
|
public void Resource(TextWriter Output, ResourceDefinition Resource, string Url, string Condition, Dictionary<string, string> TagAttributes) {
|
||||||
UI.Resources.ResourceManager.WriteResource(Output, Resource, Url, Condition);
|
UI.Resources.ResourceManager.WriteResource(Output, Resource, Url, Condition, TagAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteLiteralScripts(TextWriter output, IEnumerable<string> scripts) {
|
private static void WriteLiteralScripts(TextWriter output, IEnumerable<string> scripts) {
|
||||||
@@ -266,12 +266,13 @@ namespace Orchard.Core.Shapes {
|
|||||||
|
|
||||||
var path = context.GetResourceUrl(defaultSettings, appPath);
|
var path = context.GetResourceUrl(defaultSettings, appPath);
|
||||||
var condition = context.Settings.Condition;
|
var condition = context.Settings.Condition;
|
||||||
|
var attributes = context.Settings.HasAttributes ? context.Settings.Attributes : null;
|
||||||
IHtmlString result;
|
IHtmlString result;
|
||||||
if (resourceType == "stylesheet") {
|
if (resourceType == "stylesheet") {
|
||||||
result = Display.Style(Url: path, Condition: condition, Resource: context.Resource);
|
result = Display.Style(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = Display.Resource(Url: path, Condition: condition, Resource: context.Resource);
|
result = Display.Resource(Url: path, Condition: condition, Resource: context.Resource, TagAttributes: attributes);
|
||||||
}
|
}
|
||||||
Output.Write(result);
|
Output.Write(result);
|
||||||
}
|
}
|
||||||
|
@@ -7,11 +7,11 @@
|
|||||||
|
|
||||||
@{
|
@{
|
||||||
Style.Include("site.css");
|
Style.Include("site.css");
|
||||||
|
Style.Include("ie.css").UseCondition("lte IE 8").SetAttribute("media", "screen, projection");
|
||||||
|
Style.Include("ie6.css").UseCondition("lte IE 6").SetAttribute("media", "screen, projection");
|
||||||
Script.Require("jQuery");
|
Script.Require("jQuery");
|
||||||
Script.Require("ShapesBase");
|
Script.Require("ShapesBase");
|
||||||
Script.Include("admin.js");
|
Script.Include("admin.js");
|
||||||
RegisterLink(new LinkEntry { Condition = "lte IE 8", Rel = "stylesheet", Type = "text/css", Href = Url.Content("~/Themes/TheAdmin/Styles/ie.css") }.AddAttribute("media", "screen, projection"));
|
|
||||||
RegisterLink(new LinkEntry { Condition = "lte IE 6", Rel = "stylesheet", Type = "text/css", Href = Url.Content("~/Themes/TheAdmin/Styles/ie6.css") }.AddAttribute("media", "screen, projection"));
|
|
||||||
// these are just hacked together to fire existing partials... can change
|
// these are just hacked together to fire existing partials... can change
|
||||||
Model.Header.Add(Display.Header());
|
Model.Header.Add(Display.Header());
|
||||||
|
|
||||||
|
@@ -83,7 +83,8 @@ namespace Orchard.DisplayManagement.Descriptors.ResourceBindingStrategy {
|
|||||||
var output = displayContext.ViewContext.Writer;
|
var output = displayContext.ViewContext.Writer;
|
||||||
ResourceDefinition resource = shape.Resource;
|
ResourceDefinition resource = shape.Resource;
|
||||||
string condition = shape.Condition;
|
string condition = shape.Condition;
|
||||||
ResourceManager.WriteResource(output, resource, hit.fileVirtualPath, condition);
|
Dictionary<string, string> attributes = shape.TagAttributes;
|
||||||
|
ResourceManager.WriteResource(output, resource, hit.fileVirtualPath, condition, attributes);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
namespace Orchard.UI.Resources {
|
namespace Orchard.UI.Resources {
|
||||||
public class RequireSettings {
|
public class RequireSettings {
|
||||||
|
private Dictionary<string, string> _attributes;
|
||||||
|
|
||||||
public string BasePath { get; set; }
|
public string BasePath { get; set; }
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
@@ -11,6 +16,13 @@ namespace Orchard.UI.Resources {
|
|||||||
public ResourceLocation Location { get; set; }
|
public ResourceLocation Location { get; set; }
|
||||||
public string Condition { get; set; }
|
public string Condition { get; set; }
|
||||||
public Action<ResourceDefinition> InlineDefinition { get; set; }
|
public Action<ResourceDefinition> InlineDefinition { get; set; }
|
||||||
|
public Dictionary<string, string> Attributes {
|
||||||
|
get { return _attributes ?? (_attributes = new Dictionary<string, string>()); }
|
||||||
|
set { _attributes = value; }
|
||||||
|
}
|
||||||
|
public bool HasAttributes {
|
||||||
|
get { return _attributes != null && _attributes.Any(a => a.Value != null); }
|
||||||
|
}
|
||||||
|
|
||||||
public RequireSettings AtHead() {
|
public RequireSettings AtHead() {
|
||||||
return AtLocation(ResourceLocation.Head);
|
return AtLocation(ResourceLocation.Head);
|
||||||
@@ -66,8 +78,32 @@ namespace Orchard.UI.Resources {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RequireSettings SetAttribute(string name, string value) {
|
||||||
|
if (_attributes == null) {
|
||||||
|
_attributes = new Dictionary<string, string>();
|
||||||
|
}
|
||||||
|
_attributes[name] = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<string, string> MergeAttributes(RequireSettings other) {
|
||||||
|
// efficiently merge the two dictionaries, taking into account that one or both may not exist
|
||||||
|
// and that attributes in 'other' should overridde attributes in this, even if the value is null.
|
||||||
|
if (_attributes == null) {
|
||||||
|
return other._attributes == null ? null : new Dictionary<string, string>(other._attributes);
|
||||||
|
}
|
||||||
|
if (other._attributes == null) {
|
||||||
|
return new Dictionary<string, string>(_attributes);
|
||||||
|
}
|
||||||
|
var mergedAttributes = new Dictionary<string, string>(_attributes);
|
||||||
|
foreach (var pair in other._attributes) {
|
||||||
|
mergedAttributes[pair.Key] = pair.Value;
|
||||||
|
}
|
||||||
|
return mergedAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
public RequireSettings Combine(RequireSettings other) {
|
public RequireSettings Combine(RequireSettings other) {
|
||||||
return (new RequireSettings {
|
var settings = (new RequireSettings {
|
||||||
Name = Name,
|
Name = Name,
|
||||||
Type = Type
|
Type = Type
|
||||||
}).AtLocation(Location).AtLocation(other.Location)
|
}).AtLocation(Location).AtLocation(other.Location)
|
||||||
@@ -77,6 +113,8 @@ namespace Orchard.UI.Resources {
|
|||||||
.UseCulture(Culture).UseCulture(other.Culture)
|
.UseCulture(Culture).UseCulture(other.Culture)
|
||||||
.UseCondition(Condition).UseCondition(other.Condition)
|
.UseCondition(Condition).UseCondition(other.Condition)
|
||||||
.Define(InlineDefinition).Define(other.InlineDefinition);
|
.Define(InlineDefinition).Define(other.InlineDefinition);
|
||||||
|
settings._attributes = MergeAttributes(other);
|
||||||
|
return settings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -56,11 +56,16 @@ namespace Orchard.UI.Resources {
|
|||||||
return tagBuilder;
|
return tagBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteResource(TextWriter writer, ResourceDefinition resource, string url, string condition) {
|
public static void WriteResource(TextWriter writer, ResourceDefinition resource, string url, string condition, Dictionary<string,string> attributes) {
|
||||||
if (!string.IsNullOrEmpty(condition)) {
|
if (!string.IsNullOrEmpty(condition)) {
|
||||||
writer.WriteLine("<!--[if " + condition + "]>");
|
writer.WriteLine("<!--[if " + condition + "]>");
|
||||||
}
|
}
|
||||||
writer.WriteLine(GetTagBuilder(resource, url).ToString(resource.TagRenderMode));
|
var tagBuilder = GetTagBuilder(resource, url);
|
||||||
|
if (attributes != null) {
|
||||||
|
// todo: try null value
|
||||||
|
tagBuilder.MergeAttributes(attributes, true);
|
||||||
|
}
|
||||||
|
writer.WriteLine(tagBuilder.ToString(resource.TagRenderMode));
|
||||||
if (!string.IsNullOrEmpty(condition)) {
|
if (!string.IsNullOrEmpty(condition)) {
|
||||||
writer.WriteLine("<![endif]-->");
|
writer.WriteLine("<![endif]-->");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user