Module: Habl

Defined in:
lib/habl.rb

Constant Summary collapse

INTRO =
'<?xml version="1.0" encoding="utf-8" ?>' + $/
DOCTYPE =
'<!DOCTYPE xbel PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML" "http://www.python.org/topics/xml/dtds/xbel-1.0.dtd">' + $/
OPTIONS =
{ :attr_wrapper => '"', :ugly => true, :autoclose => [], :preserve => [] }

Class Method Summary collapse

Class Method Details

.open(path) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/habl.rb', line 9

def open(path)
  engine = Haml::Engine.new File.read(path), OPTIONS
  xml = engine.render

  unless xml.include? 'DOCTYPE xbel'
    offset = xml.index(INTRO) + INTRO.length
    xml.insert offset, DOCTYPE
  end

  XBEL.parse xml
end