Class: RD::RD2tDiaryVisitor

Inherits:
RD2HTMLVisitor
  • Object
show all
Defined in:
lib/tdiary/style/rd.rb

Direct Known Subclasses

RD2tDiaryCHTMLVistor

Instance Method Summary collapse

Constructor Details

#initialize(date = nil, idx = nil, opt = nil, author = nil) ⇒ RD2tDiaryVisitor

Returns a new instance of RD2tDiaryVisitor.



10
11
12
13
14
15
16
# File 'lib/tdiary/style/rd.rb', line 10

def initialize( date=nil, idx=nil, opt=nil, author=nil )
    @td_date = date
  @td_idx = idx
  @td_opt = opt
  @td_author = author
  super()
end

Instance Method Details

#apply_to_DescListItem(element, term, description) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/tdiary/style/rd.rb', line 40

def apply_to_DescListItem(element, term, description)
  %Q[<dt>#{term.join}</dt>] +
    if description.empty? then
      "\n"
    else
      %Q[\n<dd>\n#{description.join("\n").chomp}\n</dd>]
    end
end

#apply_to_DocumentElement(element, content) ⇒ Object



18
19
20
21
22
# File 'lib/tdiary/style/rd.rb', line 18

def apply_to_DocumentElement(element, content)
  ret = ""
  ret << html_body(content) + "\n"
  ret
end

#apply_to_Footnote(element, content) ⇒ Object



85
86
87
88
# File 'lib/tdiary/style/rd.rb', line 85

def apply_to_Footnote(element, content)
  escaped_content = content.join.gsub( /%>/, "%%>" )
  %Q|<%=fn apply_plugin( #{escaped_content.dump} ) %>|
end

#apply_to_Headline(element, title) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/tdiary/style/rd.rb', line 29

def apply_to_Headline(element, title)
  level = element.level + TDIARY_BASE_LEVEL
  title = title.join
  if level == 3
    r = %Q[<h#{level}><%= subtitle_proc( Time::at( #{@td_date.to_i} ), #{title.to_s.dump.gsub( /%/, '\\\\045' )} ) %></h#{level}>]
  else
    r = %Q[<h#{level}>#{title}</h#{level}>]
  end
  r
end

#apply_to_Index(element, content) ⇒ Object

use for native html



81
82
83
# File 'lib/tdiary/style/rd.rb', line 81

def apply_to_Index(element, content)
    CGI.unescapeHTML(content.join)
end

#apply_to_Keyboard(element, content) ⇒ Object

use for tDiary plugin :-p



75
76
77
78
# File 'lib/tdiary/style/rd.rb', line 75

def apply_to_Keyboard(element, content)
    plugin, args = CGI.unescapeHTML(content.join("")).split(/\s+/, 2)
  %Q[<%=#{plugin} #{args}%>]
end

#apply_to_MethodList(element, items) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/tdiary/style/rd.rb', line 49

def apply_to_MethodList(element, items)
  if /^(<.+>)?$/ =~ element.items[0].term.to_label
    %Q[#{items.join("\n").chomp}\n]
  else
    %Q[<dl>\n#{items.join("\n").chomp}\n</dl>]
  end
end

#apply_to_MethodListItem(element, term, description) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/tdiary/style/rd.rb', line 57

def apply_to_MethodListItem(element, term, description)
  case term
  when /^&lt;([^\s]+)\s*.*&gt;/
    closetag = "</#{CGI.unescapeHTML($1)}>"
    r = CGI.unescapeHTML(term)
    if description.size > 0
      r << %Q[\n#{description.join("\n")}\n]
      r << closetag
    end
    r
  when ''
    "<hr>"
  else
    super
  end
end

#apply_to_RefToElement(element, content) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/tdiary/style/rd.rb', line 90

def apply_to_RefToElement(element, content)
  label = element.to_label
  key, opt = label.split(/:/, 2)

  case key
  when "IMG"
    ref_ext_IMG(label, content.join, opt)
  when "RAA"
    ref_ext_RAA(label, content.join, opt)
  when /^ruby-(talk|list|dev|math|ext|core)$/
    ref_ext_RubyML(label, content.join, key, opt)
  when /^(\d{4}|\d{6}|\d{8}|\d{8}-\d+)[^\d]*?#?([pct]\d+)?$/
    %Q[<%=my "#{key}","#{content.join}"%>]
  else
    opt = "" unless opt # case of no ":"
    %Q[<%=a "#{key}","#{opt}","#{content.join}"%>]
  end
end