lib/metanorma/plugin/glossarist/dataset_preprocessor.rb in metanorma-plugin-glossarist-0.1.8 vs lib/metanorma/plugin/glossarist/dataset_preprocessor.rb in metanorma-plugin-glossarist-0.2.0

- old
+ new

@@ -63,22 +63,21 @@ @datasets = {} @rendered_bibliographies = {} end def process(document, reader) - input_lines = reader.readlines.to_enum + input_lines = reader.lines.to_enum file_system = ::Liquid::LocalFileSystem.new( relative_file_path(document, ""), ) @config[:file_system] = file_system processed_doc = prepare_document(document, input_lines) - Asciidoctor::Reader.new( - processed_doc.to_s.split("\n"), - ) + Asciidoctor::PreprocessorReader.new(document, + processed_doc.to_s.split("\n")) end private def prepare_document(document, input_lines, end_mark = nil) @@ -174,40 +173,40 @@ dataset = @datasets[context_name.strip] liquid_doc.add_content( dataset.concepts.map do |concept_name, _concept| concept_template(context_name, concept_name) - end.join("\n") + end.join("\n"), ) end def process_bibliography(liquid_doc, match) dataset_name = match[1].strip dataset = @datasets[dataset_name] liquid_doc.add_content( dataset.concepts.map do |_concept_name, concept| concept_bibliography(concept) - end.compact.sort.join("\n") + end.compact.sort.join("\n"), ) end def process_bibliography_entry(liquid_doc, match) dataset_name, concept_name = match[1].split(",").map(&:strip) concept = @datasets[dataset_name][concept_name] liquid_doc.add_content( - concept_bibliography(concept) + concept_bibliography(concept), ) end def concept_bibliography(concept) bibliography = concept["eng"]["sources"].map do |source| ref = source["origin"]["ref"] next if @rendered_bibliographies[ref] - @rendered_bibliographies[ref] = ref.gsub(/[ \/:]/, '_') + @rendered_bibliographies[ref] = ref.gsub(/[ \/:]/, "_") "* [[[#{@rendered_bibliographies[ref]},#{ref}]]]" end.compact.join("\n") bibliography == "" ? nil : bibliography end