lib/asciidoctor/rfc/common/base.rb in metanorma-ietf-1.0.6 vs lib/asciidoctor/rfc/common/base.rb in metanorma-ietf-1.0.8
- old
+ new
@@ -2,12 +2,12 @@
require "nokogiri"
require "htmlentities"
require "json"
require "pathname"
require "open-uri"
-require "pp"
require "set"
+require "fileutils"
module Asciidoctor
module Rfc::Common
module Base
def convert(node, transform = nil, opts = {})
@@ -372,11 +372,11 @@
end
"??"
end
def cache_workgroup(node)
- wgcache_name = "#{Dir.home}/.asciidoc-rfc-workgroup-cache.json"
+ wgcache_name = "#{Dir.home}/.metanorma-ietf-workgroup-cache.json"
# If we are required to, clear the wg cache
if node.attr("flush-caches") == "true"
FileUtils.rm wgcache_name, :force => true
end
# Is there already a wg cache? If not, create it.
@@ -416,21 +416,27 @@
end
wg
end
def cache_biblio(node)
- bibliocache_name = "#{Dir.home}/.asciidoc-rfc-biblio-cache.json"
+ bibliocache_name = "#{Dir.home}/.metanorma-ietf-biblio-cache.json"
# If we are required to, clear the biblio cache
if node.attr("flush-caches") == "true"
system("rm -f #{bibliocache_name}")
end
# Is there already a biblio cache? If not, create it.
biblio = {}
if Pathname.new(bibliocache_name).file?
+ begin
File.open(bibliocache_name, "r") do |f|
biblio = JSON.parse(f.read)
end
- else
+ rescue Exception => e
+ warn "JSON in #{bibliocache_name} is corrupt: deleting"
+ end
+ end
+
+ if biblio.empty?
File.open(bibliocache_name, "w") do |b|
STDERR.puts "Reading references from https://xml2rfc.tools.ietf.org/public/rfc/bibxml/..."
Kernel.open("https://xml2rfc.tools.ietf.org/public/rfc/bibxml/") do |f|
# I'm just working off the ls output
f.each_line do |line|