Skip to content

Instantly share code, notes, and snippets.

@kapfenho
Created February 15, 2012 14:32
Show Gist options
  • Save kapfenho/1836190 to your computer and use it in GitHub Desktop.
Save kapfenho/1836190 to your computer and use it in GitHub Desktop.
Joomla articles (J2XML) to HTML pages converter, eg Oracle Web Center
###############################################################
# Joomla to Oracle Web Center Content Server transformer
# Thanks to http://railstips.org/
#
gem 'libxml-ruby'
%w[benchmark pp rubygems htmlentities xml].each { |x| require x }
puts Benchmark.measure {
parser = XML::Parser.file('input/input.xml')
doc, list = parser.parse, []
doc.find('//j2xml/content').each do |s|
h = { }
%w[id title alias introtext sectionid catid created modified_by].each do |a|
h[a.intern] = s.find(a).first.content
end
list << h
end
# create doc files
list.each do |item|
f = File::new('output/' + item[:id] + '.html', "w+")
coder = HTMLEntities.new
f << <<-EOS
<h2>
#{coder.decode(item[:title])}</h2>
<h3>
#{coder.decode(item[:alias])}</h3>
<p>
#{coder.decode(item[:introtext])}</p>
EOS
f.close
end
# create batch file
f = File::new('output/batch.txt', "w+")
list.each do |item|
f << <<-EOS
Action=insert
dDocName=HR001
dDocType=Form
dDocTitle=New Employee Information Form
dDocAuthor=Olson
dSecurityGroup=Public
primaryFile=#{item[:id]}.html
dIndate=3/15/97
<<EOD>>
EOS
end
f.close
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment