paprite 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/app/assets/papr_script.js +161 -0
- data/app/assets/papr_stylesheet.css +50 -0
- data/app/controllers/paprs_controller.rb +52 -0
- data/app/migrations/migration.rb +11 -0
- data/app/models/papr.rb +6 -0
- data/app/views/papr_partial/_comments.html.erb +45 -0
- data/app/views/paprs/callback.html.erb +15 -0
- data/app/views/paprs/redir.html.erb +4 -0
- data/lib/generators/paprite/install_generator.rb +41 -0
- data/lib/paprite/proxy/proxy.rb +47 -0
- data/lib/paprite/rails/routes.rb +10 -0
- data/lib/paprite/version.rb +3 -0
- data/lib/paprite.rb +3 -0
- data/paprite.gemspec +24 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,161 @@
|
|
1
|
+
$(document).ready( function ()
|
2
|
+
{
|
3
|
+
var cookie = readPaprCookie('papr');
|
4
|
+
if (cookie)
|
5
|
+
{
|
6
|
+
data_hash =
|
7
|
+
{
|
8
|
+
user: cookie.split('_')[0];
|
9
|
+
};
|
10
|
+
ajax_hash =
|
11
|
+
{
|
12
|
+
data = data_hash,
|
13
|
+
dataType: 'text',
|
14
|
+
url: 'papr/confirm'
|
15
|
+
};
|
16
|
+
$.ajax(ajax_hash).success( function (data)
|
17
|
+
{
|
18
|
+
if (data == 'true')
|
19
|
+
{
|
20
|
+
$('#papr_sign_in').hide();
|
21
|
+
}
|
22
|
+
else
|
23
|
+
{
|
24
|
+
$('#papr_comment_form').hide();
|
25
|
+
}
|
26
|
+
});
|
27
|
+
}
|
28
|
+
else
|
29
|
+
{
|
30
|
+
$('#papr_comment_form').hide();
|
31
|
+
}
|
32
|
+
});
|
33
|
+
|
34
|
+
function submitPaprCommentForm (id)
|
35
|
+
{
|
36
|
+
$('#papr_submit_button').click( function ()
|
37
|
+
{
|
38
|
+
var content = $('.papr_content_field').val()
|
39
|
+
var data_hash =
|
40
|
+
{
|
41
|
+
content: content,
|
42
|
+
id: id,
|
43
|
+
user: readPaprCookie('papr').split('_')[0]
|
44
|
+
};
|
45
|
+
var ajax_hash =
|
46
|
+
{
|
47
|
+
data: data_hash,
|
48
|
+
dataType: 'text',
|
49
|
+
url: '/papr/submit'
|
50
|
+
};
|
51
|
+
$.ajax(ajax_hash).success(function (data)
|
52
|
+
{
|
53
|
+
if (data == 'true')
|
54
|
+
{
|
55
|
+
//say submitted
|
56
|
+
}
|
57
|
+
else
|
58
|
+
{
|
59
|
+
//say error
|
60
|
+
}
|
61
|
+
});
|
62
|
+
|
63
|
+
//sync with Papr master
|
64
|
+
var papr_hash =
|
65
|
+
{
|
66
|
+
data: data_hash,
|
67
|
+
dataType: 'text'
|
68
|
+
//url: //insert this
|
69
|
+
};
|
70
|
+
$.ajax(papr_hash)
|
71
|
+
});
|
72
|
+
};
|
73
|
+
|
74
|
+
function readPaprCookie (name)
|
75
|
+
{
|
76
|
+
var nameEQ = name + '+';
|
77
|
+
var ca = document.cookie.split(';');
|
78
|
+
for (var i = 0; i < ca.length; i++)
|
79
|
+
{
|
80
|
+
var c = ca[i];
|
81
|
+
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
82
|
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
83
|
+
return null;
|
84
|
+
}
|
85
|
+
};
|
86
|
+
|
87
|
+
function createPaprCookie (name,value,days)
|
88
|
+
{
|
89
|
+
if (days)
|
90
|
+
{
|
91
|
+
var date = new Date();
|
92
|
+
date.setTime(date.getTime()+(days*24*60*60*1000));
|
93
|
+
var expires = "; expires="+date.toGMTString();
|
94
|
+
}
|
95
|
+
else var expires = "";
|
96
|
+
document.cookie = name+"="+value+expires+"; path=/";
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
//sign in with twitter
|
101
|
+
function openPaprPopup ()
|
102
|
+
{
|
103
|
+
var windowSizeArray = [ "width=200,height=200",
|
104
|
+
"width=300,height=400,scrollbars=yes" ];
|
105
|
+
var windowName = $('.twitter_popup').attr("name");
|
106
|
+
var windowSize = windowSizeArray[$('.twitter_popup').attr("rel")];
|
107
|
+
window.open('/twitter/redir', windowName, windowSize);
|
108
|
+
event.preventDefault();
|
109
|
+
var t = setTimeout( function ()
|
110
|
+
{
|
111
|
+
recursivelyCheckForAuthenticationCompletion();
|
112
|
+
}, 4000);
|
113
|
+
};
|
114
|
+
|
115
|
+
function signInPaprWithTwitter ()
|
116
|
+
{
|
117
|
+
var data_hash =
|
118
|
+
{
|
119
|
+
domain: getDomainName(window.location.href.toString())
|
120
|
+
};
|
121
|
+
var ajax_hash =
|
122
|
+
{
|
123
|
+
data: data_hash,
|
124
|
+
dataType: 'text',
|
125
|
+
url: '/twitter/authenticate'
|
126
|
+
};
|
127
|
+
$.ajax(ajax_hash).success( function (data)
|
128
|
+
{
|
129
|
+
window.location.href = data;
|
130
|
+
});
|
131
|
+
};
|
132
|
+
|
133
|
+
function recursivelyCheckForAuthenticationCompletion ()
|
134
|
+
{
|
135
|
+
var t = setTimeout( function ()
|
136
|
+
{
|
137
|
+
var ajax_hash =
|
138
|
+
{
|
139
|
+
url: '/twitter/ping_loop',
|
140
|
+
dataType: 'text'
|
141
|
+
};
|
142
|
+
$.ajax(ajax_hash).success( function (data)
|
143
|
+
{
|
144
|
+
if (data != 'false')
|
145
|
+
{
|
146
|
+
createPaprCookie('papr', data, 360);
|
147
|
+
$('#papr_sign_in').hide();
|
148
|
+
$('#papr_comment_form').show();
|
149
|
+
console.log('authentication successful');
|
150
|
+
}
|
151
|
+
else
|
152
|
+
{
|
153
|
+
recursivelyCheckForAuthenticationCompletion();
|
154
|
+
}
|
155
|
+
});
|
156
|
+
}, 1000);
|
157
|
+
};
|
158
|
+
|
159
|
+
function getDomainName (url) {
|
160
|
+
return url.match(/:\/\/(.[^/]+)/)[1];
|
161
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#papr_area
|
2
|
+
{
|
3
|
+
border-top:1px solid #C0C0C0;
|
4
|
+
max-width:800px;
|
5
|
+
margin:0px auto;
|
6
|
+
}
|
7
|
+
|
8
|
+
#papr_area a
|
9
|
+
{
|
10
|
+
text-decoration:none;
|
11
|
+
}
|
12
|
+
|
13
|
+
#papr_tally
|
14
|
+
{
|
15
|
+
float:right;
|
16
|
+
padding-right:5%;
|
17
|
+
}
|
18
|
+
|
19
|
+
.papr_h1
|
20
|
+
{
|
21
|
+
font-size:100%;
|
22
|
+
float:left;
|
23
|
+
padding-left:5%;
|
24
|
+
}
|
25
|
+
|
26
|
+
.add_comment
|
27
|
+
{
|
28
|
+
margin-left:5%;
|
29
|
+
}
|
30
|
+
|
31
|
+
.papr_list
|
32
|
+
{
|
33
|
+
overflow:hidden;
|
34
|
+
}
|
35
|
+
|
36
|
+
.papr_list li
|
37
|
+
{
|
38
|
+
float:left;
|
39
|
+
list-style:none;
|
40
|
+
}
|
41
|
+
|
42
|
+
.twitter_sign_in_papr
|
43
|
+
{
|
44
|
+
width:151px; height:23px;
|
45
|
+
}
|
46
|
+
|
47
|
+
.clear
|
48
|
+
{
|
49
|
+
clear:both;
|
50
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class PaprsController < ApplicationController
|
2
|
+
require 'paprite'
|
3
|
+
|
4
|
+
def submit
|
5
|
+
c = Comment.new({ :content => params[:content], :article_id => params[:id].to_i})
|
6
|
+
if c.save!
|
7
|
+
respond_to do |format|
|
8
|
+
format.text { render :text => 'true' }
|
9
|
+
end
|
10
|
+
else
|
11
|
+
respond_to do |format|
|
12
|
+
format.text { render :text => 'false' }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def redir
|
18
|
+
@ext = params[:ext]
|
19
|
+
end
|
20
|
+
|
21
|
+
#-- proxies
|
22
|
+
#-- twitter
|
23
|
+
#/twitter/authenticate
|
24
|
+
def authenticate
|
25
|
+
response = Paprite::Proxy.authenticate(params[:domain])
|
26
|
+
respond_to do |format|
|
27
|
+
format.text { render :text => response }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#/twitter/ping_loop
|
32
|
+
def ping_loop
|
33
|
+
response = Paprite::Proxy.ping_loop
|
34
|
+
respond_to do |format|
|
35
|
+
format.text { render :text => response }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
#/twitter/callback
|
40
|
+
def callback
|
41
|
+
name = Paprite::Proxy.callback(params[:oauth_verifier])
|
42
|
+
end
|
43
|
+
|
44
|
+
#-- papr
|
45
|
+
def confirm
|
46
|
+
response = Paprite::Proxy.confirm_login(params[:user])
|
47
|
+
respond_to do |format|
|
48
|
+
format.text { render :text => response }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/app/models/papr.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
<!-- comment tally -->
|
2
|
+
<%
|
3
|
+
tally = 0
|
4
|
+
article.paprs.each do |hp|
|
5
|
+
hp.paprs.each do |lp|
|
6
|
+
tally += 1
|
7
|
+
end
|
8
|
+
tally += 1
|
9
|
+
end
|
10
|
+
tally = tally.to_s
|
11
|
+
%>
|
12
|
+
|
13
|
+
<div id="papr_area">
|
14
|
+
<h1 class="papr_h1"> Keep up with Papr </h1>
|
15
|
+
<h1 id="papr_tally" class="papr_h1"> <%= tally %> Comments </h1>
|
16
|
+
<div class="clear">
|
17
|
+
|
18
|
+
</div>
|
19
|
+
<div id="papr_sign_in">
|
20
|
+
<span class="add_comment">Add a comment with:</span>
|
21
|
+
<ul class="papr_list">
|
22
|
+
<li class="twitter_sign_in_papr" onclick="openPaprPopup();">
|
23
|
+
<%= image_tag 'https://si0.twimg.com/images/dev/buttons/sign-in-with-twitter-l.png' %>
|
24
|
+
<%= link_to "", '#', :class => 'twitter_popup', :onclick => 'signInPaprWithTwitter();', :rel => '1', :name => 'Authenticate' %>
|
25
|
+
</li>
|
26
|
+
<li>Facebook</li>
|
27
|
+
</ul>
|
28
|
+
</div>
|
29
|
+
<div id="papr_comment_form">
|
30
|
+
<%= form_for Papr.new do |f| %>
|
31
|
+
<%= f.text_area :content, :class => 'papr_content_field' %>
|
32
|
+
<%= button_to_function("submit", "submitPaprCommentForm(#{article.id.to_s});", :id => 'papr_submit_button') %>
|
33
|
+
<% end %>
|
34
|
+
</div>
|
35
|
+
<% article.paprs.each do |comment| %>
|
36
|
+
<div>
|
37
|
+
<%= comment.content %>
|
38
|
+
</div>
|
39
|
+
<% comment.paprs.each do |reply| %>
|
40
|
+
<div>
|
41
|
+
<%= reply.content %>
|
42
|
+
</div>
|
43
|
+
<% end %>
|
44
|
+
<% end %>
|
45
|
+
</div>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%= javascript_include_tag :application %>
|
2
|
+
<script>
|
3
|
+
var ajax_hash =
|
4
|
+
{
|
5
|
+
dataType: 'text',
|
6
|
+
url: 'http://papr.heroku.com/twitter/complete'
|
7
|
+
};
|
8
|
+
$.ajax(ajax_hash).success( function (data)
|
9
|
+
{
|
10
|
+
if (data == 'true')
|
11
|
+
{
|
12
|
+
window.close();
|
13
|
+
}
|
14
|
+
});
|
15
|
+
</script>
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Paprite
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
|
6
|
+
desc "Copy MVC files and database migration file"
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
@source_root ||= File.expand_path("../../../../app", __FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
def copy_model
|
13
|
+
copy_file("models/papr.rb", "app/models/papr.rb")
|
14
|
+
end
|
15
|
+
|
16
|
+
def copy_views
|
17
|
+
copy_file("views/papr_partial/_comments.html.erb", "app/views/papr_partial/_comments.html.erb")
|
18
|
+
copy_file("views/paprs/callback.html.erb", "app/views/paprs/callback.html.erb")
|
19
|
+
copy_file("views/paprs/redir.html.erb", "app/views/paprs/redir.html.erb")
|
20
|
+
end
|
21
|
+
|
22
|
+
def copy_controller
|
23
|
+
copy_file("controllers/paprs_controller.rb", "app/controllers/paprs_controller.rb")
|
24
|
+
end
|
25
|
+
|
26
|
+
def copy_assets
|
27
|
+
copy_file("assets/papr_stylesheet.css", "app/assets/stylesheets/papr_stylesheet.css")
|
28
|
+
copy_file("assets/papr_script.js", "app/assets/javascripts/papr_script.js")
|
29
|
+
end
|
30
|
+
|
31
|
+
def copy_migrations
|
32
|
+
copy_file("migrations/migration.rb", "db/migrate/#{Time.now.to_s.split.join('_')}_create_paprs.rb")
|
33
|
+
end
|
34
|
+
|
35
|
+
def setup_routes
|
36
|
+
route("add_papr_routes")
|
37
|
+
route("resources :paprs")
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Paprite
|
2
|
+
|
3
|
+
class Proxy
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
#Tells papr to request first OAuth token, as well as provides the domain for the
|
10
|
+
#callback url to be constructed off of.
|
11
|
+
def authenticate(domain)
|
12
|
+
url = "http://papr.heroku.com/twitter/authenticate?domain=#{domain.to_s}"
|
13
|
+
res = Net::HTTP.get_response(URI.parse(url))
|
14
|
+
response = res.body
|
15
|
+
return response
|
16
|
+
end
|
17
|
+
|
18
|
+
#Pings Papr every second (after a 4sec delay) to see if authentication is completed
|
19
|
+
#Papr will respond with either 'false' if uncomplete or with a unique string to be saved
|
20
|
+
#into a cookie
|
21
|
+
def ping_loop
|
22
|
+
url = 'http://papr.heroku.com/twitter/ping_loop'
|
23
|
+
res = Net::HTTP.get_response(URI.parse(url))
|
24
|
+
response = res.body
|
25
|
+
return response
|
26
|
+
end
|
27
|
+
|
28
|
+
#forwards the OAuth verifier to Papr
|
29
|
+
def callback(verifier)
|
30
|
+
url = 'http://papr.heroku.com/twitter/callback?oauth_verifier=' + verifier.to_s
|
31
|
+
res = Net::HTTP.get_response(URI.parse(url))
|
32
|
+
response = res.body
|
33
|
+
return response
|
34
|
+
end
|
35
|
+
|
36
|
+
#-- papr
|
37
|
+
def confirm_login(user)
|
38
|
+
url = 'http://papr.heroku.com/confirm/login?user=' + user
|
39
|
+
res = Net::HTTP.get_response(URI.parse(url))
|
40
|
+
response = res.body
|
41
|
+
return response
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module ActionDispatch::Routing
|
2
|
+
class Mapper
|
3
|
+
def add_papr_routes
|
4
|
+
match '/twitter/authenticate' => 'paprs#authenticate'
|
5
|
+
match '/twitter/ping_loop' => 'paprs#ping_loop'
|
6
|
+
match '/twitter/callback' => 'paprs#callback'
|
7
|
+
match '/twitter/redir' => 'paprs#redir'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/paprite.rb
ADDED
data/paprite.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "paprite/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "paprite"
|
7
|
+
s.version = Paprite::VERSION
|
8
|
+
s.authors = ["Gideon Providence"]
|
9
|
+
s.email = ["jprovidence@live.ca"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Powerful Ruby on Rails commenting engine.}
|
12
|
+
s.description = %q{A powerful commenting engine that greatly boosts the community aspect of your site and drives users to follow along}
|
13
|
+
|
14
|
+
s.rubyforge_project = "paprite"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paprite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gideon Providence
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-08-15 00:00:00 Z
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A powerful commenting engine that greatly boosts the community aspect of your site and drives users to follow along
|
17
|
+
email:
|
18
|
+
- jprovidence@live.ca
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
|
+
files:
|
26
|
+
- .gitignore
|
27
|
+
- Gemfile
|
28
|
+
- Rakefile
|
29
|
+
- app/assets/papr_script.js
|
30
|
+
- app/assets/papr_stylesheet.css
|
31
|
+
- app/controllers/paprs_controller.rb
|
32
|
+
- app/migrations/migration.rb
|
33
|
+
- app/models/papr.rb
|
34
|
+
- app/views/papr_partial/_comments.html.erb
|
35
|
+
- app/views/paprs/callback.html.erb
|
36
|
+
- app/views/paprs/redir.html.erb
|
37
|
+
- lib/generators/paprite/install_generator.rb
|
38
|
+
- lib/paprite.rb
|
39
|
+
- lib/paprite/proxy/proxy.rb
|
40
|
+
- lib/paprite/rails/routes.rb
|
41
|
+
- lib/paprite/version.rb
|
42
|
+
- paprite.gemspec
|
43
|
+
homepage: ""
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: paprite
|
66
|
+
rubygems_version: 1.8.7
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Powerful Ruby on Rails commenting engine.
|
70
|
+
test_files: []
|
71
|
+
|