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
-
#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_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
#compile ⇒ Object
Compile Metanorma adoc per EXPRESS schema
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/suma/schema_attachment.rb', line 86 def compile 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!" 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
61 62 63 |
# File 'lib/suma/schema_attachment.rb', line 61 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_xml_path ⇒ Object
99 100 101 |
# File 'lib/suma/schema_attachment.rb', line 99 def output_xml_path filename_adoc("xml") end |
#save_adoc ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# 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}" FileUtils.mkdir_p(File.dirname(filename_adoc)) config_relative = Pathname.new(filename_config) .relative_path_from(Pathname.new(File.dirname(filename_adoc))) File.write(filename_adoc, to_adoc(config_relative)) end |
#save_config ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/suma/schema_attachment.rb', line 76 def save_config relative_path = Pathname.new(filename_config).relative_path_from(Dir.pwd) Utils.log "Save schema config: #{relative_path}" 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) <<~HEREDOC = #{@id} :lutaml-express-index: schemas; #{path_to_schema_yaml}; :bare: true :mn-document-class: iso :mn-output-extensions: #{output_extensions} [lutaml_express_liquid,schemas,context] ---- {% for schema in context.schemas %} [%unnumbered] == #{@id} [source%unnumbered] -- {{ schema.formatted }} -- {% endfor %} ---- HEREDOC end |
#to_config(path: nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/suma/schema_attachment.rb', line 65 def to_config(path: nil) @config = Expressir::SchemaManifest.new @config.schemas << Expressir::SchemaManifestEntry.new( id: @schema.id, path: @schema.path, ) path and @config.path = path @config end |