Example #1
0
        public ShopifyLiquidThemeEngine(IMemoryCache memoryCache, IWorkContextAccessor workContextAccessor,
                                        IHttpContextAccessor httpContextAccessor,
                                        IStorefrontUrlBuilder storeFrontUrlBuilder, IContentBlobProvider contentBlobProvder, IOptions <LiquidThemeEngineOptions> options)
        {
            _workContextAccessor  = workContextAccessor;
            _httpContextAccessor  = httpContextAccessor;
            _storeFrontUrlBuilder = storeFrontUrlBuilder;
            _options           = options.Value;
            _memoryCache       = memoryCache;
            _themeBlobProvider = contentBlobProvder;

            Liquid.UseRubyDateFormat = true;
            // Register custom tags (Only need to do this once)
            Template.RegisterFilter(typeof(CommonFilters));
            Template.RegisterFilter(typeof(CommerceFilters));
            Template.RegisterFilter(typeof(TranslationFilter));
            Template.RegisterFilter(typeof(UrlFilters));
            Template.RegisterFilter(typeof(DateFilters));
            Template.RegisterFilter(typeof(MoneyFilters));
            Template.RegisterFilter(typeof(HtmlFilters));
            Template.RegisterFilter(typeof(StringFilters));
            Template.RegisterFilter(typeof(ArrayFilters));
            Template.RegisterFilter(typeof(MathFilters));

            Condition.Operators["contains"] = CommonOperators.ContainsMethod;

            Template.RegisterTag <AntiforgeryTag>("anti_forgery");
            Template.RegisterTag <LayoutTag>("layout");
            Template.RegisterTag <FormTag>("form");
            Template.RegisterTag <PaginateTag>("paginate");
        }
 public AssetController(IWorkContextAccessor workContextAccessor, IStorefrontUrlBuilder urlBuilder, ILiquidThemeEngine themeEngine,
                        IContentBlobProvider staticContentBlobProvider, IHostingEnvironment hostingEnvironment)
     : base(workContextAccessor, urlBuilder)
 {
     _themeEngine         = themeEngine;
     _contentBlobProvider = staticContentBlobProvider;
     _hostingEnvironment  = hostingEnvironment;
 }
Example #3
0
 public StaticContentService(IStorefrontMemoryCache memoryCache, IStaticContentItemFactory contentItemFactory,
                             IContentBlobProvider contentBlobProvider, IStaticContentLoaderFactory metadataFactory)
 {
     _contentItemFactory  = contentItemFactory;
     _contentBlobProvider = contentBlobProvider;
     _memoryCache         = memoryCache;
     _metadataFactory     = metadataFactory;
 }
 public StaticContentService(IMemoryCache memoryCache, IWorkContextAccessor workContextAccessor,
                             IStorefrontUrlBuilder urlBuilder, IStaticContentItemFactory contentItemFactory,
                             IContentBlobProvider contentBlobProvider)
 {
     _urlBuilder          = urlBuilder;
     _contentItemFactory  = contentItemFactory;
     _contentBlobProvider = contentBlobProvider;
     _memoryCache         = memoryCache;
     _markdownPipeline    = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
 }
Example #5
0
 public ShopifyLiquidThemeEngine(IMemoryCache memoryCache, IWorkContextAccessor workContextAccessor,
                                 IHttpContextAccessor httpContextAccessor,
                                 IStorefrontUrlBuilder storeFrontUrlBuilder, IContentBlobProvider contentBlobProvder, IOptions <LiquidThemeEngineOptions> options)
 {
     _workContextAccessor  = workContextAccessor;
     _httpContextAccessor  = httpContextAccessor;
     _storeFrontUrlBuilder = storeFrontUrlBuilder;
     _options           = options.Value;
     _memoryCache       = memoryCache;
     _themeBlobProvider = contentBlobProvder;
 }
Example #6
0
 public ShopifyLiquidThemeEngine(IStorefrontMemoryCache memoryCache, IWorkContextAccessor workContextAccessor, IHttpContextAccessor httpContextAccessor,
                                 IStorefrontUrlBuilder storeFrontUrlBuilder, IContentBlobProvider contentBlobProvider, ISassFileManager sassFileManager, IOptions <LiquidThemeEngineOptions> options, IFeaturesAgent featuresAgent)
 {
     _workContextAccessor     = workContextAccessor;
     _httpContextAccessor     = httpContextAccessor;
     UrlBuilder               = storeFrontUrlBuilder;
     _options                 = options.Value;
     _memoryCache             = memoryCache;
     _themeBlobProvider       = contentBlobProvider;
     _sassFileManager         = sassFileManager;
     _featuresAgent           = featuresAgent;
     SassCompiler.FileManager = sassFileManager;
 }
        private static JObject InnerGetAllSettings(IContentBlobProvider themeBlobProvider, string themePath)
        {
            JObject retVal       = null;
            var     settingsPath = Path.Combine(themePath, "config\\settings_data.json");

            if (themeBlobProvider.PathExists(settingsPath))
            {
                using (var stream = themeBlobProvider.OpenRead(settingsPath))
                {
                    retVal = JsonConvert.DeserializeObject <JObject>(stream.ReadToString());
                }
            }
            return(retVal);
        }
        public ShopifyLiquidThemeEngine(ILocalCacheManager cacheManager, Func <WorkContext> workContextFactory, Func <IStorefrontUrlBuilder> storeFrontUrlBuilderFactory, IContentBlobProvider themeBlobProvider, IContentBlobProvider globalThemeBlobProvider, string themesAssetsRelativeUrl, string globalThemeAssetsRelativeUrl)
        {
            _workContextFactory           = workContextFactory;
            _storeFrontUrlBuilderFactory  = storeFrontUrlBuilderFactory;
            _themesAssetsRelativeUrl      = themesAssetsRelativeUrl;
            _globalThemeAssetsRelativeUrl = globalThemeAssetsRelativeUrl;
            _cacheManager            = cacheManager;
            _themeBlobProvider       = themeBlobProvider;
            _globalThemeBlobProvider = globalThemeBlobProvider;

            Liquid.UseRubyDateFormat = true;
            // Register custom tags (Only need to do this once)
            Template.RegisterFilter(typeof(CommonFilters));
            Template.RegisterFilter(typeof(CommerceFilters));
            Template.RegisterFilter(typeof(TranslationFilter));
            Template.RegisterFilter(typeof(UrlFilters));
            Template.RegisterFilter(typeof(DateFilters));
            Template.RegisterFilter(typeof(MoneyFilters));
            Template.RegisterFilter(typeof(HtmlFilters));
            Template.RegisterFilter(typeof(StringFilters));
            Template.RegisterFilter(typeof(ArrayFilters));
            Template.RegisterFilter(typeof(BundleFilters));
            Template.RegisterFilter(typeof(MathFilters));

            Condition.Operators["contains"] = CommonOperators.ContainsMethod;

            Template.RegisterTag <LayoutTag>("layout");
            Template.RegisterTag <FormTag>("form");
            Template.RegisterTag <PaginateTag>("paginate");

            //Observe themes content system changes to invalidate cache if changes occur
            _themeBlobProvider.Changed += (sender, args) =>
            {
                _cacheManager.Clear();
            };
            _themeBlobProvider.Renamed += (sender, args) =>
            {
                _cacheManager.Clear();
            };
            _globalThemeBlobProvider.Changed += (sender, args) =>
            {
                _cacheManager.Clear();
            };
            _globalThemeBlobProvider.Renamed += (sender, args) =>
            {
                _cacheManager.Clear();
            };
        }
        private static JObject InnerGetSettings(IContentBlobProvider themeBlobProvider, string themePath)
        {
            JObject retVal       = null;
            var     settingsPath = Path.Combine(themePath, "config\\settings_data.json");

            if (themeBlobProvider.PathExists(settingsPath))
            {
                using (var stream = themeBlobProvider.OpenRead(settingsPath))
                {
                    var settings = JsonConvert.DeserializeObject <JObject>(stream.ReadToString());
                    // now get settings for current theme and add it as a settings parameter
                    retVal = settings["current"] as JObject ?? settings["presets"][settings["current"].ToString()] as JObject;
                }
            }
            return(retVal);
        }
        private static JObject InnerReadLocalization(IContentBlobProvider themeBlobProvider, string themePath, Language language)
        {
            JObject retVal           = null;
            var     localeFolderPath = Path.Combine(themePath, "locales");

            if (themeBlobProvider.PathExists(localeFolderPath))
            {
                JObject localeJson  = null;
                JObject defaultJson = null;

                foreach (var languageName in new[] { language.CultureName, language.TwoLetterLanguageName })
                {
                    var currentLocalePath = Path.Combine(localeFolderPath, string.Concat(languageName, ".json"));

                    if (themeBlobProvider.PathExists(currentLocalePath))
                    {
                        using (var stream = themeBlobProvider.OpenRead(currentLocalePath))
                        {
                            localeJson = JsonConvert.DeserializeObject <dynamic>(stream.ReadToString());
                        }
                        break;
                    }
                }

                var localeDefaultPath = themeBlobProvider.Search(localeFolderPath, "*.default.json", false).FirstOrDefault();

                if (localeDefaultPath != null && themeBlobProvider.PathExists(localeDefaultPath))
                {
                    using (var stream = themeBlobProvider.OpenRead(localeDefaultPath))
                    {
                        defaultJson = JsonConvert.DeserializeObject <dynamic>(stream.ReadToString());
                    }
                }

                //Need merge default and requested localization json to resulting object
                retVal = defaultJson ?? localeJson;

                if (defaultJson != null && localeJson != null)
                {
                    retVal.Merge(localeJson, new JsonMergeSettings {
                        MergeArrayHandling = MergeArrayHandling.Merge
                    });
                }
            }
            return(retVal);
        }
        public ShopifyLiquidThemeEngine(ILocalCacheManager cacheManager, Func<WorkContext> workContextFactory, Func<IStorefrontUrlBuilder> storeFrontUrlBuilderFactory, IContentBlobProvider themeBlobProvider, IContentBlobProvider globalThemeBlobProvider, string themesAssetsRelativeUrl, string globalThemeAssetsRelativeUrl)
        {
            _workContextFactory = workContextFactory;
            _storeFrontUrlBuilderFactory = storeFrontUrlBuilderFactory;
            _themesAssetsRelativeUrl = themesAssetsRelativeUrl;
            _globalThemeAssetsRelativeUrl = globalThemeAssetsRelativeUrl;
            _cacheManager = cacheManager;
            _themeBlobProvider = themeBlobProvider;
            _globalThemeBlobProvider = globalThemeBlobProvider;

            Liquid.UseRubyDateFormat = true;
            // Register custom tags (Only need to do this once)
            Template.RegisterFilter(typeof(CommonFilters));
            Template.RegisterFilter(typeof(CommerceFilters));
            Template.RegisterFilter(typeof(TranslationFilter));
            Template.RegisterFilter(typeof(UrlFilters));
            Template.RegisterFilter(typeof(DateFilters));
            Template.RegisterFilter(typeof(MoneyFilters));
            Template.RegisterFilter(typeof(HtmlFilters));
            Template.RegisterFilter(typeof(StringFilters));

            Condition.Operators["contains"] = CommonOperators.ContainsMethod;

            Template.RegisterTag<LayoutTag>("layout");
            Template.RegisterTag<FormTag>("form");
            Template.RegisterTag<PaginateTag>("paginate");

            //Observe themes content system changes to invalidate cache if changes occur
            _themeBlobProvider.Changed += (sender, args) =>
            {
                _cacheManager.Clear();
            };
            _themeBlobProvider.Renamed += (sender, args) =>
            {
                _cacheManager.Clear();
            };
            _globalThemeBlobProvider.Changed += (sender, args) =>
            {
                _cacheManager.Clear();
            };
            _globalThemeBlobProvider.Renamed += (sender, args) =>
            {
                _cacheManager.Clear();
            };
        }
        private static JObject InnerGetAllSettings(IContentBlobProvider themeBlobProvider, string settingsPath)
        {
            if (settingsPath == null)
            {
                throw new ArgumentNullException(nameof(settingsPath));
            }

            var result = new JObject();

            if (themeBlobProvider.PathExists(settingsPath))
            {
                using (var stream = themeBlobProvider.OpenRead(settingsPath))
                {
                    result = JsonConvert.DeserializeObject <JObject>(stream.ReadToString());
                }
            }
            return(result);
        }
        private string ReadTemplateByPath(string templatePath)
        {
            var retVal = _cacheManager.Get(GetCacheKey("ReadTemplateByName", templatePath), "LiquidThemeRegion", () =>
            {
                if (!String.IsNullOrEmpty(templatePath))
                {
                    //First try find content in current store themer
                    IContentBlobProvider blobProvider = _themeBlobProvider;
                    if (!blobProvider.PathExists(templatePath))
                    {
                        //Else search in global theme
                        blobProvider = _globalThemeBlobProvider;
                    }
                    using (var stream = blobProvider.OpenRead(templatePath))
                    {
                        return(stream.ReadToString());
                    }
                }
                throw new FileSystemException("Error - No such template {0}.", templatePath);
            });

            return(retVal);
        }
        public StaticContentServiceImpl(Markdown markdownRender, ILiquidThemeEngine liquidEngine,
                                        ILocalCacheManager cacheManager, Func <WorkContext> workContextFactory,
                                        Func <IStorefrontUrlBuilder> urlBuilderFactory, Func <string, ContentItem> contentItemFactory,
                                        IContentBlobProvider contentBlobProvider)
        {
            _markdownRender = markdownRender;
            _liquidEngine   = liquidEngine;

            _cacheManager        = cacheManager;
            _workContextFactory  = workContextFactory;
            _urlBuilderFactory   = urlBuilderFactory;
            _contentItemFactory  = contentItemFactory;
            _contentBlobProvider = contentBlobProvider;

            //Observe content changes to invalidate cache if changes occur
            _contentBlobProvider.Changed += (sender, args) =>
            {
                _cacheManager.Clear();
            };
            _contentBlobProvider.Renamed += (sender, args) =>
            {
                _cacheManager.Clear();
            };
        }
        public StaticContentServiceImpl(Markdown markdownRender, ILiquidThemeEngine liquidEngine,
                                        ILocalCacheManager cacheManager, Func<WorkContext> workContextFactory,
                                        Func<IStorefrontUrlBuilder> urlBuilderFactory, Func<string, ContentItem> contentItemFactory,
                                        IContentBlobProvider contentBlobProvider)
        {
            _markdownRender = markdownRender;
            _liquidEngine = liquidEngine;
            
            _cacheManager = cacheManager;
            _workContextFactory = workContextFactory;
            _urlBuilderFactory = urlBuilderFactory;
            _contentItemFactory = contentItemFactory;
            _contentBlobProvider = contentBlobProvider;

            //Observe content changes to invalidate cache if changes occur
            _contentBlobProvider.Changed += (sender, args) =>
            {
                _cacheManager.Clear();
            };
            _contentBlobProvider.Renamed += (sender, args) =>
            {
                _cacheManager.Clear();
            };
        }
 public StaticContentService(IStorefrontMemoryCache memoryCache, IContentBlobProvider contentBlobProvider, IStaticContentItemBuilder builder)
 {
     _contentBlobProvider = contentBlobProvider;
     _builder             = builder;
     _memoryCache         = memoryCache;
 }
Example #17
0
 public GenerateSitemapJob(IContentBlobProvider contentBlobProvider, ISitemapsModuleApiClient siteMapApiClient, IStorefrontUrlBuilder urlBuilder)
 {
     _contentBlobProvider = contentBlobProvider;
     _siteMapApiClient    = siteMapApiClient;
     _urlBuilder          = urlBuilder;
 }
Example #18
0
 public SassFileManager(IContentBlobProvider contentBlobProvider)
 {
     _contentBlobProvider = contentBlobProvider;
 }
        private static JObject InnerReadLocalization(IContentBlobProvider themeBlobProvider, string themePath, Language language)
        {
            JObject retVal = null;
            var localeFolderPath = Path.Combine(themePath, "locales");
            if (themeBlobProvider.PathExists(localeFolderPath))
            {
                var currentLocalePath = Path.Combine(localeFolderPath, string.Concat(language.TwoLetterLanguageName, ".json"));
                var localeDefaultPath = themeBlobProvider.Search(localeFolderPath, "*.default.json", false).FirstOrDefault();

                JObject localeJson = null;
                JObject defaultJson = null;

                if (themeBlobProvider.PathExists(currentLocalePath))
                {
                    using (var stream = themeBlobProvider.OpenRead(currentLocalePath))
                    {
                        localeJson = JsonConvert.DeserializeObject<dynamic>(stream.ReadToString());
                    }
                }

                if (localeDefaultPath != null && themeBlobProvider.PathExists(localeDefaultPath))
                {
                    using (var stream = themeBlobProvider.OpenRead(localeDefaultPath))
                    {
                        defaultJson = JsonConvert.DeserializeObject<dynamic>(stream.ReadToString());
                    }
                }

                //Need merge default and requested localization json to resulting object
                retVal = defaultJson ?? localeJson;
                if (defaultJson != null && localeJson != null)
                {
                    retVal.Merge(localeJson, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Merge });
                }
            }
            return retVal;
        }
 private static JObject InnerGetSettings(IContentBlobProvider themeBlobProvider, string themePath)
 {
     JObject retVal = null;
     var settingsPath = Path.Combine(themePath, "config\\settings_data.json");
     if (themeBlobProvider.PathExists(settingsPath))
     {
         using (var stream = themeBlobProvider.OpenRead(settingsPath))
         {
             var settings = JsonConvert.DeserializeObject<JObject>(stream.ReadToString());
             // now get settings for current theme and add it as a settings parameter
             retVal = settings["current"] as JObject;
             if (retVal == null)
             {
                 //is setting preset name need return it as active
                 retVal = settings["presets"][settings["current"].ToString()] as JObject;
             }
         }
     }
     return retVal;
 }