Created
March 16, 2012 14:54
-
-
Save EricLondon/2050420 to your computer and use it in GitHub Desktop.
Drupal to Rails JSON parsing script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# loop through nodes:story data | |
json_data['nodes']['story'].each do |i, story| | |
################################################## | |
# modify html per google prettify | |
# scan for <code> tags | |
matches = story['body'].scan(/(<code>)(.*?)(<\/code>)/im) | |
matches.each do |match| | |
new_string = '<pre class="prettyprint"><code class="prettyprint">' + match[1].gsub(/<\?php/, '<?php') + '</code></pre>' | |
story['body'].gsub!(match.join.to_s, new_string) | |
end | |
# scan for php tags | |
matches = story['body'].scan(/(<\?php)(.*?)(\?>)/im) | |
matches.each do |match| | |
new_string = '<pre class="prettyprint"><code class="prettyprint">' + match.join + '</code></pre>' | |
story['body'].gsub!(match.join, new_string) | |
end | |
################################################## | |
# create new post object | |
new_post = Post.create!(:id => story['nid'], | |
:content => story['body'], | |
:created_at => story['created'], | |
:status => story['status'], | |
:title => story['title'], | |
:updated_at => story['changed'], | |
:user_id => story['uid'], | |
:tag_list => story['taxonomy']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment