Module: RedCloth::Formatters::AST
- Includes:
- Base
- Defined in:
- lib/redcloth-formatters-ast/formatters/ast.rb
Constant Summary
collapse
- @@ast =
[]
- @@list_levels =
{ :ul => 0, :ol => 0, :last => nil }
- @@ol_level =
0
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, opts) ⇒ Object
205
206
207
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 205
def method_missing(method, opts)
opts[:text] || ""
end
|
Class Method Details
.ast ⇒ Object
150
151
152
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 150
def self.ast
@@ast
end
|
.reset! ⇒ Object
154
155
156
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 154
def self.reset!
@@ast = []
end
|
Instance Method Details
#bc_close(opts) ⇒ Object
145
146
147
148
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 145
def bc_close(opts)
opts[:append_to_parent] = false
""
end
|
#bc_open(opts) ⇒ Object
127
128
129
130
131
132
133
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 127
def bc_open(opts)
opts[:block] = true
opts[:append_to_parent] = true
options = parse_css(opts[:style])
@@ast << { :type => :code, :text => "", :title => options[:name], :options => options, :language => (options[:language] rescue nil) }
""
end
|
#bq_close(opts) ⇒ Object
121
122
123
124
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 121
def bq_close(opts)
opts[:append_to_parent] = false
""
end
|
#bq_open(opts) ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 113
def bq_open(opts)
opts[:block] = true
opts[:append_to_parent] = true
options = parse_css(opts[:style])
@@ast << { :type => :blockquote, :text => "", :by => options[:by], :options => options }
""
end
|
#code(opts) ⇒ Object
135
136
137
138
139
140
141
142
143
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 135
def code(opts)
if opts[:append_to_parent]
@@ast.last[:text] << "#{opts[:text]}\n\n"
else
options = parse_css(opts[:style])
@@ast << { :type => :code, :text => opts[:text], :options => parse_css(opts[:style]), :language => (options[:language] rescue nil) }
end
""
end
|
#em(opts) ⇒ Object
17
18
19
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 17
def em(opts)
"<i>#{opts[:text]}</i>"
end
|
#fn(opts) ⇒ Object
96
97
98
99
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 96
def fn(opts)
@@ast << { :type => :footnote, :id => opts[:id], :text => opts[:text], :options => parse_css(opts[:style]) }
""
end
|
91
92
93
94
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 91
def (opts)
opts[:id] ||= opts[:text]
"<sup>#{opts[:id]}</sup>"
end
|
#image(opts) ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 105
def image(opts)
options = parse_css(opts[:style])
width = options[:width] || "100%"
@@ast << { :type => :image, :title => opts[:title], :src => opts[:src], :width => width, :options => options }
""
end
|
#li_close(opts = nil) ⇒ Object
63
64
65
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 63
def li_close(opts=nil)
""
end
|
#li_open(opts) ⇒ Object
58
59
60
61
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 58
def li_open(opts)
@@ast.last[:items] << { :type => :list_item, :text => opts[:text], :level => @@list_levels[@@list_levels[:last]]-1, :options => parse_css(opts[:style]) }
""
end
|
#link(opts) ⇒ Object
101
102
103
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 101
def link(opts)
"<u><link href='#{opts[:href]}'>#{opts[:name] || opts[:href]}</link></u>"
end
|
#ol_close(opts) ⇒ Object
53
54
55
56
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 53
def ol_close(opts)
@@list_levels[:ol] -= 1
""
end
|
#ol_open(opts) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 46
def ol_open(opts)
@@ast << { :type => :numbered_list, :items => [], :options => parse_css(opts[:style]) } if @@list_levels[:ol] == 0
@@list_levels[:ol] += 1
@@list_levels[:last] = :ol
""
end
|
#p(opts) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 21
def p(opts)
return "" if opts[:text] =~ /^[\n]$+/
if opts[:append_to_parent]
@@ast.last[:text] << "#{opts[:text]}\n\n"
else
@@ast << { :type => :p, :text => opts[:text], :options => parse_css(opts[:style]) }
end
""
end
|
#strong(opts) ⇒ Object
13
14
15
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 13
def strong(opts)
"<b>#{opts[:text]}</b>"
end
|
#table_close(opts) ⇒ Object
74
75
76
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 74
def table_close(opts)
""
end
|
#table_open(opts) ⇒ Object
68
69
70
71
72
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 68
def table_open(opts)
options = parse_css(opts[:style])
@@ast << { :type => :table, :title => options[:name], :header => false, :rows => [], :options => options }
""
end
|
#td(opts) ⇒ Object
83
84
85
86
87
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 83
def td(opts)
@@ast.last[:header] = true if opts[:th]
@@ast.last[:rows].last << { :type => :table_cell, :text => opts[:text].strip, :header => !opts[:th].nil? }
""
end
|
#tr_open(opts) ⇒ Object
78
79
80
81
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 78
def tr_open(opts)
@@ast.last[:rows] << []
""
end
|
#ul_close(opts) ⇒ Object
40
41
42
43
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 40
def ul_close(opts)
@@list_levels[:ul] -= 1
""
end
|
#ul_open(opts) ⇒ Object
33
34
35
36
37
38
|
# File 'lib/redcloth-formatters-ast/formatters/ast.rb', line 33
def ul_open(opts)
@@ast << { :type => :unnumbered_list, :items => [], :options => parse_css(opts[:style]) } if @@list_levels[:ul] == 0
@@list_levels[:ul] += 1
@@list_levels[:last] = :ul
""
end
|