This extension allows the admin to upload new spree store themes from backend. This extension provides an interface where admin can manage all the themes by editing them, deleting old themes and publishing theme to store for the users.
Admin can even preview the theme after modifying it from the backend before publishing it to the users.
View the demo application at url:-
credentials: firstname.lastname@example.org / spree123
Sample Theme Repositories:
This extension currently supports Ruby >= 2.2.2, Rails 5 and Spree 3.2.
Some of the current functionalities are:-
- Upload the theme
- Preview the theme.
- Publish the theme on spree store.
- Download the theme.
- Remove the uploaded theme.
- Modify the uploaded / published theme.
- Add this extension to your Gemfile:
ruby gem 'vinsol_spree_themes'
Note:- Add this gem at the end of your gemfile as it has some sprocket-rails dependency and needs to be loaded after all gems are loaded.
- Also add the following gem above the extension:
ruby gem 'sprockets-helpers', '~> 1.2.1'
Note:- This gem is dependent for the preview feature.
Install the gem using Bundler:
Copy & run migrations
bundle exec rails g vinsol_spree_themes:install
Restart your server
Make sure to set the following config in environment file
config.assets.debug = false
After installing the extension, admin will see a tab
vinsol spree themes on left sidebar of admin panel. Or you can visit the link
Then, admin uploads the new theme in zip file(Download sample themes from the links added below). Once uploaded, admin can preview the theme and also modify it accordingly through the editor.
Theme templates can be modified through the editor. Later theme can be published for the spree store users.
Note:- Before publishing the theme, admin needs to compile it using the link provided with other options for all assets to load properly.
Once the extension is installed, admin gets a spree store default theme uploaded on the system and is published for the store users.
Besides preview and publishing, admin can delete the uploaded theme or download it in zip format.
Some spree store themes can be cloned from the following link:-
After clonning, zip the files of the theme and upload the zip file from the admin interface.
Yay!! new theme is ready to be published.
Theme file structure for the zip file to be uploaded:-
- views: These views will be the spree frontend view directory.
- snapshot.png: This is the snapshot for the theme visible at backend.
- meta_info.yml: This .yml file contains meta info of the theme.
Note:- When uploading, files starting with '__' or '.' will be ignored
Create a meta_info.yml file on the theme directory which contains the meta info of the theme. Format of the file should be following:-
* name: Name of the theme
* version: Version of the theme
* authors: Authors of the theme
If you wish to modify the theme directly from the filesystem, follow these steps:-
Publish the theme which need to be updated/modified.
Update the theme assets, stylesheets, scripts and templates from the path.
If application is running, reload the store page and you will see the changes on the browser.
Once all the changes are done and final theme is ready, run the following rake task to sync the updated files with the database.
bundle exec rake db:sync_templates THEME_NAME=<theme_name>
Admin can download the theme in the zip format after modifying it. While uploading the downloaded theme, admin needs to follow the below steps:-
Make sure to change the theme name (Theme name is the name of the zip file).
Make sure to update the meta info of the theme in the file
meta_info.ymlwhen the theme is updated.
Extract the downloaded zip file and then need to compress the files within the extracted folder. Otherwise, the theme structure will change and there will be issue while uploading.
Set the following configuration for production environment in environment file
config.assets.compile = true
config.public_file_server.enabled = true
Also, set the assets compressors in
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
For Capistrano: Add the following path to the shared linked dir in deploy.rb file.
set :linked_dirs, %w( public/vinsol_spree_themes )
While developing this extensions, we faced few issues related to assets precompilation, spree fragment caching and rails template caching. To resolve these issues we made few assumptions:
For clearing cache, we used rails resolvers. We are assuming that whenever the template is modified, we are clearing the cache.
When previewing the theme, we remove the cache directory under
tmp/cachefor proper theme rendering.
We are assuming the theme zip filename to be the theme name and admin cannot upload the other theme with the same name.
We need to compile and minify the assets before publishing the theme using the compile link for proper rendering of theme.
Rails app is using centeral cache store. So that Rails.cache.clear can flush cache for all application servers.
First bundle your dependencies, then run
rake will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using
bundle bundle exec rake
When testing your applications integration with this extension you may use it's factories.
Simply add this require statement to your spec_helper:
Some other features which need to work on and are under development:-
- Theme revisions and rollback to previous theme versions.
- Maintaining the themes in multiple instances / cluster mode.
- Extension Dependencies for Spree < 3.2 and Rails 4.
- Update theme images like scripts and styles from admin interface.
- Flexibility to modify other spree extension views according to the theme.
- Displaying Theme information using theme meta info.
If you'd like to contribute, please follow the below steps:-
- Fork the repo.
- Clone your repo.
- Run bundle install.
- Run bundle exec rake test_app to create the test application in spec/test_app.
- Make your changes.
- Ensure specs pass by running bundle exec rspec spec.
- Submit your pull request.
Copyright (c) 2017 vinsol.com, released under the New MIT License