File: extension.rb

package info (click to toggle)
ruby-wikicloth 0.8.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 588 kB
  • ctags: 278
  • sloc: ruby: 2,548; makefile: 14
file content (60 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download | duplicates (4)
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
module WikiCloth
  class Extension

    def initialize(options={})
      @options = options
    end

    class << self

      def html_elements
        @@html_elements ||= {}
      end

      def functions
        @@functions ||= {}
      end

      def element(*args,&block)
        options  = args.last.is_a?(Hash) ? args.pop : {}
        key      = args.shift

        html_elements[key] = { :klass => self, :block => block, :options => { 
          :skip_html => false, :run_globals => true }.merge(options) }
      end

      def skip_html?(elem)
        return true if !element_exists?(elem)
        html_elements[elem][:options][:skip_html]
      end

      def run_globals?(elem)
        return false if !element_exists?(elem)
        html_elements[elem][:options][:run_globals]
      end

      def element_exists?(elem)
        html_elements.has_key?(elem)
      end

      def function(name,&block)
        functions[name] = { :klass => self, :block => block }
      end

      def function_exists?(name)
        functions.has_key?(name)
      end

      protected
      def html_elements=(val)
        @@html_elements = val
      end

      def functions=(val)
        @@functions = val
      end

    end

  end
end