Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Re-introduce a Ox::Raw type #117

Merged
merged 4 commits into from Sep 2, 2015
Merged

Re-introduce a Ox::Raw type #117

merged 4 commits into from Sep 2, 2015

Conversation

cade
Copy link
Contributor

@cade cade commented Sep 1, 2015

Ref: #100

I ran into the same use case as @tim-vandecasteele today and found his abandoned PR, so I thought I'd pick it up and try to drive it to completion.

I'd like to be able to:

doc = Ox::Document.new(version: '1.0', encoding: 'UTF-8')
ox_root = Ox::Element.new(:projects)
doc << ox_root

@user.projects.each do |project|
  key = "project-#{project.id}-#{project.updated_at.to_i}"
  project_xml = Rails.cache.read key
  if project_xml
    ox_root << Ox::Raw.new(project_xml)
  else
    ox_project = Ox::Element.new(:project)
    ox_project << (Ox::Element.new(:id) << project.id.to_s)
    # ... populate ox_project with other attributes
    ox_root << ox_project
    Rails.cache.write key, Ox.dump(ox_project)
  end
end

Ox.dump doc

Let me know if you need anything else from me or have any questions/suggestions! Ox is awesome, and thanks very much for your work! ❤️

(Tim: I hope you don't mind that I amended your commit to clean it up. I wanted you to have credit without adding "revert whitespace" commits.)


module Ox
# Raw elements are used to inject existing XML strings into a document
class Raw < Node
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include a caveat that use of this feature can result in invalid XML.

@ohler55
Copy link
Owner

ohler55 commented Sep 2, 2015

Other than a warning that you can shoot yourself in the foot I'll merge when the comment is updated. Thanks.

@cade
Copy link
Contributor Author

cade commented Sep 2, 2015

Comment added. Thanks for looking so quickly!

ohler55 added a commit that referenced this pull request Sep 2, 2015
Re-introduce a Ox::Raw type
@ohler55 ohler55 merged commit 3c21808 into ohler55:master Sep 2, 2015
@ohler55
Copy link
Owner

ohler55 commented Sep 2, 2015

I'll get this in a release this week.

liseki added a commit to Silverfin-Engineering/dav4rack that referenced this pull request Aug 26, 2021
Nokogiri was updated to 1.12 to match what we have in production and ox
was updated to ohler55/master since Tim's original patch in branch
add-raw was eventually merged there (see
ohler55/ox#117).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants