Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rjcorwin/6688856 to your computer and use it in GitHub Desktop.

Select an option

Save rjcorwin/6688856 to your computer and use it in GitHub Desktop.
This file assumes it's living in a CouchDB doc and will find and save the file to be transformed to the CouchDB Doc that it is sitting in.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Find and Replace</title>
<script src="http://code.jquery.com/jquery-2.0.3.js"></script>
</head>
<body>
click me to transform
</body>
<script>
$(document).ready(function() {
var find = 'find me'
var replace = 'I\nam\nthe\nreplacement'
var fileName = 'transformMe.txt'
$('body').click(function() {
$.get(fileName, function(transformFile) {
var transformedFile = transformFile.replace(find, replace)
$.getJSON('./', function(response){
$.ajax({
type: 'PUT',
url: 'transformedFile.txt?rev=' + response._rev,
data: transformedFile
}).done(function() {
$('body').html('<a href="transformedFile.txt">Check out the tranformed file</a>')
})
})
})
})
})
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment