Skip to content

Commit

Permalink
Updated the README with instructions for installation and basic usage.
Browse files Browse the repository at this point in the history
Added an export command which outputs all active subscribers for a list as csv. Requires fastercsv to work.
The index and list views for Subscribers have classes added to make them look a bit more like other radiant admin pages.
  • Loading branch information
nelstrom committed Jun 15, 2008
1 parent 6bd8283 commit 72e223a
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 10 deletions.
43 changes: 41 additions & 2 deletions README
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
= Subscriber Lists
Subscriber Lists
================

Description goes here
Created by: Andrew Neil
Version: 1.0
Contact: andrew.jr.neil AT gmail DOT com

This is an extension for Radiant CMS, which lets you create subscriber lists, e.g. for subscription to a newsletter.

This is essentially a stripped down version of Andrea Franz excellent [Newsletter extension](http://github.com/pilu/radiant-newsletter/tree/master). The subscriber lists extension does not require you to configure ActionMailer to send emails, so if your unsure how to do that, you may prefer to use this instead of the Newsletter extension.

Installation
------------

This extension uses the `fastercsv` gem, so if you don't already have it installed, run:

sudo gem install fastercsv

This extension is hosted on github. If you have git installed, then `cd` to the root of your radiant project and issue this command:

git clone git://github.com/nelstrom/radiant-subscriber-lists-extension.git vendor/extensions/subscriber_lists

If you don't have git, then you can instead download the tarball from this URL:

http://github.com/nelstrom/radiant-subscriber-lists-extension/tarball/master

and expand the contents to `your-radiant-project/vendor/extensions/subscriber_lists`.

Once you have the extension added to your radiant project, you can run the rake task:

rake radiant:extensions:subscriber_lists:install
# and/or
rake RAILS_ENV="production" radiant:extensions:subscriber_lists:install

Usage
-----

Create a subscriber list page by running the following task:

rake radiant:extensions:subscriber_lists:page:new

This will create a subscriber list called "Newsletter", with all the necessary page parts.
43 changes: 39 additions & 4 deletions app/controllers/subscribers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
class SubscribersController < ApplicationController

require 'fastercsv'

def index
@lists = Page.find_all_by_class_name("SubscriberListPage")
end

def list
@list = Page.find(params[:id])
@subscribers = Subscriber.find_active_subscribers_by_subscriber_list(@list)
@unsubscribers = Subscriber.find_unsubscribers_by_subscriber_list(@list)
end


def export
@list = Page.find(params[:id])
subscribers = Subscriber.find_active_subscribers_by_subscriber_list(@list)
stream_csv do |csv|
csv << ["email","name"]
subscribers.each do |subscriber|
csv << [subscriber.email,subscriber.name]
end
end
end

private

def stream_csv
filename = params[:action] + ".csv"
filename = "#{@list.title}-subscribers-#{Time.now().strftime("%d%b%y")}.csv"
#this is required if you want this to work with IE
if request.env['HTTP_USER_AGENT'] =~ /msie/i
headers['Pragma'] = 'public'
headers["Content-type"] = "text/plain"
headers['Cache-Control'] = 'no-cache, must-revalidate, post-check=0, pre-check=0'
headers['Content-Disposition'] = "attachment; filename=\"#{filename}\""
headers['Expires'] = "0"
else
headers["Content-Type"] ||= 'text/csv'
headers["Content-Disposition"] = "attachment; filename=\"#{filename}\""
end

render :text => Proc.new { |response, output|
csv = FasterCSV.new(output, :row_sep => "\r\n")
yield csv
}
end


end
5 changes: 4 additions & 1 deletion app/views/subscribers/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<h1>Subscribers</h1>

<table>
<table class="index">
<thead>
<th>Subscriber List</th>
<th>No. of Subscribers</th>
<th></th>
<th>Export</th>
</thead>

<tbody>
Expand All @@ -12,6 +14,7 @@
<td><a href="<%= url_for :action => "list", :id => list.id %>"><span class="title"><%= list.title %></span></a></td>
<td><%= Subscriber.count_active_subscribers(list) %></td>
<td><%= link_to "Edit page", page_edit_path(:id => list.id) %></td>
<td><%= link_to "Export", :action => "export", :id => list.id %></td>
</tr>
<%- end -%>
</tbody>
Expand Down
7 changes: 4 additions & 3 deletions app/views/subscribers/list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

<% if @subscribers and !@subscribers.empty? %>
<h2>Subscribers</h2>
<table>
<p><%= link_to "Export as CSV", :action => :export, :id => @list.id %></p>
<table class="index">
<tr>
<th>email</th>
<th>name</th>
Expand All @@ -25,8 +26,8 @@
<% if @unsubscribers and !@unsubscribers.empty? %>
<h2>Cancelled subscriptions</h2>
The following people have cancelled their subscription to this list.
<table>
<p>The following people have cancelled their subscription to this list.</p>
<table class="index">
<tr>
<th>email</th>
<th>name</th>
Expand Down
6 changes: 6 additions & 0 deletions lib/tasks/subscriber_lists_extension_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ namespace :radiant do
cp file, RAILS_ROOT + path
end
end


desc "Launches update and migrate tasks"
task :install => [:migrate, :update] do
end

end
end
end

0 comments on commit 72e223a

Please sign in to comment.