module ThemePaint
ThemePaint — build !paint command lines and apply theme overrides via PaintStore. Public: commands, apply! Depends: IrcPaint, PaintSamples, PaintStore Tests: test/lib/theme_paint_test.rb
Public Instance Methods
Source
# File lib/theme_paint.rb, line 21 def apply!(theme, network:, channel:, store: RabbotDb) rules = Array(theme[:paint_rules]) plugins = rules.map { |rule| rule[:plugin].to_s }.uniq plugins.each do |name| PaintStore.remove_for_plugin!(network: network, channel: channel, plugin: name, store: store) end saved = [] rules.each do |rule| lines = PaintSamples.lines(rule[:plugin]) next unless lines line_index = rule[:line].to_i - 1 next if line_index.negative? || line_index >= lines.length line_text = lines[line_index] result = IrcPaint.recolor_at(line_text, rule[:pos], fg: rule[:fg], bg: rule[:bg]) saved << PaintStore.save_override!( network: network, channel: channel, override: { plugin: rule[:plugin], line: rule[:line], plain_start: result[:plain_start], plain_end: result[:plain_end], fg: result[:fg], bg: result[:bg], snippet: nil }, store: store ) end saved end
Source
# File lib/theme_paint.rb, line 15 def commands(theme, plugin: nil) rules = Array(theme[:paint_rules]) rules = rules.select { |rule| rule[:plugin].to_s == plugin.to_s } if plugin rules.map { |rule| format_command(rule) } end
Source
# File lib/theme_paint.rb, line 56 def format_command(rule) colour = rule[:bg] ? "#{rule[:fg]},#{rule[:bg]}" : rule[:fg].to_s "!paint #{rule[:plugin]} #{rule[:line]} #{rule[:pos]} #{colour}" end