Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6f70cb1

Browse files
committedJun 20, 2014
Initial commit
1 parent f511acb commit 6f70cb1

File tree

8 files changed

+168
-0
lines changed

8 files changed

+168
-0
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ build/
3232

3333
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
3434
.rvmrc
35+
.DS_Store

‎Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gem 'etherpad-lite'

‎README.rdoc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
= Etherpad
2+

‎app/controllers/pads_controller.rb

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class PadsController < ApplicationController
2+
3+
before_filter :find_project
4+
5+
def show
6+
@pad_host = ENV['PAD_HOST']
7+
pad_key = ENV['PAD_KEY']
8+
session[:ep_sessions] = {} if session[:ep_sessions].nil?
9+
ether = EtherpadLite.connect(@pad_host, pad_key)
10+
# Get the EtherpadLite Group and Pad by id
11+
@group = ether.group(@project.identifier)
12+
@target_pad = "#{@group.id}$defaultpad"
13+
@pad = @group.pad(@target_pad)
14+
@user_name = User.current.name
15+
# Map the user to an EtherpadLite Author
16+
author = ether.author("my_app_user_#{User.current.id}", :name => User.current.name)
17+
# Get or create an hour-long session for this Author in this Group
18+
sess = session[:ep_sessions][@group.id] ? ether.get_session(session[:ep_sessions][@group.id]) : @group.create_session(author, 60)
19+
if sess.expired?
20+
sess.delete
21+
sess = @group.create_session(author, 60)
22+
end
23+
session[:ep_sessions][@group.id] = sess.id
24+
# Set the EtherpadLite session cookie. This will automatically be picked up by the jQuery plugin's iframe.
25+
cookies[:sessionID] = {:value => sess.id, :domain => ".tipit.net"}
26+
end
27+
28+
private
29+
def find_project
30+
@project = Project.find(params[:project_id])
31+
rescue ActiveRecord::RecordNotFound
32+
render_404
33+
end
34+
35+
end

‎app/views/pads/show.erb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<% content_for :header_tags do %>
2+
<%= javascript_include_tag('etherpad.js', :plugin => 'chiliproject_etherpad') %>
3+
<% end %>
4+
5+
<div id="pad" style="min-height: 500px"></div>
6+
7+
8+
<script>
9+
var userName = '<%=@user_name %>';
10+
var projectId = '<%=@target_pad %>';
11+
var padHost = '<%=@pad_host %>';
12+
jQuery('#pad').pad({'padId':projectId,'width':'100%', 'height':'700px', 'userName': userName, 'host': padHost });
13+
</script>

‎assets/javascripts/etherpad.js

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
(function( $ ){
2+
3+
$.fn.pad = function( options ) {
4+
var settings = {
5+
'host' : 'http://0.0.0.0:9001',
6+
'baseUrl' : '/p/',
7+
'showControls' : true,
8+
'showChat' : false,
9+
'showLineNumbers' : false,
10+
'userName' : 'nouser',
11+
'useMonospaceFont' : true,
12+
'noColors' : false,
13+
'userColor' : false,
14+
'hideQRCode' : false,
15+
'alwaysShowChat' : false,
16+
'width' : 100,
17+
'height' : 100,
18+
'border' : 0,
19+
'borderStyle' : 'solid',
20+
'toggleTextOn' : 'Disable Rich-text',
21+
'toggleTextOff' : 'Enable Rich-text'
22+
};
23+
24+
var $self = this;
25+
if (!$self.length) return;
26+
if (!$self.attr('id')) throw new Error('No "id" attribute');
27+
28+
var useValue = $self[0].tagName.toLowerCase() == 'textarea';
29+
var selfId = $self.attr('id');
30+
var epframeId = 'epframe'+ selfId;
31+
// This writes a new frame if required
32+
if ( !options.getContents ) {
33+
if ( options ) {
34+
$.extend( settings, options );
35+
}
36+
37+
var iFrameLink = '<iframe id="'+epframeId;
38+
iFrameLink = iFrameLink +'" name="'+epframeId;
39+
iFrameLink = iFrameLink +'" src="'+settings.host+settings.baseUrl+settings.padId;
40+
iFrameLink = iFrameLink + '?showControls='+settings.showControls;
41+
iFrameLink = iFrameLink + '&showChat='+settings.showChat;
42+
iFrameLink = iFrameLink + '&showLineNumbers='+settings.showLineNumbers;
43+
iFrameLink = iFrameLink + '&useMonospaceFont='+settings.useMonospaceFont;
44+
iFrameLink = iFrameLink + '&userName=' + settings.userName;
45+
iFrameLink = iFrameLink + '&noColors=' + settings.noColors;
46+
iFrameLink = iFrameLink + '&userColor=' + settings.userColor;
47+
iFrameLink = iFrameLink + '&hideQRCode=' + settings.hideQRCode;
48+
iFrameLink = iFrameLink + '&alwaysShowChat=' + settings.alwaysShowChat;
49+
iFrameLink = iFrameLink +'" style="border:'+settings.border;
50+
iFrameLink = iFrameLink +'; border-style:'+settings.borderStyle;
51+
iFrameLink = iFrameLink +';" width="'+ '100%';//settings.width;
52+
iFrameLink = iFrameLink +'" height="'+ settings.height;
53+
iFrameLink = iFrameLink +'"></iframe>';
54+
55+
56+
var $iFrameLink = $(iFrameLink);
57+
58+
if (useValue) {
59+
var $toggleLink = $('<a href="#'+ selfId +'">'+ settings.toggleTextOn +'</a>').click(function(){
60+
var $this = $(this);
61+
$this.toggleClass('active');
62+
if ($this.hasClass('active')) $this.text(settings.toggleTextOff);
63+
$self.pad({getContents: true});
64+
return false;
65+
});
66+
$self
67+
.hide()
68+
.after($toggleLink)
69+
.after($iFrameLink)
70+
;
71+
}
72+
else {
73+
$self.html(iFrameLink);
74+
}
75+
}
76+
77+
// This reads the etherpad contents if required
78+
else {
79+
var frameUrl = $('#'+ epframeId).attr('src').split('?')[0];
80+
var contentsUrl = frameUrl + "/export/html";
81+
var target = $('#'+ options.getContents);
82+
83+
// perform an ajax call on contentsUrl and write it to the parent
84+
$.get(contentsUrl, function(data) {
85+
86+
if (target.is(':input')) {
87+
target.val(data).show();
88+
}
89+
else {
90+
target.html(data);
91+
}
92+
93+
$('#'+ epframeId).remove();
94+
});
95+
}
96+
97+
98+
return $self;
99+
};
100+
})( jQuery );

‎config/routes.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#connect 'projects/:project_id/pad', :controller => 'pads', :action => 'show'
2+
3+
ActionController::Routing::Routes.draw do |map|
4+
5+
map.connect 'projects/:project_id/pad', :controller => 'pads', :action => 'show'
6+
7+
end

‎init.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'redmine'
2+
3+
Redmine::Plugin.register :chiliproject_etherpad do
4+
name 'Chiliproject Etherpad plugin'
5+
author 'NicoPaez'
6+
description 'This plugin integrates Etherpad into Chiliproject'
7+
version '0.0.1'
8+
url 'http://www.tipit.net/about'
9+
end

0 commit comments

Comments
 (0)
Please sign in to comment.