Class: Suma::SchemaAttachment
- Inherits:
-
Object
- Object
- Suma::SchemaAttachment
- Defined in:
- lib/suma/schema_attachment.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#id ⇒ Object
Returns the value of attribute id.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#schema ⇒ Object
Returns the value of attribute schema.
Instance Method Summary collapse
- #clean_artifacts ⇒ Object
-
#compile ⇒ Object
Compile Metanorma adoc per EXPRESS schema.
- #filename_adoc(ext = "adoc") ⇒ Object
- #filename_config ⇒ Object
-
#initialize(schema:, output_path:) ⇒ SchemaAttachment
constructor
A new instance of SchemaAttachment.
- #output_extensions ⇒ Object
- #output_folder ⇒ Object
- #output_xml_path ⇒ Object
- #save_adoc ⇒ Object
- #save_config ⇒ Object
- #to_adoc(path_to_schema_yaml) ⇒ Object
- #to_config(path: nil) ⇒ Object
Constructor Details
#initialize(schema:, output_path:) ⇒ SchemaAttachment
Returns a new instance of SchemaAttachment.
10 11 12 13 14 |
# File 'lib/suma/schema_attachment.rb', line 10 def initialize(schema:, output_path:) @schema = schema @id = schema.id @output_path = output_path end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/suma/schema_attachment.rb', line 8 def config @config end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/suma/schema_attachment.rb', line 8 def id @id end |
#output_path ⇒ Object
Returns the value of attribute output_path.
8 9 10 |
# File 'lib/suma/schema_attachment.rb', line 8 def output_path @output_path end |
#schema ⇒ Object
Returns the value of attribute schema.
8 9 10 |
# File 'lib/suma/schema_attachment.rb', line 8 def schema @schema end |
Instance Method Details
#clean_artifacts ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/suma/schema_attachment.rb', line 116 def clean_artifacts [ filename_config, filename_adoc, filename_adoc("presentation.xml"), filename_adoc("adoc.lutaml.log.txt"), filename_adoc("err.html"), ].each do |filename| FileUtils.rm_rf(filename) end end |
#compile ⇒ Object
Compile Metanorma adoc per EXPRESS schema
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/suma/schema_attachment.rb', line 92 def compile # TODO: Clean artifacts after compiling # I am commenting out because I'm playing with the schemas-only status # return self if File.exist?(output_xml_path) save_config save_adoc relative_path = Pathname.new(filename_adoc).relative_path_from(Dir.pwd) Utils.log "Compiling schema (id: #{id}, type: #{self.class}) => #{relative_path}" Metanorma::Compile.new.compile(filename_adoc, agree_to_terms: true, install_fonts: false) Utils.log "Compiling schema (id: #{id}, type: #{self.class}) => #{relative_path}... done!" # clean_artifacts # filename_adoc('xml') self end |
#filename_adoc(ext = "adoc") ⇒ Object
45 46 47 |
# File 'lib/suma/schema_attachment.rb', line 45 def filename_adoc(ext = "adoc") File.join(@output_path, "doc_#{@schema.id}.#{ext}") end |
#filename_config ⇒ Object
64 65 66 |
# File 'lib/suma/schema_attachment.rb', line 64 def filename_config File.join(@output_path, "schema_#{@schema.id}.yaml") end |
#output_extensions ⇒ Object
16 17 18 |
# File 'lib/suma/schema_attachment.rb', line 16 def output_extensions "xml,html" end |
#output_folder ⇒ Object
128 |
# File 'lib/suma/schema_attachment.rb', line 128 def output_folder; end |
#output_xml_path ⇒ Object
112 113 114 |
# File 'lib/suma/schema_attachment.rb', line 112 def output_xml_path filename_adoc("xml") end |
#save_adoc ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/suma/schema_attachment.rb', line 49 def save_adoc relative_path = Pathname.new(filename_adoc).relative_path_from(Dir.pwd) Utils.log "Save EXPRESS adoc: #{relative_path}" # return if File.exist?(filename_adoc) FileUtils.mkdir_p(File.dirname(filename_adoc)) relative_path = Pathname.new(filename_config) .relative_path_from(Pathname.new(File.dirname(filename_adoc))) # Utils.log "relative_path #{relative_path}" File.write(filename_adoc, to_adoc(relative_path)) end |
#save_config ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/suma/schema_attachment.rb', line 80 def save_config relative_path = Pathname.new(filename_config).relative_path_from(Dir.pwd) Utils.log "Save schema config: #{relative_path}" # Still overwrite even if the file exists # return if File.exist?(filename_config) FileUtils.mkdir_p(File.dirname(filename_config)) to_config.save_to_path(filename_config) end |
#to_adoc(path_to_schema_yaml) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/suma/schema_attachment.rb', line 20 def to_adoc(path_to_schema_yaml) " = \#{@id}\n :lutaml-express-index: schemas; \#{path_to_schema_yaml};\n :bare: true\n :mn-document-class: iso\n :mn-output-extensions: \#{output_extensions}\n\n [lutaml_express_liquid,schemas,context]\n ----\n {% for schema in context.schemas %}\n\n [%unnumbered]\n == \#{@id}\n\n [source%unnumbered]\n --\n {{ schema.formatted }}\n --\n {% endfor %}\n ----\n\n HEREDOC\nend\n" |
#to_config(path: nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/suma/schema_attachment.rb', line 68 def to_config(path: nil) # return @config unless @config @config = Expressir::SchemaManifest.new @config.schemas << Expressir::SchemaManifestEntry.new( id: @schema.id, path: @schema.path, ) path and @config.path = path @config end |