Introducing the CSSLite gem

require 'domle'
require 'csslite'

s = "b {background-color: #ff3322 }"
xml = "<a><b>red</b><b2>green</b2><b>blue</b></a>"

doc = Domle.new(xml)
css = CSSLite.new s
css.propagate doc.root

puts doc.root.xml pretty: true


<a style=''>
  <b style='background-color:#ff3322'>red</b>
  <b2 style=''>green</b2>
  <b style='background-color:#ff3322'>blue</b>
</a>

Resources