spread 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/MIT-LICENSE +16 -0
- data/README +43 -0
- data/Rakefile +22 -0
- data/deleted_files +14 -0
- data/files/public/images/spread/email.png +0 -0
- data/init.rb +9 -0
- data/install.rb +20 -0
- data/lib/spread.rb +9 -0
- data/lib/spread/asset_copier.rb +90 -0
- data/lib/spread/controller.rb +44 -0
- data/spread.gemspec +30 -0
- data/tasks/asset_copier.rake +11 -0
- data/templates/email.html.erb +3 -0
- data/templates/form.html.erb +9 -0
- metadata +70 -0
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
10/22/08 - Initial version [Matthew Bass]
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Copyright (c) 2007-2008 Matthew Bass (http://matthewbass.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
4
|
+
and associated documentation files (the "Software"), to deal in the Software without
|
5
|
+
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
6
|
+
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
Software is furnished to do so, subject to the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or
|
10
|
+
substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
13
|
+
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
14
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
15
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
= spread
|
2
|
+
|
3
|
+
Makes it easy to add tell-a-friend functionality to any Rails app.
|
4
|
+
|
5
|
+
|
6
|
+
== Installation
|
7
|
+
|
8
|
+
Install the gem directly:
|
9
|
+
|
10
|
+
sudo gem install pelargir-spread --source=http://gems.github.com
|
11
|
+
|
12
|
+
Or install the gem in your Rails project as a plugin:
|
13
|
+
|
14
|
+
script/plugin install git://github.com/pelargir/spread.git
|
15
|
+
|
16
|
+
Or clone the project:
|
17
|
+
|
18
|
+
git clone git://github.com/pelargir/spread.git
|
19
|
+
|
20
|
+
|
21
|
+
== Usage
|
22
|
+
|
23
|
+
Use spread's view helper to embed a link on the page you want to share:
|
24
|
+
|
25
|
+
<%= spread :something %>
|
26
|
+
|
27
|
+
Let your controller know you're using spread:
|
28
|
+
|
29
|
+
class SomeController < ActionController::Base
|
30
|
+
spread :something
|
31
|
+
end
|
32
|
+
|
33
|
+
That's all there is to it! (Spread's templates are currently static.
|
34
|
+
I'm working on making them overrideable so expect that soon.)
|
35
|
+
|
36
|
+
|
37
|
+
== Resources
|
38
|
+
|
39
|
+
Repository: http://github.com/pelargir/spread
|
40
|
+
Blog: http://matthewbass.com
|
41
|
+
Author: Matthew Bass
|
42
|
+
|
43
|
+
Extraction work sponsored by Terralien
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the spread plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the spread plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'spread'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
data/deleted_files
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Generated by the asset_copier plugin
|
2
|
+
# http://github.com/pelargir/asset_copier
|
3
|
+
#
|
4
|
+
# Files that have been removed from the plugin and should also be removed from
|
5
|
+
# any Rails projects that use the plugin should be listed here, one entry
|
6
|
+
# per line. For example:
|
7
|
+
#
|
8
|
+
# public/javascripts/foo.js
|
9
|
+
# app/views/foo/bar.erb.html
|
10
|
+
#
|
11
|
+
# Adding the paths above to this file would ensure that foo.js and bar.erb.html
|
12
|
+
# both get removed from the target Rails project the next time the plugin's
|
13
|
+
# files are copied over.
|
14
|
+
|
Binary file
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Generated by the asset_copier plugin
|
2
|
+
# http://github.com/pelargir/asset_copier
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
begin
|
7
|
+
puts "============================================================="
|
8
|
+
puts "Attempting to install required files into your application..."
|
9
|
+
puts "============================================================="
|
10
|
+
RAKE_FILE = File.expand_path(File.join(File.dirname(__FILE__), 'tasks', 'asset_copier.rake'))
|
11
|
+
load RAKE_FILE
|
12
|
+
|
13
|
+
Rake::Task['spread:install'].invoke
|
14
|
+
puts "=========================================================="
|
15
|
+
puts "Success!"
|
16
|
+
puts "=========================================================="
|
17
|
+
rescue Exception => ex
|
18
|
+
puts "FAILED TO INSTALL REQUIRED FILES. PLEASE RUN rake spread:install."
|
19
|
+
puts "EXCEPTION: #{ex}"
|
20
|
+
end
|
data/lib/spread.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
module Spread
|
2
|
+
def spread(action)
|
3
|
+
html = image_tag "spread/email.png", :alt => "Share with a friend", :size => "16x16", :valign => "middle"
|
4
|
+
html += link_to "Share with a friend", :action => action, :url => request.url
|
5
|
+
content_tag :div, html
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
ActionView::Base.send :include, Spread
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Generated by the asset_copier plugin
|
2
|
+
# http://github.com/pelargir/asset_copier
|
3
|
+
|
4
|
+
require 'find'
|
5
|
+
require 'digest/md5'
|
6
|
+
|
7
|
+
module Spread
|
8
|
+
class AssetCopier
|
9
|
+
@source = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'files'))
|
10
|
+
@destination = RAILS_ROOT
|
11
|
+
@deleted_files = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'deleted_files'))
|
12
|
+
class << self
|
13
|
+
attr_accessor :source, :destination, :deleted_files
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.copy(plugin_name)
|
17
|
+
begin
|
18
|
+
each_path do |path, dest_path, short_path|
|
19
|
+
if File.directory?(path)
|
20
|
+
unless File.exists?(dest_path)
|
21
|
+
FileUtils.mkdir_p(dest_path)
|
22
|
+
log "Creating directory #{short_path} for #{plugin_name}"
|
23
|
+
end
|
24
|
+
elsif !compare(path, dest_path)
|
25
|
+
FileUtils.cp(path, dest_path)
|
26
|
+
log "Copying #{short_path} from #{plugin_name}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
rescue Exception => e
|
30
|
+
log "Error trying to copy files: #{e.inspect}"
|
31
|
+
raise e
|
32
|
+
end
|
33
|
+
print_deletion_warnings(plugin_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.warn(plugin_name)
|
37
|
+
each_path do |path, dest_path, short_path|
|
38
|
+
next if File.directory?(path)
|
39
|
+
reinstall = false
|
40
|
+
if File.exists?(dest_path)
|
41
|
+
unless compare(path, dest_path)
|
42
|
+
log "WARNING: #{short_path} is out of date and needs to be reinstalled"
|
43
|
+
reinstall = true
|
44
|
+
end
|
45
|
+
else
|
46
|
+
reinstall = true
|
47
|
+
log "WARNING: #{short_path} is missing and needs to be installed"
|
48
|
+
end
|
49
|
+
log "WARNING: Please run rake #{plugin_name}:install" if reinstall
|
50
|
+
end
|
51
|
+
print_deletion_warnings(plugin_name)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.compare(file1, file2)
|
55
|
+
File.exists?(file1) && File.exists?(file2) &&
|
56
|
+
Digest::MD5.hexdigest(File.read(file1)) == Digest::MD5.hexdigest(File.read(file2))
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.print_deletion_warnings(plugin_name)
|
60
|
+
File.open(deleted_files, "r") do |f|
|
61
|
+
f.readlines.reject { |l| l =~ /^#/ || l.strip.blank? }.each do |l|
|
62
|
+
log "WARNING: #{l} is no longer required by the #{plugin_name} plugin " <<
|
63
|
+
"and can can be safely removed" if File.exists?(l)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.paths
|
69
|
+
returning [] do |paths|
|
70
|
+
Find.find(source) do |path|
|
71
|
+
Find.prune if path =~ /\/\..+/
|
72
|
+
Find.prune if path =~ /(CVS|.svn|.git)/
|
73
|
+
paths << path
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.each_path
|
79
|
+
paths.each do |path|
|
80
|
+
dest_path = path.gsub(source, destination)
|
81
|
+
short_path = dest_path.gsub("#{destination}/", "")
|
82
|
+
yield path, dest_path, short_path
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.log(msg)
|
87
|
+
puts msg
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Spread
|
2
|
+
module Controller
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
def spread(action)
|
10
|
+
mailer = construct_mailer
|
11
|
+
construct_action(action, mailer)
|
12
|
+
end
|
13
|
+
|
14
|
+
def construct_mailer
|
15
|
+
mailer = Class.new(ActionMailer::Base) do
|
16
|
+
def email(email, url)
|
17
|
+
recipients email
|
18
|
+
body :url => url
|
19
|
+
end
|
20
|
+
end
|
21
|
+
mailer.template_root = "#{RAILS_ROOT}/vendor/plugins/spread/templates/"
|
22
|
+
mailer
|
23
|
+
end
|
24
|
+
|
25
|
+
def construct_action(action, mailer)
|
26
|
+
define_method action do
|
27
|
+
if request.post?
|
28
|
+
if params[:email].blank?
|
29
|
+
flash[:error] = "Email cannot be blank"
|
30
|
+
else
|
31
|
+
mailer.deliver_email(params[:email], params[:url])
|
32
|
+
flash[:notice] = "An email has been sent to #{params[:email]}"
|
33
|
+
redirect_to params[:url] || "/" and return
|
34
|
+
end
|
35
|
+
end
|
36
|
+
render :file => "#{RAILS_ROOT}/vendor/plugins/spread/templates/form.html.erb"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
ActionController::Base.send :include, Spread::Controller
|
data/spread.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "spread"
|
3
|
+
s.version = "0.5"
|
4
|
+
s.date = "2008-10-22"
|
5
|
+
s.summary = "Makes it easy to add tell-a-friend functionality to any Rails app."
|
6
|
+
s.email = "pelargir@gmail.com"
|
7
|
+
s.homepage = "http://github.com/pelargir/spread"
|
8
|
+
s.description = "Makes it easy to add tell-a-friend functionality to any Rails app."
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.authors = ["Matthew Bass"]
|
11
|
+
s.files = [
|
12
|
+
"CHANGELOG",
|
13
|
+
"deleted_files",
|
14
|
+
"files/public/images/spread/email.png",
|
15
|
+
"init.rb",
|
16
|
+
"install.rb",
|
17
|
+
"lib/spread.rb",
|
18
|
+
"lib/spread/asset_copier.rb",
|
19
|
+
"lib/spread/controller.rb",
|
20
|
+
"MIT-LICENSE",
|
21
|
+
"Rakefile",
|
22
|
+
"README",
|
23
|
+
"spread.gemspec",
|
24
|
+
"tasks/asset_copier.rake",
|
25
|
+
"templates/email.html.erb",
|
26
|
+
"templates/form.html.erb"
|
27
|
+
]
|
28
|
+
s.rdoc_options = ["--main", "README"]
|
29
|
+
s.extra_rdoc_files = ["README"]
|
30
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Generated by the asset_copier plugin
|
2
|
+
# http://github.com/pelargir/asset_copier
|
3
|
+
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/spread/asset_copier')
|
5
|
+
|
6
|
+
namespace :spread do
|
7
|
+
desc "Install files required by spread"
|
8
|
+
task :install do
|
9
|
+
Spread::AssetCopier.copy "spread"
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spread
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.5"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Bass
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-22 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Makes it easy to add tell-a-friend functionality to any Rails app.
|
17
|
+
email: pelargir@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- CHANGELOG
|
26
|
+
- deleted_files
|
27
|
+
- files/public/images/spread/email.png
|
28
|
+
- init.rb
|
29
|
+
- install.rb
|
30
|
+
- lib/spread.rb
|
31
|
+
- lib/spread/asset_copier.rb
|
32
|
+
- lib/spread/controller.rb
|
33
|
+
- MIT-LICENSE
|
34
|
+
- Rakefile
|
35
|
+
- README
|
36
|
+
- spread.gemspec
|
37
|
+
- tasks/asset_copier.rake
|
38
|
+
- templates/email.html.erb
|
39
|
+
- templates/form.html.erb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/pelargir/spread
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --main
|
47
|
+
- README
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.4
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Makes it easy to add tell-a-friend functionality to any Rails app.
|
69
|
+
test_files: []
|
70
|
+
|