about summary refs log tree commit homepage
path: root/lib
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 /lib
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.
Diffstat (limited to 'lib')
-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
4 files changed, 48 insertions, 2 deletions
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
+%>