about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-04-21 23:56:54 +0000
committerEric Wong <e@80x24.org>2019-04-22 01:15:36 +0000
commit7555233ebc31d8c2e30629a61a9e1203a5eb573c (patch)
treee5051c9f9661b113cfa952c13e69f749393d76b8
parentc9f6755f28fd5c55dbb74427d23c51c4cbceafc1 (diff)
downloadolddoc-7555233ebc31d8c2e30629a61a9e1203a5eb573c.tar.gz
"oldweb" remains for compatibility and we still have minimal styling.

Some browsers (e.g. Firefox 67.0a1 via "ui.systemUsesDarkTheme") are
adding support for the "prefers-color-scheme" @media query.  So this
allows pages to respect user choice when it comes to dark or light
schemes.

OLED and CRT displays measure significant power savings when using
dark schemes.  Dark themes work better with less ambient light, so
favoring darkness can lead to overall power savings even with CCFL
and LED-lit displays.
-rw-r--r--Documentation/olddoc.1.txt4
-rw-r--r--GNUmakefile2
-rw-r--r--README14
-rw-r--r--lib/dark216.rb40
-rw-r--r--lib/olddoc.rb3
-rw-r--r--lib/oldweb.rb1
-rw-r--r--lib/oldweb/_head.rhtml6
7 files changed, 60 insertions, 10 deletions
diff --git a/Documentation/olddoc.1.txt b/Documentation/olddoc.1.txt
index c294cdb..25bf88b 100644
--- a/Documentation/olddoc.1.txt
+++ b/Documentation/olddoc.1.txt
@@ -10,9 +10,11 @@ olddoc - old-fashioned RDoc HTML generator
 
 `rdoc` -f oldweb
 
+`rdoc` -f dark216
+
 # DESCRIPTION
 
-olddoc features oldweb, and old-fashioned RDoc HTML generator.
+olddoc features dark216, and old-fashioned RDoc HTML generator.
 You can also use "olddoc prepare" to generate NEWS files from
 git tags.
 
diff --git a/GNUmakefile b/GNUmakefile
index 038bc25..1df29ae 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -41,7 +41,7 @@ doc: $(placeholders)
         $(MAKE) -C Documentation html
         rm -rf doc
         olddoc prepare
-        rdoc --debug -f oldweb
+        rdoc --debug -f dark216
         olddoc merge
         ln NEWS.atom.xml doc/
 
diff --git a/README b/README
index 4b5aa1f..b9538e7 100644
--- a/README
+++ b/README
@@ -3,15 +3,17 @@
 olddoc contains old-fashioned document generators for those who do not
 wish to impose bloated, new-fangled web cruft on their readers.
 
-olddoc contains oldweb, an HTML generator without any images, frames,
-CSS, or JavaScript.  It is designed for users of text-based browsers
-and/or low-bandwidth connections.  oldweb focuses on text as it is
-the lowest common denominator for accessibility and compatibility
+olddoc contains dark216, a HTML generator without any images, frames,
+or JavaScript.  It is designed for users of text-based browsers
+and/or low-bandwidth connections; yet respects user preference for
+light color schemes in new CSS browsers while favoring darkness for
+power savings on OLED and CRT displays.  dark216 focuses on text as
+it is the lowest common denominator for accessibility and compatibility
 with people and hardware.
 
 == Reasons
 
-* No CSS.  Encouraging users to use CSS leads to problems like
+* No CSS required.  Encouraging users to use CSS leads to problems like
   copy-paste hijacking: https://thejh.net/misc/website-terminal-copy-paste
   External CSS also increases page load time as it often blocks page
   rendering.  Asynchronous loading of CSS also causes accessibility
@@ -38,7 +40,7 @@ missing out!
 
         gem install olddoc
         cd $ANY_RDOC_USING_RUBY_PROJECT
-        rdoc -f oldweb
+        rdoc -f dark216
 
 You can also use olddoc to generate NEWS entries
 assuming you have git tags, a README file and .olddoc.yml
diff --git a/lib/dark216.rb b/lib/dark216.rb
new file mode 100644
index 0000000..a01584c
--- /dev/null
+++ b/lib/dark216.rb
@@ -0,0 +1,40 @@
+# Copyright (C) 2019 all contributors <olddoc-public@80x24.org>
+# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
+
+# Loosely derived from Darkfish in the main rdoc distribution
+require_relative 'oldweb'
+
+# dark216 is an \RDoc template and not intended as a programming API.
+# It respect prefers-color-scheme:light on newer browsers with CSS
+# support, but favors darkness for power-savings.
+# You may specify it as an \RDoc formatter:
+#
+#   rdoc -f dark216 ...
+class Dark216 < Oldweb
+  RDoc::RDoc.add_generator(self) # :nodoc:
+  include ERB::Util # :nodoc:
+
+  # description of the generator
+  DESCRIPTION = 'minimal dark HTML generator'
+
+  # default to a dark, web-safe (216 color) palette for power-savings.
+  # Color-capable browsers can respect the prefers-color-scheme:light
+  # @media query (browser support a work-in-progress)
+  STYLE = <<''.gsub(/^\s*/m, '').delete!("\n") # :nodoc:
+@media screen {
+  *{background:#000;color:#ccc}
+  a{color:#69f}
+  a:visited{color:#96f}
+}
+@media screen AND (prefers-color-scheme:light) {
+  *{background:#fff;color:#333}
+  a{color:#00f}
+  a:visited{color:#808}
+}
+
+  def initialize(*args) # :nodoc:
+    super
+    @oldweb_style = STYLE
+  end
+end
+# :startdoc:
diff --git a/lib/olddoc.rb b/lib/olddoc.rb
index 3061e73..d5d6b37 100644
--- a/lib/olddoc.rb
+++ b/lib/olddoc.rb
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2016 all contributors <olddoc-public@80x24.org>
+# Copyright (C) 2015-2019 all contributors <olddoc-public@80x24.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 module Olddoc # :nodoc:
   autoload :Gemspec, 'olddoc/gemspec'
@@ -16,3 +16,4 @@ module Olddoc # :nodoc:
   end
 end
 require_relative 'oldweb'
+require_relative 'dark216'
diff --git a/lib/oldweb.rb b/lib/oldweb.rb
index ccc37f7..5b55019 100644
--- a/lib/oldweb.rb
+++ b/lib/oldweb.rb
@@ -91,6 +91,7 @@ class Oldweb
       cgit_url << '#n%d' # lineno
       @old_vcs_url = cgit_url
     end
+    @oldweb_style = nil # used by dark216
   end
 
   def generate # :nodoc:
diff --git a/lib/oldweb/_head.rhtml b/lib/oldweb/_head.rhtml
index 720fd95..15a428e 100644
--- a/lib/oldweb/_head.rhtml
+++ b/lib/oldweb/_head.rhtml
@@ -8,4 +8,8 @@ type="application/atom+xml" /><%
 end
 %><meta
 http-equiv="Content-Type"
-content="text/html; charset=<%= @options.charset %>">
+content="text/html; charset=<%= @options.charset %>"><%
+if @oldweb_style
+%><style><%= @oldweb_style %></style><%
+end
+%>