omf_web 0.9.9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +31 -0
  3. data/bin/omf_web_server.rb +157 -0
  4. data/doc/screenshot2.png +0 -0
  5. data/doc/widget_detail.png +0 -0
  6. data/example/demo/data_sources/downloads.rb +2 -1
  7. data/example/simple/README.md +12 -13
  8. data/example/simple/create_waveform.rb +29 -0
  9. data/example/simple/introduction.md +17 -0
  10. data/example/simple/sample.sq3 +0 -0
  11. data/example/simple/sample.sql +1008 -0
  12. data/example/simple/simple.yaml +62 -0
  13. data/example/simple/simple_dynamic.yaml +66 -0
  14. data/lib/irods4r/file.rb +15 -14
  15. data/lib/irods4r/icommands.rb +18 -18
  16. data/lib/irods4r.rb +9 -9
  17. data/lib/omf-web/config.ru +41 -16
  18. data/lib/omf-web/content/git_repository.rb +32 -31
  19. data/lib/omf-web/content/irods_repository.rb +34 -33
  20. data/lib/omf-web/content/repository.rb +48 -44
  21. data/lib/omf-web/data_source_proxy.rb +33 -22
  22. data/lib/omf-web/rack/session_authenticator.rb +48 -12
  23. data/lib/omf-web/rack/tab_mapper.rb +30 -36
  24. data/lib/omf-web/rack/websocket_handler.rb +26 -25
  25. data/lib/omf-web/session_store.rb +16 -13
  26. data/lib/omf-web/theme/abstract_page.rb +26 -22
  27. data/lib/omf-web/theme/bright/page.rb +84 -34
  28. data/lib/omf-web/theme/bright/stacked_renderer.rb +20 -19
  29. data/lib/omf-web/theme.rb +14 -9
  30. data/lib/omf-web/thin/runner.rb +38 -36
  31. data/lib/omf-web/thin/server.rb +255 -0
  32. data/lib/omf-web/version.rb +1 -1
  33. data/lib/omf-web/widget/data_widget.rb +6 -6
  34. data/lib/omf-web/widget/text/maruku/helpers.rb +33 -30
  35. data/lib/omf-web/widget/text/maruku/input/parse_block.rb +117 -117
  36. data/lib/omf-web/widget/text/maruku/output/to_html.rb +155 -154
  37. data/lib/omf-web/widget/text/maruku.rb +17 -16
  38. data/omf_web.gemspec +6 -2
  39. data/sample.sq3 +0 -0
  40. data/share/htdocs/graph/js/gauge.js +524 -0
  41. data/share/htdocs/vendor/VERSION_MAP.yaml +3 -3
  42. data/share/htdocs/vendor/backbone-1.0.0/backbone.js +1571 -0
  43. data/share/htdocs/vendor/d3-3.0/LICENSE.brewer.txt +38 -0
  44. data/share/htdocs/vendor/d3-3.0/colorbrewer.js +1 -0
  45. data/share/htdocs/vendor/d3-3.0/d3.js +8810 -0
  46. data/share/htdocs/vendor/d3-3.0/d3.min.js +5 -0
  47. data/share/htdocs/vendor/geo_json/Readme.txt +71 -0
  48. data/share/htdocs/vendor/geo_json/regions.json +41 -0
  49. data/share/htdocs/vendor/geo_json/switzerland.json +24 -0
  50. data/share/htdocs/vendor/geo_json/world.json +497 -0
  51. data/share/htdocs/vendor/nv_d3/js/nv.d3.js +8801 -4447
  52. data/share/htdocs/vendor/spin/jquery.spin.js +46 -0
  53. data/share/htdocs/vendor/spin/spin.js +349 -0
  54. data/share/htdocs/vendor/spin/spin.min.js +1 -0
  55. data/share/htdocs/vendor/underscore-1.4.4/underscore.js +1227 -0
  56. metadata +63 -48
  57. data/example/simple/data_sources/gimi31.sq3 +0 -0
  58. data/example/simple/data_sources/ping_source.rb +0 -56
  59. data/example/simple/simple_viz_server.rb +0 -39
  60. data/example/simple/widgets/charts_tab.yaml +0 -38
  61. data/share/.DS_Store +0 -0
  62. data/share/htdocs/.DS_Store +0 -0
  63. data/share/htdocs/vendor/backbone-0.5.3/backbone.js +0 -1158
  64. data/share/htdocs/vendor/underscore-1.2.1/underscore.js +0 -958
@@ -2,17 +2,17 @@
2
2
  # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
3
3
  #
4
4
  # This file is part of Maruku.
5
- #
5
+ #
6
6
  # Maruku is free software; you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
8
8
  # the Free Software Foundation; either version 2 of the License, or
9
9
  # (at your option) any later version.
10
- #
10
+ #
11
11
  # Maruku is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
- #
15
+ #
16
16
  # You should have received a copy of the GNU General Public License
17
17
  # along with Maruku; if not, write to the Free Software
18
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -25,7 +25,7 @@ begin
25
25
  require 'rexml/formatters/default'
26
26
  $rexml_new_version = true
27
27
  rescue LoadError
28
- $rexml_new_version = false
28
+ $rexml_new_version = false
29
29
  end
30
30
 
31
31
  class String
@@ -40,13 +40,13 @@ end
40
40
  # This module groups all functions related to HTML export.
41
41
  module MaRuKu; module Out; module HTML
42
42
  include REXML
43
-
43
+
44
44
  # Render as an HTML fragment (no head, just the content of BODY). (returns a string)
45
45
  def to_html(context={})
46
46
  Thread.current['maruku_context'] = context
47
47
  indent = context[:indent] || -1
48
48
  ie_hack = context[:ie_hack] || true
49
-
49
+
50
50
  div = Element.new 'dummy'
51
51
  children_to_html.each do |e|
52
52
  div << e
@@ -56,10 +56,10 @@ module MaRuKu; module Out; module HTML
56
56
  if @doc.footnotes_order.size > 0
57
57
  div << render_footnotes
58
58
  end
59
-
59
+
60
60
  doc = Document.new(nil,{:respect_whitespace =>:all})
61
61
  doc << div
62
-
62
+
63
63
  # REXML Bug? if indent!=-1 whitespace is not respected for 'pre' elements
64
64
  # containing code.
65
65
  xml =""
@@ -80,45 +80,45 @@ module MaRuKu; module Out; module HTML
80
80
  xml.gsub!(/\A<dummy\s*\/>/,'')
81
81
  xml
82
82
  end
83
-
83
+
84
84
  # Render to a complete HTML document (returns a string)
85
85
  def to_html_document(context={})
86
86
  indent = context[:indent] || -1
87
87
  ie_hack = context[:ie_hack] ||true
88
88
  doc = to_html_document_tree
89
- xml = ""
90
-
89
+ xml = ""
90
+
91
91
  # REXML Bug? if indent!=-1 whitespace is not respected for 'pre' elements
92
92
  # containing code.
93
93
  doc.write(xml,indent,transitive=true,ie_hack);
94
-
94
+
95
95
  Xhtml11_mathml2_svg11 + xml
96
96
  end
97
-
98
- unless defined? Xhtml10strict
99
- Xhtml10strict =
97
+
98
+ unless defined? Xhtml10strict
99
+ Xhtml10strict =
100
100
  "<?xml version='1.0' encoding='utf-8'?>
101
101
  <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
102
102
  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n"
103
-
103
+
104
104
  Xhtml11strict_mathml2 = '<?xml version="1.0" encoding="utf-8"?>
105
105
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
106
106
  "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" [
107
107
  <!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
108
108
  ]>
109
109
  '
110
-
111
- Xhtml11_mathml2_svg11 =
110
+
111
+ Xhtml11_mathml2_svg11 =
112
112
  '<?xml version="1.0" encoding="utf-8"?>
113
113
  <!DOCTYPE html PUBLIC
114
114
  "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
115
115
  "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
116
116
  '
117
117
  end
118
-
119
-
118
+
119
+
120
120
  def xml_newline() Text.new("\n") end
121
-
121
+
122
122
 
123
123
  =begin maruku_doc
124
124
  Attribute: title
@@ -198,22 +198,22 @@ Example:
198
198
  def to_html_document_tree
199
199
  doc = Document.new(nil,{:respect_whitespace =>:all})
200
200
  # doc << XMLDecl.new
201
-
201
+
202
202
  root = Element.new('html', doc)
203
203
  root.add_namespace('http://www.w3.org/1999/xhtml')
204
204
  root.add_namespace('svg', "http://www.w3.org/2000/svg" )
205
205
  lang = self.attributes[:lang] || 'en'
206
206
  root.attributes['xml:lang'] = lang
207
-
207
+
208
208
  root << xml_newline
209
209
  head = Element.new 'head', root
210
-
210
+
211
211
  #<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
212
212
  me = Element.new 'meta', head
213
213
  me.attributes['http-equiv'] = 'Content-type'
214
- # me.attributes['content'] = 'text/html;charset=utf-8'
215
- me.attributes['content'] = 'application/xhtml+xml;charset=utf-8'
216
-
214
+ # me.attributes['content'] = 'text/html;charset=utf-8'
215
+ me.attributes['content'] = 'application/xhtml+xml;charset=utf-8'
216
+
217
217
  METAS.each do |m|
218
218
  if value = self.attributes[m.to_sym]
219
219
  meta = Element.new 'meta', head
@@ -221,8 +221,8 @@ Example:
221
221
  meta.attributes['content'] = value.to_s
222
222
  end
223
223
  end
224
-
225
-
224
+
225
+
226
226
  self.attributes.each do |k,v|
227
227
  if k.to_s =~ /\Ameta-(.*)\Z/
228
228
  meta = Element.new 'meta', head
@@ -230,21 +230,21 @@ Example:
230
230
  meta.attributes['content'] = v.to_s
231
231
  end
232
232
  end
233
-
234
233
 
235
-
234
+
235
+
236
236
  # Create title element
237
237
  doc_title = self.attributes[:title] || self.attributes[:subject] || ""
238
238
  title = Element.new 'title', head
239
239
  title << Text.new(doc_title)
240
-
240
+
241
241
  add_css_to(head)
242
-
243
-
242
+
243
+
244
244
  root << xml_newline
245
-
245
+
246
246
  body = Element.new 'body'
247
-
247
+
248
248
  children_to_html.each do |e|
249
249
  body << e
250
250
  end
@@ -253,15 +253,15 @@ Example:
253
253
  if @doc.footnotes_order.size > 0
254
254
  body << render_footnotes
255
255
  end
256
-
257
- # When we are rendering a whole document, we add a signature
258
- # at the bottom.
256
+
257
+ # When we are rendering a whole document, we add a signature
258
+ # at the bottom.
259
259
  if get_setting(:maruku_signature)
260
- body << maruku_html_signature
260
+ body << maruku_html_signature
261
261
  end
262
-
262
+
263
263
  root << body
264
-
264
+
265
265
  doc
266
266
  end
267
267
 
@@ -273,12 +273,12 @@ Example:
273
273
  link.attributes['type'] = 'text/css'
274
274
  link.attributes['rel'] = 'stylesheet'
275
275
  link.attributes['href'] = css
276
- head << link
276
+ head << link
277
277
  head << xml_newline
278
278
  end
279
279
  end
280
280
  end
281
-
281
+
282
282
  # returns "st","nd","rd" or "th" as appropriate
283
283
  def day_suffix(day)
284
284
  s = {
@@ -301,8 +301,8 @@ Example:
301
301
  day_suffix(t.day)+
302
302
  t.strftime(", %Y")
303
303
  end
304
-
305
- def maruku_html_signature
304
+
305
+ def maruku_html_signature
306
306
  div = Element.new 'div'
307
307
  div.attributes['class'] = 'maruku_signature'
308
308
  Element.new 'hr', div
@@ -316,7 +316,7 @@ Example:
316
316
  span << Text.new(nice_date+".")
317
317
  div
318
318
  end
319
-
319
+
320
320
  def render_footnotes()
321
321
  div = Element.new 'div'
322
322
  div.attributes['class'] = 'footnotes'
@@ -327,7 +327,7 @@ Example:
327
327
  if f
328
328
  li = f.wrap_as_element('li')
329
329
  li.attributes['id'] = "#{get_setting(:doc_prefix)}fn:#{num}"
330
-
330
+
331
331
  a = Element.new 'a'
332
332
  a.attributes['href'] = "\##{get_setting(:doc_prefix)}fnref:#{num}"
333
333
  a.attributes['rev'] = 'footnote'
@@ -348,17 +348,17 @@ Example:
348
348
  def to_html_linebreak; Element.new 'br' end
349
349
 
350
350
  # renders children as html and wraps into an element of given name
351
- #
351
+ #
352
352
  # Sets 'id' if meta is set
353
353
  def wrap_as_element(name, attributes_to_copy=[])
354
354
  m = create_html_element(name, attributes_to_copy)
355
355
  children_to_html.each do |e| m << e; end
356
-
356
+
357
357
  # m << Comment.new( "{"+self.al.to_md+"}") if not self.al.empty?
358
358
  # m << Comment.new( @attributes.inspect) if not @attributes.empty?
359
359
  m
360
360
  end
361
-
361
+
362
362
  =begin maruku_doc
363
363
  Attribute: id
364
364
  Scope: element
@@ -386,21 +386,21 @@ Output: HTML
386
386
 
387
387
  It is copied as a standard HTML attribute.
388
388
  =end
389
-
390
-
391
-
392
-
393
-
389
+
390
+
391
+
392
+
393
+
394
394
  unless defined? HTML4Attributes
395
395
  HTML4Attributes = {}
396
396
  end
397
-
397
+
398
398
  coreattrs = [:id, :class, :style, :title]
399
399
  i18n = [:lang, 'xml:lang'.to_sym]
400
400
  events = [
401
- :onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover,
401
+ :onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover,
402
402
  :onmousemove, :onmouseout,
403
- :onkeypress, :onkeydown, :onkeyup]
403
+ :onkeypress, :onkeydown, :onkeyup]
404
404
  attrs = coreattrs + i18n + events
405
405
  cellhalign = [:align, :char, :charoff]
406
406
  cellvalign = [:valign]
@@ -408,32 +408,32 @@ It is copied as a standard HTML attribute.
408
408
  ['body', attrs + [:onload, :onunload]],
409
409
  ['address', attrs],
410
410
  ['div', attrs],
411
- ['a', attrs+[:charset, :type, :name, :rel, :rev, :accesskey, :shape, :coords, :tabindex,
411
+ ['a', attrs+[:charset, :type, :name, :rel, :rev, :accesskey, :shape, :coords, :tabindex,
412
412
  :onfocus,:onblur]],
413
413
  ['img', attrs + [:longdesc, :name, :height, :width, :alt] ],
414
414
  ['p', attrs],
415
- [['h1','h2','h3','h4','h5','h6'], attrs],
415
+ [['h1','h2','h3','h4','h5','h6'], attrs],
416
416
  [['pre'], attrs],
417
417
  [['q', 'blockquote'], attrs+[:cite]],
418
418
  [['ins','del'], attrs+[:cite,:datetime]],
419
419
  [['ol','ul','li'], attrs],
420
420
  ['table',attrs+[:summary, :width, :frame, :rules, :border, :cellspacing, :cellpadding]],
421
- ['caption',attrs],
421
+ ['caption',attrs],
422
422
  [['colgroup','col'],attrs+[:span, :width]+cellhalign+cellvalign],
423
423
  [['thead','tbody','tfoot'], attrs+cellhalign+cellvalign],
424
424
  [['td','td','th'], attrs+[:abbr, :axis, :headers, :scope, :rowspan, :colspan, :cellvalign, :cellhalign]],
425
-
425
+
426
426
  # altri
427
427
  [['em','code','strong','hr','span','dl','dd','dt'], attrs]
428
428
  ].each do |el, a| [*el].each do |e| HTML4Attributes[e] = a end end
429
-
430
-
429
+
430
+
431
431
  def create_html_element(name, attributes_to_copy=[])
432
432
  m = Element.new name
433
- if atts = HTML4Attributes[name] then
433
+ if atts = HTML4Attributes[name] then
434
434
  atts.each do |att|
435
- if v = @attributes[att] then
436
- m.attributes[att.to_s] = v.to_s
435
+ if v = @attributes[att] then
436
+ m.attributes[att.to_s] = v.to_s
437
437
  end
438
438
  end
439
439
  else
@@ -442,24 +442,24 @@ It is copied as a standard HTML attribute.
442
442
  m
443
443
  end
444
444
 
445
-
445
+
446
446
  def to_html_ul
447
447
  if @attributes[:toc]
448
448
  # render toc
449
449
  html_toc = @doc.toc.to_html
450
450
  return html_toc
451
451
  else
452
- add_ws wrap_as_element('ul')
452
+ add_ws wrap_as_element('ul')
453
453
  end
454
454
  end
455
-
456
-
455
+
456
+
457
457
  def to_html_paragraph
458
458
  #add_ws wrap_as_element('p')
459
459
  dt = Element.new 'p'
460
460
  dt.attributes['class'] = 'drop-target'
461
461
  dt.attributes['line_no'] = Thread.current['line_no']
462
- dt.attributes['delegate'] = 'plan' # should most likely go into the js column handler
462
+ dt.attributes['delegate'] = 'plan' # should most likely go into the js column handler
463
463
  p = wrap_as_element('p')
464
464
  p.attributes['class'] = 'content'
465
465
  [Text.new("\n"), p, dt, Text.new("\n")]
@@ -485,7 +485,7 @@ by Maruku, to have the same results in both HTML and LaTeX.
485
485
  # nil if not applicable, else string
486
486
  def section_number
487
487
  return nil if not get_setting(:use_numbered_headers)
488
-
488
+
489
489
  n = @attributes[:section_number]
490
490
  if n && (not n.empty?)
491
491
  n.join('.')+". "
@@ -493,7 +493,7 @@ by Maruku, to have the same results in both HTML and LaTeX.
493
493
  nil
494
494
  end
495
495
  end
496
-
496
+
497
497
  # nil if not applicable, else SPAN element
498
498
  def render_section_number
499
499
  # if we are bound to a section, add section number
@@ -506,11 +506,11 @@ by Maruku, to have the same results in both HTML and LaTeX.
506
506
  nil
507
507
  end
508
508
  end
509
-
509
+
510
510
  def to_html_header_orig
511
- element_name = "h#{self.level}"
511
+ element_name = "h#{self.level}"
512
512
  h = wrap_as_element element_name
513
-
513
+
514
514
  if span = render_section_number
515
515
  h.insert_before(h.children.first, span)
516
516
  end
@@ -518,9 +518,9 @@ by Maruku, to have the same results in both HTML and LaTeX.
518
518
  end
519
519
 
520
520
  def to_html_header
521
- element_name = "h#{self.level}"
521
+ element_name = "h#{self.level}"
522
522
  h = wrap_as_element element_name
523
-
523
+
524
524
  if span = render_section_number
525
525
  h.insert_before(h.children.first, span)
526
526
  end
@@ -535,7 +535,7 @@ by Maruku, to have the same results in both HTML and LaTeX.
535
535
  source = source.gsub(/'/,'&#39;') # IE bug
536
536
  Text.new(source, true, nil, true )
537
537
  end
538
-
538
+
539
539
  =begin maruku_doc
540
540
  Attribute: html_use_syntax
541
541
  Scope: global, document, element
@@ -552,8 +552,8 @@ Examples:
552
552
  require 'maruku'
553
553
  {:lang=ruby html_use_syntax=true}
554
554
 
555
- and
556
-
555
+ and
556
+
557
557
  <div style="text-align:center">Div</div>
558
558
  {:lang=html html_use_syntax=true}
559
559
 
@@ -570,16 +570,16 @@ and
570
570
  =end
571
571
 
572
572
  $syntax_loaded = false
573
- def to_html_code;
573
+ def to_html_code;
574
574
  source = self.raw_code
575
575
 
576
- lang = self.attributes[:lang] || @doc.attributes[:code_lang]
576
+ lang = self.attributes[:lang] || @doc.attributes[:code_lang]
577
577
 
578
578
  lang = 'xml' if lang=='html'
579
579
 
580
580
  use_syntax = get_setting :html_use_syntax
581
-
582
- element =
581
+
582
+ element =
583
583
  if use_syntax && lang
584
584
  begin
585
585
  if not $syntax_loaded
@@ -589,78 +589,78 @@ and
589
589
  $syntax_loaded = true
590
590
  end
591
591
  convertor = Syntax::Convertors::HTML.for_syntax lang
592
-
592
+
593
593
  # eliminate trailing newlines otherwise Syntax crashes
594
594
  source = source.gsub(/\n*\Z/,'')
595
-
595
+
596
596
  html = convertor.convert( source )
597
597
  html = html.gsub(/\&apos;/,'&#39;') # IE bug
598
598
  html = html.gsub(/'/,'&#39;') # IE bug
599
- # html = html.gsub(/&/,'&amp;')
600
-
599
+ # html = html.gsub(/&/,'&amp;')
600
+
601
601
  code = Document.new(html, {:respect_whitespace =>:all}).root
602
602
  code.name = 'code'
603
603
  code.attributes['class'] = lang
604
604
  code.attributes['lang'] = lang
605
-
605
+
606
606
  pre = Element.new 'pre'
607
607
  pre << code
608
608
  pre
609
609
  rescue LoadError => e
610
610
  maruku_error "Could not load package 'syntax'.\n"+
611
611
  "Please install it, for example using 'gem install syntax'."
612
- to_html_code_using_pre(source)
612
+ to_html_code_using_pre(source)
613
613
  rescue Object => e
614
614
  maruku_error"Error while using the syntax library for code:\n#{source.inspect}"+
615
615
  "Lang is #{lang} object is: \n"+
616
- self.inspect +
616
+ self.inspect +
617
617
  "\nException: #{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
618
-
618
+
619
619
  tell_user("Using normal PRE because the syntax library did not work.")
620
620
  to_html_code_using_pre(source)
621
621
  end
622
622
  else
623
623
  to_html_code_using_pre(source)
624
624
  end
625
-
625
+
626
626
  color = get_setting(:code_background_color)
627
627
  if color != Globals[:code_background_color]
628
628
  element.attributes['style'] = "background-color: #{color};"
629
629
  end
630
630
  add_ws element
631
631
  end
632
-
632
+
633
633
  =begin maruku_doc
634
634
  Attribute: code_background_color
635
635
  Scope: global, document, element
636
636
  Summary: Background color for code blocks.
637
637
 
638
638
  The format is either a named color (`green`, `red`) or a CSS color
639
- of the form `#ff00ff`.
639
+ of the form `#ff00ff`.
640
640
 
641
- * for **HTML output**, the value is put straight in the `background-color` CSS
641
+ * for **HTML output**, the value is put straight in the `background-color` CSS
642
642
  property of the block.
643
643
 
644
644
  * for **LaTeX output**, if it is a named color, it must be a color accepted
645
645
  by the LaTeX `color` packages. If it is of the form `#ff00ff`, Maruku
646
- defines a color using the `\color[rgb]{r,g,b}` macro.
646
+ defines a color using the `\color[rgb]{r,g,b}` macro.
647
647
 
648
648
  For example, for `#0000ff`, the macro is called as: `\color[rgb]{0,0,1}`.
649
649
 
650
650
  =end
651
-
652
-
651
+
652
+
653
653
  def to_html_code_using_pre(source)
654
654
  pre = create_html_element 'pre'
655
655
  code = Element.new 'code', pre
656
656
  s = source
657
-
657
+
658
658
  # s = s.gsub(/&/,'&amp;')
659
659
  s = Text.normalize(s)
660
660
  s = s.gsub(/\&apos;/,'&#39;') # IE bug
661
661
  s = s.gsub(/'/,'&#39;') # IE bug
662
662
 
663
- if get_setting(:code_show_spaces)
663
+ if get_setting(:code_show_spaces)
664
664
  # 187 = raquo
665
665
  # 160 = nbsp
666
666
  # 172 = not
@@ -669,7 +669,7 @@ of the form `#ff00ff`.
669
669
  end
670
670
 
671
671
  text = Text.new(s, respect_ws=true, parent=nil, raw=true )
672
-
672
+
673
673
  if lang = self.attributes[:lang]
674
674
  code.attributes['lang'] = lang
675
675
  code.attributes['class'] = lang
@@ -678,21 +678,21 @@ of the form `#ff00ff`.
678
678
  pre
679
679
  end
680
680
 
681
- def to_html_inline_code;
681
+ def to_html_inline_code;
682
682
  pre = create_html_element 'code'
683
683
  source = self.raw_code
684
- pre << source2html(source)
685
-
684
+ pre << source2html(source)
685
+
686
686
  color = get_setting(:code_background_color)
687
687
  if color != Globals[:code_background_color]
688
688
  pre.attributes['style'] = "background-color: #{color};"+(pre.attributes['style']||"")
689
689
  end
690
-
690
+
691
691
  pre
692
692
  end
693
693
 
694
694
  def add_class_to(el, cl)
695
- el.attributes['class'] =
695
+ el.attributes['class'] =
696
696
  if already = el.attributes['class']
697
697
  already + " " + cl
698
698
  else
@@ -702,10 +702,10 @@ of the form `#ff00ff`.
702
702
 
703
703
  def add_class_to_link(a)
704
704
  return # not ready yet
705
-
705
+
706
706
  # url = a.attributes['href']
707
707
  # return if not url
708
- #
708
+ #
709
709
  # if url =~ /^#/
710
710
  # add_class_to(a, 'maruku-link-samedoc')
711
711
  # elsif url =~ /^http:/
@@ -713,11 +713,11 @@ of the form `#ff00ff`.
713
713
  # else
714
714
  # add_class_to(a, 'maruku-link-local')
715
715
  # end
716
- #
716
+ #
717
717
  # puts a.attributes['class']
718
718
  end
719
-
720
-
719
+
720
+
721
721
  def to_html_immediate_link
722
722
  a = create_html_element 'a'
723
723
  url = self.url
@@ -727,11 +727,11 @@ of the form `#ff00ff`.
727
727
  add_class_to_link(a)
728
728
  a
729
729
  end
730
-
730
+
731
731
  def to_html_link
732
732
  a = wrap_as_element 'a'
733
733
  id = self.ref_id
734
-
734
+
735
735
  if ref = @doc.refs[id]
736
736
  url = ref[:url]
737
737
  title = ref[:title]
@@ -747,12 +747,13 @@ of the form `#ff00ff`.
747
747
  # add_class_to_link(a)
748
748
  return a
749
749
  end
750
-
750
+
751
751
  def to_html_im_link
752
752
  if url = self.url
753
753
  title = self.title
754
754
  a = wrap_as_element 'a'
755
755
  a.attributes['href'] = url
756
+ a.attributes['xhref'] = url # BUG ALERT: Strange behaviour of jquery's replaceWith related to href
756
757
  a.attributes['title'] = title if title
757
758
  return a
758
759
  else
@@ -761,12 +762,12 @@ of the form `#ff00ff`.
761
762
  return wrap_as_element('span')
762
763
  end
763
764
  end
764
-
765
+
765
766
  def add_ws(e)
766
767
  [Text.new("\n"), e, Text.new("\n")]
767
768
  end
768
769
  ##### Email address
769
-
770
+
770
771
  def obfuscate(s)
771
772
  res = ''
772
773
  s.each_byte do |char|
@@ -774,7 +775,7 @@ of the form `#ff00ff`.
774
775
  end
775
776
  res
776
777
  end
777
-
778
+
778
779
  def to_html_email_address
779
780
  email = self.email
780
781
  a = create_html_element 'a'
@@ -783,7 +784,7 @@ of the form `#ff00ff`.
783
784
  #"mailto:"+obfuscate(email),false,nil,true))
784
785
  # Sorry, for the moment it doesn't work
785
786
  a.attributes['href'] = "mailto:#{email}"
786
-
787
+
787
788
  a << Text.new(obfuscate(email),false,nil,true)
788
789
  a
789
790
  end
@@ -797,7 +798,7 @@ of the form `#ff00ff`.
797
798
  url = ref[:url]
798
799
  title = ref[:title]
799
800
  a.attributes['src'] = url.to_s
800
- a.attributes['alt'] = children_to_s
801
+ a.attributes['alt'] = children_to_s
801
802
  else
802
803
  maruku_error"Could not find id = #{id.inspect} for\n #{self.inspect}"
803
804
  tell_user "Could not create image with ref_id = #{id.inspect};"+
@@ -807,7 +808,7 @@ of the form `#ff00ff`.
807
808
  raise "IMAGE: #{url}"
808
809
  return a
809
810
  end
810
-
811
+
811
812
  def to_html_im_image
812
813
  if not url = self.url
813
814
  maruku_error "Image with no url: #{self.inspect}"
@@ -822,7 +823,7 @@ of the form `#ff00ff`.
822
823
  title = self.title
823
824
  a = create_html_element 'img'
824
825
  a.attributes['src'] = url.to_s
825
- a.attributes['alt'] = children_to_s
826
+ a.attributes['alt'] = children_to_s
826
827
  return a
827
828
  end
828
829
 
@@ -836,7 +837,7 @@ If true, raw HTML is discarded from the output.
836
837
 
837
838
  def to_html_raw_html
838
839
  return [] if get_setting(:filter_html)
839
-
840
+
840
841
  raw_html = self.raw_html
841
842
  if rexml_doc = @parsed_html
842
843
  root = rexml_doc.root
@@ -849,9 +850,9 @@ If true, raw HTML is discarded from the output.
849
850
  #div << Text.new(s)
850
851
  return div
851
852
  end
852
-
853
+
853
854
  # copies the @children array (FIXME is it deep?)
854
- elements = root.to_a
855
+ elements = root.to_a
855
856
  return elements
856
857
  else # invalid
857
858
  # Creates red box with offending HTML
@@ -871,28 +872,28 @@ If true, raw HTML is discarded from the output.
871
872
  abbr.attributes['title'] = self.title if self.title
872
873
  abbr
873
874
  end
874
-
875
+
875
876
  def to_html_footnote_reference
876
877
  id = self.footnote_id
877
-
878
+
878
879
  # save the order of used footnotes
879
880
  order = @doc.footnotes_order
880
-
881
+
881
882
  if order.include? id
882
883
  # footnote has already been used
883
884
  return []
884
885
  end
885
-
886
+
886
887
  if not @doc.footnotes[id]
887
888
  return []
888
889
  end
889
-
890
+
890
891
  # take next number
891
892
  order << id
892
-
893
- #num = order.size;
893
+
894
+ #num = order.size;
894
895
  num = order.index(id) + 1
895
-
896
+
896
897
  sup = Element.new 'sup'
897
898
  sup.attributes['id'] = "#{get_setting(:doc_prefix)}fnref:#{num}"
898
899
  a = Element.new 'a'
@@ -900,15 +901,15 @@ If true, raw HTML is discarded from the output.
900
901
  a.attributes['href'] = "\##{get_setting(:doc_prefix)}fn:#{num}"
901
902
  a.attributes['rel'] = 'footnote'
902
903
  sup << a
903
-
904
+
904
905
  sup
905
906
  end
906
-
907
+
907
908
  ## Definition lists ###
908
909
  def to_html_definition_list() add_ws wrap_as_element('dl') end
909
910
  def to_html_definition() children_to_html end
910
911
  def to_html_definition_term() add_ws wrap_as_element('dt') end
911
- def to_html_definition_data() add_ws wrap_as_element('dd') end
912
+ def to_html_definition_data() add_ws wrap_as_element('dd') end
912
913
 
913
914
  # FIXME: Ugly code
914
915
  def to_html_table
@@ -922,28 +923,28 @@ If true, raw HTML is discarded from the output.
922
923
  rows << @children.slice(i, num_columns)
923
924
  i += num_columns
924
925
  end
925
-
926
+
926
927
  table = create_html_element 'table'
927
928
  thead = Element.new 'thead'
928
929
  tr = Element.new 'tr'
929
930
  array_to_html(head).each do |x| tr<<x end
930
931
  thead << tr
931
932
  table << thead
932
-
933
+
933
934
  tbody = Element.new 'tbody'
934
935
  rows.each do |row|
935
936
  tr = Element.new 'tr'
936
- array_to_html(row).each_with_index do |x,i|
937
- x.attributes['style'] ="text-align: #{align[i].to_s};"
938
- tr<<x
937
+ array_to_html(row).each_with_index do |x,i|
938
+ x.attributes['style'] ="text-align: #{align[i].to_s};"
939
+ tr<<x
939
940
  end
940
-
941
+
941
942
  tbody << tr << Text.new("\n")
942
943
  end
943
944
  table << tbody
944
945
  table
945
946
  end
946
-
947
+
947
948
  def to_html_head_cell; wrap_as_element('th') end
948
949
  def to_html_cell
949
950
  if @attributes[:scope]
@@ -952,22 +953,22 @@ If true, raw HTML is discarded from the output.
952
953
  wrap_as_element('td')
953
954
  end
954
955
  end
955
-
956
- def to_html_entity
956
+
957
+ def to_html_entity
957
958
  MaRuKu::Out::Latex.need_entity_table
958
-
959
+
959
960
  entity_name = self.entity_name
960
-
961
+
961
962
  if (e = MaRuKu::Out::Latex::ENTITY_TABLE[entity_name]) && e.html_num
962
963
  entity_name = e.html_num
963
964
  end
964
-
965
+
965
966
  # Fix for Internet Explorer
966
967
  if entity_name == 'apos'
967
968
  entity_name = 39
968
969
  end
969
970
 
970
-
971
+
971
972
  if entity_name.kind_of? Fixnum
972
973
  # Entity.new(entity_name)
973
974
  Text.new('&#%d;' % [entity_name], false, nil, true)
@@ -993,7 +994,7 @@ If true, raw HTML is discarded from the output.
993
994
  # puts "init: #{res.inspect}"
994
995
  first_header = true
995
996
  array.each do |c|
996
- method = c.kind_of?(MDElement) ?
997
+ method = c.kind_of?(MDElement) ?
997
998
  "to_html_#{c.node_type}" : "to_html"
998
999
 
999
1000
  if not c.respond_to?(method)
@@ -1001,7 +1002,7 @@ If true, raw HTML is discarded from the output.
1001
1002
  next
1002
1003
  end
1003
1004
 
1004
-
1005
+
1005
1006
  Thread.current['line_no'] = c.line_no if c.respond_to? :line_no
1006
1007
  h = c.send(method)
1007
1008
  # puts "HHHHH: #{h.inspect} e: #{e.inspect}"