Skip to content

Commit 4f3a3b4

Browse files
authored
Merge pull request #1127 from ElixirTeSS/theme-config
Configure themes in tess.yml
2 parents b16b1d0 + d3c651f commit 4f3a3b4

6 files changed

Lines changed: 74 additions & 41 deletions

File tree

app/models/space.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class Space < ApplicationRecord
1414
has_many :administrator_roles, -> { where(key: :admin) }, class_name: 'SpaceRole'
1515
has_many :administrators, through: :administrator_roles, source: :user, class_name: 'User'
1616

17-
THEMES = ['default', 'green', 'blue', 'space'].freeze
18-
validates :theme, inclusion: { in: THEMES, allow_blank: true }
17+
validates :theme, inclusion: { in: TeSS::Config.themes.keys, allow_blank: true }
1918

2019
has_image(placeholder: TeSS::Config.placeholder['content_provider'])
2120

app/views/spaces/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<%= f.input :description, as: :markdown_area, input_html: { rows: '10' } %>
99

10-
<%= f.input :theme, collection: Space::THEMES, selected: @space.theme || 'default' %>
10+
<%= f.input :theme, collection: TeSS::Config.themes.keys, selected: @space.theme || 'default' %>
1111

1212
<div class="form-group">
1313
<%= render partial: 'common/image_form', locals: { form: f } %>

config/application.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ class Application < Rails::Application
8484
tess_config['placeholder']['content_provider'] = tess_config['placeholder']['provider']
8585
end
8686

87+
# Apply legacy `icon_primary_color` and `icon_secondary_color` to default theme
88+
if tess_config.dig('site', 'icon_primary_color')
89+
warn "DEPRECATION WARNING: 'icon_primary_color' should now be 'primary_color' under 'themes', 'default' in: config/tess.yml"
90+
tess_config['themes'] ||= {}
91+
tess_config['themes']['default'] ||= {}
92+
tess_config['themes']['default']['primary'] ||= tess_config.dig('site', 'icon_primary_color')
93+
end
94+
95+
if tess_config.dig('site', 'icon_secondary_color')
96+
warn "DEPRECATION WARNING: 'icon_secondary_color' should now be 'secondary_color' under 'themes', 'default' in: config/tess.yml"
97+
tess_config['themes'] ||= {}
98+
tess_config['themes']['default'] ||= {}
99+
tess_config['themes']['default']['secondary'] ||= tess_config.dig('site', 'icon_secondary_color')
100+
end
101+
87102
def self.merge_config(default_config, config, current_path = '')
88103
default_config.each do |key, value|
89104
unless config.key?(key)

config/tess.example.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ default: &default
9595
logo_open_graph: ''
9696
logo_email: ''
9797
default_theme: default
98-
# Colours of the SVG icons used throughout TeSS, requires `rake assets:precompile` if changed
99-
icon_primary_color: '#047EAA' # Blue by default
100-
icon_secondary_color: '#F47D21' # Orange by default
10198
repository: 'https://github.com/ElixirTeSS/TeSS'
10299
supported_by: 'elixir_supported_by'
103100
widget_example:
@@ -245,6 +242,22 @@ default: &default
245242
# featured_providers:
246243
# node:
247244
# name: United Kingdom
245+
# Themes enabled in TeSS:
246+
# "primary" and "secondary" refer to the colours of the SVG icons used throughout TeSS,
247+
# requires `rake assets:precompile` if changed
248+
themes:
249+
default:
250+
primary: '#047eaa' # Blue by default
251+
secondary: '#f47d21' # Orange by default
252+
green:
253+
primary: '529d00'
254+
secondary: '#829d30'
255+
blue:
256+
primary: '#024552'
257+
secondary: '#00839d'
258+
space:
259+
primary: '#260252'
260+
secondary: '#5c29b1'
248261
development:
249262
<<: *default
250263

docs/customization.md

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,60 @@ Secure settings such as database credentials, API keys, email settings etc. can
1515

1616
## Styles
1717

18-
TeSS' UI is built on [Bootstrap 3](https://getbootstrap.com/docs/3.4/). To customize the appearance of TeSS, go into
19-
the themes folder (`app/assets/stylesheets/themes`) and make a copy of the default theme file (`default.scss`).
20-
In your copy, you can tweak any of the existing variables, add overrides for any Bootstrap variables
21-
([reference](https://github.com/twbs/bootstrap-sass/blob/master/assets/stylesheets/bootstrap/_variables.scss)) and add new CSS/Sass styles (look at the other themes in that directory, and the `mixins/_modern_base.scss` mixin for reference).
18+
TeSS' UI is built on [Bootstrap 3](https://getbootstrap.com/docs/3.4/).
19+
To customize the appearance of TeSS, you can either select one of the pre-made themes, or create your own.
2220

23-
To use your theme as the site default, edit your `config/tess.yml` config file and change
24-
(or add if not present) the `default_theme` variable under the `site` section to reference your new theme file (sans the `.scss` extension):
21+
### Switching theme
22+
23+
To change the site default theme, edit your `config/tess.yml` config file and change (or add if not present)
24+
the `default_theme` variable under the `site` section to reference one of the configured themes
25+
(listed under the `themes` section in `config/tess.yml` or `config/tess.example.yml`):
2526

2627
```yml
2728
default: &default
2829
# ...
2930
site:
3031
# ...
31-
default_theme: my_theme
32+
default_theme: green
33+
```
34+
35+
### Creating your own theme
36+
37+
1. Go into the themes folder (`app/assets/stylesheets/themes`) and make a copy of the default theme file (`default.scss`).
38+
39+
2. Add your theme to the list of themes in `config/tess.yml` (see `config/tess.example.yml` for reference).
40+
The `primary` and `secondary` properties are colours that will be used in the various SVG icons in TeSS.
41+
```yml
42+
default: &default
43+
# ...
44+
themes:
45+
default:
46+
primary: '#047eaa' # Blue by default
47+
secondary: '#f47d21' # Orange by default
48+
# ...
49+
my_theme:
50+
primary: '#ff0000'
51+
secondary: '#ffff00'
3252
```
3353

34-
Additionally, you will need to create a symlink for the theme's images:
54+
3. Enable your theme as the default them according to the section above.
55+
56+
4. Create a symlink for the theme's SVG images:
3557

58+
```shell
3659
ln -s app/assets/images/modern app/assets/images/themes/my_theme
60+
```
61+
62+
*Alternatively, if you would like to make changes to the SVG images (beyond the colour changes that are automatically applied),
63+
you may want to copy the images instead of making a symlink.*
64+
65+
In your theme's .scss file you can tweak any of the existing variables, add overrides for any Bootstrap variables ([reference](https://github.com/twbs/bootstrap-sass/blob/master/assets/stylesheets/bootstrap/_variables.scss))
66+
and add new CSS/Sass styles (look at the other themes in that directory, and the `mixins/_modern_base.scss` mixin for reference).
3767

3868
Be sure to recompile assets (`bundle exec rake assets:recompile`), or rebuild your docker image,
39-
and restart the application to apply the new styles.
69+
and restart the application to apply the new styles (except in development mode, where CSS changes should be applied automatically).
4070

41-
You can visit <http://localhost:3000/theme_showcase> on your local instance to see various Bootstrap elements with the
71+
You can visit <http://localhost:3000/theme_showcase> on your local instance to see various UI elements with the
4272
current theme applied.
4373

4474
You can also add a query parameter `theme_preview` to the URL of any page to preview different themes, e.g. <http://localhost:3000/theme_showcase?theme_preview=blue>

lib/svg_recolourer.rb

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,6 @@ class SvgRecolourer
66
'#f47d21' => :secondary
77
}
88

9-
# Configured themes. TODO: Read this from some config
10-
THEMES = {
11-
'default' => {
12-
primary: TeSS::Config.site['icon_primary_color'],
13-
secondary: TeSS::Config.site['icon_secondary_color']
14-
},
15-
'green' => {
16-
primary: '#529d00',
17-
secondary: '#829d30'
18-
},
19-
'blue' => {
20-
primary: '#024552',
21-
secondary: '#00839d'
22-
},
23-
'space' => {
24-
primary: '#260252',
25-
secondary: '#5c29b1'
26-
},
27-
'dark' => {
28-
primary: '#260252',
29-
secondary: '#5c29b1'
30-
}
31-
}
32-
339
REGEXP = Regexp.new('(' + MAPPING.keys.map { |k| Regexp.quote(k) }.join('|') + ')', Regexp::IGNORECASE)
3410

3511
def initialize(filename, &block)
@@ -44,7 +20,7 @@ def render(context, empty_hash_wtf)
4420
def self.run(filename, source, context)
4521
match_data = filename.match(/images\/themes\/([^\/]+)\//)
4622
return source unless match_data
47-
theme = THEMES[match_data[1]]
23+
theme = TeSS::Config.themes[match_data[1]]
4824
raise "Missing theme #{match_data[1]}" unless theme
4925

5026
source.gsub(REGEXP) do |match|

0 commit comments

Comments
 (0)