Skip to content

Commit

Permalink
Plugin 2nd implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ploubser committed Oct 11, 2010
1 parent 7d183f4 commit daf4628
Show file tree
Hide file tree
Showing 18 changed files with 1,175 additions and 61 deletions.
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def get_plugins
plugins = Dir.glob("/home/psy/code/stomp/trunk/bernardboard/app/views/griditems/plugins/**")
plugins = Dir.glob("app/views/griditems/plugins/**")
plugins.each_with_index do |item, i|
if item =~ /.*plugins\/(.+)/
plugins[i] = $1.capitalize
Expand All @@ -11,7 +11,7 @@ def get_plugins
end

def get_javascript
javascript = Dir.glob("/home/psy/code/stomp/trunk/bernardboard/public/javascripts/*.js")
javascript = Dir.glob("public/javascripts/*.js")
javascript.each_with_index do |item, i|
if item =~/.*javascripts\/(.+)/
javascript[i] = $1
Expand Down
12 changes: 0 additions & 12 deletions app/helpers/griditems_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,4 @@ def get_remote_file(remote_server, file)
end
end

def get_feed(path)
require 'rss/1.0'
require 'rss/2.0'

content = ""
open(path) do |p|
content = p.read
end

return RSS::Parser.parse(content, false)
end

end
992 changes: 992 additions & 0 deletions log/development.log

Large diffs are not rendered by default.

47 changes: 0 additions & 47 deletions public/javascripts/bernard.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
var popup = 0; //show popup = false
var gaugeArray = new Object;
var lastTarget = ""; //last clicked item
//var currentFeed = 0
//var feedSize = 0

//Gauge plugin
google.load('visualization', '1', {packages:['gauge']});
Expand Down Expand Up @@ -266,51 +264,6 @@ function positionItem(item, x, y){
jQuery(i).offset({top : y, left : x })
}

//Resize feed and twitter plugin text
function resizeText(container, currentFeed){
var max = 12;
jQuery('#feed-description' + currentFeed).wrapInner('<div id="fontfit' + currentFeed + '"></div>');
var dheight = jQuery(container).height() - jQuery('#feed-header' + currentFeed).height();
var cheight = jQuery("#fontfit" + currentFeed).height();
var fsize = ((jQuery('#feed-description' + currentFeed).css("font-size")).slice(0,-2))*1;
while(cheight<dheight-jQuery(container).css("borderWidth").slice(0,-2)*2 && fsize<max) {
fsize+=1;
jQuery('#feed-description' + currentFeed).css("font-size",fsize+"px");
cheight = jQuery("#fontfit" + currentFeed).height();
}
while(cheight>dheight-jQuery(container).css("borderWidth").slice(0,-2)*2 || fsize>max && fsize > 1) {
fsize-=1;
jQuery('#feed-description' + currentFeed).css("font-size",fsize+"px");
cheight = jQuery("#fontfit"+ currentFeed).height();
}
}

function update_feed(size){
jQuery('#feed0').show();
var feedSize = size;
var currentFeed = 0;
var container = null
var interval = setInterval(function(){
jQuery('.feed').hide();
jQuery('#feed' + currentFeed).show();
container = jQuery('#feed' + currentFeed).parent().parent();
//This deals with the sudden descruction of the dom object
//Implemented to handle delete from rightclick menu
if(jQuery(container).attr("id") == null){
clearInterval(interval);
}
else{
resizeText(container, currentFeed);
}
if(currentFeed < feedSize -1){
currentFeed++;
}
else{
currentFeed = 0;
}
}, 10000);
}

function update_twitterfeed(size){
jQuery('#twitterfeed0').show();
var feedSize = size;
Expand Down
20 changes: 20 additions & 0 deletions vendor/plugins/feed/MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2010 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall 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 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.
13 changes: 13 additions & 0 deletions vendor/plugins/feed/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Feed
====

Introduction goes here.


Example
=======

Example goes here.


Copyright (c) 2010 [name of plugin creator], released under the MIT license
23 changes: 23 additions & 0 deletions vendor/plugins/feed/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the feed plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the feed plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Feed'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
1 change: 1 addition & 0 deletions vendor/plugins/feed/init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ActionView::Base.send :include, Feed
1 change: 1 addition & 0 deletions vendor/plugins/feed/install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Install hook code here
12 changes: 12 additions & 0 deletions vendor/plugins/feed/lib/feed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Feed
require 'rss/1.0'
require 'rss/2.0'

def get_feed(path)
content = ""
open(path) do |p|
content = p.read
end
return RSS::Parser.parse(content, false)
end
end
55 changes: 55 additions & 0 deletions vendor/plugins/feed/lib/javascripts/feed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Feed plugin javascript functions
Pieter Loubser
October 2010
Version 0.8
*/

var lastTarget = "";

//Update feed item periodically.
// - currently hardcoded at 10s.
function update_feed(size){
jQuery('#feed0').show();
var feedSize = size;
var currentFeed = 0;
var container = null;
var interval = setInterval(function(){
jQuery('.feed').hide();
jQuery('#feed' + currentFeed).show();
container = jQuery('#feed' + currentFeed).parent().parent();
//This deals with the sudden descruction of the item container
//Implemented to handle delete from rightclick menu
if(jQuery(container).attr("id") == null){
clearInterval(interval);
}
else{
resizeText(container, currentFeed);
}

if(currentFeed < feedSize -1){
currentFeed++;
}
else{
currentFeed = 0;
}
}, 10000);
}

//Resize feed story text to fit in container
function resizeText(container, currentFeed){
var max = 12; //Default max font size. Might change. #Issue 6
jQuery('#feed-description' + currentFeed).wrapInner('<div id="fontfit' + currentFeed + '"></div>');
var dheight = jQuery(container).height() - jQuery('#feed-header' + currentFeed).height();
var cheight = jQuery("#fontfit" + currentFeed).height();
var fsize = ((jQuery('#feed-description' + currentFeed).css("font-size")).slice(0,-2))*1;
while(cheight<dheight-jQuery(container).css("borderWidth").slice(0,-2)*2 && fsize<max) {
fsize+=1;
jQuery('#feed-description' + currentFeed).css("font-size",fsize+"px");
cheight = jQuery("#fontfit" + currentFeed).height();
}
while(cheight>dheight-jQuery(container).css("borderWidth").slice(0,-2)*2 || fsize>max && fsize > 1) {
fsize-=1;
jQuery('#feed-description' + currentFeed).css("font-size",fsize+"px");
cheight = jQuery("#fontfit"+ currentFeed).height();
}
}
23 changes: 23 additions & 0 deletions vendor/plugins/feed/lib/views/_feed.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% feed = get_feed(@parameters["url"])%>

<div class="ui-widget">
<div class="ui-widget-header">
<%= @parameters["title"] %>
</div>

<% feed.items.each_with_index do |topic,i| %>
<div id="feed<%=i%>" class="feed" style="display:none;">
<div id="feed-header<%=i%>"
<%= image_tag "rss_icon.gif", :html => {"align" => "left"}%>
<%= topic.title %><br>
<small> Added on <%= topic.date.strftime('%m/%d/%Y')%> </small>
<HR>
</div>

<div id="feed-description<%=i%>"><%= topic.description.gsub(/<[^>]+>/,"").squeeze(" ").strip %></div>
</div>
<% end %>
</div>

<%= javascript_tag "update_feed(#{feed.items.size})"%>

9 changes: 9 additions & 0 deletions vendor/plugins/feed/lib/views/_formfor_feed.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% form_remote_tag :html => { :action => url_for(:controller => "griditems", :action =>"create_grid_item"), :id => "form_for"} do %>
Title : <%= text_field_tag "title" %><br>
Width : <%= text_field_tag "width", "", :size=>4%><br>
Height: <%= text_field_tag "height", "", :size=>4%><br>
RSS url: <%= text_field_tag "url", "", :size=>24 %><br>
<%= hidden_field_tag "refresh_rate", "0" %>
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"} %> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"} %>
<% end %>
Binary file added vendor/plugins/feed/tasks/.feed_tasks.rake.swp
Binary file not shown.
12 changes: 12 additions & 0 deletions vendor/plugins/feed/tasks/feed_tasks.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace :feed do
desc "Sync plugin files with Bernard-Board"
task :sync do
a = system "rsync -ruv vendor/plugins/feed/lib/views/* app/views/griditems/plugins/feed"
a = system "rsync -ruv vendor/plugins/feed/lib/javascripts/* public/javascripts"
if a == true
system "echo '\n\nSync was successful!'"
else
system "echo '\n\nSync failed!"
end
end
end
8 changes: 8 additions & 0 deletions vendor/plugins/feed/test/feed_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class FeedTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
3 changes: 3 additions & 0 deletions vendor/plugins/feed/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'rubygems'
require 'active_support'
require 'active_support/test_case'
1 change: 1 addition & 0 deletions vendor/plugins/feed/uninstall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Uninstall hook code here

0 comments on commit daf4628

Please sign in to comment.