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:
100644 103 lines (84 sloc) 2.704 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
module Mephisto
  module SpamDetectionEngine
    class Template
      include ActionView::Helpers::TagHelper
      include ActionView::Helpers::FormHelper
      include ActionView::Helpers::FormTagHelper
 
      def initialize(template_text)
        @template_text = ERB.new(template_text)
      end
 
      def render(context)
        context.each_pair do |key, value|
          instance_variable_set("@#{key}", value)
        end
 
        @template_text.result(binding)
      end
    end
 
    class Base
      attr_reader :site, :options, :logger
 
      def initialize(site)
        @site, @options = site, site.spam_engine_options || {}
        @logger = site.logger
      end
 
      # Is this the null engine ?
      def null?
        false
      end
 
      # The default sort order is the original order.
      def sort_block
        lambda {|c| 0}
      end
 
      # Returns a fully formed HTML fragment that renders statistics on this
      # engine's performance.
      def statistics_template
        raise SubclassResponsibilityError
      end
 
      # Returns a series of HTML classes that should be added to the comment's blockquote.
      def classes(comment)
        ""
      end
 
      # Announces a new article was created.
      def announce_article(permalink_url, article)
        raise SubclassResponsibilityError
      end
 
      # Determines if a single comment is either ham or spam.
      def ham?(permalink_url, comment, options={})
        raise SubclassResponsibilityError
      end
 
      # Marks false positives as ham.
      def mark_as_ham(permalink_url, comment)
        raise SubclassResponsibilityError
      end
 
      # Marks false negatives as spam.
      def mark_as_spam(permalink_url, comment)
        raise SubclassResponsibilityError
      end
 
      # Returns information about the comment, to be shown right next
      # to the comment's author.
      def info(comment)
        ""
      end
 
      # Determines if the configuration is valid or not.
      def valid?
        raise SubclassResponsibilityError
      end
 
      # Contacts the remote service and checks to see if the key is valid.
      def valid_key?
        raise SubclassResponsibilityError
      end
 
      # Returns an Array of error messages explaining why this spam engine is in an invalid state.
      def errors
      end
 
      class << self
        # Returns a fully rendered HTML template from which the engine can extract options.
        def settings_template(site)
          ""
        end
 
        # Loads the named file as an ERB template. Returns a Template.
        def load_template(full_path)
          Template.new(File.read(full_path))
        end
      end
    end
  end
end