Skip to content

Commit

Permalink
Allow Haml versions >= 5.2 and < 7.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Apr 3, 2023
1 parent fb9e666 commit dda3365
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -5,7 +5,7 @@ gemspec
gem "rdf", github: "ruby-rdf/rdf", branch: "develop"
gem "rdf-spec", github: "ruby-rdf/rdf-spec", branch: "develop"
gem "rdf-xsd", github: "ruby-rdf/rdf-xsd", branch: "develop"
gem "nokogiri", '~> 1.13', '>= 1.13.4', platforms: [:mri, :jruby]
gem "nokogiri", '~> 1.14', platforms: [:mri, :jruby]
gem 'equivalent-xml', '~> 0.6'

group :development, :test do
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -399,7 +399,7 @@ The template hash defines four Haml templates:
## Dependencies
* [Ruby](https://ruby-lang.org/) (>= 2.6)
* [RDF.rb](https://rubygems.org/gems/rdf) (~> 3.2)
* [Haml](https://rubygems.org/gems/haml) (~> 5.2)
* [Haml](https://rubygems.org/gems/haml) (>- 5.2, < 7)
* [HTMLEntities](https://rubygems.org/gems/htmlentities) (~> 4.3)
* Soft dependency on [Nokogiri](https://rubygems.org/gems/nokogiri) (~> 1.12)

Expand Down
10 changes: 9 additions & 1 deletion lib/rdf/rdfa/writer.rb
Expand Up @@ -721,6 +721,8 @@ def get_curie(resource)
# @return [String]
# Entity-encoded string
def escape_entities(str)
# Haml 6 does escaping
return str if Haml.const_defined?(:Template)
CGI.escapeHTML(str).gsub(/[\n\r]/) {|c| '&#x' + c.unpack('h').first + ';'}
end

Expand Down Expand Up @@ -761,7 +763,13 @@ def hamlify(template, locals = {})
template = template.align_left
log_debug {"hamlify locals: #{locals.inspect}"}

Haml::Engine.new(template, @options[:haml_options] || HAML_OPTIONS).render(self, locals) do |*args|
haml_opts = @options[:haml_options] || HAML_OPTIONS
haml_runner = if Haml.const_defined?(:Template)
Haml::Template.new(**haml_opts) {template}
else
Haml::Engine.new(template, **haml_opts)
end
haml_runner.render(self, locals) do |*args|
yield(*args) if block_given?
end
rescue Haml::Error => e
Expand Down
66 changes: 33 additions & 33 deletions lib/rdf/rdfa/writer/haml_templates.rb
Expand Up @@ -10,11 +10,11 @@ class Writer
doc: %q(
!!! XML
!!! 5
%html{xmlns: "http://www.w3.org/1999/xhtml", lang: lang, prefix: prefix}
%html{**{xmlns: "http://www.w3.org/1999/xhtml", lang: lang, prefix: prefix}.compact}
- if base || title
%head
- if base
%base{href: base}
%base{**{href: base}.compact}
- if title
%title= title
%body
Expand All @@ -33,13 +33,13 @@ class Writer
# Yield: predicates.each
subject: %q(
- if element == :li
%li{rel: rel, resource: (about || resource), typeof: typeof, inlist: inlist}
%li{**{rel: rel, resource: (about || resource), typeof: typeof, inlist: inlist}.compact}
- if typeof
%span.type!= typeof
- predicates.each do |predicate|
!= yield(predicate)
- else
%div{rel: rel, resource: (about || resource), typeof: typeof, inlist: inlist}
%div{**{rel: rel, resource: (about || resource), typeof: typeof, inlist: inlist}.compact}
- if typeof
%span.type!= typeof
- predicates.each do |predicate|
Expand All @@ -53,7 +53,7 @@ class Writer
# Otherwise, render result
property_value: %q(
- if heading_predicates.include?(predicate) && object.literal?
%h1{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}= escape_entities(get_value(object))
%h1{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
- else
%div.property
%span.label
Expand All @@ -63,13 +63,13 @@ class Writer
- elsif get_curie(object) == 'rdf:nil'
%span{rel: get_curie(predicate), inlist: ''}
- elsif object.node?
%span{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}= get_curie(object)
%span{**{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}.compact}= get_curie(object)
- elsif object.uri?
%a{property: get_curie(predicate), href: object.to_s, inlist: inlist}= object.to_s
%a{**{property: get_curie(predicate), href: object.to_s, inlist: inlist}.compact}= object.to_s
- elsif object.datatype == RDF.XMLLiteral
%span{property: get_curie(predicate), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}<!= get_value(object)
%span{**{property: get_curie(predicate), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}<!= get_value(object)
- else
%span{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}= escape_entities(get_value(object))
%span{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
),

# Output for multi-valued properties
Expand All @@ -84,14 +84,14 @@ class Writer
- if res = yield(object)
!= res
- elsif object.node?
%li{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}= get_curie(object)
%li{**{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}.compact}= get_curie(object)
- elsif object.uri?
%li
%a{property: get_curie(predicate), href: object.to_s, inlist: inlist}= object.to_s
%a{**{property: get_curie(predicate), href: object.to_s, inlist: inlist}.compact}= object.to_s
- elsif object.datatype == RDF.XMLLiteral
%li{property: get_curie(predicate), lang: get_lang(object), datatype: get_curie(object.datatype), inlist: inlist}<!= get_value(object)
%li{**{property: get_curie(predicate), lang: get_lang(object), datatype: get_curie(object.datatype), inlist: inlist}.compact}<!= get_value(object)
- else
%li{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}= escape_entities(get_value(object))
%li{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
),
}

Expand All @@ -106,10 +106,10 @@ class Writer
doc: %q(
!!! XML
!!! 5
%html{xmlns: "http://www.w3.org/1999/xhtml", lang: lang, prefix: prefix}
%html{**{xmlns: "http://www.w3.org/1999/xhtml", lang: lang, prefix: prefix}.compact}
- if base
%head
%base{href: base}
%base{*{href: base}.compact}
%body
- subjects.each do |subject|
!= yield(subject)
Expand All @@ -121,7 +121,7 @@ class Writer
# Locals: about, typeof, predicates, :inlist
# Yield: predicates.each
subject: %q(
%div{rel: rel, resource: (about || resource), typeof: typeof}
%div{**{rel: rel, resource: (about || resource), typeof: typeof}.compact}
- predicates.each do |predicate|
!= yield(predicate)
),
Expand All @@ -138,13 +138,13 @@ class Writer
- elsif get_curie(object) == 'rdf:nil'
%span{rel: get_curie(predicate), inlist: ''}
- elsif object.node?
%span{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}= get_curie(object)
%span{**{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}.compact}= get_curie(object)
- elsif object.uri?
%a{property: get_curie(predicate), href: object.to_s, inlist: inlist}= object.to_s
%a{**{property: get_curie(predicate), href: object.to_s, inlist: inlist}.compact}= object.to_s
- elsif object.datatype == RDF.XMLLiteral
%span{property: get_curie(predicate), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}<!= get_value(object)
%span{**{property: get_curie(predicate), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}<!= get_value(object)
- else
%span{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}= escape_entities(get_value(object))
%span{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
)
}

Expand All @@ -156,7 +156,7 @@ class Writer
doc: %q(
!!! XML
!!! 5
%html{xmlns: "http://www.w3.org/1999/xhtml", lang: lang, prefix: prefix}
%html{**{xmlns: "http://www.w3.org/1999/xhtml", lang: lang, prefix: prefix}.compact}
- if base || title
%head
- if base
Expand Down Expand Up @@ -189,21 +189,21 @@ class Writer
# Yield: predicates.each
subject: %q(
- if element == :li
%li{rel: rel, resource: (about || resource), typeof: typeof, inlist: inlist}
%li{**{rel: rel, resource: (about || resource), typeof: typeof, inlist: inlist}.compact}
- if typeof
%span.type!= typeof
%table.properties
- predicates.each do |predicate|
!= yield(predicate)
- elsif rel
%td{rel: rel, resource: (about || resource), typeof: typeof, inlist: inlist}
%td{**{rel: rel, resource: (about || resource), typeof: typeof, inlist: inlist}.compact}
- if typeof
%span.type!= typeof
%table.properties
- predicates.each do |predicate|
!= yield(predicate)
- else
%div{resource: (about || resource), typeof: typeof, inlist: inlist}
%div{**{resource: (about || resource), typeof: typeof, inlist: inlist}.compact}
- if typeof
%span.type!= typeof
%table.properties
Expand All @@ -218,7 +218,7 @@ class Writer
# Otherwise, render result
property_value: %q(
- if heading_predicates.include?(predicate) && object.literal?
%h1{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}= escape_entities(get_value(object))
%h1{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
- else
%tr.property
%td.label
Expand All @@ -228,14 +228,14 @@ class Writer
- elsif get_curie(object) == 'rdf:nil'
%td{rel: get_curie(predicate), inlist: ''}= "Empty"
- elsif object.node?
%td{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}= get_curie(object)
%td{**{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}.compact}= get_curie(object)
- elsif object.uri?
%td
%a{property: get_curie(predicate), href: object.to_s, inlist: inlist}= object.to_s
%a{**{property: get_curie(predicate), href: object.to_s, inlist: inlist}.compact}= object.to_s
- elsif object.datatype == RDF.XMLLiteral
%td{property: get_curie(predicate), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}<!= get_value(object)
%td{**{property: get_curie(predicate), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}<!= get_value(object)
- else
%td{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}= escape_entities(get_value(object))
%td{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
),

# Output for multi-valued properties
Expand All @@ -251,14 +251,14 @@ class Writer
- if res = yield(object)
!= res
- elsif object.node?
%li{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}= get_curie(object)
%li{**{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}.compact}= get_curie(object)
- elsif object.uri?
%li
%a{property: get_curie(predicate), href: object.to_s, inlist: inlist}= object.to_s
%a{**{property: get_curie(predicate), href: object.to_s, inlist: inlist}.compact}= object.to_s
- elsif object.datatype == RDF.XMLLiteral
%li{property: get_curie(predicate), lang: get_lang(object), datatype: get_curie(object.datatype), inlist: inlist}<!= get_value(object)
%li{**{property: get_curie(predicate), lang: get_lang(object), datatype: get_curie(object.datatype), inlist: inlist}.compact}<!= get_value(object)
- else
%li{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}= escape_entities(get_value(object))
%li{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
),
}
HAML_TEMPLATES = {base: BASE_HAML, min: MIN_HAML, distiller: DISTILLER_HAML}
Expand Down
2 changes: 1 addition & 1 deletion rdf-rdfa.gemspec
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |gem|

gem.add_runtime_dependency 'rdf', '~> 3.2'
gem.add_runtime_dependency 'rdf-vocab', '~> 3.2'
gem.add_runtime_dependency 'haml', '~> 5.2'
gem.add_runtime_dependency 'haml', '>= 5.2', "< 7"
gem.add_runtime_dependency 'rdf-xsd', '~> 3.2'
gem.add_runtime_dependency 'rdf-aggregate-repo', '~> 3.2'
gem.add_runtime_dependency 'htmlentities', '~> 4.3'
Expand Down
8 changes: 4 additions & 4 deletions script/tc
Expand Up @@ -92,7 +92,7 @@ options = {

opts = GetoptLong.new(
["--help", "-?", GetoptLong::NO_ARGUMENT],
["--dbg", GetoptLong::NO_ARGUMENT],
["--debug", GetoptLong::NO_ARGUMENT],
["--format", GetoptLong::REQUIRED_ARGUMENT],
["--host-language", "-h", GetoptLong::REQUIRED_ARGUMENT],
["--library", GetoptLong::REQUIRED_ARGUMENT],
Expand All @@ -107,7 +107,7 @@ def help(options)
puts "Usage: #{$0} [options] [test-number ...]"
puts "Options:"
puts " --dump: Dump raw output, otherwise serialize to Ruby"
puts " --dbg: Display detailed debug output"
puts " --debug: Display detailed debug output"
puts " --expand Expand graph with vocab_expansion option"
puts " --format: Format for output, defaults to #{options[:format].inspect}"
puts " --host-language: Run for specified host language, defaults to #{options[:host_language]}"
Expand All @@ -124,7 +124,7 @@ end
opts.each do |opt, arg|
case opt
when '--help' then help(options)
when '--dbg' then logger.level = Logger::DEBUG
when '--debug' then logger.level = Logger::DEBUG
when '--format' then options[:format] = arg.to_sym
when '--host-language' then options[:host_language] = arg
when '--library' then options[:library] = arg.to_sym
Expand All @@ -142,7 +142,7 @@ result_count = {}
Fixtures::TestCase.for_specific(options[:host_language], options[:version]) do |tc|
next unless ARGV.empty? || ARGV.any? {|n| tc.num.match(/#{n}/)}
next if tc.classification.to_s =~ /deprecated/
run_tc(tc, options.merge(result_count: result_count))
run_tc(tc, **options.merge(result_count: result_count))
end

result_count.each do |result, count|
Expand Down

0 comments on commit dda3365

Please sign in to comment.