cachai 0.0.7 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cachai.gemspec +1 -1
- data/examples/test-site/.gitignore +2 -0
- data/examples/test-site/Gemfile +4 -0
- data/examples/test-site/config.ru +8 -0
- data/examples/test-site/config/database.yml +9 -0
- data/examples/test-site/readme.md +7 -0
- data/lib/cachai.rb +62 -3
- data/lib/views/comment.erb +71 -0
- data/lib/views/comments.erb +13 -0
- data/lib/views/layout.erb +59 -0
- data/lib/views/posts.erb +10 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5677c8d22b6c5823c95243a8f96f53f470f1dc8c
|
4
|
+
data.tar.gz: 7c68c94430c37fa4d7399c1d509ed4cbcb1d1313
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4997bdeb894e3ae33d1089f4f12178153908609e283f979158f20d005aba4c56a5d38b3afd200635b4c2ff977db090af9eeb647b38cd4856c6c403ce55b3d34a
|
7
|
+
data.tar.gz: 43d3fb372b95d74b32138fdd8789872b38ea821d68af4538ff5d72370cc394e2f1d56390fd17c41708f5150c0edd49106948e005495d3a4b214b38b519bcd8d9
|
data/cachai.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "cachai"
|
7
|
-
spec.version = '0.0
|
7
|
+
spec.version = '0.1.0'
|
8
8
|
spec.authors = ["Tomás Pollak"]
|
9
9
|
spec.email = ["tomas@forkhq.com"]
|
10
10
|
spec.description = %q{Middleware for embedabble comments.}
|
data/lib/cachai.rb
CHANGED
@@ -21,8 +21,7 @@ module Cachai
|
|
21
21
|
|
22
22
|
CACHE_MINUTES = 10 * 60 # 10 minutes
|
23
23
|
|
24
|
-
def initialize(app, opts =
|
25
|
-
opts = opts || {}
|
24
|
+
def initialize(app, opts = {})
|
26
25
|
domain = opts.delete(:domain) or raise 'Domain required.'
|
27
26
|
redis_host = opts.delete(:redis_host) || 'localhost'
|
28
27
|
|
@@ -31,7 +30,7 @@ module Cachai
|
|
31
30
|
Cachai.load_db!
|
32
31
|
|
33
32
|
if key = opts.delete(:akismet_key)
|
34
|
-
@akismet = Akismet.new(:api_key => key, :blog => "http://#{domain}")
|
33
|
+
@akismet = Akismet.new(:api_key => key, :blog => "http://#{Cachai.domain}")
|
35
34
|
else
|
36
35
|
puts "No Akismet key found! Will not check comments for spam."
|
37
36
|
end
|
@@ -208,4 +207,64 @@ module Cachai
|
|
208
207
|
|
209
208
|
end
|
210
209
|
|
210
|
+
class Admin < Sinatra::Base
|
211
|
+
|
212
|
+
# set :public_folder, File.join(settings.root, '..', 'public')
|
213
|
+
# set :views, File.join(settings.root, 'views')
|
214
|
+
# use Rack::Static, :urls => %w(/css /img /js /favicon.ico), :root => 'public'
|
215
|
+
enable :method_override
|
216
|
+
use ActiveRecord::ConnectionAdapters::ConnectionManagement
|
217
|
+
|
218
|
+
def initialize(opts = {})
|
219
|
+
require 'tilt/erb'
|
220
|
+
Cachai.load_db!
|
221
|
+
super
|
222
|
+
end
|
223
|
+
|
224
|
+
get '/' do
|
225
|
+
redirect to('/posts')
|
226
|
+
end
|
227
|
+
|
228
|
+
get '/posts' do
|
229
|
+
@posts = Cachai::Post.all.order(:id => :desc)
|
230
|
+
deliver @posts, :posts
|
231
|
+
end
|
232
|
+
|
233
|
+
get '/posts/:id' do
|
234
|
+
@post = Cachai::Post.find(params[:id])
|
235
|
+
@comments = @post.responses.comment
|
236
|
+
deliver @comments, :comments
|
237
|
+
end
|
238
|
+
|
239
|
+
get '/comments' do
|
240
|
+
@comments = Cachai::Response.all.order(:created_at => :desc)
|
241
|
+
deliver @comments, :comments
|
242
|
+
end
|
243
|
+
|
244
|
+
get '/comments/:id' do
|
245
|
+
@comment = Cachai::Response.find(params[:id])
|
246
|
+
deliver @comment, :comment
|
247
|
+
end
|
248
|
+
|
249
|
+
put '/comments/:id' do
|
250
|
+
@comment = Cachai::Response.find(params[:id])
|
251
|
+
@comment.update_attributes(params[:comment])
|
252
|
+
redirect back
|
253
|
+
end
|
254
|
+
|
255
|
+
def deliver(obj, view)
|
256
|
+
if request.xhr?
|
257
|
+
json(obj)
|
258
|
+
else
|
259
|
+
erb view
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def json(obj)
|
264
|
+
content_type 'application/json'
|
265
|
+
return obj.is_a?(String) ? obj : obj.to_json
|
266
|
+
end
|
267
|
+
|
268
|
+
end
|
269
|
+
|
211
270
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
<h1>Comment <%= @comment.id %></h1>
|
2
|
+
|
3
|
+
<form method="post" action="<%= url("/comments/#{@comment.id}") %>">
|
4
|
+
<input type="hidden" name="_method" value="put" />
|
5
|
+
|
6
|
+
<table class="table">
|
7
|
+
|
8
|
+
<tr>
|
9
|
+
<td>Post </td>
|
10
|
+
<td><a href="<%= url("/posts/#{@comment.post.id}") %>"><%= @comment.post.path %></a></td>
|
11
|
+
</tr>
|
12
|
+
|
13
|
+
<tr>
|
14
|
+
<td>Comment ID</td>
|
15
|
+
<td><%= @comment.id %></td>
|
16
|
+
</tr>
|
17
|
+
|
18
|
+
<tr>
|
19
|
+
<td>Approved</td>
|
20
|
+
<td>
|
21
|
+
<span><%= @comment.approved %></span>
|
22
|
+
<input type="hidden" name="comment[approved]" value="<%= @comment.approved %>" />
|
23
|
+
</td>
|
24
|
+
</tr>
|
25
|
+
|
26
|
+
<tr>
|
27
|
+
<td>Author name</td>
|
28
|
+
<td>
|
29
|
+
<span><%= @comment.author_name %></span>
|
30
|
+
<input type="hidden" name="comment[author_url]" value="<%= @comment.author_name %>" />
|
31
|
+
</td>
|
32
|
+
</tr>
|
33
|
+
|
34
|
+
<tr>
|
35
|
+
<td>Author email</td>
|
36
|
+
<td>
|
37
|
+
<span><%= @comment.author_email %></span>
|
38
|
+
<input type="hidden" name="comment[author_url]" value="<%= @comment.author_email %>" />
|
39
|
+
</td>
|
40
|
+
</tr>
|
41
|
+
|
42
|
+
<tr>
|
43
|
+
<td>Author URL</td>
|
44
|
+
<td>
|
45
|
+
<span><%= @comment.author_url %></span>
|
46
|
+
<input type="hidden" name="comment[author_url]" value="<%= @comment.author_url %>" />
|
47
|
+
</td>
|
48
|
+
</tr>
|
49
|
+
|
50
|
+
<tr>
|
51
|
+
<td>Content</td>
|
52
|
+
<td class="textarea">
|
53
|
+
<span><%= @comment.content %></span>
|
54
|
+
<textarea style="display: none" name="comment[content]"><%= @comment.content %></textarea>
|
55
|
+
</td>
|
56
|
+
</tr>
|
57
|
+
|
58
|
+
<tr>
|
59
|
+
<td>Parent ID</td>
|
60
|
+
<td><%= @comment.parent_id %></td>
|
61
|
+
</tr>
|
62
|
+
|
63
|
+
<tr>
|
64
|
+
<td>Created at</td>
|
65
|
+
<td><%= @comment.created_at %></td>
|
66
|
+
</tr>
|
67
|
+
|
68
|
+
</table>
|
69
|
+
|
70
|
+
<button type="submit">Update</button>
|
71
|
+
</form>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<h1><%= @comments.count %> comments</h1>
|
2
|
+
|
3
|
+
<table class="table">
|
4
|
+
<% @comments.each do |comm| %>
|
5
|
+
<tr>
|
6
|
+
<td><a href="<%= url("/comments/#{comm.id}") %>"><%= comm.id %></a></td>
|
7
|
+
<td><%= comm.author_name %></td>
|
8
|
+
<td><%= comm.author_email %></td>
|
9
|
+
<td><%= comm.author_url %></td>
|
10
|
+
<td><%= comm.content[0..50] + '...' %></td>
|
11
|
+
</tr>
|
12
|
+
<% end %>
|
13
|
+
</table>
|
@@ -0,0 +1,59 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html xml:lang="en" lang="en">
|
3
|
+
<head>
|
4
|
+
<title>Cachai::Admin</title>
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
7
|
+
<meta http-equiv="cleartype" content="on">
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
9
|
+
<meta name="description" content="Cachai Admin">
|
10
|
+
<meta name="author" content="Fork Ltd.">
|
11
|
+
|
12
|
+
<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
|
13
|
+
<link rel="stylesheet" href="http://tomas.github.io/base.css/build/base-min.css" type="text/css" media="screen" />
|
14
|
+
<style type="text/css">
|
15
|
+
body {
|
16
|
+
padding: 30px;
|
17
|
+
}
|
18
|
+
|
19
|
+
h1,h2 {
|
20
|
+
margin-bottom: 1em;
|
21
|
+
}
|
22
|
+
</style>
|
23
|
+
</head>
|
24
|
+
|
25
|
+
<body>
|
26
|
+
|
27
|
+
<div id="main" class="fluid container clearfix">
|
28
|
+
<%= yield %>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
32
|
+
<script>
|
33
|
+
|
34
|
+
function show_input(input) {
|
35
|
+
input.type = 'text';
|
36
|
+
$(input).prev().hide();
|
37
|
+
}
|
38
|
+
|
39
|
+
function hide_input(input) {
|
40
|
+
input.type = 'hidden';
|
41
|
+
$(input).prev().show().text(input.value);
|
42
|
+
}
|
43
|
+
|
44
|
+
$('table').on('dblclick', 'td', function(e) {
|
45
|
+
if ($(this).hasClass('textarea')) {
|
46
|
+
var val = $(this).find('textarea').toggle().val();
|
47
|
+
$(this).find('span').toggle().html(val);
|
48
|
+
} else {
|
49
|
+
var input = $(this).find('input');
|
50
|
+
if (input[0].type == 'hidden') {
|
51
|
+
show_input(input[0]);
|
52
|
+
} else {
|
53
|
+
hide_input(input[0]);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
})
|
57
|
+
</script>
|
58
|
+
</body>
|
59
|
+
</html>
|
data/lib/views/posts.erb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cachai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomás Pollak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,10 +150,19 @@ files:
|
|
150
150
|
- Rakefile
|
151
151
|
- cachai.gemspec
|
152
152
|
- db/schema.rb
|
153
|
+
- examples/test-site/.gitignore
|
154
|
+
- examples/test-site/Gemfile
|
155
|
+
- examples/test-site/config.ru
|
156
|
+
- examples/test-site/config/database.yml
|
157
|
+
- examples/test-site/readme.md
|
153
158
|
- lib/akismet.rb
|
154
159
|
- lib/cachai.rb
|
155
160
|
- lib/models.rb
|
156
161
|
- lib/time_ago.rb
|
162
|
+
- lib/views/comment.erb
|
163
|
+
- lib/views/comments.erb
|
164
|
+
- lib/views/layout.erb
|
165
|
+
- lib/views/posts.erb
|
157
166
|
- spec/get_comments_test.rb
|
158
167
|
- spec/post_comments_test.rb
|
159
168
|
- spec/spec_helper.rb
|