voteable_mongoid 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/doc/index.html ADDED
@@ -0,0 +1,157 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>Documentation by YARD 0.6.5</title>
7
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
8
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
9
+
10
+ <script type="text/javascript" charset="utf-8">
11
+ relpath = '';
12
+ if (relpath != '') relpath += '/';
13
+ </script>
14
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
15
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
16
+
17
+ </head>
18
+ <body>
19
+ <script type="text/javascript" charset="utf-8">
20
+ if (window.top.frames.main) document.body.className = 'frames';
21
+ </script>
22
+
23
+ <div id="header">
24
+ <div id="menu">
25
+
26
+ <a href="_index.html" title="Index">Index</a> &raquo;
27
+ <span class="title">File: README</span>
28
+
29
+
30
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
31
+ </div>
32
+
33
+ <div id="search">
34
+ <a id="class_list_link" href="#">Class List</a>
35
+ <a id="method_list_link" href="#">Method List</a>
36
+ <a id ="file_list_link" href="#">File List</a>
37
+ </div>
38
+
39
+ <div class="clear"></div>
40
+ </div>
41
+
42
+ <iframe id="search_frame"></iframe>
43
+
44
+ <div id="content"><div id='filecontents'>
45
+ <h1>Voteable Mongoid</h1>
46
+
47
+ <p>Voteable Mongoid allows you to make your Mongoid::Document objects voteable
48
+ (up or down)</p>
49
+
50
+ <p>For instance, in a Q&amp;A site, a user can vote up (or down) on a post or
51
+ a comment.</p>
52
+
53
+ <p>When user provided enough information, voteable_mongoid will use only one
54
+ update-in-place operation per collection.</p>
55
+
56
+ <h2>Installation</h2>
57
+
58
+ <h3>Rails 3.0.x</h3>
59
+
60
+ <p>To install the gem, add this to your Gemfile</p>
61
+
62
+ <pre class="code"><span class='gem identifier id'>gem</span> <span class='string val'>'voteable_mongoid'</span>
63
+ </pre>
64
+
65
+ <p>After that, remember to run “bundle install”</p>
66
+
67
+ <h2>Usage</h2>
68
+
69
+ <h3>Making Post and Comment voteable, User being the voter</h3>
70
+
71
+ <p>post.rb</p>
72
+
73
+ <pre class="code"><span class='class class kw'>class</span> <span class='Post constant id'>Post</span>
74
+ <span class='include identifier id'>include</span> <span class='Mongoid constant id'>Mongoid</span><span class='colon2 op'>::</span><span class='Document constant id'>Document</span>
75
+ <span class='include identifier id'>include</span> <span class='Mongoid constant id'>Mongoid</span><span class='colon2 op'>::</span><span class='Voteable constant id'>Voteable</span>
76
+
77
+ <span class='comment val'># set points for each vote</span>
78
+ <span class='vote_point identifier id'>vote_point</span> <span class='self self kw'>self</span><span class='comma token'>,</span> <span class='symbol val'>:up</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='integer val'>+1</span><span class='comma token'>,</span> <span class='symbol val'>:down</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='integer val'>-1</span>
79
+
80
+ <span class='references_many identifier id'>references_many</span> <span class='symbol val'>:comments</span>
81
+ <span class='end end kw'>end</span>
82
+ </pre>
83
+
84
+ <p>comment.rb</p>
85
+
86
+ <pre class="code"><span class='require identifier id'>require</span> <span class='string val'>'post'</span>
87
+
88
+ <span class='class class kw'>class</span> <span class='Comment constant id'>Comment</span>
89
+ <span class='include identifier id'>include</span> <span class='Mongoid constant id'>Mongoid</span><span class='colon2 op'>::</span><span class='Document constant id'>Document</span>
90
+ <span class='include identifier id'>include</span> <span class='Mongoid constant id'>Mongoid</span><span class='colon2 op'>::</span><span class='Voteable constant id'>Voteable</span>
91
+
92
+ <span class='referenced_in identifier id'>referenced_in</span> <span class='symbol val'>:post</span>
93
+
94
+ <span class='vote_point identifier id'>vote_point</span> <span class='self self kw'>self</span><span class='comma token'>,</span> <span class='symbol val'>:up</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='integer val'>+1</span><span class='comma token'>,</span> <span class='symbol val'>:down</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='integer val'>-3</span>
95
+
96
+ <span class='comment val'># each vote on a comment can affect votes count and point of the related post as well</span>
97
+ <span class='vote_point identifier id'>vote_point</span> <span class='Post constant id'>Post</span><span class='comma token'>,</span> <span class='symbol val'>:up</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='integer val'>+2</span><span class='comma token'>,</span> <span class='symbol val'>:down</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='integer val'>-1</span>
98
+ <span class='end end kw'>end</span>
99
+ </pre>
100
+
101
+ <p>user.rb</p>
102
+
103
+ <pre class="code"><span class='class class kw'>class</span> <span class='User constant id'>User</span>
104
+ <span class='include identifier id'>include</span> <span class='Mongoid constant id'>Mongoid</span><span class='colon2 op'>::</span><span class='Document constant id'>Document</span>
105
+ <span class='include identifier id'>include</span> <span class='Mongoid constant id'>Mongoid</span><span class='colon2 op'>::</span><span class='Voter constant id'>Voter</span>
106
+ <span class='end end kw'>end</span>
107
+ </pre>
108
+
109
+ <h3>Making a vote</h3>
110
+
111
+ <pre class="code"><span class='@user ivar id'>@user</span><span class='dot token'>.</span><span class='vote identifier id'>vote</span><span class='lparen token'>(</span><span class='@post ivar id'>@post</span><span class='comma token'>,</span> <span class='symbol val'>:up</span><span class='rparen token'>)</span>
112
+ <span class='comment val'># is equivalent to</span>
113
+ <span class='@post ivar id'>@post</span><span class='dot token'>.</span><span class='vote identifier id'>vote</span><span class='lparen token'>(</span><span class='symbol val'>:voter_id</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='@user ivar id'>@user</span><span class='dot token'>.</span><span class='id identifier id'>id</span><span class='comma token'>,</span> <span class='symbol val'>:value</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='symbol val'>:up</span><span class='rparen token'>)</span>
114
+
115
+ <span class='comment val'># this will affect @post.votes_count and @post.votes_point as well</span>
116
+ <span class='@user ivar id'>@user</span><span class='dot token'>.</span><span class='vote identifier id'>vote</span><span class='lparen token'>(</span><span class='@comment ivar id'>@comment</span><span class='comma token'>,</span> <span class='symbol val'>:down</span><span class='rparen token'>)</span>
117
+ </pre>
118
+
119
+ <h3>Getting votes count and points</h3>
120
+
121
+ <pre class="code"><span class='puts identifier id'>puts</span> <span class='@post ivar id'>@post</span><span class='dot token'>.</span><span class='votes_point identifier id'>votes_point</span>
122
+ <span class='puts identifier id'>puts</span> <span class='@post ivar id'>@post</span><span class='dot token'>.</span><span class='votes_count identifier id'>votes_count</span>
123
+ <span class='puts identifier id'>puts</span> <span class='@post ivar id'>@post</span><span class='dot token'>.</span><span class='up_votes_count identifier id'>up_votes_count</span>
124
+ <span class='puts identifier id'>puts</span> <span class='@post ivar id'>@post</span><span class='dot token'>.</span><span class='down_votes_count identifier id'>down_votes_count</span>
125
+ </pre>
126
+
127
+ <h3>Getting the list of voted objects (votees) of a class</h3>
128
+
129
+ <pre class="code"><span class='@user ivar id'>@user</span><span class='dot token'>.</span><span class='votees identifier id'>votees</span><span class='lparen token'>(</span><span class='Post constant id'>Post</span><span class='rparen token'>)</span>
130
+ </pre>
131
+
132
+ <h3>Undo a vote</h3>
133
+
134
+ <pre class="code"><span class='@user ivar id'>@user</span><span class='dot token'>.</span><span class='unvote identifier id'>unvote</span><span class='lparen token'>(</span><span class='@comment ivar id'>@comment</span><span class='rparen token'>)</span>
135
+ </pre>
136
+
137
+ <h2>Credits</h2>
138
+ <ul><li>
139
+ <p>Alex N. - Author</p>
140
+ </li><li>
141
+ <p>Stefan N. - Unvoting</p>
142
+ </li></ul>
143
+
144
+ <p>Copyright © 2010-2011 Vinova Pte Ltd (<a
145
+ href="http://vinova.sg">vinova.sg</a>)</p>
146
+
147
+ <p>Licensed under the MIT license.</p>
148
+ </div></div>
149
+
150
+ <div id="footer">
151
+ Generated on Wed Mar 30 11:06:26 2011 by
152
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
153
+ 0.6.5 (ruby-1.8.7).
154
+ </div>
155
+
156
+ </body>
157
+ </html>
data/doc/js/app.js ADDED
@@ -0,0 +1,203 @@
1
+ function createSourceLinks() {
2
+ $('.method_details_list .source_code').
3
+ before("<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>");
4
+ $('.toggleSource').toggle(function() {
5
+ $(this).parent().next().slideDown(100);
6
+ $(this).text("Hide source");
7
+ },
8
+ function() {
9
+ $(this).parent().next().slideUp(100);
10
+ $(this).text("View source");
11
+ });
12
+ }
13
+
14
+ function createDefineLinks() {
15
+ var tHeight = 0;
16
+ $('.defines').after(" <a href='#' class='toggleDefines'>more...</a>");
17
+ $('.toggleDefines').toggle(function() {
18
+ tHeight = $(this).parent().prev().height();
19
+ $(this).prev().show();
20
+ $(this).parent().prev().height($(this).parent().height());
21
+ $(this).text("(less)");
22
+ },
23
+ function() {
24
+ $(this).prev().hide();
25
+ $(this).parent().prev().height(tHeight);
26
+ $(this).text("more...")
27
+ });
28
+ }
29
+
30
+ function createFullTreeLinks() {
31
+ var tHeight = 0;
32
+ $('.inheritanceTree').toggle(function() {
33
+ tHeight = $(this).parent().prev().height();
34
+ $(this).parent().toggleClass('showAll');
35
+ $(this).text("(hide)");
36
+ $(this).parent().prev().height($(this).parent().height());
37
+ },
38
+ function() {
39
+ $(this).parent().toggleClass('showAll');
40
+ $(this).parent().prev().height(tHeight);
41
+ $(this).text("show all")
42
+ });
43
+ }
44
+
45
+ function fixBoxInfoHeights() {
46
+ $('dl.box dd.r1, dl.box dd.r2').each(function() {
47
+ $(this).prev().height($(this).height());
48
+ });
49
+ }
50
+
51
+ function searchFrameLinks() {
52
+ $('#method_list_link').click(function() {
53
+ toggleSearchFrame(this, relpath + 'method_list.html');
54
+ });
55
+
56
+ $('#class_list_link').click(function() {
57
+ toggleSearchFrame(this, relpath + 'class_list.html');
58
+ });
59
+
60
+ $('#file_list_link').click(function() {
61
+ toggleSearchFrame(this, relpath + 'file_list.html');
62
+ });
63
+ }
64
+
65
+ function toggleSearchFrame(id, link) {
66
+ var frame = $('#search_frame');
67
+ $('#search a').removeClass('active').addClass('inactive');
68
+ if (frame.attr('src') == link && frame.css('display') != "none") {
69
+ frame.slideUp(100);
70
+ $('#search a').removeClass('active inactive');
71
+ }
72
+ else {
73
+ $(id).addClass('active').removeClass('inactive');
74
+ frame.attr('src', link).slideDown(100);
75
+ }
76
+ }
77
+
78
+ function linkSummaries() {
79
+ $('.summary_signature').click(function() {
80
+ document.location = $(this).find('a').attr('href');
81
+ });
82
+ }
83
+
84
+ function framesInit() {
85
+ if (window.top.frames.main) {
86
+ document.body.className = 'frames';
87
+ $('#menu .noframes a').attr('href', document.location);
88
+ $('html head title', window.parent.document).text($('html head title').text());
89
+ }
90
+ }
91
+
92
+ function keyboardShortcuts() {
93
+ if (window.top.frames.main) return;
94
+ $(document).keypress(function(evt) {
95
+ if (evt.altKey || evt.ctrlKey || evt.metaKey || evt.shiftKey) return;
96
+ if (typeof evt.orignalTarget !== "undefined" &&
97
+ (evt.originalTarget.nodeName == "INPUT" ||
98
+ evt.originalTarget.nodeName == "TEXTAREA")) return;
99
+ switch (evt.charCode) {
100
+ case 67: case 99: $('#class_list_link').click(); break; // 'c'
101
+ case 77: case 109: $('#method_list_link').click(); break; // 'm'
102
+ case 70: case 102: $('#file_list_link').click(); break; // 'f'
103
+ }
104
+ });
105
+ }
106
+
107
+ function summaryToggle() {
108
+ $('.summary_toggle').click(function() {
109
+ localStorage.summaryCollapsed = $(this).text();
110
+ $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
111
+ var next = $(this).parent().parent().next();
112
+ if (next.hasClass('compact')) {
113
+ next.toggle();
114
+ next.next().toggle();
115
+ }
116
+ else if (next.hasClass('summary')) {
117
+ var list = $('<ul class="summary compact" />');
118
+ list.html(next.html());
119
+ list.find('.summary_desc, .note').remove();
120
+ list.find('a').each(function() {
121
+ $(this).html($(this).find('strong').html());
122
+ $(this).parent().html($(this)[0].outerHTML);
123
+ });
124
+ next.before(list);
125
+ next.toggle();
126
+ }
127
+ return false;
128
+ });
129
+ if (localStorage) {
130
+ if (localStorage.summaryCollapsed == "collapse") $('.summary_toggle').click();
131
+ else localStorage.summaryCollapsed = "expand";
132
+ }
133
+ }
134
+
135
+ function fixOutsideWorldLinks() {
136
+ $('a').each(function() {
137
+ if (window.location.host != this.host) this.target = '_parent';
138
+ });
139
+ }
140
+
141
+ function generateTOC() {
142
+ if ($('#filecontents').length == 0) return;
143
+ var _toc = $('<ol class="top"></ol>');
144
+ var show = false;
145
+ var toc = _toc;
146
+ var counter = 0;
147
+ var tags = ['h2', 'h3', 'h4', 'h5', 'h6'];
148
+ if ($('#filecontents h1').length > 1) tags.unshift('h1');
149
+ for (i in tags) { tags[i] = '#filecontents ' + tags[i] }
150
+ var lastTag = parseInt(tags[0][1]);
151
+ $(tags.join(', ')).each(function() {
152
+ if (this.id == "filecontents") return;
153
+ show = true;
154
+ var thisTag = parseInt(this.tagName[1]);
155
+ if (this.id.length == 0) {
156
+ var proposedId = $(this).text().replace(/[^a-z0-9-]/ig, '_');
157
+ if ($('#' + proposedId).length > 0) proposedId += counter++;
158
+ this.id = proposedId;
159
+ }
160
+ if (thisTag > lastTag) {
161
+ for (var i = 0; i < thisTag - lastTag; i++) {
162
+ var tmp = $('<ol/>'); toc.append(tmp); toc = tmp;
163
+ }
164
+ }
165
+ if (thisTag < lastTag) {
166
+ for (var i = 0; i < lastTag - thisTag; i++) toc = toc.parent();
167
+ }
168
+ toc.append('<li><a href="#' + this.id + '">' + $(this).text() + '</a></li>');
169
+ lastTag = thisTag;
170
+ });
171
+ if (!show) return;
172
+ html = '<div id="toc"><p class="title"><a class="hide_toc" href="#"><strong>Table of Contents</strong></a> <small>(<a href="#" class="float_toc">left</a>)</small></p></div>';
173
+ $('#content').prepend(html);
174
+ $('#toc').append(_toc);
175
+ $('#toc .hide_toc').toggle(function() {
176
+ $('#toc .top').slideUp('fast');
177
+ $('#toc').toggleClass('hidden');
178
+ $('#toc .title small').toggle();
179
+ }, function() {
180
+ $('#toc .top').slideDown('fast');
181
+ $('#toc').toggleClass('hidden');
182
+ $('#toc .title small').toggle();
183
+ });
184
+ $('#toc .float_toc').toggle(function() {
185
+ $(this).text('float');
186
+ $('#toc').toggleClass('nofloat');
187
+ }, function() {
188
+ $(this).text('left')
189
+ $('#toc').toggleClass('nofloat');
190
+ });
191
+ }
192
+
193
+ $(framesInit);
194
+ $(createSourceLinks);
195
+ $(createDefineLinks);
196
+ $(createFullTreeLinks);
197
+ $(fixBoxInfoHeights);
198
+ $(searchFrameLinks);
199
+ $(linkSummaries);
200
+ $(keyboardShortcuts);
201
+ $(summaryToggle);
202
+ $(fixOutsideWorldLinks);
203
+ $(generateTOC);
@@ -0,0 +1,149 @@
1
+ var inSearch = null;
2
+ var searchIndex = 0;
3
+ var searchCache = [];
4
+ var searchString = '';
5
+
6
+ function fullListSearch() {
7
+ // generate cache
8
+ searchCache = [];
9
+ $('#full_list li').each(function() {
10
+ var link = $(this).find('.object_link a');
11
+ searchCache.push({name:link.text(), node:$(this), link:link});
12
+ });
13
+
14
+ $('#search input').keyup(function() {
15
+ searchString = this.value.toLowerCase();
16
+ if (searchString == "") {
17
+ clearTimeout(inSearch);
18
+ inSearch = null;
19
+ $('#full_list, #content').removeClass('insearch');
20
+ $('#full_list li').removeClass('found').each(function() {
21
+
22
+ var link = $(this).find('.object_link a');
23
+ link.text(link.text());
24
+ });
25
+ if (clicked) {
26
+ clicked.parents('ul').each(function() {
27
+ $(this).removeClass('collapsed').prev().removeClass('collapsed');
28
+ });
29
+ }
30
+ highlight();
31
+ }
32
+ else {
33
+ if (inSearch) clearTimeout(inSearch);
34
+ searchIndex = 0;
35
+ lastRowClass = '';
36
+ $('#full_list, #content').addClass('insearch');
37
+ $('#noresults').text('');
38
+ searchItem();
39
+ }
40
+ });
41
+
42
+ $('#search input').focus();
43
+ $('#full_list').after("<div id='noresults'></div>")
44
+ }
45
+
46
+ var lastRowClass = '';
47
+ function searchItem() {
48
+ for (var i = 0; i < searchCache.length / 50; i++) {
49
+ var item = searchCache[searchIndex];
50
+ if (item.name.toLowerCase().indexOf(searchString) == -1) {
51
+ item.node.removeClass('found');
52
+ }
53
+ else {
54
+ item.node.css('padding-left', '10px').addClass('found');
55
+ item.node.removeClass(lastRowClass).addClass(lastRowClass == 'r1' ? 'r2' : 'r1');
56
+ lastRowClass = item.node.hasClass('r1') ? 'r1' : 'r2';
57
+ item.link.html(item.name.replace(new RegExp("(" +
58
+ searchString.replace(/([\/.*+?|()\[\]{}\\])/g, "\\$1") + ")", "ig"),
59
+ '<strong>$1</strong>'));
60
+ }
61
+
62
+ if (searchCache.length == searchIndex + 1) {
63
+ return searchDone();
64
+ }
65
+ else {
66
+ searchIndex++;
67
+ }
68
+ }
69
+ inSearch = setTimeout('searchItem()', 0);
70
+ }
71
+
72
+ function searchDone() {
73
+ highlight(true);
74
+ if ($('#full_list li:visible').size() == 0) {
75
+ $('#noresults').text('No results were found.').hide().fadeIn();
76
+ }
77
+ else {
78
+ $('#noresults').text('');
79
+ }
80
+ $('#content').removeClass('insearch');
81
+ clearTimeout(inSearch);
82
+ inSearch = null;
83
+ }
84
+
85
+ clicked = null;
86
+ function linkList() {
87
+ $('#full_list li, #full_list li a:last').click(function(evt) {
88
+ if ($(this).hasClass('toggle')) return true;
89
+ if (this.tagName.toLowerCase() == "li") {
90
+ var toggle = $(this).children('a.toggle');
91
+ if (toggle.size() > 0 && evt.pageX < toggle.offset().left) {
92
+ toggle.click();
93
+ return false;
94
+ }
95
+ }
96
+ if (clicked) clicked.removeClass('clicked');
97
+ var win = window.top.frames.main ? window.top.frames.main : window.parent;
98
+ if (this.tagName.toLowerCase() == "a") {
99
+ clicked = $(this).parent('li').addClass('clicked');
100
+ win.location = this.href;
101
+ }
102
+ else {
103
+ clicked = $(this).addClass('clicked');
104
+ win.location = $(this).find('a:last').attr('href');
105
+ }
106
+ return false;
107
+ });
108
+ }
109
+
110
+ function collapse() {
111
+ if (!$('#full_list').hasClass('class')) return;
112
+ $('#full_list.class a.toggle').click(function() {
113
+ $(this).parent().toggleClass('collapsed').next().toggleClass('collapsed');
114
+ highlight();
115
+ return false;
116
+ });
117
+ $('#full_list.class ul').each(function() {
118
+ $(this).addClass('collapsed').prev().addClass('collapsed');
119
+ });
120
+ $('#full_list.class').children().removeClass('collapsed');
121
+ highlight();
122
+ }
123
+
124
+ function highlight(no_padding) {
125
+ var n = 1;
126
+ $('#full_list li:visible').each(function() {
127
+ var next = n == 1 ? 2 : 1;
128
+ $(this).removeClass("r" + next).addClass("r" + n);
129
+ if (!no_padding && $('#full_list').hasClass('class')) {
130
+ $(this).css('padding-left', (10 + $(this).parents('ul').size() * 15) + 'px');
131
+ }
132
+ n = next;
133
+ });
134
+ }
135
+
136
+ function escapeShortcut() {
137
+ $(document).keydown(function(evt) {
138
+ if (evt.which == 27) {
139
+ $('#search_frame', window.top.document).slideUp(100);
140
+ $('#search a', window.top.document).removeClass('active inactive')
141
+ $(window.top).focus();
142
+ }
143
+ });
144
+ }
145
+
146
+ $(escapeShortcut);
147
+ $(fullListSearch);
148
+ $(linkList);
149
+ $(collapse);