Module: XOXO

Defined in:
lib/xoxo.rb

Overview

XOXO is a Ruby XOXO parser and generator. It provides a Ruby API similar to Marshal and YAML (though more specific) to load and dump XOXO, an simple, open outline format written in standard XHTML and suitable for embedding in (X)HTML, Atom, RSS, and arbitrary XML.

Defined Under Namespace

Classes: Parser

Constant Summary collapse

VERSION =

xoxo.rb version number

"1.0.1"

Class Method Summary collapse

Class Method Details

.dump(struct, options = {}) ⇒ Object

Return a XOXO string corresponding to the Ruby object struct, translated to the following rules:

  • Arrays become ordered lists <ol>.

  • Hashes become definition lists <dl>, keys are stringified with to_s.

  • Everything else becomes stringified with to_s and wrapped in appropriate list elements (<li> or <dt>/<dd>).

Additionally, you can pass these options on the options hash:

:html_wrap => true

Wrap the XOXO with a basic XHTML 1.0 Transitional header.

:css => css

Reference css as stylesheet for the wrapped XOXO document.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/xoxo.rb', line 53

def self.dump(struct, options={})
  struct = [struct]  unless struct.kind_of? Array

  if options[:html_wrap]
    result = <<EOF.strip
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head profile=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
EOF
    if options[:css]
      result << %Q[<style type="text/css" >@import "#{options[:css]}";</style>]
    end

    result << "</head><body>" << make_xoxo(struct, 'xoxo') << "</body></html>"
  else
    result = make_xoxo(struct, 'xoxo')
  end

  result
end

.load(xoxo) ⇒ Object

Load and return a XOXO structure from the String, IO or StringIO or xoxo.



30
31
32
33
34
35
36
# File 'lib/xoxo.rb', line 30

def self.load(xoxo)
  structs = Parser.new(xoxo).parse.structs
  while structs.kind_of?(Array) && structs.size == 1
    structs = structs.first
  end
  structs
end