This commit is contained in:
2019-02-06 00:49:12 +03:00
commit 8dbb1bb605
4796 changed files with 506072 additions and 0 deletions

View File

@@ -0,0 +1,287 @@
# -*-perl-*-
#
# Miscalleneous notes on S2, the 2nd major
# version of the LiveJournal style system.
#
# Brad Fitzpatrick <bradfitz@livejournal.com>
# 2001-02-03
#
###########
## goals
#
# 1. flexible/extensible:
# - layers
# - full programming language (*)
# - allows for internationalization
# - not specific to one view:
# - describe how to format objects
# - makes new views automatically supported,
# at least mostly.
# 2. safe:
# - (*) programming language has no unsafe
# looping/branching. only foreach
# on finite lists, ifs, etc.
# 3. fast:
# - precompiled
# 4. easy:
# - wizards/tools to generate each layer
# of S2
#
#
###########
## layers
#
#
# core (definitions, defaults)
# style - the "style"
# colors - tied to a style.
# i18n - not tied to a style
# custom - changing comment links, counters,
# page.insert_html shit.
#
# layers are parsed and compiled before use.
# compiled into native language of appserver
# this is perl now, but easy to change later:
# parser -> AST stays the same.
# just change AST -> pretty printer.
# S2 is not tied to perl, then. can move to
# something faster later... C, anybody?
# S2 parser will be written in java, and
# tools will be provided for users to run and
# test styles on their own machines
#
###########
## core layer
#
# only layer where classes can be declared.
set layertype "core";
set author "webmaster";
class image {
var string url,
var int w,
var int h,
method void print (), # allow trailing commas: so nice.
};
method image::print {
"""<img src="$url" width=$w height=$h border=0>""";
};
class comment_read {
var string urlread,
var int comment_count,
method void print (),
};
method comment_read::print ()
{
$noun = "Comments";
if ($comment_count ==1 ) {
$noun = "Comment";
}
"""<a href="$urlread">Read $comment_count $noun</a>""";
};
class comment_post {
var string urlpost,
method void print (),
};
method comment_post::print ()
{
"""<a href="$urlpost">Leave a comment!</a>""";
}
class comment_info {
var bool can_comment,
var comment_post post,
var comment_read read,
method void print (),
};
method comment_info::print ()
{
if ($can_comment == false) {
return;
}
if ($comment_count != 0) {
call $read print;
print " | ";
}
call $post print;
}
# ack! There's English in there! ^^^^^^^^^
#
# English will be default, everywhere, since it
# is anyway, right? Later we can have our
# master team of translators make new i18n layers
# that override these defaults. still, users
# can then override those i18n layers later, with
# their own words. users won't write in S2:
# we'll have stupid little wizards that ask them
# questions and generate/compile the S2 behind
# the scenes for them. for them, the process will
# be like:
#
# Pick Style: [ \/ ]
# Pick Language: [ \/ ]
#
# [ Continue--> ]
#
# Pick Style color theme: [ \/]
# or, enter your own:
#
# [ Finish ] [ More Customization -->]
#
# What do you want the comment links to say?
# ____________________
# How many items on a page at once? _______
# More stupid questions: _____________
class journal_entry {
var string event,
var string subject,
var datetime eventtime,
var string current_mood,
var string mood_image,
var string current_music,
var bool opt_nocomments,
var user userpost,
var user userjournal,
var image userpic,
var comment_info comments,
var string urlself,
var string head,
method void print,
};
method journal_entry::print {
print "<p><table><tr><td>\n";
"<b>"; call $eventtime print_long; "</b><br>";
print $event;
if ($comments.can_comment) {
"<p>";
call $comments print;
}
"</td></tr></table>\n";
};
class page {
var string view,
var bool remote_logged_in, # logged in user?
var bool remote_is_owner, # is it the journal owner?
var journal_entry[] entries, #
method void print,
};
method page::print
{
local string title;
if ($view == "lastn") {
}
"""<html><head><title>$title</title>$head""";
print "<body>\n";
print "</body></html>";
}
########
### style layer
##
set layertype "style";
set layername "Generator";
set author "evan";
var string colitemborder = "#00f033";
var string colpageback = "#a0a0a0";
########
### color layer
##
set layertype "colors";
set overlays "Generator"; # only for style layers
set author "bradfitz";
var string colitemborder = "#ff0000";
var string colpageback = "#00cc00";
########
### i18n layer
##
set layertype "i18n";
set layerlang "de";
set author "mausal";
method comment_read::print ()
{
$noun = "Kommentar"; # warning: probably wrong.
if ($comment_count ==1 ) {
$noun = "Kommentar"; # probably wrong.
}
"""<a href="$urlread">Lesen $comment_count $noun</a>""";
};
method comment_post::print ()
{
"""<a href="$urlpost">Schrieben eine Kommentar!</a>""";
}
######
### custom layer
##
## - auto-generated from a wizard
## ... or written by hand. (unlikely)
set layertype "custom";
set author "ibrad";
# ibrad-style popcorn links
method comment_read::print ()
{
$noun = "Kernels";
if ($comment_count ==1 ) {
$noun = "Kernel";
}
"""<a href="$urlread">$comment_count $noun.</a>""";
};
# ibrad-style popcorn links
method comment_post::print ()
{
"""<a href="$urlpost">Pop!</a>""";
}
########
### implementation
#
#
request in: /users/bradfitz/
make_journal("bradfitz", "lastn");
my %methods;
foreach $layers ("core", @user_layers) {
load_layer($layers,
}
$pageob = new S2::ob::page;
$pageob->setup_all_datastructures($dbh, $user, $view);
$journal = $methods{'page'}->{'print'}->($pageob);

View File

@@ -0,0 +1,80 @@
<?page
title=>Design Goals
body<=
<a href="./">&lt;&lt; Back</a>
<?h1 Design Goals h1?>
<?p
Here is a table summarizing the primary design goals of S2 and how they contrast with the existing style system, which I guess we can call S1:
p?>
<p><table border=0 cellpadding=6>
<tr bgcolor=<?emcolor?>><td><b>Feature</b></td><td><b>S1</b></td><td><b>S2</b></td></tr>
<tr valign=top>
<td><b>Flexible & Extensible</b></td>
<td>
The current style system forces users to define a template
for each new type of view: recent entries, friends page,
day view, calendar, etc. If we want to add a new view
type, users have to basically write their style.
</td>
<td>
In the new style system you describe the formatting of objects,
not the formatting of views. Thus, we can easily add new views
in the future, and making a "lastn" view pretty much makes ally
your other views automatically.
</td>
</tr>
<tr valign=top>
<td><b>Safe</b></td>
<td>
The current system is completely safe. It's so brain-dead
that it can't be anything <i>but</i> but safe. You have
to have some intelligence to be harmful.
</td>
<td>
The new style system is its own language that gets compiled into another language, and run on the webserver. Letting users run code on the server is inherently dangerous... it obviously has to be free of things "rm -rf /", but also, it has to be free from infinite loops, and anything that could consume large amounts of resources.
<p>The S2 language does not have while loops, gotos, or any other control construct that would permit an infinite loops. It only has <tt>if/else</tt> blocks, and <tt>foreach</tt> over finite lists. Also, you can only call methods and functions defined in the core layer, so users can't write functions <tt>foo</tt> and <tt>bar</tt> which simply call each other.
</td>
</tr>
<tr valign=top>
<td><b>Fast</b></td>
<td>
The current system is a CPU hog, doing tons of parsing, text munging and substitutions and run-time.
</td>
<td>
In the new system, S2 code will be parsed, checked, and compiled before the page is loaded. When a page is loaded in the future, the code will just be run, which will already be in the language that the LiveJournal server runs on. For LiveJournal.com, this will be Perl but in the future we could write a PHP or Java servlet backend to the S2 compiler.
</td>
</tr>
<tr valign=top>
<td><b>Internationalizablilty</b></td>
<td>
The current style system can support non-English languages and locales, but hardly:
<p>-- The server injects a lot of English into S1 variables, especially in dates.
<br>-- The calendar always begins weeks on Sunday.
<br>-- The system to make nouns plural (2 Comments, 3 Replies) is very English-specific.
<br>-- Porting a style to a new language involves forking the style and modifying away, losing all future changes to the original style.
</td>
<td>
The new style system is being design for internationalization. One of the S2 layers is an "i18n layer", which overrides English method definitions from the core and sets properties, like the day weeks start on.
</td>
</tr>
<tr valign=top>
<td><b>Easy</b></td>
<td>
Hahah ... the currently style system was never designed to be easy. It was designed for a few people (me, maybe a friend or two) to make styles, which we'd then make public. I never envisioned everybody using LiveJournal to begin with, much less trying to make styles.
</td>
<td>
Wizards and tools will generate S2 behind the scenes for most users. The hard-core users can write their styles and overlay layers in the raw S2 language.
</td>
</tr>
</table>
<=body
page?>

View File

@@ -0,0 +1,19 @@
<?page
title=>S2
body<=
<?h1 What is S2 h1?>
<?p
S2 is going to be LiveJournal's new style system language, used to control the format of journals. S2 is currently the planning and development stage. If you're interested in helping, contact <A href="/userinfo.bml?user=bradfitz">bradfitz</a> to join the <a href="/userinfo.bml?user=lj_dev">lj_dev</a> group.
p?>
<?h1 Documents h1?>
<?p
<ul>
<li><a href="goals.bml">Design Goals</a> -- with a comparison to the existing style language
<li><a href="2001-02-03.txt">2001-02-03.txt</a> -- misc notes, with some hints as to what S2's syntax may look like
</ul>
p?>
<=body
page?>