module Psychgus::Stylables::StyleStylable

A helper mixin for Stylables that change a node's style.

There is no max level, because a parent's style will override all of its children.

Attributes

min_level[RW]
new_style[RW]

Public Class Methods

new(min_level=0,new_style: nil,**kargs) click to toggle source

max_level is not defined because a parent's style will override all of its children.

@param min_level [Integer] the minimum level (inclusive) to style @param new_style [Integer] the new style to set the nodes to @param kargs [Hash] capture extra keyword args, so no error for undefined args

# File lib/psychgus/stylables.rb, line 45
def initialize(min_level=0,new_style: nil,**kargs)
  @min_level = min_level
  @new_style = new_style
end

Public Instance Methods

change_style(sniffer,node) click to toggle source

Change the style of node to {new_style} if it is >= {min_level}.

# File lib/psychgus/stylables.rb, line 51
def change_style(sniffer,node)
  return unless node.respond_to?(:style=)

  node.style = @new_style if sniffer.level >= @min_level
end