Skip to content

Commit

Permalink
* Use Builder instead of Haml in writer, as Haml 6+ removes support f…
Browse files Browse the repository at this point in the history
…or custom tags.

  * Create sub-class of Builder::XmlMarkup to be able to eliminate surrounding whitespace for XML Literals.
* Use QNames everywhere instead of CURIEs.
* Updates for Ruby 2.6 compatibility.
* Remove obsolete Nokogiri Hacks and Haml Templates.
* Capture Standard output in writer tests.
  • Loading branch information
gkellogg committed Jun 19, 2023
1 parent b9b26b1 commit 8c579c6
Show file tree
Hide file tree
Showing 16 changed files with 483 additions and 330 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Run tests
run: ruby --version; bundle exec rspec spec || $ALLOW_FAILURES
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v1.1.2
uses: coverallsapp/github-action@v2
if: ${{ matrix.ruby == '3.0' && matrix.gemfile == 'Gemfile' }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -3,7 +3,6 @@ source "https://rubygems.org"
gemspec

gem 'rdf', github: "ruby-rdf/rdf", branch: "develop"
gem 'rdf-rdfa', github: "ruby-rdf/rdf-rdfa", branch: "develop"
gem "nokogiri", '~> 1.13', '>= 1.13.4', platforms: [:mri, :jruby]

group :development do
Expand Down
1 change: 0 additions & 1 deletion Gemfile-pure
Expand Up @@ -4,7 +4,6 @@ source "https://rubygems.org"
gemspec

gem 'rdf', github: "ruby-rdf/rdf", branch: "develop"
gem 'rdf-rdfa', github: "ruby-rdf/rdf-rdfa", branch: "develop"

group :development do
gem 'ebnf', github: "dryruby/ebnf", branch: "develop"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -43,8 +43,8 @@ Write a graph to a file:

## Dependencies
* [RDF.rb](https://rubygems.org/gems/rdf) (~> 3.2)
* [Haml](https://rubygems.org/gems/haml) (~>- 5.2)
* Soft dependency on [Nokogiri](https://rubygems.org/gems/nokogiri) (>= 1.12)
* [Builder](https://rubygems.org/gems/builder) (~>- 3.2)
* Soft dependency on [Nokogiri](https://rubygems.org/gems/nokogiri) (>= 1.13)

## Documentation
Full documentation available on [Rubydoc.info][RDF/XML doc])
Expand Down
3 changes: 2 additions & 1 deletion lib/rdf/rdfxml.rb
Expand Up @@ -2,7 +2,8 @@
require 'rdf'

module RDF
autoload :XML, 'rdf/rdfa/vocab'
XML = Class.new(Vocabulary("http://www.w3.org/XML/1998/namespace"))

##
# **`RDF::RDFXML`** is an RDF/XML extension for RDF.rb.
#
Expand Down
54 changes: 54 additions & 0 deletions lib/rdf/rdfxml/extensions.rb
@@ -0,0 +1,54 @@
# Extend builder to allow for better control of whitespace in XML Literals

require 'builder'

module Builder
# Extends XmlMarkup#tag! to better control whitespace when adding content from a block
#
class RdfXml < Builder::XmlMarkup
# Create a tag named +sym+. Other than the first argument which
# is the tag name, the arguments are the same as the tags
# implemented via <tt>method_missing</tt>.
#
# @see https://github.com/jimweirich/builder/blob/master/lib/builder/xmlbase.rb
def tag!(sym, *args, &block)
text = nil
attrs = args.last.is_a?(::Hash) ? args.last : {}
return super unless block && attrs[:no_whitespace]
attrs.delete(:no_whitespace)

sym = "#{sym}:#{args.shift}".to_sym if args.first.kind_of?(::Symbol)

args.each do |arg|
case arg
when ::Hash
attrs.merge!(arg)
when nil
attrs.merge!({:nil => true}) if explicit_nil_handling?
else
text ||= ''
text << arg.to_s
end
end

unless text.nil?
::Kernel::raise ::ArgumentError,
"XmlMarkup cannot mix a text argument with a block"
end

# Indent
_indent
#unless @indent == 0 || @level == 0
# text!(" " * (@level * @indent))
#end

_start_tag(sym, attrs)
begin
_nested_structures(block)
ensure
_end_tag(sym)
_newline
end
end
end
end
23 changes: 0 additions & 23 deletions lib/rdf/rdfxml/patches/nokogiri_hacks.rb

This file was deleted.

5 changes: 2 additions & 3 deletions lib/rdf/rdfxml/reader.rb
@@ -1,6 +1,6 @@
begin
require 'nokogiri'
rescue LoadError => e
rescue LoadError
:rexml
end
require 'rdf/xsd'
Expand Down Expand Up @@ -91,7 +91,7 @@ def extract_mappings(element, &cb)
# Produce the next list entry for this context
def li_next
@li_counter += 1
predicate = RDF["_#{@li_counter}"]
RDF["_#{@li_counter}"]
end

# Set XML base. Ignore any fragment
Expand Down Expand Up @@ -328,7 +328,6 @@ def nodeElement(el, ec)
end

# Handle the propertyEltList children events in document order
li_counter = 0 # this will increase for each li we iterate through
el.children.each do |child|
log_fatal "child must be a proxy not a #{child.class}" unless child.is_a?(@implementation::NodeProxy)
next unless child.element?
Expand Down

0 comments on commit 8c579c6

Please sign in to comment.