Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ Gemfile.lock
.rspec_status
spec/assets/lutaml
test.err
test.err.html
TODO.cleanup/
pkg/

.rubocop-https--*
.DS_Store
Expand Down
100 changes: 50 additions & 50 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2026-05-12 14:53:16 UTC using RuboCop version 1.86.1.
# on 2026-05-13 23:15:25 UTC using RuboCop version 1.86.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -12,75 +12,67 @@ Gemspec/RequireMFA:
Exclude:
- 'metanorma-plugin-lutaml.gemspec'

# Offense count: 1
# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: with_first_argument, with_fixed_indentation
Layout/ArgumentAlignment:
Exclude:
- 'lib/metanorma/plugin/lutaml/lutaml_klass_table_block_macro.rb'
- 'spec/regen_expected.rb'
- 'spec/regen_expected_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/ClosingParenthesisIndentation:
# Configuration parameters: IndentationWidth.
Layout/AssignmentIndentation:
Exclude:
- 'lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb'
- 'lib/metanorma/plugin/lutaml/base_preprocessor.rb'

# Offense count: 1
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLines:
Exclude:
- 'lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
Layout/FirstArgumentIndentation:
Exclude:
- 'lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb'
- 'spec/regen_expected.rb'

# Offense count: 9
# Offense count: 12
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Layout/LineLength:
Exclude:
- 'Rakefile'
- 'lib/metanorma/plugin/lutaml/base_preprocessor.rb'
- 'lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb'
- 'lib/metanorma/plugin/lutaml/lutaml_klass_table_block_macro.rb'
- 'lib/metanorma/plugin/lutaml/utils.rb'
- 'spec/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor_spec.rb'
- 'spec/metanorma/plugin/lutaml/lutaml_xsd_preprocessor_spec.rb'
- 'spec/regen_expected.rb'
- 'spec/regen_expected_spec.rb'
- 'spec/support/shared_examples/structured_data_2_text_preprocessor.rb'

# Offense count: 1
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: symmetrical, new_line, same_line
Layout/MultilineMethodCallBraceLayout:
# SupportedStyles: final_newline, final_blank_line
Layout/TrailingEmptyLines:
Exclude:
- 'lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb'
- 'Gemfile'
- 'spec/regen_expected.rb'

# Offense count: 3
# Offense count: 5
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowInHeredoc.
Layout/TrailingWhitespace:
Exclude:
- 'lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb'
- 'lib/metanorma/plugin/lutaml/lutaml_klass_table_block_macro.rb'
- 'lib/metanorma/plugin/lutaml/base_preprocessor.rb'
- 'spec/regen_expected.rb'
- 'spec/regen_expected_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods, NotImplementedExceptions.
# NotImplementedExceptions: NotImplementedError
Lint/UnusedMethodArgument:
Exclude:
- 'lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb'

# Offense count: 1
# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
Metrics/AbcSize:
Exclude:
- 'lib/metanorma/plugin/lutaml/lutaml_xsd_preprocessor.rb'
- 'lib/metanorma/plugin/lutaml/utils.rb'

# Offense count: 2
Expand All @@ -90,7 +82,7 @@ Metrics/CyclomaticComplexity:
- 'lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb'
- 'lib/metanorma/plugin/lutaml/utils.rb'

# Offense count: 3
# Offense count: 7
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 19
Expand Down Expand Up @@ -118,12 +110,6 @@ Naming/PredicateMethod:
- 'lib/metanorma/plugin/lutaml/asciidoctor/preprocessor.rb'
- 'lib/metanorma/plugin/lutaml/liquid/custom_filters/file_exist.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Performance/AncestorsInclude:
Exclude:
- 'lib/metanorma/plugin/lutaml/utils.rb'

# Offense count: 86
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
Expand All @@ -141,10 +127,16 @@ RSpec/ContextWording:
- 'spec/metanorma/plugin/lutaml/macros_data2text_spec.rb'
- 'spec/support/shared_examples/structured_data_2_text_preprocessor.rb'

# Offense count: 37
# Offense count: 1
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- 'spec/regen_expected_spec.rb'

# Offense count: 40
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 26
Max: 38

# Offense count: 13
# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
Expand All @@ -169,11 +161,11 @@ RSpec/LeakyLocalVariable:
- 'spec/metanorma/plugin/lutaml/lutaml_uml_datamodel_description_preprocessor_spec.rb'
- 'spec/metanorma/plugin/lutaml/lutaml_xmi_index_spec.rb'

# Offense count: 14
# Offense count: 16
RSpec/MultipleExpectations:
Max: 6

# Offense count: 9
# Offense count: 15
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 8
Expand All @@ -191,11 +183,17 @@ RSpec/NamedSubject:
- 'spec/metanorma/plugin/lutaml/lutaml_xmi_index_spec.rb'
- 'spec/metanorma/plugin/lutaml/source_extractor_spec.rb'

# Offense count: 117
# Offense count: 124
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 7

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
RSpec/Output:
Exclude:
- 'spec/regen_expected.rb'

# Offense count: 1
RSpec/PendingWithoutReason:
Exclude:
Expand Down Expand Up @@ -225,14 +223,16 @@ RSpec/SubjectDeclaration:

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantBegin:
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb'
- 'metanorma-plugin-lutaml.gemspec'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Style/StringLiteralsInInterpolation:
Exclude:
- 'metanorma-plugin-lutaml.gemspec'
- 'spec/metanorma/plugin/lutaml/lutaml_xsd_preprocessor_spec.rb'
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ gem "simplecov"
gem "timecop"
gem "vcr"
gem "webmock"

22 changes: 13 additions & 9 deletions lib/metanorma/plugin/lutaml/base_preprocessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module Lutaml
class BasePreprocessor < ::Asciidoctor::Extensions::Preprocessor
include Utils

FILE_SYSTEM_PATTERNS = ["%s.liquid", "_%s.liquid", "_%s.adoc"].freeze

def process(document, reader)
input_lines = Asciidoctor::PreprocessorNoIfdefsReader
.new(document, reader.lines).readlines.to_enum
Expand Down Expand Up @@ -75,6 +77,15 @@ def index_missing_message(path)
"please specify the full path."
end

def build_file_system(document, options)
include_paths = [Utils.relative_file_path(document, "")]
options["include_path"]&.split(",")&.each do |path|
include_paths.push(Utils.relative_file_path(document, path))
end
::Metanorma::Plugin::Lutaml::Liquid::LocalFileSystem
.new(include_paths, FILE_SYSTEM_PATTERNS)
end

private

def process_input_lines(document:, input_lines:, express_indexes:)
Expand Down Expand Up @@ -151,16 +162,9 @@ def render_liquid_template(document:, lines:, context_name:, # rubocop:disable M
options: options.merge("document" => document)
)

include_paths = [Utils.relative_file_path(document, "")]
options["include_path"]&.split(",")&.each do |path|
include_paths.push(Utils.relative_file_path(document, path))
end

file_system = ::Metanorma::Plugin::Lutaml::Liquid::LocalFileSystem
.new(include_paths, ["%s.liquid", "_%s.liquid", "_%s.adoc"])

parsed_template = template(lines)
parsed_template.registers[:file_system] = file_system
parsed_template.registers[:file_system] =
build_file_system(document, options)

all_items.map do |item|
parsed_template.assigns[context_name] = item[:liquid_drop]
Expand Down
54 changes: 54 additions & 0 deletions lib/metanorma/plugin/lutaml/lutaml_xsd_preprocessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module Lutaml
# lutaml-model's XSD parser and exposes the schema object to Liquid
# templates.
#
# Two syntaxes are supported:
# Block: [lutaml_xsd, path, context, options] .... ----
# Direct: lutaml_xsd::path[context, template, options]
#
# Caching: parsed XSD results are cached at two levels:
# - Class-level (@@xsd_cache) persists across document invocations
# - Document-level (document.attributes["lutaml_xsd_cache"]) within a
Expand All @@ -26,6 +30,19 @@ class LutamlXsdPreprocessor < BasePreprocessor
\] # Closing bracket
}x

XSD_DIRECT_REGEX = %r{
^\s* # Start of line
lutaml_xsd:: # Macro prefix
(?<file_path>[^\[]+?) # XSD file path
\[ # Opening bracket
(?<context_name>[^,]+) # Context name
,\s* # Comma separator
(?<template>[^,\]]+) # Template file path
(?<options>,[^\]]+)? # Optional options
\] # Closing bracket
\s*$ # End of line
}x

def initialize(_config = {})
super
@@xsd_cache ||= {}
Expand Down Expand Up @@ -71,6 +88,43 @@ def template(lines)

private

def process_text_blocks(document, input_lines, express_indexes)
match = xsd_direct?(input_lines.peek)
return handle_direct_block(document, input_lines, match) if match

super
end

def xsd_direct?(line)
line.match(XSD_DIRECT_REGEX)
end

def handle_direct_block(document, input_lines, match)
input_lines.next # consume the matched line

file_path = match[:file_path].strip
context_name = match[:context_name].strip
template_file = Utils.relative_file_path(document,
match[:template].strip)
options = match[:options] ? parse_options(match[:options].strip) : {}

schema = load_lutaml_file(document, file_path, options)
schema_drop = update_repo(options, schema).to_liquid

template_source = File.read(template_file, encoding: "UTF-8")
tmpl = template([template_source])
tmpl.registers[:file_system] = build_file_system(document, options)
tmpl.assigns[context_name] = schema_drop

tmpl.render.split("\n", -1)
rescue StandardError => e
::Metanorma::Util.log(
"[#{self.class.name}] Failed to parse LutaML block: #{e.message}",
:error,
)
raise e
end

def parse_xsd_file(full_path, location)
File.open(full_path, "r:UTF-8") do |file|
::Lutaml::Xml::Parsers::Xsd.parse(file, location: location)
Expand Down
2 changes: 1 addition & 1 deletion metanorma-plugin-lutaml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ Gem::Specification.new do |spec|
spec.add_dependency "ogc-gml", "~> 1.1"
spec.add_dependency "relaton-cli"

spec.metadata["rubygems_mfa_required"] = "false"
spec.metadata["rubygems_mfa_required"] = "true"
end
Loading
Loading