Class: BookmarkMachine::NetscapeFormatter::Writer
- Inherits:
-
Object
- Object
- BookmarkMachine::NetscapeFormatter::Writer
- Defined in:
- lib/bookmark_machine/netscape_formatter.rb
Overview
:nodoc: This is a simple writer for outputting bookmark appropriate HTML. Since the expected HTML doesn’t have a root, uses a custom doctype, and doesn’t close most tags, it’s easier to just write the output manually rather than try to get Nokogiri to format it poorly for us.
Plus this is just kind of fun in a bizarre un-fun kind of way.
Constant Summary collapse
- HEADER =
" <!DOCTYPE NETSCAPE-Bookmark-file-1>\n <!-- This is an automatically generated file.\n It will be read and overwritten.\n DO NOT EDIT! -->\n <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">\n <TITLE>Bookmarks</TITLE>\n <H1>Bookmarks</H1>\n".gsub(/^ /, "")
Instance Attribute Summary collapse
-
#folders ⇒ Object
readonly
Returns the value of attribute folders.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #<<(bookmark) ⇒ Object
- #done ⇒ Object
-
#initialize(io) ⇒ Writer
constructor
A new instance of Writer.
Constructor Details
#initialize(io) ⇒ Writer
Returns a new instance of Writer.
50 51 52 53 54 55 56 |
# File 'lib/bookmark_machine/netscape_formatter.rb', line 50 def initialize(io) @io = io @folders = [] io.set_encoding(Encoding::UTF_8) start end |
Instance Attribute Details
#folders ⇒ Object (readonly)
Returns the value of attribute folders.
48 49 50 |
# File 'lib/bookmark_machine/netscape_formatter.rb', line 48 def folders @folders end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
47 48 49 |
# File 'lib/bookmark_machine/netscape_formatter.rb', line 47 def io @io end |
Instance Method Details
#<<(bookmark) ⇒ Object
62 63 64 65 |
# File 'lib/bookmark_machine/netscape_formatter.rb', line 62 def << bookmark adjust_folders(bookmark.folders) write_bookmark(bookmark) end |
#done ⇒ Object
58 59 60 |
# File 'lib/bookmark_machine/netscape_formatter.rb', line 58 def done close_all_folders end |