Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public string GetTemplateNotCache(string resourceName, string viewVirtualPath)
        {
            string resourceType    = "template";
            var    defaultSettings = new RequireSettings
            {
                DebugMode = false,
                CdnMode   = false,
                Culture   = "" //_workContext.Value.CurrentCulture,
            };

            Require("template", resourceName);
            var httpContext = HttpContext.Current;
            var appPath     = httpContext == null || httpContext.Request == null
                ? null
                : httpContext.Request.ApplicationPath;

            var requiredResources = this.GetResources(resourceType);

            requiredResources = requiredResources.Where(t => t.Resource.Name == resourceName).ToList();
            var listTemplateTmp = new List <string>();

            foreach (var context in requiredResources)
            {
                if (viewVirtualPath != null)
                {
                    context.Settings.WithBasePath(ResourceDefinition.GetBasePathFromViewPath(resourceType, viewVirtualPath));
                }
                var path       = context.GetResourceUrl(defaultSettings, appPath);
                var condition  = context.Settings.Condition;
                var attributes = context.Settings.HasAttributes ? context.Settings.Attributes : null;

                listTemplateTmp.Add(path);
            }
            if (listTemplateTmp == null || !listTemplateTmp.Any())
            {
                throw new Exception($"no found {resourceName} View Template");
            }


            return(listTemplateTmp.FirstOrDefault());
        }
Ejemplo n.º 4
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]-->");
                }
            }
        }
Ejemplo n.º 5
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)));
 }