-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.rb
executable file
·60 lines (44 loc) · 1.29 KB
/
parser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# Add current path to load path
# https://github.com/komagata/lokka/blob/master/init.rb
$:.unshift File.dirname(__FILE__)
require 'pp'
require 'zipruby'
require 'nokogiri'
SRC_DIR = File.dirname(__FILE__)
module XMorgDown
class Parser
attr_accessor :file_xmind
attr_reader :xml_content, :html_output
CONTENT_XML_FILE = "content.xml"
XSLT_FILE = "#{SRC_DIR}/content.xsl"
def initialize(file_xmind)
Dir::chdir(".")
@file_xmind = file_xmind
@xslt = File.read(XSLT_FILE)
@nokogiri_xslt = Nokogiri::XSLT(@xslt)
@xml_content = ''
@html_output = ''
end
## Parse a XMind XML and convert it to html
def parse()
## Read XMind file as a zip file
Zip::Archive.open(@file_xmind) do |ar|
ar.fopen(CONTENT_XML_FILE) do |f|
@xml_content = f.read
end
end
## Parse XMind XML with Nokogiri and XSLT
nokogiri_xml = Nokogiri::XML(@xml_content)
@html_output = @nokogiri_xslt.apply_to(nokogiri_xml).to_s
end
end
end
## main
if __FILE__ == $PROGRAM_NAME
## for test
file_xmind = "/Users/yuki/Dropbox/Projects/app_dev/MOrgDown/data/12.07.16_MOrgDown_idea.xmind"
parser = XMorgDown::Parser.new(file_xmind)
parser.parse()
end