Ejemplo n.º 1
0
 internal Resource(ResourceSet parent, Resource copy)
 {
     ParentSet = parent;
     Path = copy.Path;
     Mode = copy.Mode;
     ForwardCookie = copy.ForwardCookie;
     Minifier = copy.Minifier;
 }
        public string TransformContent(ResourceSet resourceSet, Resource resource, string content)
        {
            var extension = Path.GetExtension(resource.Path);
            if (extension != null && !extension.Equals(".coffee", StringComparison.InvariantCultureIgnoreCase))
                return content;

            var engine = new CoffeeSharp.CoffeeScriptEngine();
            return engine.Compile(content, filename: resource.Path);
        }
Ejemplo n.º 3
0
        public string TransformContent(ResourceSet resourceSet, Resource resource, string content)
        {
            content += " namespace(\"Parking.Resources.i18n\");";
            Dictionary<string, string> en = Utilities.GetResources("en-US");
            Dictionary<string, string> es = Utilities.GetResources("es-MX");
            //Func<string, Dictionary<string, string>> toJSON =
            //ServiceStack.Text.JsonExtensions.
            string jsEn = string.Format("resx['i18n']['en-US'] = {0};", en.ToJson());
            string jsEs = string.Format("resx['i18n']['es-MX'] = {0};", es.ToJson());

            content += " (function(resx, undefined) { " + jsEn + jsEs + " })(Parking.Resources);";
            return content;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// If remote resource, return the URL as-is.
 /// If local resource (static or dynamic), append the URL with a content hash
 /// to make sure the browser always requests the latest contents.
 /// 
 /// Per http://combres.codeplex.com/discussions/348659#post810556, 
 /// retain only the first 32 chars to avoid being too long
 /// </summary>
 private static string GetResourceUrl(Resource resource)
 {
     if (!resource.IsInSameApplication)
         return resource.Path.ToAbsoluteUrl();
     var url = resource.Mode == ResourceMode.Dynamic
                   ? resource.Path.ToAbsoluteUrl()
                   : resource.Path.ResolveUrl();
     var contentHash = resource.ReadFromCache(true).GetHash();
     contentHash = contentHash.Length > 32 
         ? contentHash.Substring(0, 32)
         : contentHash;
     return (url + (url.Contains("?") ? "&" : "?") + contentHash)
         .AppendHost(resource.ParentSet.Settings);
 }
Ejemplo n.º 5
0
 public string TransformContent(ResourceSet resourceSet, Resource resource, string content)
 {
     var engine = new LessEngine(new Parser(new ConsoleStylizer(), new Importer(new AdeptFileReader(resource.Path))));
     return engine.TransformToCss(content, resource.Path);
 }
Ejemplo n.º 6
0
 public void Set(Resource resource, string content)
 {
     using (synchLock.Write())
     {
         cache[resource] = content;
     }
 }
Ejemplo n.º 7
0
 public void Remove(Resource resource)
 {
     using (synchLock.Write())
     {
         cache.Remove(resource);
     }
 }
Ejemplo n.º 8
0
 public string Get(Resource resource)
 {
     using (synchLock.Read())
     {
         return cache.ContainsKey(resource) ? cache[resource] : null;
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Generates a path:template pair
 /// </summary>
 /// <param name="resourceSet"></param>
 /// <param name="resource"></param>
 /// <param name="content"></param>
 /// <returns></returns>
 public string TransformContent(ResourceSet resourceSet, Resource resource, string content)
 {
     string path = resource.Path.Replace("~", "");
     return string.Format("\"{0}\":'{1}',", path, HttpUtility.JavaScriptStringEncode(content));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// If remote resource, return the URL as-is.
 /// If local resource (static or dynamic), append the URL with a content hash
 /// to make sure the browser always requests the latest contents.
 /// </summary>
 private static string GetResourceUrl(Resource resource)
 {
     if (!resource.IsInSameApplication)
         return resource.Path.ToAbsoluteUrl();
     var url = resource.Mode == ResourceMode.Dynamic
                   ? resource.Path.ToAbsoluteUrl()
                   : resource.Path.ResolveUrl();
     var contentHash = resource.ReadFromCache(true).GetHash();
     return url + (url.Contains("?") ? "&" : "?") + contentHash;
 }