Module: MaquinaStream::Themes

Defined in:
lib/maquina_stream/themes.rb

Overview

Two stylesheets, one per scheme, generated from the Rouge themes named in the configuration.

Highlighting emits classes and never inline colour, so switching to dark mode is a stylesheet concern and needs no re-render — which matters, because a re-render mid-stream would mean re-broadcasting sealed blocks to change a colour.

The two files are generated, not written: rake maquina_stream:themes rewrites them from config.themes. A host that changes those theme names re-runs that task.

Defined Under Namespace

Classes: UnknownTheme

Constant Summary collapse

SCOPE =

Every generated rule is scoped to a code block, so the themes cannot reach anything else on a host's page.

"[data-ms-code]"
DARK_SELECTOR =

An explicitly chosen dark theme.

'[data-theme="dark"]'
LIGHT_SELECTOR =

An explicitly chosen light theme, and the default.

':root:not([data-theme="dark"])'

Class Method Summary collapse

Class Method Details

.path(scheme) ⇒ Object

Where the generated stylesheet for scheme lives on disk. What the rake task writes to.



48
49
50
# File 'lib/maquina_stream/themes.rb', line 48

def path(scheme)
  File.expand_path("../../app/assets/stylesheets/maquina_stream/themes/#{scheme}.css", __dir__)
end

.stylesheet(scheme, config: MaquinaStream.config) ⇒ Object

The generated CSS for one scheme, as a String.

scheme is :light or :dark; anything else raises ArgumentError. An unknown Rouge theme name raises UnknownTheme.



38
39
40
41
42
43
44
# File 'lib/maquina_stream/themes.rb', line 38

def stylesheet(scheme, config: MaquinaStream.config)
  case scheme.to_sym
  when :light then light(config)
  when :dark then dark(config)
  else raise ArgumentError, "scheme must be :light or :dark"
  end
end