/// <summary> /// Return stream for requested asset file (used for search current and base themes assets) /// </summary> /// <param name="filePath"></param> /// <returns></returns> public async Task <Stream> GetAssetStreamAsync(string filePath) { Stream retVal = null; var filePathWithoutExtension = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)); //file.ext => file.ext || file || file.liquid || file.ext.liquid var searchPatterns = new[] { filePath, filePathWithoutExtension, string.Format(_liquidTemplateFormat, filePathWithoutExtension), string.Format(_liquidTemplateFormat, filePath) }; string currentThemeFilePath = null; //try to search in current store theme if (_themeBlobProvider.PathExists(Path.Combine(CurrentThemePath, "assets"))) { currentThemeFilePath = searchPatterns.SelectMany(x => _themeBlobProvider.Search(Path.Combine(CurrentThemePath, "assets"), x, true)).FirstOrDefault(); } //If not found by current theme path try find them by base path if it is defined if (currentThemeFilePath == null && BaseThemePath != null) { currentThemeFilePath = searchPatterns.SelectMany(x => _themeBlobProvider.Search(Path.Combine(BaseThemePath, "assets"), x, true)).FirstOrDefault(); } if (currentThemeFilePath != null) { retVal = _themeBlobProvider.OpenRead(currentThemeFilePath); filePath = currentThemeFilePath; } if (retVal != null && filePath.EndsWith(".liquid")) { var context = WorkContext.Clone() as WorkContext; context.Settings = GetSettings("''"); var templateContent = retVal.ReadToString(); retVal.Dispose(); var template = await RenderTemplateAsync(templateContent, filePath, context.ToScriptObject()); retVal = new MemoryStream(Encoding.UTF8.GetBytes(template)); } if (retVal != null && (filePath.Contains(".scss.") && filePath.EndsWith(".liquid") || filePath.EndsWith(".scss"))) { var content = retVal.ReadToString(); retVal.Dispose(); try { //handle scss resources var result = SassCompiler.Compile(content); content = result.CompiledContent; retVal = new MemoryStream(Encoding.UTF8.GetBytes(content)); } catch (Exception ex) { throw new SaasCompileException(filePath, content, ex); } } return(retVal); }