Class: Raf::Raf2Html
- Inherits:
-
Object
- Object
- Raf::Raf2Html
- Defined in:
- lib/raf2html.rb
Constant Summary collapse
- VERSION =
File.readlines(File.join(File.dirname(__FILE__),"../VERSION"))[0].strip
- RELEASE =
File.readlines(File.join(File.dirname(__FILE__),"../RELEASE"))[0].strip
Instance Method Summary collapse
- #body ⇒ Object
- #css ⇒ Object
- #footer ⇒ Object
- #footnote ⇒ Object
- #header ⇒ Object
- #header_title ⇒ Object
- #index ⇒ Object
- #index_terminate(level, level_pre) ⇒ Object
-
#initialize(src, options = {}) ⇒ Raf2Html
constructor
A new instance of Raf2Html.
- #metadata ⇒ Object
- #setup_metadata ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(src, options = {}) ⇒ Raf2Html
Returns a new instance of Raf2Html.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/raf2html.rb', line 12 def initialize(src, = {}) @debug = true # options @css = File.open(File.([:css])).readlines.to_s unless [:css].nil? @language = [:language] @index = [:index] = [:metadata] @quiet = [:quiet] @raf = BlockParser.new = @nodes = @raf.parse src end |
Instance Method Details
#body ⇒ Object
45 46 47 |
# File 'lib/raf2html.rb', line 45 def body @nodes.map do |node| node.apply end.join end |
#css ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/raf2html.rb', line 130 def css # str = <<EOL #<link href="screen.css" rel="stylesheet" type="text/css" media="screen" /> #<link href="handheld.css" rel="stylesheet" type="text/css" media="handheld" /> #<link href="print.css" rel="stylesheet" type="text/css" media="print" /> #EOL str = "" str += %%<style type="text/css"><!--\n#{@css}\n--></style>\n% unless @css.nil? str end |
#footer ⇒ Object
141 142 143 144 145 146 |
# File 'lib/raf2html.rb', line 141 def str = "\n" str += "<div id='rights'>#{@metadata[:rights]}</div>\n" unless [:rights].nil? str += "</body>\n</html>" str end |
#footnote ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/raf2html.rb', line 98 def footnote return "" if @raf.inline_index[:footnote].nil? str = "<div id='raf-footnote'>" @raf.inline_index[:footnote].each_with_index do |f,i| str += "<a id='raf-footnote-#{i+1}' class='footnote' />" str += "<a href='#raf-footnote-#{i+1}-reverse' class='footnote-reverse'>*#{i+1}</a>" str += " #{f[:content].map{|c| c.apply}}<br />" end str += "</div>" str end |
#header ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/raf2html.rb', line 110 def header str = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"\#{@metadata[:language]}\">\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" str += css str += " <title>\#{@metadata[:subject]}</title>\n </head>\n<body>\n" end |
#header_title ⇒ Object
126 127 128 |
# File 'lib/raf2html.rb', line 126 def header_title "<h1>#{@metadata[:subject]}</h1>\n" end |
#index ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/raf2html.rb', line 49 def index return "" if @raf.index[:head].nil? str = "<div id='raf-index'>" level_pre = 1 @raf.index[:head].each_with_index do |h,i| next if h[:level] == 1 or h[:level] == 6 if h[:level] == 5 str += "<div class=><a href='#raf-head#{h[:level]}-#{i+1}'><span class='space' />#{h[:title]}</a></div>\n" else str += index_terminate(h[:level], level_pre) str += "<li><a href='#raf-head#{h[:level]}-#{i+1}'>#{h[:index]}#{h[:title]}</a>\n" level_pre = h[:level] end end str += index_terminate(2, level_pre) + "</ul>" str += "</div>" str end |
#index_terminate(level, level_pre) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/raf2html.rb', line 69 def index_terminate(level, level_pre) str = "" case level <=> level_pre when 1 (level - level_pre).times do str += "<ul>" end when -1 (level_pre - level).times do str += "</ul></li>" end else str += "</li>" end str end |
#metadata ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/raf2html.rb', line 86 def str = "<div id='raf-metadata'>" str += %[<div>#{CGI.escapeHTML(@metadata[:description])}</div>] unless [:description].nil? str += %[<ul class="list-inline">] %w{ creator date update publisher version contributer revision tag }.each do |m| str += %[<li><strong>#{m}</strong>:#{CGI.escapeHTML(@metadata[m.to_sym])}</li>] unless [m.to_sym].nil? end str += "</ul>" str += "</div>" str end |
#setup_metadata ⇒ Object
27 28 29 30 31 |
# File 'lib/raf2html.rb', line 27 def = @raf. [:language] = @language if [:language].nil? end |
#to_html ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/raf2html.rb', line 33 def to_html html = "" html += header unless @quiet html += header_title html += if html += index if @index html += body html += footnote html += unless @quiet html end |