Replace String#indent from activesupport with helper method

This commit is contained in:
Benjamin Neff 2017-04-05 00:00:58 +02:00
parent 40919b4c69
commit 696f50f40d
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
3 changed files with 8 additions and 3 deletions

View file

@ -34,7 +34,7 @@ module DiasporaFederation
<subject>#{data[:subject]}</subject>
<created_at>#{data[:created_at].utc.iso8601}</created_at>
<participant_handles>#{data[:participants]}</participant_handles>
#{data[:messages].map {|a| a.to_xml.to_s.indent(2) }.join("\n")}
#{data[:messages].map {|a| indent(a.to_xml.to_s, 2) }.join("\n")}
</conversation>
XML

View file

@ -6,7 +6,7 @@ module DiasporaFederation
<poll>
<guid>#{data[:guid]}</guid>
<question>#{data[:question]}</question>
#{data[:poll_answers].map {|a| a.to_xml.to_s.indent(2) }.join("\n")}
#{data[:poll_answers].map {|a| indent(a.to_xml.to_s, 2) }.join("\n")}
</poll>
XML
@ -17,7 +17,7 @@ XML
"guid": "#{data[:guid]}",
"question": "#{data[:question]}",
"poll_answers": [
#{data[:poll_answers].map {|a| JSON.pretty_generate(a.to_json).indent(6) }.join(",\n")}
#{data[:poll_answers].map {|a| indent(JSON.pretty_generate(a.to_json), 6) }.join(",\n")}
]
}
}

View file

@ -35,3 +35,8 @@ def change_time(time, options={})
::Time.utc(time.year, time.month, time.day, new_hour, new_min, new_sec)
end
# indent helper
def indent(string, amount)
string.gsub(/^/, " " * amount)
end