Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 14, 2016
0 parents commit 68edba1
Show file tree
Hide file tree
Showing 91 changed files with 1,436 additions and 0 deletions.
27 changes: 27 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Freeware License, some rights reserved

Copyright (c) 2009 Joe Lennon

Permission is hereby granted, free of charge, to anyone obtaining a copy
of this software and associated documentation files (the "Software"),
to work with the Software within the limits of freeware distribution and fair use.
This includes the rights to use, copy, and modify the Software for personal use.
Users are also allowed and encouraged to submit corrections and modifications
to the Software for the benefit of other users.

It is not allowed to reuse, modify, or redistribute the Software for
commercial use in any way, or for a user�s educational materials such as books
or blog articles without prior permission from the copyright holder.

The above copyright notice and this permission notice need to be included
in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#Apress Source Code

This repository accompanies [*Beginning CouchDB*](http://www.apress.com/9781430272373) by Joe Lennon (Apress, 2009).

![Cover image](9781430272373.jpg)

Download the files as a zip using the green button, or clone the repository to your machine using Git.

##Releases

Release v1.0 corresponds to the code in the published book, without corrections or updates.

##Contributions

See the file Contributing.md for more information on how you can contribute to this repository.
4 changes: 4 additions & 0 deletions Source Code/Appendix B/Listing B-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POST /db HTTP/1.1
Content-type: application/json

{�type�:�category�,�name�:�Web Tutorials�,�slug�:�web-tutorials�}
8 changes: 8 additions & 0 deletions Source Code/Appendix B/Listing B-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Server: CouchDB/0.9.0 (Erlang OTP/R13B)
Date: Sun, 04 Oct 2009 20:50:00 GMT
Content-Type: text/plain;charset=utf-8
Content-Length: 40
Cache-Control: must-revalidate

{"couchdb":"Welcome","version":"0.9.0"}
3 changes: 3 additions & 0 deletions Source Code/Chapter 10/Listing 10-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
easy_install couchdb
easy_install simplejson
easy_install couchapp
44 changes: 44 additions & 0 deletions Source Code/Chapter 10/Listing 10-10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ul#my_tasks {
list-style: none;
margin: 0; padding: 0;
border: 1px solid #ccc;
border-top: none;
}

ul#my_tasks li {
list-style: none;
display: block;
padding: 10px;
background-color: #fff;
border-top: 1px solid #ccc;
}

ul#my_tasks div.desc {
width: 80%;
float: left;
font-size: 1.1em;
}

ul#my_tasks li div.link {
width: 20%;
float: left;
text-align: right;
}

ul#my_tasks li div.clear {
clear: both;
}

ul#my_tasks li a {
background-color: maroon;
color: #fff;
padding: 2px;
font-size: 1.1em;
border: 1px solid #000;
font-weight: bold;
text-decoration: none;
}

ul#my_tasks li a:hover {
background-color: red;
}
69 changes: 69 additions & 0 deletions Source Code/Chapter 10/Listing 10-11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
$.CouchApp(function(app) {
$('form#add_task').submit(function(e) {
e.preventDefault();
var newTask = {
desc: $('#desc').val()
}
if(newTask.desc.length > 0) {
app.db.saveDoc(newTask, { success: function(resp) {
$('ul#my_tasks').append('<li id="'+newTask._id+'">'
+'<div class="desc">'+newTask.desc+'</div>'
+'<div class="link">'
+'<a href="#" onclick="return false;"'
+' id="'+newTask._rev+'">Delete</a>'
+'</div>'
+'<div class="clear"></clear>'
+'</li>');
$('#'+newTask._rev).click(function() {
if(confirm("Are you sure you want to delete this task?")) {
var delTask = {
_id: newTask._id,
_rev: newTask._rev
}
app.db.removeDoc(delTask, {});
$('#'+newTask._id).show().fadeOut(2000);
var del_count = parseInt($('#task_count span').html(), 10);
del_count--;
$('#task_count span').html(del_count);
return false;
}
});
$('ul#my_tasks li:last').hide().fadeIn(1500);
$('#desc').val('');
var task_count = parseInt($('#task_count span').html(), 10);
task_count++;
$('#task_count span').html(task_count);
}});
} else {
alert('You must enter a description to create a new task!');
}
});

app.view("get_tasks", { success: function(json) {
json.rows.map(function(row) {
$('ul#my_tasks').append('<li id="'+row.value._id+'">'
+'<div class="desc">'+row.key+'</div>'
+'<div class="link">'
+'<a href="#" onclick="return false;"'
+' id="'+row.value._rev+'">Delete</a>'
+'</div>'
+'<div class="clear"></clear>'
+'</li>');
$('#'+row.value._rev).click(function() {
if(confirm("Are you sure you want to delete this task?")) {
var delTask = {
_id: row.value._id,
_rev: row.value._rev
}
app.db.removeDoc(delTask, {});
$('#'+row.value._id).show().fadeOut(2000);
var del_count = parseInt($('#task_count span').html(), 10);
del_count--;
$('#task_count span').html(del_count);
return false;
}
});
});
$('#task_count span').html(json.rows.length);
}});
});
2 changes: 2 additions & 0 deletions Source Code/Chapter 10/Listing 10-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mkdir ~/couchapps
cd ~/couchapps
14 changes: 14 additions & 0 deletions Source Code/Chapter 10/Listing 10-3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Super CouchApp</title>
<link rel="stylesheet" href="style/main.css" type="text/css">
</head>
<body>
<h1>Super CouchApp</h1>
<p>This ain't no placeholder page no more!</p>
</body>
<script src="/_utils/script/json2.js"></script>
<script src="/_utils/script/jquery.js?1.3.1"></script>
<script src="/_utils/script/jquery.couch.js?0.9.0"></script>
</html>
31 changes: 31 additions & 0 deletions Source Code/Chapter 10/Listing 10-4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>CouchTasks</title>
<link rel="stylesheet" href="style/main.css" type="text/css">
</head>
<body>
<h1>CouchTasks</h1>
<p>A simple CouchApp that allows you to create new tasks
and delete completed ones.</p>
<form name="add_task" id="add_task">
<fieldset>
<legend>New Task</legend>
<label for="desc">Description:</label><br />
<textarea id="desc" name="desc"></textarea><br />
<input type="submit" id="create" value="Create" />
</fieldset>
</form>
<form name="tasks" id="tasks">
<fieldset>
<legend>My Tasks</legend>
<div id="task_count">You have <span>0</span> Task(s).</div>
<ul id="my_tasks"></ul>
</fieldset>
</form>
</body>
<script src="/_utils/script/json2.js"></script>
<script src="/_utils/script/jquery.js?1.3.1"></script>
<script src="/_utils/script/jquery.couch.js?0.9.0"></script>
<script src="vendor/couchapp/jquery.couchapp.js"></script>
</html>
62 changes: 62 additions & 0 deletions Source Code/Chapter 10/Listing 10-5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
* {
font-family: Helvetica, Arial, sans-serif;
}

body {
margin: 0px; padding: 0px;
}

h1 {
margin:0;
padding: 0px 0px 0px 20px;
background-color: #336699;
color: #fff;
}

p {
border: 1px solid #342c03;
color: #342c03;
background-color: #f0ffc2;
padding: 10px;
margin: 10px 20px 10px 20px;
font-weight: bold;
}

fieldset {
border: 1px solid #666;
margin: 0px 20px 20px 20px;
background-color: #eee;
}

legend {
padding: 5px 15px 5px 15px;
background-color: #ccc;
border: 1px solid #666;
font-weight: bold;
font-size: 0.9em;
}

label {
font-weight: bold;
font-size: 0.8em;
}

textarea {
width: 95%;
height: 100px;
margin-bottom: 10px;
}

input[type=submit] {
font-size: 1.1em;
font-weight: bold;
}

div#task_count {
font-size: 0.8em;
color: #888;
}

div#task_count span {
font-weight: bold;
}
20 changes: 20 additions & 0 deletions Source Code/Chapter 10/Listing 10-6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$.CouchApp(function(app) {
$('form#add_task').submit(function(e) {
e.preventDefault();
var newTask = {
desc: $('#desc').val()
}
if(newTask.desc.length > 0) {
app.db.saveDoc(newTask, { success: function(resp) {
$('ul#my_tasks').append('<li>'+newTask.desc+'</li>');
$('ul#my_tasks li:last').hide().fadeIn(1500);
$('#desc').val('');
var task_count = parseInt('#task_count span').html(), 10);
task_count++;
$('#task_count span').html(task_count);
}});
} else {
alert('You must enter a description to create a new task!');
}
});
});
33 changes: 33 additions & 0 deletions Source Code/Chapter 10/Listing 10-7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<title>CouchTasks</title>
<link rel="stylesheet" href="style/main.css" type="text/css">
</head>
<body>
<h1>CouchTasks</h1>
<p>A simple CouchApp that allows you to create
new tasks and delete completed ones.</p>
<form name="add_task" id="add_task">
<fieldset>
<legend>New Task</legend>
<label for="desc">Description:</label><br />
<textarea id="desc" name="desc"></textarea><br />
<input type="submit" id="create" value="Create" />
</fieldset>
</form>

<form name="tasks" id="tasks">
<fieldset>
<legend>My Tasks</legend>
<div id="task_count">You have <span>0</span> Task(s).</div>
<ul id="my_tasks"></ul>
</fieldset>
</form>
</body>
<script src="/_utils/script/json2.js"></script>
<script src="/_utils/script/jquery.js?1.3.1"></script>
<script src="/_utils/script/jquery.couch.js?0.9.0"></script>
<script src="vendor/couchapp/jquery.couchapp.js"></script>
<script src="script/main.js"></script>
</html>
3 changes: 3 additions & 0 deletions Source Code/Chapter 10/Listing 10-8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function(doc) {
emit(doc.desc, doc);
}
27 changes: 27 additions & 0 deletions Source Code/Chapter 10/Listing 10-9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$.CouchApp(function(app) {
$('form#add_task').submit(function(e) {
e.preventDefault();
var newTask = {
desc: $('#desc').val()
}
if(newTask.desc.length > 0) {
app.db.saveDoc(newTask, { success: function(resp) {
$('ul#my_tasks').append('<li>'+newTask.desc+'</li>');
$('ul#my_tasks li:last').hide().fadeIn(1500);
$('#desc').val('');
var task_count = parseInt($('#task_count span').html(), 10);
task_count++;
$('#task_count span').html(task_count);
}});
} else {
alert('You must enter a description to create a new task!');
}
});

app.view("get_tasks", { success: function(json) {
json.rows.map(function(row) {
$('ul#my_tasks').append('<li>'+row.key+'</li>');
});
$('#task_count span').html(json.rows.length);
}});
});
3 changes: 3 additions & 0 deletions Source Code/Chapter 11/Listing 11-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from couchdbkit.client import Server
server = Server()
server.create_db("python_test")

0 comments on commit 68edba1

Please sign in to comment.