-
Notifications
You must be signed in to change notification settings - Fork 22
/
Rakefile
95 lines (77 loc) · 2.66 KB
/
Rakefile
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Author: Nicholas Long
# Specific gems used elsewhere
require 'nokogiri'
require 'rubyXL'
require 'pp'
require 'json'
require 'csv'
# Local files
require_relative 'src/data_dictionary'
desc 'generate data dictionary'
task :generate_data_dictionary do
dd = DataDictionary.new
dd.generate
end
desc 'Convert tabs to spaces'
task :remove_tabs do
Dir['examples/**/*.xml', 'BuildingSync.xsd', 'proposals/**/*.xml'].each do |file|
puts " Cleaning #{file}"
doc = Nokogiri.XML(File.read(file)) do |config|
config.default_xml.noblanks
end
doc.xpath('//comment()').each do |node|
if node.text =~ /XMLSpy/
node.remove
end
end
File.open(file, 'w') { |f| f << doc.to_xml(:indent => 2) }
end
if File.exist? "BuildingSync.json"
f = JSON.parse(File.read('BuildingSync.json'))
File.open('BuildingSync.json', 'w') do |file|
file << JSON.pretty_generate(f)
end
end
end
csv_filename = "./schema_documentation.csv"
desc 'Generate CSV of the schema\'s documentation elements'
task :generate_documentation_csv do
# WARNING: this task is coupled with the `update_documentation` task
CSV.open(csv_filename, "w") do |csv|
csv << ["file_line", "original_documentation", "updated_documentation", "xpath"]
doc = Nokogiri.XML(File.read("BuildingSync.xsd")) do |config|
config.default_xml.noblanks
end
doc.xpath('//xs:documentation', 'xs' => 'http://www.w3.org/2001/XMLSchema').each do |node|
csv << ["BuildingSync.xsd:%d" % [node.line], node.text, '', node.path]
end
end
end
desc 'Update schema\'s documentation elements from CSV'
task :update_documentation do
# WARNING: this task is coupled with the `generate_documentation_csv` task
doc = Nokogiri.XML(File.read("BuildingSync.xsd")) do |config|
config.default_xml.noblanks
end
csv_row_number = 1
CSV.foreach(csv_filename, :headers => :first_row) do |row|
csv_row_number += 1
updated_documentation = row.field("updated_documentation")
if updated_documentation == nil || updated_documentation.length == 0
next
end
documentation_elem = doc.xpath(row.field("xpath"))
if documentation_elem.length != 1
raise "%s:%d Xpath returned an unexpected number of elements (expected one)" % [csv_filename, csv_row_number]
end
documentation_elem[0].content = updated_documentation
end
File.open("BuildingSync.xsd", 'w') { |f| f << doc.to_xml(:indent => 2) }
end
require 'rspec/core/rake_task'
# require 'ci/reporter/rake/rspec' # Always create spec reports
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.rspec_opts = ['--format', 'progress']
spec.pattern = FileList['spec/**/*_spec.rb']
end
task :default => :spec