-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdemo.rb
44 lines (35 loc) · 902 Bytes
/
demo.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
require 'crichton'
require 'launchy'
require './db/connection'
require './db/seed'
require './app/models/drd'
require './app/models/drds'
def launch(output, type = :html)
output_file = "./tmp/output.#{type}"
file = File.open(output_file, 'w')
if type == :html
file.write(output)
else
pretty_xml(output, file)
end
file. close
Launchy.open(output_file) do |exception|
puts "Attempted to open #{uri} and failed because #{exception}"
end
end
def drds_descriptor
Crichton.registry['drds'].parent_descriptor
end
def show_alps
launch(drds_descriptor.to_xml, :xml)
end
private
def pretty_xml(output, file)
require "rexml/document"
doc = REXML::Document.new(output)
doc.context[:attribute_quote] = :quote
formatter = REXML::Formatters::Pretty.new
# Compact uses as little whitespace as possible
formatter.compact = true
formatter.write(doc, file)
end