Closed ronaldtse closed 2 months ago
There is currently one failure:
1) Sts round-trips TBX-ISO-TML example file
Failure/Error:
expect(Xml::C14n.format(generated))
.to be_analogous_with(Xml::C14n.format(doc))
DIFF 1: expected node: <tbx:break/>
actual node :
diff from : <tbx:break/>
diff to :
DIFF 2: expected node: <tbx:break/>
actual node :
diff from : <tbx:break/>
diff to :
# ./spec/sts_spec.rb:38:in `block (2 levels) in <top (required)>'
Finished in 4.77 seconds (files took 0.11461 seconds to load)
7 examples, 1 failure
This failure is due to the file at:
This file actually does not contain an element called <tbx:break/>
. However, in the code of table_wrap.rb
, it looks like this:
module Sts
module TbxIsoTml
class Th < Sts::Mapper
attribute :content, Lutaml::Model::Type::String
attribute :colspan, Lutaml::Model::Type::String
attribute :align, Lutaml::Model::Type::String
attribute :scope, Lutaml::Model::Type::String
attribute :style, Lutaml::Model::Type::String
attribute :rowspan, Lutaml::Model::Type::String
attribute :break, Lutaml::Model::Type::String
attribute :content_type, Lutaml::Model::Type::String
attribute :char, Lutaml::Model::Type::String
attribute :charoff, Lutaml::Model::Type::String
attribute :valign, Lutaml::Model::Type::String
attribute :italic, Italic
attribute :bold, Bold
attribute :std, Sts::NisoSts::ReferenceStandard
attribute :xref, Xref
attribute :inline_formula, Sts::NisoSts::InlineFormula, collection: true
xml do
root "th", mixed: true
map_content to: :content
map_attribute "colspan", to: :colspan
map_attribute "align", to: :align
map_attribute "scope", to: :scope
map_attribute "style", to: :style
map_attribute "rowspan", to: :rowspan
map_attribute "content-type", to: :content_type
map_attribute "char", to: :char
map_attribute "charoff", to: :charoff
map_attribute "valign", to: :valign
map_element "break", to: :break, render_nil: true
map_element "italic", to: :italic
map_element "bold", to: :bold
map_element "std", to: :std
map_element "xref", to: :xref
map_element "inline-formula", to: :inline_formula
end
end
end
end
Where the blank
element is handled as a render_nil
. This means that if the element doesn't exist, it will still be rendered.
So this is a lutaml-model weakness -- this blank
element needs to be reproduced when it exists, but not reproduced when it is not present:
blank
is not a Boolean because it has no true/false
valuesblank
is not a render_nil
issue because when it does not exist, it should not exist in the serialized content.I think we need a new "value type" in Lutaml::Model to handle this?
Thoughts @HassanAkbar ?
@ronaldtse I think this is a good idea, we can add a Blank
or Empty
type and set that when the element is found and is empty.
Then we will only render if the value is not nil.
Is this the correct approach?
@HassanAkbar yes I think so. Or is it just this:
class Break < Lutaml::Model::Serialize
xml do
end
end
@HassanAkbar I've fixed it with the empty element approach, so it's just this:
module Sts
module TbxIsoTml
class TableBreak < Lutaml::Model::Serializable
end
end
end
module Sts
module TbxIsoTml
class Th < Lutaml::Model::Serializable
# ...
attribute :break, TableBreak
# ...
xml do
# ...
map_element "break", to: :break
# ...
end
end
end
end
Merging first.
Metanorma PR checklist