lib/genit/builder.rb in genit-0.1 vs lib/genit/builder.rb in genit-0.2
- old
+ new
@@ -7,11 +7,11 @@
# Build a document from various sources.
class Builder
# Public: Constructor.
#
- # document - A Nokogiri::HTML document
+ # document - A Nokogiri::XML::Document
def initialize document
@document = document
end
# Public: Replace a tag (and its children) from the current document by a
@@ -22,13 +22,36 @@
#
# Examples
#
# doc = builder.replace('genit.pages', "<working />")
#
- # Return the changed Nokogiri::HTML document.
+ # Return the updated Nokogiri::XML::Document document.
def replace css_rule, replacement
tag = @document.at_css(css_rule)
tag.replace replacement
+ @document
+ end
+
+ # Public: Mark the <a> element of the menu that is selected (the displayed
+ # page).
+ #
+ # page_name - The String filename of the page
+ #
+ # Examples
+ #
+ # menu = Nokogiri::XML(File.open('menu.html'))
+ # builder = Builder.new(menu)
+ # menu = builder.select_menu('index.html')
+ #
+ # Return the updated Nokogiri::XML::Document document.
+ def select_menu page_name
+ tags = @document.css("ul#menu a")
+ tags.each {|tag|
+ if tag['href'] == page_name.gsub(/\.markdown$/, '.html')
+ tag['id'] = 'selected'
+ break
+ end
+ }
@document
end
end