themer 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 64fe2347d19c1daa85c4dd3574e3fc81314810267008f3822dd8194eb3bb7489
4
+ data.tar.gz: dd7825bc27780bf4bba075d47738433818b259726e9aab62280082d7c4ac1dad
5
+ SHA512:
6
+ metadata.gz: 4fb70dde509d4bd7e00e7a9ff5274bfbcc5fd87b0a6876e91607cd92d1d4edacfbe8695db124a29542f653178125870049efa6092ed78bf44136ceb6380b4155
7
+ data.tar.gz: fbc277fa1874a6b4d11e1913427f55f9e4d35dfdf1fa69443c74affa159c2b01e118c220bd5a30526b73b5824ae5cb6f7415ba5eef0518f00725df0a06493be8
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ### master
4
+
5
+ * nothing yet
6
+
7
+ ### 1.0.0 - 2018/01/20
8
+
9
+ * initial release
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Jonas Hübotter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,199 @@
1
+ # Themer
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/themer.svg)](https://badge.fury.io/rb/themer) <img src="https://travis-ci.org/jonhue/themer.svg?branch=master" />
4
+
5
+ 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.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ * [Installation](#installation)
12
+ * [Usage](#usage)
13
+ * [Stylesheets](#stylesheets)
14
+ * [Methods](#methods)
15
+ * [Switching themes automatically](#switching-themes-automatically)
16
+ * [Configuration](#configuration)
17
+ * [To Do](#to-do)
18
+ * [Contributing](#contributing)
19
+ * [Contributors](#contributors)
20
+ * [Semantic versioning](#semantic-versioning)
21
+ * [License](#license)
22
+
23
+ ---
24
+
25
+ ## Installation
26
+
27
+ Themer works with Rails 5 onwards. You can add it to your `Gemfile` with:
28
+
29
+ ```ruby
30
+ gem 'themer'
31
+ ```
32
+
33
+ And then execute:
34
+
35
+ $ bundle
36
+
37
+ Or install it yourself as:
38
+
39
+ $ gem install themer
40
+
41
+ If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
42
+
43
+ ```ruby
44
+ gem 'themer', github: 'jonhue/themer'
45
+ ```
46
+
47
+ Now run the generator:
48
+
49
+ $ rails g themer
50
+
51
+ ---
52
+
53
+ ## Usage
54
+
55
+ To setup Themer, use the `themify_class` helper method to specify the current theme in your views `html` tag:
56
+
57
+ ```erb
58
+ <html class="<%= themify_class %>">
59
+ ```
60
+
61
+ Then create a `current_theme` helper method in your `ApplicationHelper` (`app/helpers/application_helper.rb`):
62
+
63
+ ```ruby
64
+ def current_theme
65
+ themer current_user.theme
66
+ end
67
+ ```
68
+
69
+ **Note:** This helper method is not required but helpful when you want to store information about selected themes in your database.
70
+
71
+ Lastly, add the following to your `application.sass` file (`app/assets/stylesheets/application.sass`):
72
+
73
+ ```sass
74
+ @import "themer/default"
75
+ @import "themer"
76
+ ```
77
+
78
+ ### Stylesheets
79
+
80
+ To get started define your colors in the `'default'` theme (`app/assets/stylesheets/themer/default.sass`):
81
+
82
+ ```scss
83
+ $themer--default: (
84
+ text: (
85
+ dark: #000000,
86
+ base: #eeeeee
87
+ ),
88
+ background: #ffffff
89
+ );
90
+ ```
91
+
92
+ In your Sass stylesheets you are able to use the `color` function to access your theme colors:
93
+
94
+ ```sass
95
+ html
96
+ background: color(background)
97
+ p
98
+ color: color(text, base)
99
+ ```
100
+
101
+ **Note:** If you need to get a HEX value for a specific color pass `true` as a third attribute to the color function. This will return the color for the theme set as default.
102
+
103
+ ### Methods
104
+
105
+ Themer adds a couple of helpful methods to your controllers and views:
106
+
107
+ ```ruby
108
+ # Returns the currently used theme. Passed parameter overrides theme stored in cookies and default theme.
109
+ themer current_user.theme
110
+
111
+ # Set the theme
112
+ set_themer 'default'
113
+
114
+ # Check if a theme is available
115
+ themer_available? 'default'
116
+
117
+ # Return Themer class for `html` tag
118
+ themer_class
119
+ ```
120
+
121
+ ### Switching themes automatically
122
+
123
+ You can [configure](#configuration) Themer to update the theme based on day and nighttime.
124
+
125
+ To automatically select a theme just set the theme to `'auto'`:
126
+
127
+ ```ruby
128
+ set_themer 'auto'
129
+ ```
130
+
131
+ ---
132
+
133
+ ## Configuration
134
+
135
+ You can configure Themer by passing a block to `configure`. This can be done in `config/initializers/themer.rb`:
136
+
137
+ ```ruby
138
+ Themer.configure do |config|
139
+ config.themes = ['default']
140
+ end
141
+ ```
142
+
143
+ * `themes` Array of available themes. Takes an array of strings. Defaults to `['default']`.
144
+ * `default` Default theme. Takes a string. Defaults to `'default'`.
145
+ * `auto` Enable automatic themes. Takes a boolean. Defaults to `false`.
146
+ * `day` Day theme. Takes a string. Defaults to `'light'`.
147
+ * `night` Night theme. Takes a string. Defaults to `'dark'`.
148
+ * `day_time` Beginning of daytime. Takes a string. Defaults to `'6:00 am'`.
149
+ * `night_time` Beginning of nighttime. Takes a string. Defaults to `'6:00 pm'`.
150
+
151
+ ---
152
+
153
+ ## To Do
154
+
155
+ [Here](https://github.com/jonhue/themer/projects/1) is the full list of current projects.
156
+
157
+ To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/themer/issues/new).
158
+
159
+ ---
160
+
161
+ ## Contributing
162
+
163
+ We hope that you will consider contributing to Themer. Please read this short overview for some information about how to get started:
164
+
165
+ [Learn more about contributing to this repository](CONTRIBUTING.md), [Code of Conduct](CODE_OF_CONDUCT.md)
166
+
167
+ ### Contributors
168
+
169
+ Give the people some :heart: who are working on this project. See them all at:
170
+
171
+ https://github.com/jonhue/themer/graphs/contributors
172
+
173
+ ### Semantic Versioning
174
+
175
+ Themer follows Semantic Versioning 2.0 as defined at http://semver.org.
176
+
177
+ ## License
178
+
179
+ MIT License
180
+
181
+ Copyright (c) 2018 Jonas Hübotter
182
+
183
+ Permission is hereby granted, free of charge, to any person obtaining a copy
184
+ of this software and associated documentation files (the "Software"), to deal
185
+ in the Software without restriction, including without limitation the rights
186
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
187
+ copies of the Software, and to permit persons to whom the Software is
188
+ furnished to do so, subject to the following conditions:
189
+
190
+ The above copyright notice and this permission notice shall be included in all
191
+ copies or substantial portions of the Software.
192
+
193
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
194
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
195
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
196
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
198
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
199
+ SOFTWARE.
@@ -0,0 +1,32 @@
1
+ module ThemerHelper
2
+
3
+ def themer theme = nil
4
+ theme ||= cookies[:themer] || Themer.configuration.default
5
+ if Themer.configuration.auto && theme == 'auto'
6
+ if Time.now < Time.parse(Themer.configuration.day_time) || Time.now > Time.parse(Themer.configuration.night_time)
7
+ theme = Themer.configuration.day
8
+ else
9
+ theme = Themer.configuration.night
10
+ end
11
+ end
12
+ theme
13
+ end
14
+
15
+ def set_themer theme
16
+ cookies[:themer] = theme
17
+ theme
18
+ end
19
+
20
+ def themer_class
21
+ begin
22
+ "themer--#{current_theme}"
23
+ rescue NoMethodError
24
+ "themer--#{themer}"
25
+ end
26
+ end
27
+
28
+ def themer_available? theme
29
+ Themer.configuration.themes.include? theme
30
+ end
31
+
32
+ end
@@ -0,0 +1,25 @@
1
+ Themer.configure do |config|
2
+
3
+ # Array of available themes
4
+ # config.themes = ['default']
5
+
6
+ # Default theme
7
+ # config.default = 'default'
8
+
9
+
10
+ ### Automatic themes ###
11
+
12
+ # Enable automatic themes
13
+ # config.auto = false
14
+
15
+ # Day theme
16
+ # config.day = 'light'
17
+ # Night theme
18
+ # config.night = 'dark'
19
+
20
+ # Beginning of daytime
21
+ # config.day_time = '6:00 am'
22
+ # Beginning of nighttime
23
+ # config.night_time = '6:00 pm'
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ $themer--default: (
2
+ base: #ffffff
3
+ );
@@ -0,0 +1,19 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ class ThemerGenerator < Rails::Generators::Base
5
+
6
+ include Rails::Generators::Migration
7
+
8
+ source_root File.join File.dirname(__FILE__), 'templates'
9
+ desc 'Install Themer'
10
+
11
+ def create_initializer
12
+ template 'initializer.rb', 'config/initializers/themer.rb'
13
+ end
14
+
15
+ def create_assets
16
+ template 'theme.scss', 'app/assets/stylesheets/themer/default.scss'
17
+ end
18
+
19
+ end
@@ -0,0 +1,10 @@
1
+ require 'themer/version'
2
+
3
+ module Themer
4
+
5
+ require 'themer/configuration'
6
+
7
+ require 'themer/engine'
8
+ require 'themer/railtie'
9
+
10
+ end
@@ -0,0 +1,33 @@
1
+ module Themer
2
+
3
+ class << self
4
+ attr_accessor :configuration
5
+ end
6
+
7
+ def self.configure
8
+ self.configuration ||= Configuration.new
9
+ yield configuration
10
+ end
11
+
12
+ class Configuration
13
+
14
+ attr_accessor :themes
15
+ attr_accessor :default
16
+ attr_accessor :auto
17
+ attr_accessor :day
18
+ attr_accessor :night
19
+ attr_accessor :day_time
20
+ attr_accessor :night_time
21
+
22
+ def initialize
23
+ @themes = ['default']
24
+ @default = 'default'
25
+ @auto = false
26
+ @day = 'light'
27
+ @night = 'dark'
28
+ @day_time = '6:00 am'
29
+ @night_time = '6:00 pm'
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails/railtie'
2
+
3
+ module Themer
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/railtie'
2
+
3
+ module Themer
4
+ class Railtie < Rails::Railtie
5
+
6
+ initializer 'themer.initialize' do
7
+ ActiveSupport.on_load :action_controller do
8
+ include ThemerHelper
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Themer
2
+
3
+ VERSION = '1.0.0'
4
+
5
+ end
@@ -0,0 +1,21 @@
1
+ html
2
+ <% Themer.configuration.themes.each do |theme| %>&.themer--<%= theme %>
3
+ @each $name, $color in $themer--<%= theme %>
4
+ @if type-of($color) == map
5
+ @each $subname, $subsize in $color
6
+ --color-#{$name}-#{$subname}: #{$subsize}
7
+ @else if type-of($color) == color
8
+ --color-#{$name}: #{$color}
9
+ <% end %>
10
+
11
+ @function color( $color-name, $color-variant:null, $true-val:false )
12
+ @if $true-val == true
13
+ @if ( $color-variant != null )
14
+ @return map-get(map-get($themer--<%= Themer.configuration.default %>,$color-name),$color-variant)
15
+ @else
16
+ @return map-get($themer--<%= Themer.configuration.default %>,$color-name)
17
+ @else
18
+ @if ( $color-variant != null )
19
+ @return var(--color-#{$color-name}-#{$color-variant})
20
+ @else
21
+ @return var(--color-#{$color-name})
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: themer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonas Hübotter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionpack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sass-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.52'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.52'
97
+ description: Add support for multiple color themes in your Rails app. Themer uses
98
+ CSS variables to make your apps themes truly dynamic and changeable on the fly.
99
+ email: me@jonhue.me
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - CHANGELOG.md
105
+ - LICENSE
106
+ - README.md
107
+ - app/helpers/themer_helper.rb
108
+ - lib/generators/templates/initializer.rb
109
+ - lib/generators/templates/theme.scss
110
+ - lib/generators/themer_generator.rb
111
+ - lib/themer.rb
112
+ - lib/themer/configuration.rb
113
+ - lib/themer/engine.rb
114
+ - lib/themer/railtie.rb
115
+ - lib/themer/version.rb
116
+ - vendor/assets/stylesheets/themer.sass.erb
117
+ homepage: https://github.com/jonhue/themer
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '2.3'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.7.4
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Themes for Rails apps
141
+ test_files: []