Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

OM does not work with elements that have a hyphen #46

Open
mstroming opened this issue Mar 5, 2014 · 0 comments
Open

OM does not work with elements that have a hyphen #46

mstroming opened this issue Mar 5, 2014 · 0 comments

Comments

@mstroming
Copy link
Contributor

Given this terminology:

set_terminology do |t|
  t.root(:path => "orcid-work")
  t.work_title(:path => "work-title")
end

This does not work:
object.work_title = "test title"

This is because Nokogiri does not support this:

xml.work-title("test title")

Instead, it supports:

xml.send(:'work-title', 'test title')

OM is using eval to run a string as a line of code. That line of code is Nokogiri code. We need to convert the string as it is now to use sends. Nested sends might look like this:

b = Nokogiri::XML::Builder.new do |xml|
  xml.send(:'foo-bar') {
    xml.send(:'bar-foo', 'hello')
  }
end

https://github.com/projecthydra/om/blob/v3.0.4/lib/om/xml/term_value_operators.rb#L170
The code that needs to change is around here:
class: lib/om/xml/term_value_operators.rb
method: insert_from_template(parent_node, new_values, template)

builder = Nokogiri::XML::Builder.with(parent_node) do |xml|
      new_values.each do |builder_new_value|
        builder_new_value = builder_new_value.gsub(/'/, "\\\\'") # escape any apostrophes in the new value
        if matchdata = /xml\.@(\w+)/.match(template)
          parent_node.set_attribute(matchdata[1], builder_new_value)
        else
          builder_arg = eval('"'+ template + '"') # this inserts builder_new_value into the builder template
          eval(builder_arg)
        end
      end
    end
    return parent_node
  end

One possible solution is that builder_arg needs to get converted to use sends.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant