Project

themer

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
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.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.7
~> 0.52

Runtime

 Project Readme

Themer

Gem Version

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.

Themer has been merged into Myg and Myg on Rails


Table of Contents

  • Installation
  • Usage
    • Stylesheets
    • Methods
    • Switching themes automatically
  • Configuration
  • To Do
  • Contributing
    • Contributors
    • Semantic versioning
  • License

Installation

Themer works with Rails 5 onwards. You can add it to your Gemfile with:

gem 'themer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install themer

If you always want to be up to date fetch the latest from GitHub in your Gemfile:

gem 'themer', github: 'jonhue/themer'

Now run the generator:

$ rails g themer

Usage

To setup Themer, use the themify_class helper method to specify the current theme in your views html tag:

<html class="<%= themify_class %>">

Then create a current_theme helper method in your ApplicationHelper (app/helpers/application_helper.rb):

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 (app/assets/stylesheets/application.sass):

@import "themer/default"
@import "themer"

Stylesheets

To get started define your colors in the 'default' theme (app/assets/stylesheets/themer/default.sass):

$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.

Methods

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 'auto':

set_themer 'auto'

Configuration

You can configure Themer by passing a block to configure. This can be done in config/initializers/themer.rb:

Themer.configure do |config|
    config.themes = ['default']
end
  • themes Array of available themes. Takes an array of strings. Defaults to ['default'].
  • default Default theme. Takes a string. Defaults to 'default'.
  • auto Enable automatic themes. Takes a boolean. Defaults to false.
  • day Day theme. Takes a string. Defaults to 'light'.
  • night Night theme. Takes a string. Defaults to 'dark'.
  • day_time Beginning of daytime. Takes a string. Defaults to '6:00 am'.
  • night_time Beginning of nighttime. Takes a string. Defaults to '6:00 pm'.

To Do

Here is the full list of current projects.

To propose your ideas, initiate the discussion by adding a new issue.


Contributing

We hope that you will consider contributing to Themer. Please read this short overview for some information about how to get started:

Learn more about contributing to this repository, Code of Conduct

Contributors

Give the people some ❤️ who are working on this project. See them all at:

https://github.com/jonhue/themer/graphs/contributors

Semantic Versioning

Themer follows Semantic Versioning 2.0 as defined at http://semver.org.

License

MIT License

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.