Class: Deplate::Formatter::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/deplate/mod/soffice.rb,
lib/deplate/mod/endnotes.rb,
lib/deplate/mod/babelfish.rb,
lib/deplate/mod/php-extra.rb,
lib/deplate/mod/html-jsmath.rb,
lib/deplate/mod/html-mathml.rb,
lib/deplate/mod/html-sidebar.rb,
lib/deplate/mod/validate-html.rb,
lib/deplate/mod/html-asciimath.rb,
lib/deplate/mod/html-deplate-button.rb,
lib/deplate/mod/html-headings-navbar.rb,
lib/deplate/mod/html-obfuscate-email.rb,
lib/deplate/mod/html-highstep.rb

Overview

html-obfuscate-email.rb @Author: Thomas Link (micathom AT gmail com) @Website: deplate.sf.net/ @License: GPL (see www.gnu.org/licenses/gpl.txt) @Created: 13-Jul-2005. @Revision: 0.36

Direct Known Subclasses

HTML_Snippet, XHTML10transitional

Instance Method Summary collapse

Instance Method Details

#format_highstep(invoker, txt = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/deplate/mod/html-highstep.rb', line 31

def format_highstep(invoker, txt=nil)
    txt ||= invoker.elt || invoker.text
    idx = invoker.step_index
    beg = (@variables['stepwiseBegin'] || '0').to_i
    cls = (beg == 0 or idx > beg) ? 'steppreview' : 'stephighlight'
    args = {
        # 'style' => "visibility:#{vis};"
        'class' => cls,
        'id' => "HighStep#{idx}",
    }
    inline_tag(invoker, 'span', txt, args)
end

#format_list_of_endnotes(invoker) ⇒ Object Also known as: format_list_of_footnotes



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/deplate/mod/endnotes.rb', line 37

def format_list_of_endnotes(invoker)
    title = plain_text(@deplate.msg("Notes"))
    acc   = []
    acc << %{<div class="endnotes"><h1 class="endnotes">%s</h1>} % title
    for l, f in @deplate.footnotes.sort {|a, b| a[1].elt.n <=> b[1].elt.n}
        fn     = f.elt
        idx    = fn.n
        hclass = "sdfootnoteanc"
        id     = "sdfootnote%d"    % idx
        name   = "sdfootnote%danc" % idx
        href   = Deplate::Macro::Footnote::FootnoteTemplate % idx
        t      = [%{<div id="#{id}">},
            %{<p class="sdendnote">}, 
            %{<a class="sdendnotesym" name="#{href}" href="##{name}">#{idx}</a>},
            %{#{fn.body}},
            %{</p></div>}
        ]
        acc << t.join("\n")
    end
    acc << "</div>"
    join_blocks(acc)
end

#format_math(invoker) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/deplate/mod/html-jsmath.rb', line 31

def format_math(invoker)
    block, formula = bare_latex_formula(invoker.text)
    if formula
        %{<span class="math">#{formula}</span>}
    else
        invoker.log(['Internal error', invoker.text], :error)
    end
end

#format_math_re_jsmathObject



30
# File 'lib/deplate/mod/html-jsmath.rb', line 30

alias :format_math_re_jsmath :format_math

#format_math_re_mathmlObject



21
22
23
24
25
26
27
28
# File 'lib/deplate/mod/html-mathml.rb', line 21

def format_math(invoker)
    block, formula = bare_latex_formula(invoker.text)
    if formula
        %{<span class="math">#{formula}</span>}
    else
        invoker.log(['Internal error', invoker.text], :error)
    end
end

#format_pagenumber(invoker) ⇒ Object



20
21
22
# File 'lib/deplate/mod/soffice.rb', line 20

def format_pagenumber(invoker)
    "<SDFIELD TYPE=PAGE SUBTYPE=RANDOM FORMAT=PAGE></SDFIELD>"
end

#format_url(invoker, name, dest, anchor, literal = false) ⇒ Object



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
# File 'lib/deplate/mod/html-obfuscate-email.rb', line 13

def format_url(invoker, name, dest, anchor, literal=false)
    rv = format_url_re_js_obfuscate_email(invoker, name, dest, anchor, literal)
    if dest =~ /^mailto:/
        encoded = rv.unpack('C' * rv.size).join(',')
        dest0   = dest.sub(/^mailto:/, '')
        significant_name = (name != dest and name != dest0)
        if @deplate.variables['noObfuscatedNoscript']
            noscript = significant_name ? name : ''
        else
            at  = @deplate.variables['obfuscatedNoscriptAt'] || ' AT '
            dot = @deplate.variables['obfuscatedNoscriptDot'] || ' DOT '
            if significant_name
                noscript = %{#{name} (#{dest})}
            else
                noscript = name
            end
            noscript.gsub!(/(mailto:|[@.])/) do |t|
                case t
                when '@'
                    at
                when '.'
                    dot
                when 'mailto:'
                    ''
                end
            end
        end
        js = %{<script type="text/javascript"><!--
document.write(String.fromCharCode(#{encoded}))
--></script><noscript>#{noscript}</noscript>}
    else
        rv
    end
end

#format_url_re_js_obfuscate_emailObject



11
# File 'lib/deplate/mod/html-obfuscate-email.rb', line 11

alias :format_url_re_js_obfuscate_email :format_url

#formatter_initialize_headings_navbarObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/deplate/mod/html-headings-navbar.rb', line 11

def formatter_initialize_headings_navbar
    def_advice("html-headings-navbar", :format_heading,
              :wrap => Proc.new do |agent, rv, invoker, *rest|
                max_level = @deplate.variables["headingsNavbarMaxLevel"]
                if max_level
                    max_level = max_level.to_i
                else
                    max_level = 1
                end
                if invoker.level <= max_level
                    nb = invoke_service("navigation_bar",
                                        :invoker => invoker,
                                        'noNavButtons' => true)
                    join_blocks([nb, rv])
                else
                    rv
                end
              end
             )
end

#formatter_initialize_html_asciimathObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/deplate/mod/html-asciimath.rb', line 11

def formatter_initialize_html_asciimath
    if @deplate.variables["bodyOptions"]
        @deplate.variables["bodyOptions"] += %{ onload="translate()"}
    else
        @deplate.variables["bodyOptions"] = %{onload="translate()"}
    end
    if @deplate.variables["htmlDefEtc"]
        @deplate.variables["htmlDefEtc"] += %{ xmlns:mml="http://www.w3.org/1998/Math/MathML"}
    else
        @deplate.variables["htmlDefEtc"] = %{xmlns:mml="http://www.w3.org/1998/Math/MathML"}
    end

    @special_symbols["$"] = Proc.new{|e| e == :pre ? "$" : "\\$"}
    @special_symbols["`"] = Proc.new{|e| e == :pre ? "`" : "\\`"}
    build_plain_text_rx
end

#initialize_page_comments(invoker) ⇒ Object



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
# File 'lib/deplate/mod/php-extra.rb', line 14

def initialize_page_comments(invoker)
    unless @deplate.options.page_comments
        file = 'page-comment.inc.php'
        fn   = @deplate.find_in_lib(file, :pwd => true)
        dir  = File.dirname(output_destination)
        dest = File.join(dir, file)
        unless File.exist?(dest)
            Deplate::Template.copy(@deplate, fn, dest, invoker) do |args|
                unless @variables['commentLocale']
                    args['commentLocale'] = @deplate.options.messages.prop('lang', 'php')
                end
            end
            # tpl = File.open(fn) {|io| io.read}
            # src = invoker ? invoker.source : nil
            # tpl = Deplate::Template.new(:template  => tpl,
            #                             :source => src,
            #                             :container => self)
            # args = {}
            # unless @variables['commentLocale']
            #     args['commentLocale'] = @deplate.options.messages.prop('lang', 'php')
            # end
            # Deplate::Define.let_variables(@deplate, args) do
            #     tpl = tpl.fill_in(@deplate, :source => src)
            # end
            # tpl = tpl.join("\n")
            # File.open(dest, 'w') {|io| io.puts(tpl)}
        end
        # @deplate.copy_file(fn, dest)
        @deplate.options.page_comments = true
    end
end

#inlatex(invoker) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/deplate/mod/html-mathml.rb', line 13

def inlatex(invoker)
    case invoker
    when Deplate::Macro::Math
    else
        inlatex_re_mathml(invoker)
    end
end

#inlatex_re_mathmlObject



12
# File 'lib/deplate/mod/html-mathml.rb', line 12

alias :inlatex_re_mathml :inlatex

#prepare_babelfishObject



20
21
22
23
24
25
26
# File 'lib/deplate/mod/babelfish.rb', line 20

def prepare_babelfish
    if @deplate.formatter.matches?("html")
        babel = %{<script type="text/javascript" src="http://www.altavista.com/r?entr"></script>}
        # babel = %{<script type="text/javascript" src="http://www.altavista.com/r?inc_translate"></script>}
        output_at(:post, :pre_body_end, %{<div align="right" class="pageicons">%s</div>} % babel)
    end
end

#prepare_html_asciimathObject



28
29
30
31
32
33
34
35
# File 'lib/deplate/mod/html-asciimath.rb', line 28

def prepare_html_asciimath
    output_at(:pre, :mod_head, <<END_OF_HTML
<object id="mathplayer" classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987">
</object><?import namespace="mml" implementation="#mathplayer"?>
<script type="text/javascript" src="ASCIIMathML.js"></script>
END_OF_HTML
             )
end

#prepare_html_deplate_buttonObject



11
12
13
14
# File 'lib/deplate/mod/html-deplate-button.rb', line 11

def prepare_html_deplate_button
    buttons = %{<a href="http://deplate.sourceforge.net"><img src="http://deplate.sourceforge.net/deplate-mini.png" border="0" alt="deplate Logo" /></a>}
    output_at(:post, :html_pageicons, buttons) unless buttons.empty?
end

#prepare_html_jsmathObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/deplate/mod/html-jsmath.rb', line 11

def prepare_html_jsmath
    output_at(:pre, :body_pre, <<END_OF_HTML
<script type="text/javascript" src="jsMath/jsMath.js"></script>
<noscript>
<div style="color:#CC0000; text-align:center">
  <b>Warning: <a href="http://www.math.union.edu/locate/jsMath">jsMath</a>
  requires JavaScript to process the mathematics on this page.<br/>
  If your browser supports JavaScript, be sure it is enabled.</b>
</div>
<hr/>
</noscript>
END_OF_HTML
             )
    output_at(:post, :body_post, <<END_OF_HTML
<script> jsMath.Process() </script>
END_OF_HTML
             )
end

#prepare_html_sidebarObject



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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/deplate/mod/html-sidebar.rb', line 20

def prepare_html_sidebar
    opt0  = @deplate.variables["bodyOptions"]
    @deplate.variables["navGif"] ||= "navigation_back.gif"
    optSB = %{onload="Event_init()" background="#{@deplate.variables["navGif"]}"}
    @deplate.variables["bodyOptions"] = opt0 ? "%s %s" % [opt0, optSB] : optSB
    
    mouseThresholdIn  = @deplate.variables["mouseThresholdIn"]  || 420
    mouseThresholdOut = @deplate.variables["mouseThresholdOut"] || 270
    
    html = <<EndOfHTML
<!-- Based on code from selfhtml: http://selfhtml.teamone.de/ -->
<!-- dhtml.js: DHTML-Bibliothek (SelfHTML -> DHTML -> Allgemeine DHTML-Bibliothek) -->
<script type="text/javascript">
<!--
var DHTML = 0, DOM = 0, MS = 0, NS = 0, OP = 0;

function DHTML_init() {

 if (window.opera) {
 OP = 1;
 }
 if(document.getElementById) {
   DHTML = 1;
   DOM = 1;
 }
 if(document.all && !OP) {
   DHTML = 1;
   MS = 1;
 }
if(document.layers && !OP) {
   DHTML = 1;
   NS = 1;
 }
}

function getElem(p1,p2,p3) {
 var Elem;
 if(DOM) {
   if(p1.toLowerCase()=="id") {
 if (typeof document.getElementById(p2) == "object")
 Elem = document.getElementById(p2);
 else Elem = void(0);
 return(Elem);
   }
   else if(p1.toLowerCase()=="name") {
 if (typeof document.getElementsByName(p2) == "object")
 Elem = document.getElementsByName(p2)[p3];
 else Elem = void(0);
 return(Elem);
   }
   else if(p1.toLowerCase()=="tagname") {
 if (typeof document.getElementsByTagName(p2) == "object" ||
    (OP && typeof document.getElementsByTagName(p2) == "function"))
 Elem = document.getElementsByTagName(p2)[p3];
 else Elem = void(0);
 return(Elem);
   }
   else return void(0);
 }
 else if(MS) {
   if(p1.toLowerCase()=="id") {
 if (typeof document.all[p2] == "object")
 Elem = document.all[p2];
 else Elem = void(0);
 return(Elem);
   }
   else if(p1.toLowerCase()=="tagname") {
 if (typeof document.all.tags(p2) == "object")
 Elem = document.all.tags(p2)[p3];
 else Elem = void(0);
 return(Elem);
   }
   else if(p1.toLowerCase()=="name") {
 if (typeof document[p2] == "object")
 Elem = document[p2];
 else Elem = void(0);
 return(Elem);
   }
   else return void(0);
 }
 else if(NS) {
   if(p1.toLowerCase()=="id" || p1.toLowerCase()=="name") {
   if (typeof document[p2] == "object")
 Elem = document[p2];
 else Elem = void(0);
 return(Elem);
   }
   else if(p1.toLowerCase()=="index") {
if (typeof document.layers[p2] == "object")
 Elem = document.layers[p2];
else Elem = void(0);
 return(Elem);
   }
   else return void(0);
 }
}

function getCont(p1,p2,p3) {
   var Cont;
   if(DOM && getElem(p1,p2,p3) && getElem(p1,p2,p3).firstChild) {
 if(getElem(p1,p2,p3).firstChild.nodeType == 3)
   Cont = getElem(p1,p2,p3).firstChild.nodeValue;
 else
   Cont = "";
 return(Cont);
   }
   else if(MS && getElem(p1,p2,p3)) {
 Cont = getElem(p1,p2,p3).innerText;
 return(Cont);
   }
   else return void(0);
}

function getAttr(p1,p2,p3,p4) {
   var Attr;
   if((DOM || MS) && getElem(p1,p2,p3)) {
 Attr = getElem(p1,p2,p3).getAttribute(p4);
 return(Attr);
   }
   else if (NS && getElem(p1,p2)) {
   if (typeof getElem(p1,p2)[p3] == "object")
    Attr=getElem(p1,p2)[p3][p4]
   else
    Attr=getElem(p1,p2)[p4]
     return Attr;
   }
   else return void(0);
}

function setCont(p1,p2,p3,p4) {
   if(DOM && getElem(p1,p2,p3) && getElem(p1,p2,p3).firstChild)
 getElem(p1,p2,p3).firstChild.nodeValue = p4;
   else if(MS && getElem(p1,p2,p3))
 getElem(p1,p2,p3).innerText = p4;
   else if(NS && getElem(p1,p2,p3)) {
 getElem(p1,p2,p3).document.open();
 getElem(p1,p2,p3).document.write(p4);
 getElem(p1,p2,p3).document.close();
   }
}

DHTML_init();

function Menue() {
if(DOM) {
    if(MS)
        getElem("id","Contents",null).style.top = document.body.scrollTop + 50;
    else
        getElem("id","Contents",null).style.top = window.pageYOffset + 50;
}
if(DOM || MS) {
    if (!DOM) getElem("id","Contents",null).style.top = document.body.scrollTop + 50;
    if (OP) getElem("id","ContentsBlock",null).style.pixelTop = NavLinksPos;
        getElem("id","Contents",null).style.visibility = "visible";
    }
else if(NS) {
    getElem("id","Contents",null).top = window.pageYOffset + 50;
    getElem("id","Contents",null).visibility = "show";
}
}

function noMenue() {
if(DOM || MS)
    getElem("id","Contents",null).style.visibility = "hidden";
if(NS)
    getElem("id","Contents",null).visibility = "hide";
}

function handleMove(ev) {
if(!MS) {
    Event = ev;
    if(Event.screenX < #{mouseThresholdOut})
        Menue();
    else if(Event.screenX > #{mouseThresholdIn})
        noMenue();
}
}

function MShandleMove() {
if(MS) {
    if(window.event.clientX < #{mouseThresholdOut})
        Menue();
    else if(window.event.clientX > #{mouseThresholdIn})
        noMenue();
}
}

function Event_init() {
if(DOM && !MS && !OP) {
    getElem("tagname","body",0).addEventListener("mousemove", handleMove, true);
}
if(NS) {
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove=handleMove;
}
if (DOM && OP) {
    document.onmousemove=handleMove;
    NavLinksPos=42; //Position des Bereiches NavLinks
    getElem("id","ContentsBlock",null).style.pixelTop=NavLinksPos;
}
if (MS) getElem("tagname","body",0).onmousemove=MShandleMove;
}
//-->
</script>
EndOfHTML
    output_at(:pre, :javascript, html)
    text = "minitoc"
    args = {"type"=>"pre", "slot"=>"pre_bottom"}
    minitoc = Deplate::Command::LIST.new(@deplate, nil, text, nil, args, "LIST")
    minitoc = minitoc.finish.process
    @deplate.accum_elements.unshift(minitoc)
end

#prepare_validate_htmlObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/deplate/mod/validate-html.rb', line 20

def prepare_validate_html
    valid = []
    unless @deplate.variables["noHtmlValid"]
        valid << %{<a href="http://validator.w3.org/check?uri=referer"><img border="0"
                  src="http://www.w3.org/Icons/valid-html401"
                  alt="Valid HTML 4.01!" height="31" width="88"></a>}
    end
    unless @deplate.variables["noCssValid"]
        valid << %{<a href="http://jigsaw.w3.org/css-validator/">
                  <img style="border:0;width:88px;height:31px"
                   src="http://jigsaw.w3.org/css-validator/images/vcss" 
                   alt="Valid CSS!"></a>}
    end
    output_at(:post, :html_pageicons, valid) unless valid.empty?
end