2. Layer Types

As previously mentioned, there are 6 layers types in S2:

  => core
    => i18nc
    => layout
      => i18n
      => theme
      => user

The hierarchy above indicates which layer types are specific to which others. For example, any given i18n, theme, or user layer is specific to a certain layout. You can't have a theme which works with any layout, since the theme is tied to that layout.

Layouts are tied to a core, but since there's at present only 1 core layer, a layout can pretty much be thought of as the top layer. If in the future it becomes apparent that design mistakes were made at the core layer we can then make a new core layer and support both. Layouts will then be able to be written to any version of the core.

Core Layer (core)

The core layer defines the classes of objects which will be provided to the S2 code by the web application. Further, it defines the methods on those objects and useful global functions.

Only the core layer can define builtin functions and methods, where the implementation isn't in S2, but implemented by the host web application. Users cannot create new core layers. More than likely, there will only be one core layer on the system. However, the core layer is versioned in case the web application changes drastically and needs a new core layer. In that case, multiple core layers can exist at the same time, and it's the web application's job to check the version number on the core layer in use and provide the right data structures to it.

The core also provides basic implementations for everything, in case other layers don't override them. One major advantage of this is that it makes it extremely easy for LiveJournal to add more view types in the future and have them be compatible with all existing layers: since those layers wouldn't know how to generate a "FooPage", they'll just inherit the FooPage from the core. (Inheritance note)

Core Internationalization Layer (i18nc)

The i18nc layer overrides text properties in the core, translating them into a specific language. It also overrides the default short, medium, and long date and time formats and functions which do things like return ordinal numbers from cardinal numbers and map item counts onto their plural form.

The core layer should have properties for every textual string likely to be used by more than one layout, to reduce work for translators. Because the i18nc layer overrides the core, and not specific layouts, all layouts can take advantage of things defined in the core and i18nc layers.

Layout Layer (layout)

A layout is the largest and most involved layer type developers will create. A layout defines the look & feel of the journal and provides all the properties which the three child layers have access to modify.

Layout Internationalization Layer (i18n)

An i18n layer is like i18nc, but it's specific to a layout.

If a layout introduces new textual or locale-specific properties/functions because it couldn't use stuff already in the core, an i18n layer overrides just those new items. The fact that there are two i18n layers is hidden from the user... they just select "Deutsch" (or it's selected by default automatically, based on their browser settings) and the system picks the i18nc and i18n layers which match the "de" language code for their layout and core. (their core layer is also automatically selected if there are more than one, based on the layout they choose)

Theme Layer (theme)

A theme layer overrides color, image, font, and sound properties provided in the layout (some of which the layout may simply pass on from the core).

User Layer (user)

A user layer tweaks any last properties. A graphical wizard on the site auto-generates this after showing the end-user all the available properties. Everything is incredibly simple: colors are picked using a color-picker widget, for example.

2.1. Layer Capabilities

The following table summarizes what each layer type is permitted to do:

core i18nc layout i18n theme user
Define classes X
Define builtin functions/methods X
Define global functions X X
Define class methods X X[a]
Define properties X X
Expose properties to graphical wizard X
Override name/description of properties - X X X
Override functions/methods - X X X X
Set properties X X X X X X

[a] Layouts adding methods to classes must prefix the method name with lay_ to avoid future namespace collisions should the core layer expand.