Esempio n. 1
0
    /// <summary>
    /// Retrieves the specified resources and wraps them in an data container.
    /// </summary>
    /// <param name="settings">CSS settings</param>
    /// <param name="name">Resource name</param>
    /// <param name="cached">If true, the result will be cached</param>
    /// <returns>The data container with the resulting stylesheet data</returns>
    private static CMSOutputResource GetResource(CMSCssSettings settings, string name, bool cached)
    {
        List <CMSOutputResource> resources = new List <CMSOutputResource>();

        // Add files
        if (settings.Files != null)
        {
            foreach (string item in settings.Files)
            {
                // Get the resource
                CMSOutputResource resource = GetFile(item, CSS_FILE_EXTENSION);
                resources.Add(resource);
            }
        }

        // Add stylesheets
        if (settings.Stylesheets != null)
        {
            foreach (string item in settings.Stylesheets)
            {
                // Get the resource
                CMSOutputResource resource = GetStylesheet(item);
                resources.Add(resource);
            }
        }

        // Add web part containers
        if (settings.Containers != null)
        {
            foreach (string item in settings.Containers)
            {
                // Get the resource
                CMSOutputResource resource = GetContainer(item);
                resources.Add(resource);
            }
        }

        // Add web parts
        if (settings.WebParts != null)
        {
            foreach (string item in settings.WebParts)
            {
                // Get the resource
                CMSOutputResource resource = GetWebPart(item);
                resources.Add(resource);
            }
        }

        // Add templates
        if (settings.Templates != null)
        {
            foreach (string item in settings.Templates)
            {
                // Get the resource
                CMSOutputResource resource = GetTemplate(item);
                resources.Add(resource);
            }
        }

        // Add layouts
        if (settings.Layouts != null)
        {
            foreach (string item in settings.Layouts)
            {
                // Get the resource
                CMSOutputResource resource = GetLayout(item);
                resources.Add(resource);
            }
        }

        // Add transformation containers
        if (settings.Transformations != null)
        {
            foreach (string item in settings.Transformations)
            {
                // Get the resource
                CMSOutputResource resource = GetTransformation(item);
                resources.Add(resource);
            }
        }

        // Add web part layouts
        if (settings.WebPartLayouts != null)
        {
            foreach (string item in settings.WebPartLayouts)
            {
                // Get the resource
                CMSOutputResource resource = GetWebPartLayout(item);
                resources.Add(resource);
            }
        }

        // Combine to a single output
        CMSOutputResource result = CombineResources(resources);

        // Resolve the macros
        if (CSSHelper.ResolveMacrosInCSS)
        {
            MacroContext context = new MacroContext()
            {
                TrackCacheDependencies = cached
            };

            if (cached)
            {
                // Add the default dependencies
                context.AddCacheDependencies(settings.GetCacheDependencies());
                context.AddFileCacheDependencies(settings.GetFileCacheDependencies());
            }

            result.Data = CMSContext.ResolveMacros(result.Data, context);

            if (cached)
            {
                // Add cache dependency
                result.CacheDependency = CacheHelper.GetCacheDependency(context.FileCacheDependencies, context.CacheDependencies);
            }
        }
        else if (cached)
        {
            // Only the cache dependency from settings
            result.CacheDependency = settings.GetCacheDependency();
        }

        // Minify
        MinifyResource(result, mCssMinifier, CSSHelper.StylesheetMinificationEnabled && settings.EnableMinification, settings.EnableMinification);

        return(result);
    }
    /// <summary>
    /// Retrieves the specified resources and wraps them in an data container.
    /// </summary>
    /// <param name="settings">CSS settings</param>
    /// <param name="name">Resource name</param>
    /// <param name="cached">If true, the result will be cached</param>
    /// <returns>The data container with the resulting stylesheet data</returns>
    private static CMSOutputResource GetResource(CMSCssSettings settings, string name, bool cached)
    {
        List<CMSOutputResource> resources = new List<CMSOutputResource>();

        // Add files
        if (settings.Files != null)
        {
            foreach (CMSItem item in settings.Files)
            {
                // Get the resource
                CMSOutputResource resource = GetFile(item, CSS_FILE_EXTENSION, true, false);
                resources.Add(resource);
            }
        }

        // Add stylesheets
        if (settings.Stylesheets != null)
        {
            foreach (CMSItem item in settings.Stylesheets)
            {
                // Get the resource
                CMSOutputResource resource = GetStylesheet(item);
                resources.Add(resource);
            }
        }

        // Add web part containers
        if (settings.Containers != null)
        {
            foreach (CMSItem item in settings.Containers)
            {
                // Get the resource
                CMSOutputResource resource = GetContainer(item);
                resources.Add(resource);
            }
        }

        // Add web parts
        if (settings.WebParts != null)
        {
            foreach (CMSItem item in settings.WebParts)
            {
                // Get the resource
                CMSOutputResource resource = GetWebPart(item);
                resources.Add(resource);
            }
        }

        // Add templates
        if (settings.Templates != null)
        {
            foreach (CMSItem item in settings.Templates)
            {
                // Get the resource
                CMSOutputResource resource = GetTemplate(item);
                resources.Add(resource);
            }
        }

        // Add layouts
        if (settings.Layouts != null)
        {
            foreach (CMSItem item in settings.Layouts)
            {
                // Get the resource
                CMSOutputResource resource = GetLayout(item);
                resources.Add(resource);
            }
        }

        // Add device layouts
        if (settings.DeviceLayouts != null)
        {
            foreach (CMSItem item in settings.DeviceLayouts)
            {
                // Get the resource
                CMSOutputResource resource = GetDeviceLayout(item);
                resources.Add(resource);
            }
        }

        // Add transformation containers
        if (settings.Transformations != null)
        {
            foreach (CMSItem item in settings.Transformations)
            {
                // Get the resource
                CMSOutputResource resource = GetTransformation(item);
                resources.Add(resource);
            }
        }

        // Add web part layouts
        if (settings.WebPartLayouts != null)
        {
            foreach (CMSItem item in settings.WebPartLayouts)
            {
                // Get the resource
                CMSOutputResource resource = GetWebPartLayout(item);
                resources.Add(resource);
            }
        }

        // Combine to a single output
        CMSOutputResource result = CombineResources(resources);
        settings.ComponentFiles = result.ComponentFiles;
        result.ContentType = MimeTypeHelper.GetMimetype(CSS_FILE_EXTENSION);

        // Resolve the macros
        if (CSSHelper.ResolveMacrosInCSS)
        {
            var context = new MacroContext()
            {
                TrackCacheDependencies = cached
            };

            if (cached)
            {
                // Add the default dependencies
                context.AddCacheDependencies(settings.GetCacheDependencies());
                context.AddFileCacheDependencies(settings.GetFileCacheDependencies());
            }

            result.Data = CMSContext.ResolveMacros(result.Data, context);

            if (cached)
            {
                // Add cache dependency
                result.CacheDependency = CacheHelper.GetCacheDependency(context.FileCacheDependencies, context.CacheDependencies);
            }
        }
        else if (cached)
        {
            // Only the cache dependency from settings
            result.CacheDependency = settings.GetCacheDependency();
        }

        result.Data = HTMLHelper.ResolveCSSClientUrls(result.Data, URLHelper.GetAbsoluteUrl("~/CMSPages/GetResource.ashx"));

        // Minify
        MinifyResource(result, new CssMinifier(), CSSHelper.StylesheetMinificationEnabled && settings.EnableMinification, settings.EnableCompression);

        return result;
    }
Esempio n. 3
0
    /// <summary>
    /// Retrieves the specified resources and wraps them in an data container.
    /// </summary>
    /// <param name="settings">CSS settings</param>
    /// <param name="name">Resource name</param>
    /// <param name="cached">If true, the result will be cached</param>
    /// <returns>The data container with the resulting stylesheet data</returns>
    private static CMSOutputResource GetResource(CMSCssSettings settings, string name, bool cached)
    {
        List<CMSOutputResource> resources = new List<CMSOutputResource>();

        // Add files
        if (settings.Files != null)
        {
            foreach (string item in settings.Files)
            {
                // Get the resource
                CMSOutputResource resource = GetFile(item, CSS_FILE_EXTENSION);
                resources.Add(resource);
            }
        }

        // Add stylesheets
        if (settings.Stylesheets != null)
        {
            foreach (string item in settings.Stylesheets)
            {
                // Get the resource
                CMSOutputResource resource = GetStylesheet(item);
                resources.Add(resource);
            }
        }

        // Add web part containers
        if (settings.Containers != null)
        {
            foreach (string item in settings.Containers)
            {
                // Get the resource
                CMSOutputResource resource = GetContainer(item);
                resources.Add(resource);
            }
        }

        // Add web parts
        if (settings.WebParts != null)
        {
            foreach (string item in settings.WebParts)
            {
                // Get the resource
                CMSOutputResource resource = GetWebPart(item);
                resources.Add(resource);
            }
        }

        // Add templates
        if (settings.Templates != null)
        {
            foreach (string item in settings.Templates)
            {
                // Get the resource
                CMSOutputResource resource = GetTemplate(item);
                resources.Add(resource);
            }
        }

        // Add layouts
        if (settings.Layouts != null)
        {
            foreach (string item in settings.Layouts)
            {
                // Get the resource
                CMSOutputResource resource = GetLayout(item);
                resources.Add(resource);
            }
        }

        // Add transformation containers
        if (settings.Transformations != null)
        {
            foreach (string item in settings.Transformations)
            {
                // Get the resource
                CMSOutputResource resource = GetTransformation(item);
                resources.Add(resource);
            }
        }

        // Add web part layouts
        if (settings.WebPartLayouts != null)
        {
            foreach (string item in settings.WebPartLayouts)
            {
                // Get the resource
                CMSOutputResource resource = GetWebPartLayout(item);
                resources.Add(resource);
            }
        }

        // Combine to a single output
        CMSOutputResource result = CombineResources(resources);

        // Resolve the macros
        if (CSSHelper.ResolveMacrosInCSS)
        {
            MacroContext context = new MacroContext()
            {
                TrackCacheDependencies = cached
            };

            if (cached)
            {
                // Add the default dependencies
                context.AddCacheDependencies(settings.GetCacheDependencies());
                context.AddFileCacheDependencies(settings.GetFileCacheDependencies());
            }

            result.Data = CMSContext.ResolveMacros(result.Data, context);

            if (cached)
            {
                // Add cache dependency
                result.CacheDependency = CacheHelper.GetCacheDependency(context.FileCacheDependencies, context.CacheDependencies);
            }
        }
        else if (cached)
        {
            // Only the cache dependency from settings
            result.CacheDependency = settings.GetCacheDependency();
        }

        // Minify
        MinifyResource(result, mCssMinifier, CSSHelper.StylesheetMinificationEnabled && settings.EnableMinification, settings.EnableMinification);

        return result;
    }