Hierarchy: Head Functions

From Dreamwidth Notes
Jump to: navigation, search

This is an extension of Hierarchy, where you are introduced into the wild and baffling world of layouts and view functions. If you haven't been there yet, start there or this might not make much sense.

Purpose

Each of these pages is specifically designed to follow a function from how it appears in a view page down to its root functions, variables, and properties. Basically, by the end, you should understand in theory why a function exists and how its put together. Eventually, you will also be able to understand how to alter, change, and even override the functions and both where their variables are stored and why they're there.

In the Beginning

In Hierarchy, we went over the basic structure of a function. Functions are shortcuts, and you can make functions that have functions in them, therefore making even cooler shortcuts.

Below are the breakdown of the header functions and their structure. We'll also delve into the wild ride that are associated properties and how this all fits together.

Remember, the structure is hierarchial, so as I go down through each topic, I'll be breaking down the functions in the functions. Eventually, there will also be an explanation of variables, what they are, where you find them, and how to change them to suit your purposes.

Each enty will be structured thus: the function, the class, the functions that are related to this function, then the structure of those functions, followed by variables. At the end, there will be properties. All will be explained.

Function: print_head

class Page

Functions

function print_head [fixed];
Print server side supplied head content. This is a fixed function, so you can't override it. See [method[Page.print_custom_head()]] if you want to supply custom head content.

Structure

 
function Page::print_head() 
{
    print $.head_content;
    $this->print_custom_head();
}
function Page::print_custom_head() 
{
    # blank
}
Layers can override this to add extra HTML to the head section of the HTML document. Note that layouts are not intended to override this method.

Variables

var readonly string head_content;
Extra tags supplied by the server to go in the <head> section of the output HTML document. Layouts should include this in the head section if they are writing HTML.

Function: print_head_title

class Page

Functions

function print_head_title;
Print the title for this particular page, as in print_title, formatted with title and the journal username

Structure

function Page::print_head_title() 
{
    if ($this.journal.journal_type == "I") 
    {
    print """<title>""" + $this.journal.name + $*text_default_separator + $this->view_title() + """</title>\n""";
    }
    else 
    {
    print """<title>""" + $this.journal.username + $*text_default_separator + $this->view_title() + """</title>\n""";
    }
}
function Page::view_title() [notags] : string 
{
    return lang_viewname($.view);
}
Return a title for this particular page, such as \"Friends' Recent Entries\" for the friends view, or a date for the day view. Should be overridden in i18n layers. Ideally, layout layers should never override this. See [method[Page.title()


function lang_viewname(string viewid) [notags] : string
{
    if ($viewid == "recent") { return $*text_view_recent; }
    if ($viewid == "archive") { return $*text_view_archive; }
    if ($viewid == "read") { return $*text_view_friends; }
    if ($viewid == "day") { return "Day"; }
    if ($viewid == "month") { return "Month"; }
    if ($viewid == "userinfo") { return $*text_view_userinfo; }
    if ($viewid == "entry") { return "Read Comments"; }
    if ($viewid == "reply") { return "Post Comment"; }
    if ($viewid == "tags") { return "Tags"; }
    if ($viewid == "memories") { return $*text_view_memories; }
    return "Unknown View";
}
Overriding this function is NOT RECOMMENDED. Overriding this function could prevent sitewide improvements to styles, accessibility, or other functionality from operating in your layout. Sets strings according to layer or wizard supplied string properties.

Properties:

property string text_default_separator 
{
    des = "Text used to separate items";
    maxlength = 5;
    "size" = 5;
    example = " | ";
}
 
property string text_view_recent 
{
    des = "Text used to link to the 'Recent Entries' view";
    maxlength = 20;
    "size" = 15;
    example = "Recent Posts";
}
property string text_view_friends 
{
    des = "Text used to link to the 'Reading' view";
    maxlength = 20;
    "size" = 15;
    example = "My Reading Page";
}
 
property string text_view_archive 
{
    des = "Text used to link to the 'Archive' view";
    maxlength = 20;
    "size" = 15;
    example = "Journal Archive";
}
property string text_view_userinfo 
{
    des = "Text used to link to the 'User Information' view";
    maxlength = 20;
    "size" = 15;
    example = "My Profile";
}
property string text_view_memories 
{
    des = "Text used to link to the 'Memories' view";
    maxlength = 20;
    "size" = 15;
    example = "My Memories";
}
 
set text_default_separator  = " | ";
set text_view_recent = "Recent Entries";
set text_view_friends = "Reading";
set text_view_archive = "Archive";
set text_view_userinfo = "Profile";
set text_view_memories = "Memories";