Sha256: 29225fe65d07581c085f457d76cf5d00d55a14cb478d30e5fbfd73eae37adbd4
Contents?: true
Size: 713 Bytes
Versions: 8
Compression:
Stored size: 713 Bytes
Contents
require 'nokogiri' module RhetButler module SlideRenderers class Cues < SlideRenderer register "cues" class XPathExtensions def self.regex(node_set, pattern) re = Regexp.new(pattern) node_set.find_all do |node| node.value =~ re end end end def process(string) doc = Nokogiri::HTML::DocumentFragment.parse(string) #may need DocumentFragment::parse doc.xpath('.//*/@class[regex(.,"\b\d+\b")]', XPathExtensions).each do |attr| attr.value = "rhet-butler item " + attr.value attr.value = attr.value.gsub(/\b\d+\b/){|m| "cue-#{m[0]}"} end doc.to_s end end end end
Version data entries
8 entries across 8 versions & 1 rubygems