コード例 #1
0
ファイル: ResourceManifest.cs プロジェクト: qhme/OrchardLite
 public virtual ResourceDefinition DefineResource(string resourceType, string resourceName)
 {
     var definition = new ResourceDefinition(this, resourceType, resourceName);
     var resources = GetResources(resourceType);
     resources[resourceName] = definition;
     return definition;
 }
コード例 #2
0
ファイル: ResourceManager.cs プロジェクト: wezmag/Coevery
        public static void WriteResource(TextWriter writer, ResourceDefinition resource, string url, string condition, Dictionary<string, string> attributes) {
            if (!string.IsNullOrEmpty(condition)) {
                if (condition == NotIE) {
                    writer.WriteLine("<!--[if " + condition + "]>-->");
                }
                else {
                    writer.WriteLine("<!--[if " + condition + "]>");
                }
            }

            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 (condition == NotIE) {
                    writer.WriteLine("<!--<![endif]-->");
                }
                else {
                    writer.WriteLine("<![endif]-->");
                }
            }
        }
コード例 #3
0
ファイル: ResourceManager.cs プロジェクト: wezmag/Coevery
 private static TagBuilder GetTagBuilder(ResourceDefinition resource, string url) {
     var tagBuilder = new TagBuilder(resource.TagName);
     tagBuilder.MergeAttributes(resource.TagBuilder.Attributes);
     if (!String.IsNullOrEmpty(resource.FilePathAttributeName)) {
         if (!String.IsNullOrEmpty(url)) {
             if (VirtualPathUtility.IsAppRelative(url)) {
                 url = VirtualPathUtility.ToAbsolute(url);
             }
             tagBuilder.MergeAttribute(resource.FilePathAttributeName, url, true);
         }
     }
     return tagBuilder;
 }
コード例 #4
0
        /// <summary>
        /// Includes a resource that is already defined in a resource manifest
        /// </summary>
        /// <remarks>
        /// You can define resources in resource manifest files with ResourceManifestBuilder.
        /// For examples take a look at any ResourceManifest.cs file.
        /// </remarks>
        /// <param name="resourceName"></param>
        /// <returns></returns>
        public virtual RequireSettings Require(string resourceName)
        {
            if (resourceName == null)
            {
                throw new ArgumentNullException("resourceName");
            }
            var settings = ResourceManager.Require(ResourceType, resourceName);

            if (_viewVirtualPath != null)
            {
                settings.WithBasePath(ResourceDefinition.GetBasePathFromViewPath(ResourceType, _viewVirtualPath));
            }
            return(settings);
        }
コード例 #5
0
        private static TagBuilder GetTagBuilder(ResourceDefinition resource, string url)
        {
            var tagBuilder = new TagBuilder(resource.TagName);

            tagBuilder.MergeAttributes(resource.TagBuilder.Attributes);
            if (!String.IsNullOrEmpty(resource.FilePathAttributeName))
            {
                if (!String.IsNullOrEmpty(url))
                {
                    if (VirtualPathUtility.IsAppRelative(url))
                    {
                        url = VirtualPathUtility.ToAbsolute(url);
                    }
                    tagBuilder.MergeAttribute(resource.FilePathAttributeName, url, true);
                }
            }
            return(tagBuilder);
        }
コード例 #6
0
        public static void WriteResource(TextWriter writer, ResourceDefinition resource, string url, string condition, Dictionary <string, string> attributes)
        {
            if (!string.IsNullOrEmpty(condition))
            {
                if (condition == NotIE)
                {
                    writer.WriteLine("<!--[if " + condition + "]>-->");
                }
                else
                {
                    writer.WriteLine("<!--[if " + condition + "]>");
                }
            }

            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 (condition == NotIE)
                {
                    writer.WriteLine("<!--<![endif]-->");
                }
                else
                {
                    writer.WriteLine("<![endif]-->");
                }
            }
        }
コード例 #7
0
ファイル: CoreShapes.cs プロジェクト: Golone/Orchard
 public void Resource(TextWriter Output, ResourceDefinition Resource, string Url, string Condition, Dictionary<string, string> TagAttributes) {
     ResourceManager.WriteResource(Output, Resource, Url, Condition, TagAttributes);
 }
コード例 #8
0
ファイル: CoreShapes.cs プロジェクト: Golone/Orchard
 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
     ResourceManager.WriteResource(Html.ViewContext.Writer, Resource, Url, Condition, TagAttributes);
 }
コード例 #9
0
 /// <summary>
 /// Includes a resource with the specified path
 /// </summary>
 /// <param name="resourceDebugPath">The relative or absolute path of the resource to be used in debug mode</param>
 /// <param name="resourcePath">The relative or absolute path of the resource</param>
 public RequireSettings Include(string resourceDebugPath, string resourcePath)
 {
     if (resourcePath == null)
     {
         throw new ArgumentNullException("resourcePath");
     }
     return(ResourceManager.Include(ResourceType, resourcePath, resourceDebugPath, ResourceDefinition.GetBasePathFromViewPath(ResourceType, _viewVirtualPath)));
 }
コード例 #10
0
ファイル: ResourceManager.cs プロジェクト: wezmag/Coevery
 protected virtual void ExpandDependencies(ResourceDefinition resource, RequireSettings settings, OrderedDictionary allResources) {
     if (resource == null) {
         return;
     }
     // Settings is given so they can cascade down into dependencies. For example, if Foo depends on Bar, and Foo's required
     // location is Head, so too should Bar's location.
     // forge the effective require settings for this resource
     // (1) If a require exists for the resource, combine with it. Last settings in gets preference for its specified values.
     // (2) If no require already exists, form a new settings object based on the given one but with its own type/name.
     settings = allResources.Contains(resource)
         ? ((RequireSettings)allResources[resource]).Combine(settings)
         : new RequireSettings { Type = resource.Type, Name = resource.Name }.Combine(settings);
     if (resource.Dependencies != null) {
         var dependencies = from d in resource.Dependencies
                            select FindResource(new RequireSettings { Type = resource.Type, Name = d });
         foreach (var dependency in dependencies) {
             if (dependency == null) {
                 continue;
             }
             ExpandDependencies(dependency, settings, allResources);
         }
     }
     allResources[resource] = settings;
 }
コード例 #11
0
 public static bool TagAttributesEqual(this ResourceDefinition resource, ResourceDefinition other)
 {
     return resource.StringifyAttributes() == other.StringifyAttributes();
 }