Skip to content

Instantly share code, notes, and snippets.

@EricLondon
Created March 16, 2012 14:54
Show Gist options
  • Save EricLondon/2050420 to your computer and use it in GitHub Desktop.
Save EricLondon/2050420 to your computer and use it in GitHub Desktop.
Drupal to Rails JSON parsing script
# 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/, '&lt;?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