Sha256: eae83cb9be7b811b6cbcd0fd057e5a5d3521046c8af6cd4cfbc0e531e3b04bcc

Contents?: true

Size: 791 Bytes

Versions: 7

Compression:

Stored size: 791 Bytes

Contents

# -*- encoding: utf-8 -*-

require 'nokogiri'

module Genit

  # Build a document, that may be a fragment, from various sources.
  class Builder
  
    # Public: Constructor.
    #
    # document - A Nokogiri::XML::Document
    def initialize document
      @document = document
    end
    
    # Public: Replace a tag (and its children) from the current document by a 
    # string.
    #
    # css_rule    - The String css rule to find the tag
    # replacement - The replacement String
    #
    # Examples
    #
    #   doc = builder.replace('genit.pages', "<working />")
    #
    # Return the updated Nokogiri::XML::Document document.
    def replace css_rule, replacement
      tag = @document.at_css(css_rule)
      tag.replace replacement
      @document
    end
    
  end
  
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
genit-2.1 lib/genit/builders/builder.rb
genit-2.0 lib/genit/builders/builder.rb
genit-1.0.1 lib/genit/builders/builder.rb
genit-1.0 lib/genit/builders/builder.rb
genit-0.99 lib/genit/builders/builder.rb
genit-0.9 lib/genit/builders/builder.rb
genit-0.5 lib/genit/builder.rb