File: base.rb

package info (click to toggle)
ruby-redcloth 4.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 708 kB
  • sloc: ruby: 1,233; ansic: 201; makefile: 25
file content (63 lines) | stat: -rw-r--r-- 1,642 bytes parent folder | download
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
module RedCloth::Formatters
  module Base
    
    def ignore(opts)
      opts[:text]
    end
    alias_method :notextile, :ignore
    
    def redcloth_version(opts)
      p(:text => "#{opts[:prefix]}#{RedCloth::VERSION}")
    end

    def inline_redcloth_version(opts)
      RedCloth::VERSION::STRING
    end
    
    [:del_phrase, :sup_phrase, :sub_phrase, :span_phrase].each do |phrase_method|
      method = phrase_method.to_s.split('_')[0]
      define_method(phrase_method) do |opts|
        "#{opts[:beginning_space]}#{self.send(method, opts)}"
      end
    end
    
  private
    
    def pba(opts)
      opts.delete(:style) if filter_styles
      opts.delete(:class) if filter_classes
      opts.delete(:id) if filter_ids

      atts = ''.dup
      opts[:"text-align"] = opts.delete(:align)
      opts[:style] += ';' if opts[:style] && (opts[:style][-1..-1] != ';')
      [:float, :"text-align", :"vertical-align"].each do |a|
        opts[:style] = "#{a}:#{opts[a]};#{opts[:style]}" if opts[a]
      end
      [:"padding-right", :"padding-left"].each do |a|
        opts[:style] = "#{a}:#{opts[a]}em;#{opts[:style]}" if opts[a]
      end
      [:style, :class, :lang, :id, :colspan, :rowspan, :title, :start, :align].each do |a|
        atts << " #{a}=\"#{ html_esc(opts[a].to_s, :html_escape_attributes) }\"" if opts[a]
      end
      atts
    end
    
    def method_missing(method, opts)
      opts[:text] || ""
    end
    
    def before_transform(text)
      
    end
    
    def after_transform(text)
      
    end
    
    def formatter_methods
      singleton_methods.map! {|method| method.to_sym }
    end

  end
end