Skip to content

Commit

Permalink
refactor display_order metanorma/metanorma-bsi#419
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Aug 26, 2023
1 parent c4af84f commit b1e8923
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Gemfile.devel
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "main"
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "features/refactor-display-order"

2 changes: 1 addition & 1 deletion lib/isodoc/ieee/presentation_ref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def biblio_ids_titles(xmldoc)
b.at(ns("./formattedref")))&.text,
author: @author[b["id"]] || (b.at(ns("./title")) ||
b.at(ns("./formattedref")))&.text,
ord: b.at(ns("./docidentifier[@type = 'metanorma' or "\
ord: b.at(ns("./docidentifier[@type = 'metanorma' or " \
"@type = 'metanorma-ordinal']"))&.text }
end
end
Expand Down
14 changes: 0 additions & 14 deletions lib/isodoc/ieee/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,6 @@ def note1(elem)
prefix_name(elem, block_delim, lbl, "name")
end

def display_order(docxml)
i = 0
i = display_order_xpath(docxml, "//preface/*", i)
i = display_order_at(docxml, "//clause[@type = 'overview']", i)
i = display_order_at(docxml, @xrefs.klass.norm_ref_xpath, i)
i = display_order_at(docxml, "//sections/terms | " \
"//sections/clause[descendant::terms]", i)
i = display_order_at(docxml, "//sections/definitions", i)
i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i)
i = display_order_xpath(docxml, "//annex", i)
i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i)
display_order_xpath(docxml, "//indexsect", i)
end

def annex1(elem)
lbl = @xrefs.anchor(elem["id"], :label)
if t = elem.at(ns("./title"))
Expand Down
38 changes: 14 additions & 24 deletions lib/isodoc/ieee/xref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,21 @@ def initialize(lang, script, klass, labels, options)
@hierarchical_assets = options[:hierarchicalassets]
end

def initial_anchor_names(doc)
if @parse_settings.empty? || @parse_settings[:clauses]
doc.xpath(ns("//preface/*")).each do |c|
c.element? and preface_names(c)
end
end
if @parse_settings.empty?
if @hierarchical_assets
hierarchical_asset_names(doc.xpath("//xmlns:preface/child::*"),
"Preface")
else
sequential_asset_names(doc.xpath(ns("//preface/*")))
end
end
if @parse_settings.empty? || @parse_settings[:clauses]
n = Counter.new
n = section_names(doc.at(ns("//clause[@type = 'overview']")), n, 1)
n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1)
n = section_names(doc.at(ns("//sections/terms | " \
"//sections/clause[descendant::terms]")), n, 1)
n = section_names(doc.at(ns("//sections/definitions")), n, 1)
clause_names(doc, n)
end
def clause_order_main(docxml)
[
{ path: "//clause[@type = 'overview']" },
{ path: @klass.norm_ref_xpath },
{ path: "//sections/terms | " \
"//sections/clause[descendant::terms]" },
{ path: "//sections/definitions | " \
"//sections/clause[descendant::definitions][not(descendant::terms)]" },
{ path: @klass.middle_clause(docxml), multi: true },
]
end

def middle_sections
" #{@klass.norm_ref_xpath} | " \
"//sections/terms | //preface/clause | " \
"//sections/terms | " \
"//sections/definitions | //clause[parent::sections]"
end

Expand All @@ -47,10 +34,13 @@ def middle_section_asset_names(doc)
"#{@klass.norm_ref_xpath} | //sections/terms | " \
"//sections/definitions | //clause[parent::sections]"
if @hierarchical_assets
hierarchical_asset_names(doc.xpath("//xmlns:preface/child::*"),
"Preface")
doc.xpath(ns(middle_sections)).each do |c|
hierarchical_asset_names(c, @anchors[c["id"]][:label])
end
else
sequential_asset_names(doc.xpath(ns("//preface/*")))
sequential_asset_names(doc.xpath(ns(middle_sections)))
end
end
Expand Down

0 comments on commit b1e8923

Please sign in to comment.