[dw-free] entry metadata (currents) should print in sorted field order
[commit: http://hg.dwscoalition.org/dw-free/rev/56d0be48ab8b]
http://bugs.dwscoalition.org/show_bug.cgi?id=2944
Sort metadata fields alphabetically to make it consistent with how the site
scheme sorts it, instead of just getting the metadata in whatever order the
backend feels like. Exposes a new function "keys_alpha".
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2944
Sort metadata fields alphabetically to make it consistent with how the site
scheme sorts it, instead of just getting the metadata in whatever order the
backend feels like. Exposes a new function "keys_alpha".
Patch by
Files modified:
- bin/upgrading/s2layers/core1.s2
- bin/upgrading/s2layers/core2.s2
- cgi-bin/LJ/S2.pm
--------------------------------------------------------------------------------
diff -r ad38e69bc358 -r 56d0be48ab8b bin/upgrading/s2layers/core1.s2
--- a/bin/upgrading/s2layers/core1.s2 Wed Sep 08 22:08:26 2010 -0500
+++ b/bin/upgrading/s2layers/core1.s2 Thu Sep 09 13:21:21 2010 +0800
@@ -1877,6 +1877,9 @@ function builtin htmlattr(string name, i
function builtin htmlattr(string name, int value) : string
"If the value isn't blank, return in HTML attribute format with a leading space. HTML of name is not escaped.";
+function builtin keys_alpha(string{} elements) : string[]
+"Return the keys of the array in alphabetically sorted order.";
+
### Language
function lang_map_plural (int n) : int {
@@ -2290,7 +2293,7 @@ function Entry::print_metadata() {
function Entry::print_metadata() {
if (size $.metadata) {
"""<div class="metadata">\n""";
- foreach var string m ($.metadata) {
+ foreach var string m ( keys_alpha( $.metadata ) ) {
"<div><strong>$m</strong>: ";
if ($m == "mood") {
" $.mood_icon ";
diff -r ad38e69bc358 -r 56d0be48ab8b bin/upgrading/s2layers/core2.s2
--- a/bin/upgrading/s2layers/core2.s2 Wed Sep 08 22:08:26 2010 -0500
+++ b/bin/upgrading/s2layers/core2.s2 Thu Sep 09 13:21:21 2010 +0800
@@ -1007,6 +1007,9 @@ function builtin print_search_form(strin
function builtin print_search_form(string button_text)
"Prints a search form, with the button text as the label to the submit button.";
+function builtin keys_alpha(string{} elements) : string[]
+"Return the keys of the array in alphabetically sorted order.";
+
##[ properties ]
propgroup colors = "Colors";
@@ -4431,7 +4434,7 @@ function Entry::print_metadata() {
if (size $.metadata) {
var string position = ($*entry_metadata_position == "top") ? " top-metadata" : " bottom-metadata";
"""<div class="metadata$position">\n<ul>\n""";
- foreach var string m ($.metadata) {
+ foreach var string m ( keys_alpha( $.metadata ) ) {
var string metadata_name = lang_metadata_title($m);
"""<li><span class="metadata-label metadata-label-$m">$metadata_name: </span>""";
if ($m == "mood") {
diff -r ad38e69bc358 -r 56d0be48ab8b cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm Wed Sep 08 22:08:26 2010 -0500
+++ b/cgi-bin/LJ/S2.pm Thu Sep 09 13:21:21 2010 +0800
@@ -4334,4 +4334,12 @@ sub Siteviews__set_content {
$this->{_content}->{$content} = $text;
}
+sub keys_alpha {
+ my ( $ctx, $ref ) = @_;
+ return undef unless ref $ref eq 'HASH';
+
+ # return reference to array of sorted keys
+ return [ sort { $a cmp $b } keys %$ref ];
+}
+
1;
--------------------------------------------------------------------------------
