forked from xaviershay/enki
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,044 additions
and
6 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
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
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,7 +1,3 @@ | ||
database.yml | ||
defensio.yml | ||
<<<<<<< HEAD:config/.gitignore | ||
newrelic.yml | ||
======= | ||
newrelic.yml | ||
>>>>>>> 5e29f7f21b667ccc8f30e0e679fbe8f4033f38d5:config/.gitignore |
16 changes: 16 additions & 0 deletions
16
db/migrate/20090608144306_add_defensio_columns_to_comments.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,16 @@ | ||
class AddDefensioColumnsToComments < ActiveRecord::Migration | ||
def self.up | ||
add_column :comments, :spam, :boolean, :default => false | ||
add_column :comments, :spaminess, :float | ||
add_column :comments, :signature, :string | ||
# Uncomment this if you wanna customize when an article is announced to Defensio server | ||
# add_column :article, :announced, :boolean, :default => false | ||
end | ||
|
||
def self.down | ||
remove_column :comments, :spam | ||
remove_column :comments, :spaminess | ||
remove_column :comments, :signature | ||
# add_column :article, :announced | ||
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,37 @@ | ||
== Defensio | ||
|
||
* Complete doc of Defensio API: Defensio::Client | ||
* Plugin doc: Defensio::ActsAs::ClassMethods | ||
|
||
=== Installation | ||
|
||
1. Install the plugin | ||
script/plugin install http://code.macournoyer.com/svn/plugins/defensio/ | ||
2. Get an API key at http://defensio.com and dump it in config/defensio.yml | ||
3. Add new column to your spammable model | ||
script/generate defensio_migration comment | ||
|
||
You're ready to go! | ||
|
||
=== Usage | ||
|
||
In your "article" class, add: | ||
|
||
acts_as_defensio_article | ||
|
||
In your "comment" class, add: | ||
|
||
acts_as_defensio_comment :fields => { :content => :comment } | ||
|
||
The :fields option allows you to configure fields that are sent | ||
to Defensio to classify a comment. | ||
|
||
Look at Defensio::Client for a list of all those fields. | ||
|
||
In the controller, before creating a comment set the request environment variables: | ||
@comment.env = request.env | ||
|
||
Then when the comment is created the +spam+, +spaminess+ and +signature+ | ||
columns will magically be set for your own pleasure. | ||
|
||
Check out other examples in http://code.macournoyer.com/svn/plugins/defensio/example |
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,29 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
require 'rake/contrib/rubyforgepublisher' | ||
|
||
desc 'Default: run unit tests.' | ||
task :default => :test | ||
|
||
desc 'Test the defensio plugin.' | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'lib' | ||
t.pattern = 'test/**/*_test.rb' | ||
t.verbose = true | ||
end | ||
|
||
desc 'Generate documentation for the defensio plugin.' | ||
Rake::RDocTask.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'Defensio' | ||
rdoc.options << '--line-numbers' << '--inline-source' | ||
rdoc.rdoc_files.include('README') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end | ||
|
||
task :pub_doc => :rdoc do | ||
Rake::SshDirPublisher.new("macournoyer@macournoyer.com", | ||
"code.macournoyer.com/defensio", | ||
"rdoc").upload | ||
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,6 @@ | ||
class Article < ActiveRecord::Base | ||
# Columns: author, author_email, title, content, permalink | ||
has_many :comments | ||
|
||
acts_as_defensio_article | ||
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,16 @@ | ||
class Comment < ActiveRecord::Base | ||
# Columns: author, content, title, author_email, author_url, permalink, article_id | ||
attr_accessor :current_user | ||
|
||
belongs_to :article | ||
|
||
acts_as_defensio_comment | ||
|
||
def user_logged_in | ||
current_user.logged_in? | ||
end | ||
|
||
def trusted_user | ||
current_user.admin? | ||
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,37 @@ | ||
class CommentsController < ApplicationController | ||
def index | ||
@ham = @article.comments.find_all_by_spam(false) | ||
@spam = @article.comments.find_all_by_spam(true, :order => 'spaminess desc') | ||
end | ||
|
||
def create | ||
@comment = @article.comments.build(params[:comment]) | ||
@comment.env = request.env | ||
@comment.current_user = self.current_user | ||
|
||
if @comment.save | ||
if @comment.spam | ||
flash[:notice] = 'Your comment has been marked for review' | ||
else | ||
flash[:notice] = 'Comment created' | ||
end | ||
redirect_to article_url(@article) | ||
else | ||
render :action => 'new' | ||
end | ||
end | ||
|
||
def report_as_spam | ||
@comment = @article.comments.find(params[:id]) | ||
@comment.report_as_spam | ||
end | ||
|
||
def report_as_ham | ||
@comment = @article.comments.find(params[:id]) | ||
@comment.report_as_ham | ||
end | ||
|
||
def stats | ||
@stats = Comment.defensio_stats | ||
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,13 @@ | ||
development: | ||
api_key: 1234abc | ||
owner_url: http://code.macournoyer.com/svn/plugins/defensio | ||
|
||
test: | ||
api_key: 1234abc | ||
owner_url: http://code.macournoyer.com/svn/plugins/defensio | ||
# Skip validation of the API key | ||
validate_key: false | ||
|
||
production: | ||
api_key: 6789xyz | ||
owner_url: http://code.macournoyer.com/svn/plugins/defensio |
15 changes: 15 additions & 0 deletions
15
vendor/plugins/defensio/generators/defensio_migration/defensio_migration_generator.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,15 @@ | ||
class DefensioMigrationGenerator < Rails::Generator::NamedBase | ||
def manifest | ||
record do |m| | ||
m.migration_template 'migration.rb', 'db/migrate', :assigns => { | ||
:table_name => @name.tableize, :class_name => @name.classify.pluralize | ||
}, :migration_file_name => "add_defensio_columns_to_#{@name.tableize}" | ||
end | ||
end | ||
|
||
protected | ||
# Override with your own usage banner. | ||
def banner | ||
"Usage: #{$0} defensio_migration model" | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
vendor/plugins/defensio/generators/defensio_migration/templates/migration.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,16 @@ | ||
class AddDefensioColumnsTo<%= class_name %> < ActiveRecord::Migration | ||
def self.up | ||
add_column :<%= table_name %>, :spam, :boolean, :default => false | ||
add_column :<%= table_name %>, :spaminess, :float | ||
add_column :<%= table_name %>, :signature, :string | ||
# Uncomment this if you wanna customize when an article is announced to Defensio server | ||
# add_column :article, :announced, :boolean, :default => false | ||
end | ||
|
||
def self.down | ||
remove_column :<%= table_name %>, :spam | ||
remove_column :<%= table_name %>, :spaminess | ||
remove_column :<%= table_name %>, :signature | ||
# add_column :article, :announced | ||
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 @@ | ||
require 'defensio' |
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,3 @@ | ||
require 'fileutils' | ||
FileUtils.cp "#{File.dirname(__FILE__)}/example/defensio.yml", "#{RAILS_ROOT}/config/defensio.yml" | ||
puts File.read("#{File.dirname(__FILE__)}/README") |
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,2 @@ | ||
require 'defensio/client' | ||
require 'defensio/acts_as' |
Oops, something went wrong.