public
Fork of halorgium/mephisto
Description: A refactored Mephisto that has multiple spam detection engines.
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/francois/mephisto.git
Search Repo:
Spam detection engines can now provide a template that the settings page 
uses to ask the user about configuration options for this engine.

The settings page renders the template, but doesn't hide the non-selected 
one at the moment.
francois (author)
Mon Mar 03 05:13:46 -0800 2008
commit  b0ba737268b641618f9b34ee39ba4ecb2500120f
tree    06054da38d4f3c6be082abb1dafc3b20910e895e
parent  09ecfabb45832dad1d237bfc1384a5dcdd379031
...
53
54
55
56
57
58
59
60
61
62
 
 
 
 
 
 
 
 
 
63
64
65
...
53
54
55
 
 
 
 
 
 
 
56
57
58
59
60
61
62
63
64
65
66
67
0
@@ -53,13 +53,15 @@
0
     <dt><label for="site_spam_detection_engine">Spam Detection Engine</label></dt>
0
     <dd><%= f.select :spam_detection_engine, Site.spam_detection_engines %></dd>
0
   </dl>
0
- <p>At the moment Mephisto uses <%= link_to 'Akismet', 'http://akismet.com' %> to automatically handle spam. If you leave out the Akismet settings, you can moderate new comments from the Overview.</p>
0
- <dl class="setform">
0
- <dt><label>Akismet API Key</label></dt>
0
- <dd><%#= f.text_field :akismet_key %></dd>
0
- <dt><label>Blog url</label></dt>
0
- <dd><%#= f.text_field :akismet_url %></dd>
0
- </dl>
0
+ <div id="spam_detection_engines">
0
+ <%- Site.spam_detection_engines.map(&:last).each do |klass_name| -%>
0
+ <% content_tag(:div, :id => File.basename(klass_name.underscore)) do %>
0
+ <dl class="setform">
0
+ <%= klass_name.constantize.settings_template(@site) %>
0
+ </dl>
0
+ <% end %>
0
+ <%- end -%>
0
+ </div>
0
 </div>
0
 
0
 <div id="publish" class="setgroup">
...
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
4
5
...
37
38
39
 
 
 
 
 
 
 
 
 
 
 
 
40
41
42
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
0
@@ -1,5 +1,23 @@
0
 module Mephisto
0
   module SpamDetectionEngine
0
+ class Template
0
+ include ActionView::Helpers::TagHelper
0
+ include ActionView::Helpers::FormHelper
0
+ include ActionView::Helpers::FormTagHelper
0
+
0
+ def initialize(template_text)
0
+ @template_text = ERB.new(template_text)
0
+ end
0
+
0
+ def render(context)
0
+ context.each_pair do |key, value|
0
+ instance_variable_set("@#{key}", value)
0
+ end
0
+
0
+ @template_text.result(binding)
0
+ end
0
+ end
0
+
0
     class Base
0
       attr_reader :site, :options, :logger
0
 
0
@@ -37,6 +55,18 @@ module Mephisto
0
       def errors
0
       end
0
 
0
+ class << self
0
+ # Returns a fully rendered HTML template from which the engine can extract options.
0
+ def settings_template(site)
0
+ ""
0
+ end
0
+
0
+ # Loads the named file as an ERB template. Returns a Template.
0
+ def load_template(full_path)
0
+ Template.new(File.read(full_path))
0
+ end
0
+ end
0
+
0
       # Returns spam engine statistics about it's performance.
0
       # This is in Base because not all engines return performance statistics.
0
       # This default implementation returns an empty Hash, to show no statistics.
...
3
4
5
 
 
 
 
 
 
6
7
8
...
3
4
5
6
7
8
9
10
11
12
13
14
0
@@ -3,6 +3,12 @@ module Mephisto
0
     class AkismetEngine < Mephisto::SpamDetectionEngine::Base
0
       Site.register_spam_detection_engine "Akismet", self
0
 
0
+ class << self
0
+ def settings_template(site)
0
+ load_template(File.join(File.dirname(__FILE__), "akismet_settings.html.erb")).render(:site => site, :options => site.spam_engine_options)
0
+ end
0
+ end
0
+
0
       def ham?(permalink_url, comment)
0
         check_valid!
0
         !akismet.comment_check(comment_spam_options(permalink_url, comment))
...
3
4
5
 
 
 
 
 
 
6
7
8
...
3
4
5
6
7
8
9
10
11
12
13
14
0
@@ -3,6 +3,12 @@ module Mephisto
0
     class DefensioEngine < Mephisto::SpamDetectionEngine::Base
0
       Site.register_spam_detection_engine "Defensio", self
0
 
0
+ class << self
0
+ def settings_template(site)
0
+ load_template(File.join(File.dirname(__FILE__), "defensio_settings.html.erb")).render(:site => site, :options => site.spam_engine_options)
0
+ end
0
+ end
0
+
0
       def valid?
0
         [:defensio_url, :defensio_key].all? {|key| !options[key].blank?}
0
       end

Comments

    No one has commented yet.