Skip to content

Commit

Permalink
Merge pull request #10 from metanorma/refactor/move_common_convert_co…
Browse files Browse the repository at this point in the history
…de_to_single_place

Move comon code from isodoc/*_convert.rb to isodoc/base_convert.rb
  • Loading branch information
opoudjis authored Apr 20, 2019
2 parents eb92a4d + 227e96b commit be72c18
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 125 deletions.
7 changes: 5 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
version: '{build}'

cache:
- vendor/bundle

environment:
matrix:
- RUBY_VERSION: 25
Expand All @@ -17,6 +20,7 @@ install:

build_script:
- set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
- bundle config --local path vendor/bundle
- bundle update
- bundle install

Expand All @@ -26,5 +30,4 @@ before_test:
- bundle -v

test_script:
- bundle exec rake

- bundle exec rake
49 changes: 49 additions & 0 deletions lib/isodoc/csand/base_convert.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require "isodoc"
require_relative "metadata"

module IsoDoc
module Csand
module BaseConvert
def metadata_init(lang, script, labels)
@meta = Metadata.new(lang, script, labels)
end

def annex_name(annex, name, div)
div.h1 **{ class: "Annex" } do |t|
t << "#{get_anchors[annex['id']][:label]} "
t.br
t.b do |b|
name&.children&.each { |c2| parse(c2, b) }
end
end
end

def term_defs_boilerplate(div, source, term, preface)
if source.empty? && term.nil?
div << @no_terms_boilerplate
else
div << term_defs_boilerplate_cont(source, term)
end
end

def i18n_init(lang, script)
super
@annex_lbl = "Appendix"
end

def cleanup(docxml)
super
term_cleanup(docxml)
end

def term_cleanup(docxml)
docxml.xpath("//p[@class = 'Terms']").each do |d|
h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
h2.add_child("&nbsp;")
h2.add_child(d.remove)
end
docxml
end
end
end
end
43 changes: 2 additions & 41 deletions lib/isodoc/csand/html_convert.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative "base_convert"
require "isodoc"
require_relative "metadata"

module IsoDoc
module Csand
Expand Down Expand Up @@ -28,33 +28,6 @@ def default_file_locations(options)
}
end

def metadata_init(lang, script, labels)
@meta = Metadata.new(lang, script, labels)
end

def annex_name(annex, name, div)
div.h1 **{ class: "Annex" } do |t|
t << "#{get_anchors[annex['id']][:label]} "
t.br
t.b do |b|
name&.children&.each { |c2| parse(c2, b) }
end
end
end

def term_defs_boilerplate(div, source, term, preface)
if source.empty? && term.nil?
div << @no_terms_boilerplate
else
div << term_defs_boilerplate_cont(source, term)
end
end

def i18n_init(lang, script)
super
@annex_lbl = "Appendix"
end

def googlefonts()
<<~HEAD.freeze
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet">
Expand All @@ -77,19 +50,7 @@ def html_toc(docxml)
docxml
end

def cleanup(docxml)
super
term_cleanup(docxml)
end

def term_cleanup(docxml)
docxml.xpath("//p[@class = 'Terms']").each do |d|
h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
h2.add_child("&nbsp;")
h2.add_child(d.remove)
end
docxml
end
include BaseConvert
end
end
end
Expand Down
43 changes: 2 additions & 41 deletions lib/isodoc/csand/pdf_convert.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative "base_convert"
require "isodoc"
require_relative "metadata"

module IsoDoc
module Csand
Expand Down Expand Up @@ -28,33 +28,6 @@ def default_file_locations(options)
}
end

def metadata_init(lang, script, labels)
@meta = Metadata.new(lang, script, labels)
end

def annex_name(annex, name, div)
div.h1 **{ class: "Annex" } do |t|
t << "#{get_anchors[annex['id']][:label]} "
t.br
t.b do |b|
name&.children&.each { |c2| parse(c2, b) }
end
end
end

def term_defs_boilerplate(div, source, term, preface)
if source.empty? && term.nil?
div << @no_terms_boilerplate
else
div << term_defs_boilerplate_cont(source, term)
end
end

def i18n_init(lang, script)
super
@annex_lbl = "Appendix"
end

def googlefonts()
<<~HEAD.freeze
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet">
Expand All @@ -77,19 +50,7 @@ def html_toc(docxml)
docxml
end

def cleanup(docxml)
super
term_cleanup(docxml)
end

def term_cleanup(docxml)
docxml.xpath("//p[@class = 'Terms']").each do |d|
h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
h2.add_child("&nbsp;")
h2.add_child(d.remove)
end
docxml
end
include BaseConvert
end
end
end
Expand Down
43 changes: 2 additions & 41 deletions lib/isodoc/csand/word_convert.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative "base_convert"
require "isodoc"
require_relative "metadata"

module IsoDoc
module Csand
Expand Down Expand Up @@ -31,46 +31,7 @@ def default_file_locations(options)
}
end

def metadata_init(lang, script, labels)
@meta = Metadata.new(lang, script, labels)
end

def annex_name(annex, name, div)
div.h1 **{ class: "Annex" } do |t|
t << "#{get_anchors[annex['id']][:label]} "
t.br
t.b do |b|
name&.children&.each { |c2| parse(c2, b) }
end
end
end

def term_defs_boilerplate(div, source, term, preface)
if source.empty? && term.nil?
div << @no_terms_boilerplate
else
div << term_defs_boilerplate_cont(source, term)
end
end

def i18n_init(lang, script)
super
@annex_lbl = "Appendix"
end

def cleanup(docxml)
super
term_cleanup(docxml)
end

def term_cleanup(docxml)
docxml.xpath("//p[@class = 'Terms']").each do |d|
h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
h2.add_child("&nbsp;")
h2.add_child(d.remove)
end
docxml
end
include BaseConvert
end
end
end
Expand Down

0 comments on commit be72c18

Please sign in to comment.