class Raf::Raf2Html
Constants
- RELEASE
- VERSION
Public Class Methods
new(src, options = {})
click to toggle source
# File lib/raf2html.rb, line 11 def initialize(src, options = {}) @debug = true # options @css = File.open(File.expand_path(options[:css])).readlines.to_s unless options[:css].empty? @js = File.open(File.expand_path(options[:js])).readlines.to_s unless options[:js].empty? @language = options[:language] @index = options[:index] @metadata = options[:metadata] @quiet = options[:quiet] get_customized_element(options[:custom_element]) unless options[:custom_element].empty? @raf = BlockParser.new(options) @metadata = setup_metadata @nodes = @raf.parse src end
Public Instance Methods
body()
click to toggle source
# File lib/raf2html.rb, line 51 def body @nodes.map do |node| node.apply end.join end
css()
click to toggle source
# File lib/raf2html.rb, line 137 def css str = "" str += %[<style type="text/css"><!--\n#{@css}\n--></style>\n] unless @css.nil? str end
footnote()
click to toggle source
# File lib/raf2html.rb, line 104 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
get_customized_element(file)
click to toggle source
エレメントのカスタム用ファイルを読み込む
# File lib/raf2html.rb, line 29 def get_customized_element(file) require File.expand_path(file) end
header()
click to toggle source
# File lib/raf2html.rb, line 116 def header str = <<EOL <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="#{@metadata[:language]}"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> EOL str += css str += javascript str += <<EOL <title>#{@metadata[:subject]}</title> </head> <body> EOL end
header_title()
click to toggle source
# File lib/raf2html.rb, line 133 def header_title "<h1>#{@metadata[:subject]}</h1>\n" end
index()
click to toggle source
# File lib/raf2html.rb, line 55 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="nonum"><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)
click to toggle source
# File lib/raf2html.rb, line 75 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
javascript()
click to toggle source
# File lib/raf2html.rb, line 143 def javascript str = "" str += %[<script type="text/javascript">#{@js}</script>\n] unless @js.nil? str end
metadata()
click to toggle source
# File lib/raf2html.rb, line 92 def metadata str = "<div id='raf-metadata'>" str += %[<div>#{CGI.escapeHTML(@metadata[:description])}</div>] unless @metadata[:description].nil? str += %[<ul class="list-inline">] %w{ author create update publisher version tag }.each do |m| str += %[<li><strong>#{m}</strong>:#{CGI.escapeHTML(@metadata[m.to_sym])}</li>] unless @metadata[m.to_sym].nil? end str += "</ul>" str += "</div>" str end
setup_metadata()
click to toggle source
# File lib/raf2html.rb, line 33 def setup_metadata metadata = @raf.metadata metadata[:language] = @language if metadata[:language].nil? metadata end
to_html()
click to toggle source
# File lib/raf2html.rb, line 39 def to_html html = "" html += header unless @quiet html += header_title html += metadata if @metadata html += index if @index html += body html += footnote html += footer unless @quiet html end