Newbie Guide: How to Patch Styles and Themes

From Dreamwidth Notes
Revision as of 16:30, 13 March 2013 by Ninetydegrees (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Note: This supposes you already know how to make and commit changes in your dev environment. If you don't you should check other Getting Started articles first.

How do I file a new bug?

  • In Bugzilla, click on New. Select Dreamwidth Development. In Component, select Style System. Enter a Summary and a Description. Mention style and author(s) in the summary. If you're patching a color theme, add author names and submission URLs to the description. If you're patching a style, mention the style name, the number of themes it has, the name of the default theme, the author's name and the submission URL.
  • Click on Show Advanced Fields. Set Initial State to IN_PROGRESS and enter your Bugzilla e-mail address in Assign To.

Where are style files?

  • core2.s2 is in ~/dw/bin/upgrading/s2layers/
  • Theme and layout .s2 files are in ~/dw/bin/upgrading/s2layers/STYLENAME/ or ~/dw/ext/dw-nonfree/bin/upgrading/s2layers/STYLENAME/
  • .pm style files are in ~/dw/cgi-bin/LJ/S2Theme/ or ~/dw/ext/dw-nonfree/cgi-bin/LJ/S2Theme/
  • is in ~/dw/cgi-bin/LJ/ or ~/dw/ext/dw-nonfree/cgi-bin/LJ/

FIXME: still called _local in nonfree.

  • s2layers.dat is in ~/dw/cvs/dw-free/bin/upgrading/ or ~/dw/ext/dw-nonfree/bin/upgrading/

Checking usage rights

Before you patch any style or theme, make sure Dreamwidth is allowed to use it as well as the images it contains if there are any:

  • We must have the submitter's Contributor Licensing Agreement before we can use their submission. If it's from someone who already has live styles or themes on the site, we already do. If the submission entry has the '-needs cla' tag, we don't. Otherwise, check the comments to see if they've already been asked about it.
  • If design and images have been made entirely from scratch by the designer who submitted the style or theme, they need to explicitly state they made them themselves in their submission entry.
  • If design or images haven't been made entirely from scratch by the designer who submitted the style or theme, they must mention where they came from and how they're licensed. We can only use designs and images if commercial use is allowed, use in website templates is allowed and storage on one own's server is allowed. You must also check if they may only be used as-is or if any kind of transformation (also called 'remix') is allowed, and how crediting must be done.

When in doubt, comment on the bug.

Dw-free or dw-nonfree?

Dreamwidth may be allowed to use designs and images on but may not be allowed to redistribute or sublicense them to other sites. If that's the case, elements need to go to dw-nonfree:

  • Styles go to dw-nonfree if Dreamwidth can use them but can't redistribute/sublicense them.
  • Themes go to dw-nonfree if they contain images Dreamwidth can use but can't redistribute/sublicense.
  • Themes go to dw-nonfree if the base style is already in dw-nonfree. This the case for Transmogrified and Sunday Morning themes.

Adding a new style

Edit s2layers.dat

  • If this is a new Core2 style, add:
stylename/layout          layout          core2
stylename/themes          theme+          stylename/layout
  • If this is a child of Tabula Rasa, add:
stylename/layout          layout(core2base/layout)    core2
stylename/themes          theme+                      stylename/layout


FIXME: still called _local in nonfree.

Scroll down to %default_themes and add the style and default theme:

layoutname => 'stylename/defaulttheme',


  • Create in ~/dw/cgi-bin/LJ/S2Theme/ or ~/dw/ext/dw-nonfree/cgi-bin/LJ/S2Theme/.
  • Add:
package LJ::S2Theme::layoutname;
use base qw( LJ::S2Theme );
use strict;
sub layouts { ( "1" => "one-column", "1s" => "one-column-split", "2l" => "two-columns-left", "2r" => "two-columns-right", "3" => "three-columns-sides", "3r" => "three-columns-right", "3l" => "three-columns-left" ) }
sub layout_prop { "layout_type" }
  • Remove layout options which don't apply to the style.
  • If the style has new Customize properties which can be sorted into existing categories (such as Page, Header, Module, Entry, etc.) you can add them to these categories using sub xxx_props:
sub module_props {
    my $self = shift;
    my @props = qw(
        new_property 1
        new_property 2
        new_property 3
        new_property 4
        new_property 5
    return $self->_append_props( "module_props", @props );
  • Existing categories can be found in ~/dw/cgi-bin/LJ/
  • Note that, in Customize, they will be put after default properties, in the order you've listed them in in layout.s2.

Create the STYLENAME directory

Create a directory with the name of the style in ~/dw/bin/upgrading/s2layers/ or ~/dw/ext/dw-nonfree/bin/upgrading/s2layers/.

Create layout.s2

  • In the directory you've created, create a file named layout.s2. Add:
layerinfo type = "layout";
layerinfo name = "stylename";
layerinfo redist_uniq = "stylename/layout";
layerinfo author_name = "someuser";
layerinfo lang = "en";
set layout_authors = [ { "name" => "someuser", "type" => "user" } ];
  • Make sure to respect the designer's wishes concerning capitalization and that layerinfo author_name and layout_authors match.
  • If the designer doesn't want their name to be displayed as a username or isn't a user, use this instead:
set layout_authors = [ { "name" => "someuser" } ];
  • If there are resources to credit, add them with:
set layout_resources = [ { "name" => "Name", "url" => "http://URL" } ];
  • Add the style code using headers for options (presentation, colors, fonts, images, modules, text, other) and for the stylesheet:
## Stylesheet

Special case: custom properties

  • If the style has custom properties, first try to see if you can find existing ones in Core2 which would fit just as well.
  • If there aren't, make sure their names follow existing patterns: a) the property type (color, font, image, ...) b) the major area it applies to (header, entry, module,...) c) the precise element it applies to (text, link, background) and finally d) anything which might precise it further (alt, hover, active,...). The goal is to try to make it precise enough that anybody reading the code will know what it does without having to read the description.

Here are some examples:




A few exceptions to this rule:
  • image props mention whether they're background images or other sorts of images first ( e.g. image_background_entry_title, image_decoration_module_footer)
  • some custom properties can apply to an element wherever it may be displayed. In this case try to name this element as precisely as possible (e.g. font_titles for any H1, H2, H3, H4 headings or calendar_entryday_background if it applies to both the archive page calendar and the module calendar).
  • Sort them into existing groups (presentation, colors, fonts, images, modules, text, other) by appending _child to the group name. For example:
propgroup images_child {
    property string image_module_list { des = "Module list image"; }
  • Finally add a corresponding header (presentation, etc.).

Special case: custom module positions

  • If a module has more or fewer available positions than other modules, you can customize the sections it can be set to by using _override. For example:
property string module_navlinks_section_override {
    values = "none|(none)|header|Header|one|Group One|two|Group Two";
    grouped = 1;
set grouped_property_override = { "module_navlinks_section" => "module_navlinks_section_override" };
set module_navlinks_section = "header";
  • Don't forget to make sure it's printed correctly when set to every position, possibly by editing function Page::print() { }.

Special case: custom functions

  • If there is any function to be added, add a 'functions' header then briefly explain why each function had to be edited in a comment (e.g. to add an extra DIV, to add a new section for modules).

Create themes.s2

  • In the directory you've created, create a file named themes.s2.

Adding a new color theme

Edit themes.s2

  • Make sure the color theme has the right header. As Afuna explained here in [info]dw_dev_training, it should look like this:
#NEWLAYER: stylename/themename
layerinfo type = "theme";
layerinfo name = "Theme Name";
layerinfo redist_uniq = "stylename/themename";
layerinfo author_name = "someuser";
  • If the color theme author is not the style author, add this this line below, separated by a blank line:
set theme_authors = [ { "name" => "someuser", "type" => "user" } ];
  • Make sure to respect the designer's wishes concerning capitalization and that layerinfo author_name and theme_authors match.
  • If the designer doesn't want their name to be displayed as a username or isn't a user, use this instead:
set theme_authors = [ { "name" => "someuser" } ];
  • If there are resources to credit, add them with:
set layout_resources = [ { "name" => "Name", "url" => "http://URL" } ];
If there were already resources credited in the style, don't forget to add them again.
  • If the theme has any images, name them like this: Keep the image name used in other themes if there are any.
If there's only one image, give it the theme name:
If the theme has generic images used in other themes, simply use
In the theme, use stylename/, stylename/ or stylename/ as the URL.
  • If you need to add theme-specific CSS, use:
function Page::print_theme_stylesheet() {
  • Make sure to add the theme code in the right place: themes should be alphabetically sorted.
  • Each theme file must be separated by two blank lines. Leave one blank line after the last theme in the file.

Check and format your files

General rules

  • No tabs or trailing spaces.
  • No empty properties.
  • No hardcoded colors, fonts or text except shadows, :before/:after characters, colors in print_theme_stylesheet() if the designer has used a non-safe combination (color_page_text on color_entry_background instead of color_entry_text on color_entry_background ) or colors which aren't used elsewhere.
  • No redundant code.
  • Use shorthand for color codes whenever possible: #555 instead of #555555 and #abc instead of #aabbcc.
  • Fonts should be capitalized, and single-quoted if there are several words: 'News Gothic MT' instead of news gothic mt.

Sort S2 properties

  • Sort properties into categories.
In styles, possible categories are: Presentation, Colors, Fonts, Images, Modules, Text, Links List and Custom CSS in this order.
In themes, possible categories are: Presentation, Page Colors, Entry Colors, Module Colors, Fonts and Images, in this order.

Use headers to separate each category:

## Page Colors
  • In themes, properties should be sorted alphabetically within each category, but sometimes logic should prevail. For example, generic properties such as color_page_background go before specific properties such as color_header_background. Look at other themes to keep the same order.

Format CSS

  • Format CSS to be easily readable and editable. Everything should be properly indented and spaced out, selectors should be listed in the order they're displayed in the source, properties should be alphabetized.
  • In styles, add style name and style author at the top of the stylesheet:
/* Style Name
/* by style author
* In styles, use comment headers to separate sections:
<syntaxhighlight lang="css">
/* Modules
.module {
    margin: 2em .5em;
    padding: 2em;
  • Remove leading zeros from decimals: .5em instead of 0.5em.
    border: 1px solid $*color_module_border;
    border-top: none;
    list-style: square inside url($*image_list_bullet);
    margin: 2em .5em 1em;

instead of:

    border-bottom: 1px solid $*color_module_border;
    border-left: 1px solid $*color_module_border;
    border-right: 1px solid $*color_module_border;
    list-style-image: url($*image_list_bullet);
    list-style-position: inside;
    list-style-type: square;
    margin-bottom: 1em;
    margin-left: .5em;
    margin-right: .5em;
    margin-top: 2em;
  • Remove gratuitous specificity such as div.entry instead of .entry. Inserting .DIV and .SPAN when they're not needed makes it harder to override selectors and can cause conflicts or bugs down the line. Compare:
.entry-content {
background: blue;
div.entry-content {
background: red;
.entry .entry-content {
background: green;
div.entry div.entry-content {
background: yellow;
  • Group selectors whenever possible.

Adding new files to your patch

  • If the style or theme has images, they go to ~/dw/htdocs/img/styles/stylename/ or ~/dw/ext/dw-nonfree/htdocs/img/styles. If the style folder doesn't exist already, you'll have to create it.
  • Use git add FILENAME or git add . to add them to your patch.

Test, test and test

  • For styles, see the list of required features in [info]dreamscapes. Pay attention to color combinations in particular: the style must not only work with the original set of themes but also with dark on light themes, backgrounds where the original designer didn't set one, etc. Anticipate on what users and other designers could do with it.
  • In Customize, make sure everything is correctly listed and named. For styles, also make sure you can select the page layouts working with your style, and customize your style.
  • On your test account, check colors on all pages. Don't forget hover and visited links, comment subjects, bottom links, reply boxes and drop-down menus on comment pages, contextual pop-ups, the navigation strip, blockquotes in entries and comments if these have been customized. For styles, also make sure all types of layouts, all pages, all sorts of entries and comments are displayed correctly and do so in various screen resolutions and font sizes. Don't forget to check community journals too.

Preview pictures

  • To make preview pictures, you need to take a screenshot of the Recent Pages of your test account. This account needs to have one or two dummy entries with dummy titles and a generic Dreamwidth icon (or the no-userpic default graphic), no navigation strip, and generally few sidebar modules and no footer modules.
  • It is best if you take your screenshot when your screen is set to a size of 1366x768 or 1280x800 pixels as these are the most common resolutions used by Dreamwidth users, and your font size set to 14-16 pixels. None of this is mandatory, though.
  • Screenshots must then be resized to 150x114 pixels. If doing so distorts the image, you need to either edit the original screenshot in a photo editor program or edit your test journal until your screenshot can be resized without any distortion. You may also need to sharpen your image.
  • Final previews should be color-indexed .PNGs, and should NOT include any color profile.
  • If you can't do preview pictures mention it on the bug so that someone can do them for you. You can also ask for help at [info]dreamscapes.
  • A few tips:
It might be a good idea to create accounts specifically for making previews --one per style-- so that you don't lose your set-up.
If your photo editor program has scripting functions, you can use them to automate resizing and saving.
Mozilla Firefox has a few extensions to help you generate content, uncheck several modules at once, resize your window and take screenshots:
Dummy Lipsum
Web Developer
Google Chrome has two handy extensions (probably more) to help with making screenshots:
Window Resizer will make your browser window a specified size. Especially useful, if you set "screen type" to "mobile device" then the content window is made to the specified size. Using 1280x973 will resize to 150x114 nicely.
Screen Capture will take screen shots of the contents of a browser window (Macs, and maybe other OSs, let you screencap a window but it gives you content and menus, which isn't helpful). A bit buggy but does the job.
If you use a Mac or a Linux machine, you can resize, sharpen, strip any color profiles and make sure the final result is an indexed png from the command line with ImageMagick/convert as long as your screenshot is already the right aspect ratio:
convert -resize '150x114' -sharpen 25 +dither -type Palette $inputfilename png8:$outputfilename
You can also make this into a script:
for f in *.png; do
     convert -resize '150' -sharpen 25 +dither -type Palette "$f" png8:"$f"
This version also checks if any of the files have already been done (so doesn't do them again) and prints out the names of the files it resizes:

echo "  Creating Dreamwidth previews..."

for f in *.png; do

    w=$(identify -format "%w" "$f")
    h=$(identify -format "%h" "$f")
    t=$(identify -format "%r" "$f")
    c=$(identify -format "%k" "$f")

    if [ $w -ne 150 ] || [ $h -ne 114 ] || [ $t != "PseudoClassRGB" ] || [ $c -gt 256 ]; then 
        echo "    * $f"
        convert -resize '150' -sharpen 25 +dither -type Palette "$f" png8:"$f"


echo "  ... done"