Module: RDF::Vocabulary::VocabFormatExtensions
- Defined in:
- lib/rdf/vocab/extensions.rb
Instance Method Summary collapse
-
#cli_commands ⇒ Hash{Symbol => Lambda(Array, Hash)}
Hash of CLI commands appropriate for this format.
Instance Method Details
#cli_commands ⇒ Hash{Symbol => Lambda(Array, Hash)}
Hash of CLI commands appropriate for this format
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
# File 'lib/rdf/vocab/extensions.rb', line 444 def cli_commands super.merge({ "gen-vocab": { description: "Generate a vocabulary using a special serialization.", parse: false, # Only parse if there are input files, otherwise, uses vocabulary help: "gen-vocab --uri <vocabulary-URI> [--output format ttl|jsonld|html] [options] [files]\nGenerate a vocabulary from repository using a special serialization.", lambda: ->(files, ) do $stdout.puts "Generate Vocabulary" raise ArgumentError, "Must specify vocabulary URI" unless [:base_uri] # Parse input graphs, if repository is not already created if RDF::CLI.repository.empty? && !files.empty? RDF::CLI.parse(files, ) do |reader| RDF::CLI.repository << reader end end # Lookup vocabulary, or generate a new vocabulary from this URI vocab = RDF::Vocabulary.find([:base_uri]) || begin raise ArgumentError, "Must specify vocabulary prefix if vocabulary not built-in" unless [:prefix] RDF::Vocabulary.from_graph(RDF::CLI.repository, url: [:base_uri], class_name: [:prefix].to_s.upcase) end prefixes = {} prefixes[[:prefix]] = [:base_uri] if [:prefix] out = [:output] || $stdout case [:output_format] when :ttl, nil then out.write vocab.to_ttl(graph: RDF::CLI.repository, prefixes: prefixes) when :jsonld then out.write vocab.to_jsonld(graph: RDF::CLI.repository, prefixes: prefixes) when :html then out.write vocab.to_html(graph: RDF::CLI.repository, prefixes: prefixes, template: [:template]) else # Use whatever writer we find writer = RDF::Writer.for([:output_format]) || RDF::NTriples::Writer writer.new(out, ) do |w| if RDF::CLI.repository.empty? vocab.each_statement {|s| w << s} else w << RDF::CLI.repository end end end end, options: [ RDF::CLI::Option.new( symbol: :prefix, datatype: String, on: ["--prefix PREFIX"], description: "Prefix associated with vocabulary, if not built-in."), RDF::CLI::Option.new( symbol: :template, datatype: String, on: ["--template TEMPLATE"], description: "Path to local template for generating HTML, either Haml or ERB, depending on file extension.\n" + "See https://github.com/ruby-rdf/rdf-vocab/tree/develop/etc for built-in templates."), ] } }) end |