module ThemeFrame
ThemeFrame — render ASCII doodles and preview cards for themes. Public: preview, doodle_lines, heading_style Depends: IrcFormat, IrcReply Tests: test/lib/theme_frame_test.rb
Constants
- SAMPLE_BODY
- TAG
Public Instance Methods
Source
# File lib/theme_frame.rb, line 57 def coloured_doodles(theme, which) return [] unless theme.dig(:frame, which) seed = theme[:id].to_s.bytes.sum doodle_lines(theme, which).each_with_index.map do |line, index| text = line.to_s.gsub("TAG", theme[:name].to_s.upcase) if theme[:doodle_style] == :rainbow ThemeDoodle.rainbow_line(text, line_index: index, seed: seed) elsif theme[:doodle_style] == :matrix ThemeDoodleMatrix.matrix_line(text, line_index: index, seed: seed) else style = palette_style(theme.dig(:palette, :accent) || theme.dig(:palette, :title) || [14]) IrcFormat.decorate(text, style) end end end
Source
# File lib/theme_frame.rb, line 34 def doodle_lines(theme, which = :header_doodle) Array(theme.dig(:frame, which)) end
Source
# File lib/theme_frame.rb, line 38 def heading_style(theme) palette_style(theme.dig(:palette, :title) || [0, 4]) end
Source
# File lib/theme_frame.rb, line 49 def palette_style(pair) codes = Array(pair) return IrcFormat.color(codes[0]) if codes.length == 1 IrcFormat.color(codes[0], codes[1]) end
Source
# File lib/theme_frame.rb, line 19 def preview(theme) lines = [] lines.concat(coloured_doodles(theme, :header_doodle)) lines.concat(coloured_doodles(theme, :between_doodles)) lines << IrcReply.card( tag: TAG, title: theme[:name].to_s, body_lines: [SAMPLE_BODY, styled_separator(theme)], footer_parts: [theme[:id].to_s, width_label(theme[:width])], heading_style: heading_style(theme) ) lines.concat(coloured_doodles(theme, :footer_doodle)) lines.join("\n") end
Source
# File lib/theme_frame.rb, line 42 def styled_separator(theme) sep = theme.dig(:frame, :separator).to_s return sep if sep.empty? IrcFormat.decorate(sep, palette_style(theme.dig(:palette, :accent) || theme.dig(:palette, :title) || [14])) end
Source
# File lib/theme_frame.rb, line 74 def width_label(width) case width when :narrow then "narrow" when :wide then "wide" else "medium" end end