Skip to content

Commit

Permalink
Revised Plugin implementation.
Browse files Browse the repository at this point in the history
Plugins are now created by running the board_plugin generator.
  • Loading branch information
ploubser committed Oct 12, 2010
1 parent daf4628 commit 01213a3
Show file tree
Hide file tree
Showing 16 changed files with 209 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/generators/board_plugin/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Creates a skeleton for your board plugin.

Usage :
script/generate board_plugin [pluginname]
34 changes: 34 additions & 0 deletions lib/generators/board_plugin/board_plugin_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class BoardPluginGenerator < Rails::Generator::NamedBase
attr_reader :plugin_name
def initialize(runtime_args, runtime_options = {})
super
@plugin_name = file_name.underscore
end

def manifest
@plugin_name = name
record do |m|
m.directory "vendor/plugins/#{@plugin_name}/"
m.template "init.rb.erb", "vendor/plugins/#{@plugin_name}/init.rb"
m.file "README", "vendor/plugins/#{@plugin_name}/REAMDE"

m.directory "vendor/plugins/#{@plugin_name}/lib/"
m.template "lib/helpers.rb.erb", "vendor/plugins/#{@plugin_name}/lib/#{@plugin_name}.rb"
m.directory "vendor/plugins/#{@plugin_name}/lib/javascripts"
m.directory "vendor/plugins/#{@plugin_name}/lib/stylesheets"
m.directory "vendor/plugins/#{@plugin_name}/lib/views"
m.file "lib/javascripts/javascripts.js", "vendor/plugins/#{@plugin_name}/lib/javascripts/#{@plugin_name}.js"
m.file "lib/stylesheets/stylesheets.css", "vendor/plugins/#{@plugin_name}/lib/stylesheets/#{@plugin_name}.css"
m.file "lib/views/_formfor_plugin.html.erb", "vendor/plugins/#{@plugin_name}/lib/views/_formfor_#{@plugin_name}.html.erb"
m.file "lib/views/view.html.erb", "vendor/plugins/#{@plugin_name}/lib/views/#{@plugin_name}.html.erb"

m.directory "vendor/plugins/#{@plugin_name}/test/"
m.template "test/plugin_test.rb.erb", "vendor/plugins/#{@plugin_name}/test/#{@plugin_name}_test.rb"
m.file "test/test_helper.rb", "vendor/plugins/#{@plugin_name}/test/test_helper.rb"

m.directory "vendor/plugins/#{@plugin_name}/tasks/"
m.template "tasks/plugin_tasks.rake.erb", "vendor/plugins/#{@plugin_name}/tasks/#{@plugin_name}_tasks.rake"

end
end
end
13 changes: 13 additions & 0 deletions lib/generators/board_plugin/templates/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Title
====

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 lib/generators/board_plugin/templates/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 lib/generators/board_plugin/templates/init.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ActionView::Base.send :include, <%= plugin_name.capitalize%>
3 changes: 3 additions & 0 deletions lib/generators/board_plugin/templates/lib/helpers.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module <%= plugin_name.capitalize %>
#Your code goes here
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//Your Javascript goes here
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* You CSS goes here*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% form_remote_tag :html => { :action => url_for(:controller => "griditems", :action =>"create_grid_item"), :id => "form_for"} do %>
<!-- Your form goes here -->
<%= 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 %>
7 changes: 7 additions & 0 deletions lib/generators/board_plugin/templates/lib/views/view.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- Your plugin view goes here -->

<div class="ui-widget">
<div class="ui-widget-header">
<%= @parameters["title"] %>
</div>
</div>
12 changes: 12 additions & 0 deletions lib/generators/board_plugin/templates/tasks/plugin_tasks.rake.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace :<%= plugin_name.to_sym%> do
desc "Sync plugin files with Bernard-Board"
task :sync do
a = system "rsync -ruv vendor/plugins/<%= plugin_name %>/lib/views/* app/views/griditems/plugins/<%= plugin_name %>"
a = system "rsync -ruv vendor/plugins/<%= plugin_name%>/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 lib/generators/board_plugin/templates/test/plugin_test.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class <%=plugin_name%>Test < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
3 changes: 3 additions & 0 deletions lib/generators/board_plugin/templates/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'
38 changes: 38 additions & 0 deletions log/development.log
Original file line number Diff line number Diff line change
Expand Up @@ -259503,3 +259503,41 @@ Processing GriditemsController#create_grid_item (for 87.224.77.66 at 2010-10-11
Rendered griditems/plugins/feed/_feed (685.9ms)
Rendered griditems/_item (687.3ms)
Completed in 699ms (View: 695, DB: 0) | 200 OK [http://dev3.pinetecltd.net/griditems/create_grid_item?type=Feed]
/!\ FAILSAFE /!\ Tue Oct 12 18:06:31 +0100 2010
Status: 500 Internal Server Error
No such file or directory - /home/psy/code/bernardplugin/config/routes.rb
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:297:in `stat'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:297:in `routes_changed_at'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:296:in `each'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:296:in `routes_changed_at'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:274:in `reload'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:59:in `reload_application'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/reloader.rb:8:in `call'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/failsafe.rb:11:in `call'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:106:in `call'
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/static.rb:31:in `call'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:46:in `call'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `each'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `call'
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/log_tailer.rb:17:in `call'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/content_length.rb:13:in `call'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/chunked.rb:15:in `call'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:64:in `process'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:34:in `run'
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:111
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3
Expand Down
55 changes: 55 additions & 0 deletions public/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();
}
}
Binary file removed vendor/plugins/feed/tasks/.feed_tasks.rake.swp
Binary file not shown.

0 comments on commit 01213a3

Please sign in to comment.