theming.rst 9.2 KB

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