Overhaul flatpages
[mediagoblin.git] / docs / source / siteadmin / theming.rst
CommitLineData
473a4431
CAW
1.. MediaGoblin Documentation
2
3 Written in 2011, 2012 by MediaGoblin contributors
4
5 To the extent possible under law, the author(s) have dedicated all
6 copyright and related and neighboring rights to this software to
7 the public domain worldwide. This software is distributed without
8 any warranty.
9
10 You should have received a copy of the CC0 Public Domain
11 Dedication along with this software. If not, see
12 <http://creativecommons.org/publicdomain/zero/1.0/>.
13
917d4663 14.. _theming-chapter:
6a338d8e 15
917d4663
WKG
16=====================
17 Theming MediaGoblin
18=====================
5a40e1ec 19
e6aaaa96
CAW
20We try to provide a nice theme for MediaGoblin by default. But of
21course, you might want something different! Maybe you want something
22more light and colorful, or maybe you want something specifically
23tailored to your organization. Have no fear, MediaGoblin has theming
24support! This guide should walk you through installing and making themes.
25
26
04b24107
CAW
27Installing a theme
28------------------
29
30Installing the archive
31======================
32
33Say you have a theme archive such as goblincities.tar.gz. You want to
34install this theme! Don't worry, it's fairly painless.
35
36Simply cd to the "install directory" for themes (by default,
37./user_dev/themes/ relative to the mediagoblin install directory... to
38configure these things, see the next section), move the archive there,
39and decompress.
40
41 tar xvfz goblincities.tar.gz
42
43Next, open up your mediagoblin configuration file (probably
44mediagoblin_local.ini) and set the theme name:
45
46 [mediagoblin]
47 # ...
48 theme = goblincities
49
50Finally, "link the assets" so that they can be served by your web
51server.
52
53 ./bin/gmg theme assetlink
54
55Note, if you ever change the current theme in your config file, you
56should re-run the above command!
57
58(In the near future this should be even easier ;))
59
60.. In the future, this might look more like:
61.. Installing a theme in MediaGoblin is fairly easy! Assuming you
62.. already have a theme package, just do this:
63
64.. $ ./bin/gmg theme install --fullsetup goblincities.tar.gz
65
66.. This would install the theme, set it as current, and symlink its
67.. assets.
68
69
70Set up your webserver to serve theme assets
71===========================================
72
73Section to be written, ask on #mediagoblin in irc.freenode.net in the
74meanwhile ;)
75
76Configuring where things go
77===========================
78
79By default, MediaGoblin's install directory for themes is
80./user_dev/themes/ (relative to the MediaGoblin checkout or base
81config file.) However, you can change this location easily. In your
82mediagoblin config file, under the section [mediagoblin] set the
83following parameter:
84
85 [mediagoblin]
86 # ... other parameters go here ...
87 theme_install_dir = /path/to/themes/
88
89Other variables you may consider setting:
90
91 - theme_web_path: when theme-specific assets are specified, this is
92 where MediaGoblin will set the urls. By default this is
93 "/theme_static/" so in the case that your theme was trying to
94 access its file "images/shiny_button.png" MediaGoblin would link
95 to /theme_static/images/shiny_button.png
96 - theme_linked_assets_dir: Your web server needs to serve the theme
97 files out of some directory, and MediaGoblin will symlink the
98 current theme's assets here. (See "Linking assets" in the theme
99 install section)
100
101
e6aaaa96
CAW
102Making a theme
103--------------
104
e6aaaa96
CAW
105Okay, so a theme layout is pretty simple. Let's assume we're making a
106theme for an instance about hedgehogs! We'll call this the
107"hedgehogified" theme.
108
04b24107
CAW
109Change to where your theme_install_dir is set to (by default,
110./user_dev/themes/ ... make those directories if necessary and
111otherwise adjust if necessary)
112
e6aaaa96
CAW
113 hedgehogified/
114 |- theme.cfg # configuration file for this theme
115 |- templates/ # override templates
116 | '- mediagoblin/
117 | |- base.html # overriding mediagoblin/base.html
118 | '- root.html # overriding mediagoblin/root.html
119 '- assets/
120 | '- images/
121 | | |- im_a_hedgehog.png # hedgehog-containing image used by theme
122 | | '- custom_logo.png # your theme's custom logo
123 | '- css/
124 | '- hedgehog.css # your site's hedgehog-specific css
125 |- README.txt # Optionally, a readme file (not required)
126 |- AGPLv3.txt # AGPL license file for your theme. (good practice)
04b24107 127 '- CC0_1.0.txt # CC0 1.0 legalcode for the assets [if appropriate!]
e6aaaa96
CAW
128
129The top level directory of your theme should be the symbolic name for
130your theme. This is the name that users will use to refer to activate
131your theme.
132
133It's important to note that templates based on MediaGoblin's code
134should be released as AGPLv3 (or later), like MediaGoblin's code
135itself. However, all the rest of your assets are up to you. In this
136case, we are waiving our copyright for images and CSS into the public
137domain via CC0 (as MediaGoblin does) but do what's appropriate to you.
138
139The config file
04b24107 140===============
e6aaaa96 141
04b24107 142The config file is not presently strictly required, though it is nice to have.
e6aaaa96
CAW
143Only a few things need to go in here.
144
145 [theme]
04b24107 146 name = Hedgehog-ification
e6aaaa96
CAW
147 description = For hedgehog lovers ONLY
148 licensing = AGPLv3 or later templates; assets (images/css) waived under CC0 1.0
149
04b24107
CAW
150The name and description fields here are to give users an idea of what
151your theme is about. For the moment, we don't have any listing
152directories or admin interface, so this probably isn't useful, but
153feel free to set it in anticipation of a more glorious future.
154
155Licensing field is likewise a textual description of the stuff here;
156it's recommended that you preserve the "AGPLv3 or later templates" and
157specify whatever is appropriate to your assets.
e6aaaa96 158
e6aaaa96
CAW
159
160Templates
04b24107 161=========
e6aaaa96 162
04b24107
CAW
163Your template directory is where you can put any override and custom
164templates for MediaGoblin.
e6aaaa96 165
04b24107
CAW
166These follow the general MediaGoblin theming layout, which means that
167the MediaGoblin core templates are all kept under the ./mediagoblin/
168prefix directory.
e6aaaa96 169
04b24107
CAW
170You can copy files right out of MediaGoblin core and modify them in
171this matter if you wish.
e6aaaa96 172
04b24107
CAW
173To fit with best licensing form, you should either preserve the
174MediaGoblin copyright header borrowing from a MediaGoblin template, or
175you may include one like the following if a new file:
e6aaaa96 176
04b24107
CAW
177 {#
178 # [YOUR THEME], a MediaGoblin theme
179 # Copyright (C) [YEAR] [YOUR NAME]
180 #
181 # This program is free software: you can redistribute it and/or modify
182 # it under the terms of the GNU Affero General Public License as published by
183 # the Free Software Foundation, either version 3 of the License, or
184 # (at your option) any later version.
185 #
186 # This program is distributed in the hope that it will be useful,
187 # but WITHOUT ANY WARRANTY; without even the implied warranty of
188 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
189 # GNU Affero General Public License for more details.
190 #
191 # You should have received a copy of the GNU Affero General Public License
192 # along with this program. If not, see <http://www.gnu.org/licenses/>.
193 #}
e6aaaa96 194
e6aaaa96 195
04b24107
CAW
196Assets
197=======
e6aaaa96 198
04b24107
CAW
199Put any files, such as images, CSS, etc, that are specific to your
200theme in here.
e6aaaa96 201
04b24107 202You can reference these in your templates like so:
e6aaaa96 203
04b24107 204 <img src="{{ request.staticdirect('/images/im_a_shark.png', 'theme') }}" />
e6aaaa96 205
04b24107 206This will tell MediaGoblin to reference this image from the current theme.
e6aaaa96 207
e6aaaa96 208
04b24107
CAW
209Licensing file(s)
210=================
211
212You should include AGPLv3.txt with your theme as this is required for
213the assets. You can copy this from mediagoblin/licenses/
214
215In the above example, we also use CC0 to waive our copyrights to
216images and css, so we also included CC0_1.0.txt
217
218
219A README.txt file
220=================
221
222A readme file is not strictly required, but probably a good idea. You
223can put whatever in here, but restating the license choice clearly is
224probably a good idea.
225
e6aaaa96 226
62157a89
CAW
227Simple theming by adding CSS
228============================
229
230Many themes won't require anything other than the ability to override
231some of MediaGoblin's core css. Thankfully, doing so is easy if you
232combine the above steps!
233
234In your theme, do the following (make sure you make the necessary
235directories and cd to your theme's directory first):
236
237 $ cp /path/to/mediagoblin/mediagoblin/templates/mediagoblin/extra_head.html templates/mediagoblin/
238
239Great, now open that file and add something like this at the end:
240
241 <link rel="stylesheet" type="text/css"
242 href="{{ request.staticdirect('/css/theme.css', 'theme') }}"/>
243
244You can name the css file whatever you like. Now make the directory
245for assets/css/ and add the file assets/css/theme.css
246
247You can now put custom CSS files in here and any CSS you add will
248override default MediaGoblin CSS.
249
250
04b24107
CAW
251Packaging it up!
252================
e6aaaa96 253
04b24107 254Packaging a theme is really easy. It's just a matter of making an archive!
e6aaaa96 255
04b24107 256Change to the installed themes directory and run the following:
e6aaaa96 257
04b24107 258 tar cvfz yourtheme.tar.gz yourtheme
e6aaaa96 259
04b24107 260Where "yourtheme" is replaced with your theme name.
e6aaaa96 261
04b24107 262That's it!