-
Notifications
You must be signed in to change notification settings - Fork 84
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
Try Fix CDATA problem in android2csv.rb #104
base: master
Are you sure you want to change the base?
Conversation
converter = Babelish::Android2CSV.new( | ||
:csv_filename => csv_filename, | ||
:headers => headers, | ||
:filenames => [filename]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.
expected_output = [["html"], {filename => {"html" => "<![CDATA[<p>Text<p>]]>"}}] | ||
converter = Babelish::Android2CSV.new( | ||
:csv_filename => csv_filename, | ||
:headers => headers, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
|
||
expected_output = [["html"], {filename => {"html" => "<![CDATA[<p>Text<p>]]>"}}] | ||
converter = Babelish::Android2CSV.new( | ||
:csv_filename => csv_filename, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
filename = "test/data/android_cdata.xml" | ||
headers = %w{variables german} | ||
|
||
expected_output = [["html"], {filename => {"html" => "<![CDATA[<p>Text<p>]]>"}}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space inside { missing.
Line is too long. [84/80]
Space inside } missing.
converter = Babelish::Android2CSV.new( | ||
:csv_filename => csv_filename, | ||
:headers => headers, | ||
:filenames => [filename]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.
expected_output = [["html"], {filename => {"html" => "<![CDATA[<p>Text<p>]]>"}}] | ||
converter = Babelish::Android2CSV.new( | ||
:csv_filename => csv_filename, | ||
:headers => headers, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
|
||
expected_output = [["html"], {filename => {"html" => "<![CDATA[<p>Text<p>]]>"}}] | ||
converter = Babelish::Android2CSV.new( | ||
:csv_filename => csv_filename, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
filename = "test/data/android_cdata.xml" | ||
headers = %w{variables german} | ||
|
||
expected_output = [["html"], {filename => {"html" => "<![CDATA[<p>Text<p>]]>"}}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space inside { missing.
Line is too long. [84/80]
Space inside } missing.
lib/babelish/android2csv.rb
Outdated
strings.merge!(node["name"] => '<![CDATA[' + node.inner_html + ']]>') | ||
else | ||
strings.merge!(node["name"] => node.inner_html) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
lib/babelish/android2csv.rb
Outdated
@@ -15,7 +15,11 @@ def load_strings(strings_filename) | |||
end | |||
parser.xpath("//string").each do |node| | |||
if !node.nil? && !node["name"].nil? | |||
strings.merge!(node["name"] => node.inner_html) | |||
if node.cdata? | |||
strings.merge!(node["name"] => '<![CDATA[' + node.inner_html + ']]>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Line is too long. [81/80]
Looks like it's not working... I'll try something else later. |
lib/babelish/android2csv.rb
Outdated
@@ -15,7 +15,11 @@ def load_strings(strings_filename) | |||
end | |||
parser.xpath("//string").each do |node| | |||
if !node.nil? && !node["name"].nil? | |||
strings.merge!(node["name"] => node.inner_html) | |||
if "#{node.children.first.class}" == "Nokogiri::XML::CDATA" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to_s over string interpolation.
@netbe Looks like it is working now Please take a look~ Thanks~ |
:filenames => [filename]) | ||
|
||
output = converter.convert(false) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remove a line here which check if file exists.
Since the above convert
has a false
. I think the file will not exist?
Update:
I found that
Node
of<string name="cdata"><![CDATA[Line number 1.<br />Line number 2.]]></string>
will contain a
NodeSet
and the first item of thatNodeSet
will be aCDATA
Tried using
is_a?
to check the class but still not that familiar with ruby, so I ended up using string comparison.--
Hi,
Try use following method as a workaround to fix #73 (as a newbie of ruby...)
http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Node#cdata%3F-instance_method
https://github.com/sparklemotion/nokogiri/blob/master/lib/nokogiri/xml/node.rb#L454
Append the test you've written before.
Please take a look~
--
BTW I escape the string with CDATA to deal with #73 's problem for now
Turn
<string name="cdata"><![CDATA[Line number 1.<br />Line number 2.]]></string>
Into
<string name="cdata">Line number 1.<br />Line number 2.</string>
But it's kind of exhausted for me or my coworker to edit all our strings...