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

quotes instead apos for attributes when pretty_print: true; #61

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/gyoku/prettifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module Gyoku
class Prettifier
DEFAULT_INDENT = 2
DEFAULT_COMPACT = true
DEFAULT_ATTRIBUTE_QUOTE = '"'

attr_accessor :indent, :compact
attr_accessor :indent, :compact, :attribute_quote
Copy link
Contributor

Choose a reason for hiding this comment

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

This accessor is not used in this PR.

Is it meant to be used outside this class?


def self.prettify(xml, options = {})
new(options).prettify(xml)
Expand All @@ -14,6 +15,7 @@ def self.prettify(xml, options = {})
def initialize(options = {})
@indent = options[:indent] || DEFAULT_INDENT
@compact = options[:compact].nil? ? DEFAULT_COMPACT : options[:compact]
@attribute_quote = options[:attribute_quote] || DEFAULT_ATTRIBUTE_QUOTE
end

# Adds intendations and newlines to +xml+ to make it more readable
Expand All @@ -22,6 +24,7 @@ def prettify(xml)
formatter = REXML::Formatters::Pretty.new indent
formatter.compact = compact
doc = REXML::Document.new xml
doc.context[:attribute_quote] = :quote if @attribute_quote == '"'
formatter.write doc, result
result
end
Expand Down