2014-06-04

Metadata Stylesheets

Sick of having to Copy/Paste this over and over again?

  <Routes>
    <Route Style="Dashed" Start="0101" End="0202" />
    <Route Style="Dashed" Start="0101" End="0303" />
    <Route Style="Dashed" Start="0101" End="0404" /&gt;
    ...
  </Routes>

And then you decide that Fu would be better represented with dotted cyan instead, and you need to do a Find/Replace? Oh, the drudgery.

I've added a new metadata element you can use to style a few elements, borders and routes. Here's what you do:

  <Stylesheet>
    route.Fu { color: pink; style: dashed; }
  </Stylesheet>

  <Routes>
    <Route Allegiance="Fu" Start="0101" End="0303" />
    <Route Allegiance="Fu" Start="0101" End="0404" />
    ...
  </Routes>

Now all of Fu's routes are dashed pink, and more easily changed to dotted cyan.

It's similar to the CSS language used in web pages. The basic structure is a list of rules:

selector, selector, ... { property: value; property: value; ... }

Selectors (the bit up front):
  • type - border or route
  • Optionally followed by a period (.), then allegiance
    • e.g. border.Im
  • Multiple selectors can be listed, separated with commas
    • e.g. border.JuPr, border.JuRu, border.JuHl { color: blue; }
Declarations (the bit in the back):
  • A declaration list occurs in { braces } after the selector list.
  • Each declaration has a property, colon (:), value, semicolon (;)
  • Semicolons are terminators, not separators. You need a trailing semicolon after every declaration. This is different from CSS.
Properties/Values:
  • color -  HTML color name or six-digit hex color #rrggbb
    • e.g. pink or #FFC0CB
  • width - integer or floating point number
    • e.g. 2 or 1.5 or -123.456e23
  • style
    • solid, dashed or dotted
Details:
  • borders have only color
  • routes have color, width, and style
  • routes can use Type instead of Allegiance
    • e.g. route.Trade would select
  • You can use /* comments */ anywhere you can put spaces.
  • Within identifiers, you can use backslash (\) to escape characters like spaces
    • e.g. route.Core\ Route { color: purple; }
  • Explicit values on an element take precedence over a matching stylesheet rule.
Language boffins - here's the grammar:

stylesheet       := WS rule-list WS
rule-list        := rule*
rule             := selector-list '{' WS declaration-list '}' WS
selector-list    := selector WS ( ',' WS selector )* WS
selector         := element ( '.' code )?
element          := IDENT
code             := IDENT
declaration-list := declaration*
declaration      := property WS ':' WS value WS ';' WS
property         := IDENT
value            := IDENT | NUMBER | COLOR
IDENT            := [A-Za-z_]([A-Za-z0-9_] | '\' ANY)* 
NUMBER           := '-'? [0-9]* ('.' [0-9]+) ([eE] [-+]? [0-9]+)?
COLOR            := '#' [0-9A-F]{6}
WS               := ( U+0009 | U+000A | U+000D | U+0020 | '/' '*' ... '*' '/')*

And the source is on GitHub, of course. Also on GitHub you'll find the default stylesheet, which is applied after any values on the elements themselves and any sector-specific stylesheet:

border.Im { color: red; }
route.Im { color: green; }

border.SoCf { color: orange; }
route.SoCf { color: green; }

border.ZhCo { color: blue; }
route.ZhCo { color: lightblue; }

border.As { color: yellow; }
route.As { color: yellow; }

border.Hv { color: purple; }
route.Hv { color: gray; }

border.Kk { color: green; }
route.Kk { color: gray; }

border.JuPr { color: blue; }
route.JuPr { color: lightblue; }

route.Core\ Route { color: purple; style: dashed; }

This will almost certainly expand and be refined over time.

Ω