Add support for multiple color themes in your Rails app. Themer uses CSS variables to make your apps themes truly dynamic and changeable on the fly.
Table of Contents
- To Do
Themer works with Rails 5 onwards. You can add it to your
And then execute:
Or install it yourself as:
$ gem install themer
If you always want to be up to date fetch the latest from GitHub in your
gem 'themer', github: 'jonhue/themer'
Now run the generator:
$ rails g themer
To setup Themer, use the
themify_class helper method to specify the current theme in your views
<html class="<%= themify_class %>">
Then create a
current_theme helper method in your
def current_theme themer current_user.theme end
Note: This helper method is not required but helpful when you want to store information about selected themes in your database.
Lastly, add the following to your
application.sass file (
@import "themer/default" @import "themer"
To get started define your colors in the
'default' theme (
$themer--default: ( text: ( dark: #000000, base: #eeeeee ), background: #ffffff );
In your Sass stylesheets you are able to use the
color function to access your theme colors:
html background: color(background) p color: color(text, base)
Note: If you need to get a HEX value for a specific color pass
true as a third parameter to the color function. This will return the color for the theme set as default.
Themer adds a couple of helpful methods to your controllers and views:
# Returns the currently used theme. Passed parameter overrides theme stored in cookies and default theme. themer current_user.theme # Set the theme set_themer 'default' # Check if a theme is available themer_available? 'default' # Return Themer class for `html` tag themer_class
Switching themes automatically
You can configure Themer to update the theme based on day and nighttime.
To automatically select a theme just set the theme to
You can configure Themer by passing a block to
configure. This can be done in
Themer.configure do |config| config.themes = ['default'] end
themesArray of available themes. Takes an array of strings. Defaults to
defaultDefault theme. Takes a string. Defaults to
autoEnable automatic themes. Takes a boolean. Defaults to
dayDay theme. Takes a string. Defaults to
nightNight theme. Takes a string. Defaults to
day_timeBeginning of daytime. Takes a string. Defaults to
night_timeBeginning of nighttime. Takes a string. Defaults to
Here is the full list of current projects.
To propose your ideas, initiate the discussion by adding a new issue.
We hope that you will consider contributing to Themer. Please read this short overview for some information about how to get started:
Give the people some
Themer follows Semantic Versioning 2.0 as defined at http://semver.org.
Copyright (c) 2018 Jonas Hübotter
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.