Skip to content

Commit

Permalink
Pass baseassetpath to PDF generation if not explicit in arguments but…
Browse files Browse the repository at this point in the history
… inferred from filepath: metanorma/metanorma#407
  • Loading branch information
opoudjis committed Aug 28, 2024
1 parent 3aa0391 commit 40b1e9e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
10 changes: 8 additions & 2 deletions lib/isodoc/xslfo_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ def pdf_stylesheet(_docxml)
nil
end

def pdf_options(_docxml)
def baseassetpath(filename)
!@baseassetpath && filename and
@baseassetpath = File.expand_path(Pathname.new(filename).parent.to_s)
end

def pdf_options(_docxml, filename)
baseassetpath(filename)
ret = {}
font_manifest = @options.dig(MN_OPTIONS_KEY, MN2PDF_FONT_MANIFEST) and
ret[MN2PDF_FONT_MANIFEST] = font_manifest
Expand All @@ -61,7 +67,7 @@ def convert(input_fname, file = nil, debug = false,
@doctype = Nokogiri::XML(file).at(ns("//bibdata/ext/doctype"))&.text
::Metanorma::Output::XslfoPdf.new.convert(
filename, output_fname || output_filename(input_fname),
xsl, pdf_options(docxml)
xsl, pdf_options(docxml, input_fname)
)
end

Expand Down
25 changes: 19 additions & 6 deletions spec/isodoc/xslfo_convert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
)

expect(convert.pdf_options(nil)).to eq({ "--syntax-highlight": nil })
expect(convert.pdf_options(nil, nil)).to eq({ "--syntax-highlight": nil })
end

it "test default pdf_options for nil font_manifest_file" do
Expand All @@ -21,7 +21,7 @@
},
)

expect(convert.pdf_options(nil)).to eq({ "--syntax-highlight": nil })
expect(convert.pdf_options(nil, nil)).to eq({ "--syntax-highlight": nil })
end

it "test --font-manifest pdf_options" do
Expand All @@ -36,7 +36,7 @@
},
)

expect(convert.pdf_options(nil)).to eq(mn2pdf_opts)
expect(convert.pdf_options(nil, nil)).to eq(mn2pdf_opts)
end

it "test --param align-cross-elements pdf_options" do
Expand All @@ -47,7 +47,7 @@
},
)

expect(convert.pdf_options(nil))
expect(convert.pdf_options(nil, nil))
.to eq({ "--param align-cross-elements=" => "clause table note",
"--syntax-highlight": nil })
end
Expand All @@ -60,9 +60,22 @@
},
)

expect(convert.pdf_options(nil))
expect(convert.pdf_options(nil, nil))
.to eq({ "--param baseassetpath=" => "ABC",
"--syntax-highlight": nil })

convert = IsoDoc::XslfoPdfConvert.new(
{
datauriimage: false,
},
)

expect(convert.pdf_options(nil, nil))
.to eq({ "--syntax-highlight": nil })

expect(convert.pdf_options(nil, "test.xml"))
.to eq({ "--param baseassetpath=" => File.expand_path("."),
"--syntax-highlight": nil })
end

it "test pdf encryption options" do
Expand All @@ -83,7 +96,7 @@
},
)

expect(convert.pdf_options(nil))
expect(convert.pdf_options(nil, nil))
.to eq({
"--allow-access-content" => "i",
"--allow-assemble-document" => "j",
Expand Down

0 comments on commit 40b1e9e

Please sign in to comment.