Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging: https://github.com/metanorma/metanorma-plugin-glossarist/iss… #28

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/metanorma/plugin/glossarist/dataset_preprocessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def initialize(config = {})
@config = config
@datasets = {}
@rendered_bibliographies = {}
@seen_glossarist = []
end

def process(document, reader)
Expand All @@ -73,10 +74,19 @@ def process(document, reader)
@config[:file_system] = file_system

processed_doc = prepare_document(document, input_lines)
log(document, processed_doc.to_s) unless @seen_glossarist.empty?
Asciidoctor::PreprocessorReader.new(document,
processed_doc.to_s.split("\n"))
end

protected

def log(doc, text)
File.open("#{doc.attr('docfile')}.glossarist.log.txt", "w:UTF-8") do |f|
f.write(text)
end
end

private

def prepare_document(document, input_lines, end_mark = nil)
Expand Down Expand Up @@ -114,6 +124,7 @@ def process_line(document, input_lines, current_line, liquid_doc)
end

def process_dataset_tag(document, input_lines, liquid_doc, match)
@seen_glossarist << "x"
context_names = prepare_dataset_contexts(document, match[1])

dataset_section = <<~TEMPLATE
Expand All @@ -129,6 +140,7 @@ def process_dataset_tag(document, input_lines, liquid_doc, match)
end

def process_glossarist_block(document, liquid_doc, input_lines, match)
@seen_glossarist << "x"
end_mark = input_lines.next
path = relative_file_path(document, match[1])

Expand Down Expand Up @@ -160,6 +172,7 @@ def prepare_glossarist_block_params(document, match)
end

def process_render_tag(liquid_doc, match)
@seen_glossarist << "x"
context_name, concept_name = match[1].split(",")

liquid_doc.add_content(
Expand All @@ -168,6 +181,7 @@ def process_render_tag(liquid_doc, match)
end

def process_import_tag(liquid_doc, match)
@seen_glossarist << "x"
context_name = match[1].strip
dataset = @datasets[context_name.strip]

Expand All @@ -179,6 +193,7 @@ def process_import_tag(liquid_doc, match)
end

def process_bibliography(liquid_doc, match)
@seen_glossarist << "x"
dataset_name = match[1].strip
dataset = @datasets[dataset_name]

Expand All @@ -190,6 +205,7 @@ def process_bibliography(liquid_doc, match)
end

def process_bibliography_entry(liquid_doc, match)
@seen_glossarist << "x"
dataset_name, concept_name = match[1].split(",").map(&:strip)
concept = @datasets[dataset_name][concept_name]

Expand Down
1 change: 1 addition & 0 deletions metanorma-plugin-glossarist.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "glossarist", "~> 2.0.1"
spec.add_dependency "liquid", "~> 5"

spec.add_development_dependency "metanorma-standoc"
spec.add_development_dependency "pry"
spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency "rspec", "~> 3.0"
Expand Down
37 changes: 37 additions & 0 deletions spec/metanorma/plugin/glossarist/dataset_preprocessor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,43 @@
RSpec.describe Metanorma::Plugin::Glossarist::DatasetPreprocessor do
let(:document) { Asciidoctor::Document.new }

it "log" do
input = <<~TEXT
= Document title
Author
:nodoc:
:novalid:
:no-isobib:
:imagesdir: spec/assets

== Section 1
[glossarist,./spec/fixtures/dataset-glossarist-v2,concepts]
----
=== {{ concepts['entity'].term }}
----
TEXT
FileUtils.rm_rf("test.adoc.glossarist.log.txt")
metanorma_process(input)
expect(File.exist?("test.adoc.glossarist.log.txt")).to be true

input = <<~TEXT
= Document title
Author
:nodoc:
:novalid:
:no-isobib:
:imagesdir: spec/assets

== Section 1
----
=== {{ concepts['entity'].term }}
----
TEXT
FileUtils.rm_rf("test.adoc.glossarist.log.txt")
metanorma_process(input)
expect(File.exist?("test.adoc.glossarist.log.txt")).to be false
end

describe "#process" do
context "Valid concepts" do
context "[glossarist block]" do
Expand Down
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@
c.syntax = :expect
end
end

require "metanorma-standoc"

def metanorma_process(input)
Asciidoctor.convert(input, backend: :standoc, header_footer: true,
agree_to_terms: true, to_file: false, safe: :safe,
attributes: ["nodoc", "stem", "xrefstyle=short",
"docfile=test.adoc",
"output_dir="])
end
Loading