-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the README with instructions for installation and basic usage.
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
Showing
5 changed files
with
94 additions
and
10 deletions.
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
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. |
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 |
---|---|---|
@@ -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 |
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
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