This repository has been archived by the owner on Aug 15, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed a bug in has_settings, added an rss2-only (for now) feed reader…
… page plugin.
- Loading branch information
Josh Adams
committed
Dec 22, 2008
1 parent
0ffef94
commit 5aa6b5b
Showing
14 changed files
with
213 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* A simple JQuery plugin for an RSS-fed news box | ||
* | ||
* @author Francesco Vivoli <f.vivoli@gmail.com> - http://atalayasec.org | ||
* Based on code found on the JQuery mailing list | ||
*/ | ||
(function($) { | ||
|
||
/** | ||
* Configure the news box container with url, maximum number of posts | ||
* to be fetched and their text length. | ||
* @example $('#newsbox').feedreader({ | ||
* targeturl: 'http://blogs.atalayasec.org/atalaya/?feed=rss2', | ||
* items: 3, | ||
* descLength: 15 | ||
* }); | ||
* @desc fill the #newsbox element with at most 3 posts taken from the above url, and showig | ||
* a teaser of at most 15 words. | ||
* | ||
*/ | ||
$.fn.feedreader = function(options) { | ||
var defaults = { | ||
targeturl: 'http://blogs.atalayasec.org/atalaya/?feed=rss2', | ||
items: 30, | ||
descLength: 150 | ||
} | ||
if(!options.targeturl) return false; | ||
var opts = $.extend(defaults, options); | ||
$(this).each(function(){ | ||
var container = this; | ||
$.get(opts.targeturl,function(xml){ | ||
var posts=[]; | ||
var i=0; | ||
$("item", xml).each(function(){ | ||
if(i>opts.items-1) return; | ||
var post={}; | ||
$(this).find("link").each(function(){ | ||
post.link=getNodeText(this); | ||
}); | ||
$(this).find("title").each(function(){ | ||
post.title=getNodeText(this); | ||
}); | ||
$(this).find("pubDate").each(function(){ | ||
post.date=getNodeText(this); | ||
}); | ||
$(this).find("description").each(function(){ | ||
var t=getNodeText(this); | ||
post.desc=trimtext(t,opts.descLength)+'[...]'; | ||
}); | ||
posts[i++]=post; | ||
}); | ||
writeposts(container,posts); | ||
|
||
}) | ||
}); | ||
|
||
}; | ||
|
||
function trimtext(text,length){ | ||
var t = text.replace(/\s/g,' '); | ||
var words = t.split(' '); | ||
if(words.length<=length) return text; | ||
var ret=''; | ||
for(var i=0;i<length;i++){ | ||
ret+=words[i]+' '; | ||
} | ||
return ret; | ||
} | ||
|
||
function writeposts(container,posts){ | ||
$(container).empty(); | ||
var html = '<dl>'; | ||
for(var k in posts){ | ||
html+=format(posts[k]) | ||
} | ||
html += '</dl>'; | ||
$(container).append(html); | ||
} | ||
|
||
function format(post){ | ||
var html='<dt> <a href="'+post.link+'">'+post.title+'</a><br /></dt>'; | ||
html+='<dd>'+post.desc+'</dd>'; | ||
if(!post.title){ | ||
html = ''; | ||
} | ||
return html; | ||
} | ||
|
||
function getNodeText(node) | ||
{ | ||
var text = ""; | ||
if(node.text) text = node.text; | ||
if(node.firstChild) text = node.firstChild.nodeValue; | ||
return text; | ||
} | ||
|
||
})(jQuery); |
30 changes: 30 additions & 0 deletions
30
vendor/plugins/ansuz_feed_reader/app/controllers/admin/feed_readers_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Admin::FeedReadersController < Admin::BaseController | ||
unloadable | ||
|
||
before_filter :load_feed_reader, :only => [ :show, :edit, :update ] | ||
|
||
protected | ||
def load_feed_reader | ||
@feed_reader = Ansuz::JAdams::FeedReader.find params[:id] | ||
end | ||
|
||
public | ||
def show | ||
redirect_to edit_admin_feed_reader_path(@feed_reader) | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
if @feed_reader.update_attributes(params[:feed_reader]) | ||
@feed_reader.settings = params[:settings] | ||
@feed_reader.save | ||
flash[:notice] = "The feed reader has been updated." | ||
redirect_to edit_admin_feed_reader_path(@feed_reader) | ||
else | ||
flash.now[:error] = "There was a problem updating the feed reader." | ||
render :action => "edit" | ||
end | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
vendor/plugins/ansuz_feed_reader/app/controllers/feed_readers_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'open-uri' | ||
|
||
class FeedReadersController < ApplicationController | ||
unloadable | ||
|
||
def get_feed | ||
str = "" | ||
open params[:targeturl] do |f| | ||
str = f.read | ||
end | ||
render :xml => str | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
vendor/plugins/ansuz_feed_reader/app/models/ansuz/j_adams/feed_reader.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Ansuz | ||
module JAdams | ||
class FeedReader < ActiveRecord::Base | ||
has_settings | ||
|
||
def edit_path | ||
"/admin/feed_readers/#{id}" | ||
end | ||
|
||
def self.admin_partial | ||
"/admin/feed_readers/feed_reader" | ||
end | ||
|
||
def self.view_partial | ||
"/feed_readers/feed_reader" | ||
end | ||
|
||
def view_partial | ||
self.class.view_partial | ||
end | ||
end | ||
end | ||
end |
1 change: 1 addition & 0 deletions
1
vendor/plugins/ansuz_feed_reader/app/views/admin/feed_readers/_feed_reader.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
You should really just modify this plugin's content by clicking this link: <%= link_to "Feed Reader", admin_feed_reader_path(plugin_module) %> |
12 changes: 12 additions & 0 deletions
12
vendor/plugins/ansuz_feed_reader/app/views/admin/feed_readers/edit.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%= title "Edit Feed Reader" -%> | ||
<% form_for :feed_reader, :url => admin_feed_reader_path(@feed_reader), :html => { :method => :put } do |f| %> | ||
<div class='fullwidth'> | ||
<table class='form-table'> | ||
<%= form_row "Title", text_field_tag("settings[title]", @feed_reader.settings[:title]) -%> | ||
<%= form_row "Feed URL", text_field_tag("settings[feed_url]", @feed_reader.settings[:feed_url]) -%> | ||
</table> | ||
</div> | ||
<br /> | ||
<%= submit_tag "Update Feed Reader" %> | ||
<% end %> |
4 changes: 4 additions & 0 deletions
4
vendor/plugins/ansuz_feed_reader/app/views/feed_readers/_feed_reader.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<h3><%= plugin_module.settings['title'] %></h3> | ||
<div id="<%= dom_id(plugin_module) %>"> | ||
</div> | ||
<%= javascript_tag "jQuery('##{dom_id(plugin_module)}').feedreader({ targeturl: '#{get_feed_feed_readers_url(:targeturl => plugin_module.settings['feed_url'])}'})" %> |
9 changes: 9 additions & 0 deletions
9
vendor/plugins/ansuz_feed_reader/db/migrate/001_add_feed_readers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AddFeedReaders < ActiveRecord::Migration | ||
def self.up | ||
create_table "feed_readers" do |t| | ||
end | ||
end | ||
|
||
def self.down | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
vendor/plugins/ansuz_feed_reader/db/migrate/002_add_name_to_feed_readers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AddNameToFeedReaders < ActiveRecord::Migration | ||
def self.up | ||
add_column :feed_readers, :name, :string | ||
add_index :feed_readers, :name | ||
end | ||
|
||
def self.down | ||
remove_index :feed_readers, :column => :name | ||
remove_column :feed_readers, :name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Ansuz::PluginManagerInstance.register_plugin(Ansuz::JAdams::FeedReader) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace :admin do |admin| | ||
admin.resources :feed_readers | ||
end | ||
resources :feed_readers, :collection => [:get_feed] |
2 changes: 2 additions & 0 deletions
2
vendor/plugins/ansuz_photo_album/app/views/admin/photo_albums/edit.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters