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

Version Path
rhet-butler-0.14.1 lib/rhet-butler/slide-renderers/cues.rb
rhet-butler-0.14.0 lib/rhet-butler/slide-renderers/cues.rb
rhet-butler-0.13.0 lib/rhet-butler/slide-renderers/cues.rb
rhet-butler-0.12.1 lib/rhet-butler/slide-renderers/cues.rb
rhet-butler-0.11.1 lib/rhet-butler/slide-renderers/cues.rb
rhet-butler-0.11.0 lib/rhet-butler/slide-renderers/cues.rb
rhet-butler-0.10.0 lib/rhet-butler/slide-renderers/cues.rb
rhet-butler-0.9.0 lib/rhet-butler/slide-renderers/cues.rb