sinatra-s3 0.98
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.
- data/README +23 -0
- data/Rakefile +51 -0
- data/bin/sinatra-s3 +30 -0
- data/db/migrate/001_create_bits.rb +28 -0
- data/db/migrate/002_create_users.rb +24 -0
- data/db/migrate/003_create_bits_users.rb +16 -0
- data/db/migrate/004_create_torrents.rb +22 -0
- data/db/migrate/005_create_torrent_peers.rb +26 -0
- data/examples/README +9 -0
- data/examples/wiki.rb +199 -0
- data/examples/wiki.ru +5 -0
- data/examples/wikicloth/MIT-LICENSE +20 -0
- data/examples/wikicloth/README +81 -0
- data/examples/wikicloth/Rakefile +23 -0
- data/examples/wikicloth/init.rb +1 -0
- data/examples/wikicloth/install.rb +0 -0
- data/examples/wikicloth/lib/core_ext.rb +43 -0
- data/examples/wikicloth/lib/wiki_buffer/html_element.rb +237 -0
- data/examples/wikicloth/lib/wiki_buffer/link.rb +70 -0
- data/examples/wikicloth/lib/wiki_buffer/table.rb +159 -0
- data/examples/wikicloth/lib/wiki_buffer/var.rb +77 -0
- data/examples/wikicloth/lib/wiki_buffer.rb +279 -0
- data/examples/wikicloth/lib/wiki_cloth.rb +61 -0
- data/examples/wikicloth/lib/wiki_link_handler.rb +138 -0
- data/examples/wikicloth/lib/wikicloth.rb +5 -0
- data/examples/wikicloth/run_tests.rb +48 -0
- data/examples/wikicloth/sample_documents/air_force_one.wiki +170 -0
- data/examples/wikicloth/sample_documents/cheatsheet.wiki +205 -0
- data/examples/wikicloth/sample_documents/default.css +34 -0
- data/examples/wikicloth/sample_documents/elements.wiki +7 -0
- data/examples/wikicloth/sample_documents/george_washington.wiki +526 -0
- data/examples/wikicloth/sample_documents/images.wiki +15 -0
- data/examples/wikicloth/sample_documents/lists.wiki +421 -0
- data/examples/wikicloth/sample_documents/pipe_trick.wiki +68 -0
- data/examples/wikicloth/sample_documents/random.wiki +55 -0
- data/examples/wikicloth/sample_documents/tv.wiki +312 -0
- data/examples/wikicloth/sample_documents/wiki.png +0 -0
- data/examples/wikicloth/sample_documents/wiki_tables.wiki +410 -0
- data/examples/wikicloth/tasks/wikicloth_tasks.rake +0 -0
- data/examples/wikicloth/test/test_helper.rb +3 -0
- data/examples/wikicloth/test/wiki_cloth_test.rb +8 -0
- data/examples/wikicloth/uninstall.rb +0 -0
- data/examples/wikicloth/wikicloth-0.1.3.gem +0 -0
- data/examples/wikicloth/wikicloth.gemspec +69 -0
- data/lib/sinatra-s3/admin.rb +626 -0
- data/lib/sinatra-s3/base.rb +526 -0
- data/lib/sinatra-s3/errors.rb +51 -0
- data/lib/sinatra-s3/ext.rb +20 -0
- data/lib/sinatra-s3/helpers/acp.rb +100 -0
- data/lib/sinatra-s3/helpers/admin.rb +41 -0
- data/lib/sinatra-s3/helpers/tracker.rb +42 -0
- data/lib/sinatra-s3/helpers/versioning.rb +27 -0
- data/lib/sinatra-s3/helpers.rb +79 -0
- data/lib/sinatra-s3/models/bit.rb +180 -0
- data/lib/sinatra-s3/models/bucket.rb +81 -0
- data/lib/sinatra-s3/models/file_info.rb +3 -0
- data/lib/sinatra-s3/models/git_bucket.rb +3 -0
- data/lib/sinatra-s3/models/slot.rb +47 -0
- data/lib/sinatra-s3/models/torrent.rb +6 -0
- data/lib/sinatra-s3/models/torrent_peer.rb +5 -0
- data/lib/sinatra-s3/models/user.rb +35 -0
- data/lib/sinatra-s3/s3.rb +57 -0
- data/lib/sinatra-s3/tasks.rb +62 -0
- data/lib/sinatra-s3/tracker.rb +134 -0
- data/lib/sinatra-s3.rb +1 -0
- data/public/css/control.css +225 -0
- data/public/css/wiki.css +47 -0
- data/public/images/external-link.gif +0 -0
- data/public/js/prototype.js +2539 -0
- data/public/js/upload_status.js +117 -0
- data/public/test.html +8 -0
- data/s3.yml.example +17 -0
- data/test/s3api_test.rb +121 -0
- data/test/test_helper.rb +25 -0
- metadata +156 -0
@@ -0,0 +1,237 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'builder'
|
3
|
+
|
4
|
+
module WikiCloth
|
5
|
+
|
6
|
+
class WikiBuffer::HTMLElement < WikiBuffer
|
7
|
+
|
8
|
+
ALLOWED_ELEMENTS = ['a','b','i','div','span','sup','sub','strike','s','u','font','big','ref','tt','del',
|
9
|
+
'small','blockquote','strong','pre','code','references','ol','li','ul','dd','dt','dl','center',
|
10
|
+
'h2','h3','h4','h5','h6']
|
11
|
+
ALLOWED_ATTRIBUTES = ['id','name','style','class','href','start','value']
|
12
|
+
ESCAPED_TAGS = [ 'nowiki', 'pre', 'code' ]
|
13
|
+
SHORT_TAGS = [ 'meta','br','hr','img' ]
|
14
|
+
NO_NEED_TO_CLOSE = ['li','p'] + SHORT_TAGS
|
15
|
+
|
16
|
+
def initialize(d="",options={},check=nil)
|
17
|
+
super("",options)
|
18
|
+
self.buffer_type = "Element"
|
19
|
+
@in_quotes = false
|
20
|
+
@in_single_quotes = false
|
21
|
+
@start_tag = 1
|
22
|
+
@tag_check = check unless check.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def run_globals?
|
26
|
+
return ESCAPED_TAGS.include?(self.element_name) ? false : true
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
if NO_NEED_TO_CLOSE.include?(self.element_name)
|
31
|
+
return "<#{self.element_name} />" if SHORT_TAGS.include?(self.element_name)
|
32
|
+
return "</#{self.element_name}><#{self.element_name}>" if @tag_check == self.element_name
|
33
|
+
end
|
34
|
+
|
35
|
+
if ESCAPED_TAGS.include?(self.element_name)
|
36
|
+
# escape all html inside this element
|
37
|
+
self.element_content = self.element_content.gsub('<','<').gsub('>','>')
|
38
|
+
# hack to fix <code><nowiki> nested mess
|
39
|
+
self.element_content = self.element_content.gsub(/<[\/]*\s*nowiki\s*>/,'')
|
40
|
+
end
|
41
|
+
|
42
|
+
lhandler = @options[:link_handler]
|
43
|
+
case self.element_name
|
44
|
+
when "ref"
|
45
|
+
self.element_name = "sup"
|
46
|
+
named_ref = self.name_attribute
|
47
|
+
ref = lhandler.find_reference_by_name(named_ref) unless named_ref.nil?
|
48
|
+
if ref.nil?
|
49
|
+
lhandler.references << { :name => named_ref, :value => self.element_content, :count => 0 }
|
50
|
+
ref = lhandler.references.last
|
51
|
+
end
|
52
|
+
ref_id = (named_ref.nil? ? "" : "#{named_ref}_") + "#{lhandler.reference_index(ref)}-#{ref[:count]}"
|
53
|
+
self.params << { :name => "id", :value => "cite_ref-#{ref_id}" }
|
54
|
+
self.params << { :name => "class", :value => "reference" }
|
55
|
+
self.element_content = "[<a href=\"#cite_note-" + (named_ref.nil? ? "" : "#{named_ref}_") +
|
56
|
+
"#{lhandler.reference_index(ref)}\">#{lhandler.reference_index(ref)}</a>]"
|
57
|
+
ref[:count] += 1
|
58
|
+
when "references"
|
59
|
+
ref_count = 0
|
60
|
+
self.element_name = "ol"
|
61
|
+
self.element_content = lhandler.references.collect { |r|
|
62
|
+
ref_count += 1
|
63
|
+
ref_name = (r[:name].nil? ? "" : r[:name].to_slug + "_")
|
64
|
+
ret = "<li id=\"cite_note-#{ref_name}#{ref_count}\"><b>"
|
65
|
+
1.upto(r[:count]) { |x| ret += "<a href=\"#cite_ref-#{ref_name}#{ref_count}-#{x-1}\">" +
|
66
|
+
(r[:count] == 1 ? "^" : (x-1).to_s(26).tr('0-9a-p', 'a-z')) + "</a> " }
|
67
|
+
ret += "</b> #{r[:value]}</li>"
|
68
|
+
}.to_s
|
69
|
+
when "nowiki"
|
70
|
+
return self.element_content
|
71
|
+
end
|
72
|
+
|
73
|
+
tmp = elem.tag!(self.element_name, self.element_attributes) { |x| x << self.element_content }
|
74
|
+
unless ALLOWED_ELEMENTS.include?(self.element_name)
|
75
|
+
tmp.gsub!(/[\-!\|&"\{\}\[\]]/) { |r| self.escape_char(r) }
|
76
|
+
return tmp.gsub('<', '<').gsub('>', '>')
|
77
|
+
end
|
78
|
+
tmp
|
79
|
+
end
|
80
|
+
|
81
|
+
def name_attribute
|
82
|
+
params.each { |p| return p[:value].to_slug if p.kind_of?(Hash) && p[:name] == "name" }
|
83
|
+
return nil
|
84
|
+
end
|
85
|
+
|
86
|
+
def element_attributes
|
87
|
+
attr = {}
|
88
|
+
params.each { |p| attr[p[:name]] = p[:value] if p.kind_of?(Hash) }
|
89
|
+
if ALLOWED_ELEMENTS.include?(self.element_name.strip.downcase)
|
90
|
+
attr.delete_if { |key,value| !ALLOWED_ATTRIBUTES.include?(key.strip) }
|
91
|
+
end
|
92
|
+
return attr
|
93
|
+
end
|
94
|
+
|
95
|
+
def element_name
|
96
|
+
@ename ||= ""
|
97
|
+
end
|
98
|
+
|
99
|
+
def element_content
|
100
|
+
@econtent ||= ""
|
101
|
+
end
|
102
|
+
|
103
|
+
protected
|
104
|
+
|
105
|
+
def escape_char(c)
|
106
|
+
c = case c
|
107
|
+
when '-' then '-'
|
108
|
+
when '!' then '!'
|
109
|
+
when '|' then '|'
|
110
|
+
when '&' then '&'
|
111
|
+
when '"' then '"'
|
112
|
+
when '{' then '{'
|
113
|
+
when '}' then '}'
|
114
|
+
when '[' then '['
|
115
|
+
when ']' then ']'
|
116
|
+
when '*' then '*'
|
117
|
+
when '#' then '#'
|
118
|
+
when ':' then ':'
|
119
|
+
when ';' then ';'
|
120
|
+
when "'" then '''
|
121
|
+
when '=' then '='
|
122
|
+
else
|
123
|
+
c
|
124
|
+
end
|
125
|
+
return c
|
126
|
+
end
|
127
|
+
|
128
|
+
def elem
|
129
|
+
Builder::XmlMarkup.new
|
130
|
+
end
|
131
|
+
|
132
|
+
def element_name=(val)
|
133
|
+
@ename = val
|
134
|
+
end
|
135
|
+
|
136
|
+
def element_content=(val)
|
137
|
+
@econtent = val
|
138
|
+
end
|
139
|
+
|
140
|
+
def in_quotes?
|
141
|
+
@in_quotes || @in_single_quotes ? true : false
|
142
|
+
end
|
143
|
+
|
144
|
+
def new_char()
|
145
|
+
case
|
146
|
+
# tag name
|
147
|
+
when @start_tag == 1 && current_char == ' '
|
148
|
+
self.element_name = self.data.strip.downcase
|
149
|
+
self.data = ""
|
150
|
+
@start_tag = 2
|
151
|
+
|
152
|
+
# tag is closed <tag/> no attributes
|
153
|
+
when @start_tag == 1 && previous_char == '/' && current_char == '>'
|
154
|
+
self.data.chop!
|
155
|
+
self.element_name = self.data.strip.downcase
|
156
|
+
self.data = ""
|
157
|
+
@start_tag = 0
|
158
|
+
return false
|
159
|
+
|
160
|
+
# open tag
|
161
|
+
when @start_tag == 1 && previous_char != '/' && current_char == '>'
|
162
|
+
self.element_name = self.data.strip.downcase
|
163
|
+
self.data = ""
|
164
|
+
@start_tag = 0
|
165
|
+
return false if SHORT_TAGS.include?(self.element_name)
|
166
|
+
return false if self.element_name == @tag_check && NO_NEED_TO_CLOSE.include?(self.element_name)
|
167
|
+
|
168
|
+
# new tag attr
|
169
|
+
when @start_tag == 2 && current_char == ' ' && self.in_quotes? == false
|
170
|
+
self.current_param = self.data
|
171
|
+
self.data = ""
|
172
|
+
self.params << ""
|
173
|
+
|
174
|
+
# tag attribute name
|
175
|
+
when @start_tag == 2 && current_char == '=' && self.in_quotes? == false
|
176
|
+
self.current_param = self.data
|
177
|
+
self.data = ""
|
178
|
+
self.name_current_param()
|
179
|
+
|
180
|
+
# tag is now open
|
181
|
+
when @start_tag == 2 && previous_char != '/' && current_char == '>'
|
182
|
+
self.current_param = self.data
|
183
|
+
self.data = ""
|
184
|
+
@start_tag = 0
|
185
|
+
return false if SHORT_TAGS.include?(self.element_name)
|
186
|
+
return false if self.element_name == @tag_check && NO_NEED_TO_CLOSE.include?(self.element_name)
|
187
|
+
|
188
|
+
# tag is closed <example/>
|
189
|
+
when @start_tag == 2 && previous_char == '/' && current_char == '>'
|
190
|
+
self.current_param = self.data.chop
|
191
|
+
self.data = ""
|
192
|
+
@start_tag = 0
|
193
|
+
return false
|
194
|
+
|
195
|
+
# in quotes
|
196
|
+
when @start_tag == 2 && current_char == "'" && previous_char != '\\' && !@in_quotes
|
197
|
+
@in_single_quotes = !@in_single_quotes
|
198
|
+
|
199
|
+
# in quotes
|
200
|
+
when @start_tag == 2 && current_char == '"' && previous_char != '\\' && !@in_single_quotes
|
201
|
+
@in_quotes = !@in_quotes
|
202
|
+
|
203
|
+
# start of a closing tag
|
204
|
+
when @start_tag == 0 && previous_char == '<' && current_char == '/'
|
205
|
+
self.element_content += self.data.chop
|
206
|
+
self.data = ""
|
207
|
+
@start_tag = 5
|
208
|
+
|
209
|
+
when @start_tag == 5 && (current_char == '>' || current_char == ' ') && !self.data.blank?
|
210
|
+
self.data = self.data.strip.downcase
|
211
|
+
if self.data == self.element_name
|
212
|
+
self.data = ""
|
213
|
+
return false
|
214
|
+
else
|
215
|
+
if @tag_check == self.data && NO_NEED_TO_CLOSE.include?(self.element_name)
|
216
|
+
self.data = "</#{self.data}>"
|
217
|
+
return false
|
218
|
+
else
|
219
|
+
self.element_content += "</#{self.data}>"
|
220
|
+
@start_tag = 0
|
221
|
+
self.data = ""
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
else
|
226
|
+
if @start_tag == 0 && ESCAPED_TAGS.include?(self.element_name)
|
227
|
+
self.data += self.escape_char(current_char)
|
228
|
+
else
|
229
|
+
self.data += current_char
|
230
|
+
end
|
231
|
+
end
|
232
|
+
return true
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module WikiCloth
|
2
|
+
|
3
|
+
class WikiBuffer::Link < WikiBuffer
|
4
|
+
|
5
|
+
def initialize(data="",options={})
|
6
|
+
super(data,options)
|
7
|
+
@in_quotes = false
|
8
|
+
end
|
9
|
+
|
10
|
+
def internal_link
|
11
|
+
@internal_link ||= false
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
link_handler = @options[:link_handler]
|
16
|
+
unless self.internal_link
|
17
|
+
return link_handler.external_link("#{params[0]}".strip, "#{params[1]}".strip)
|
18
|
+
else
|
19
|
+
case
|
20
|
+
when params[0] =~ /^:(.*)/
|
21
|
+
return link_handler.link_for(params[0],params[1])
|
22
|
+
when params[0] =~ /^\s*([a-zA-Z0-9-]+)\s*:(.*)$/
|
23
|
+
return link_handler.link_for_resource($1,$2,params[1..-1])
|
24
|
+
else
|
25
|
+
return link_handler.link_for(params[0],params[1])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
def internal_link=(val)
|
32
|
+
@internal_link = (val == true ? true : false)
|
33
|
+
end
|
34
|
+
|
35
|
+
def new_char()
|
36
|
+
case
|
37
|
+
# check if this link is internal or external
|
38
|
+
when previous_char.blank? && current_char == '['
|
39
|
+
self.internal_link = true
|
40
|
+
|
41
|
+
# Marks the beginning of another paramater for
|
42
|
+
# the current object
|
43
|
+
when current_char == '|' && self.internal_link == true && @in_quotes == false
|
44
|
+
self.current_param = self.data
|
45
|
+
self.data = ""
|
46
|
+
self.params << ""
|
47
|
+
|
48
|
+
# URL label
|
49
|
+
when current_char == ' ' && self.internal_link == false && params[1].nil? && !self.data.blank?
|
50
|
+
self.current_param = self.data
|
51
|
+
self.data = ""
|
52
|
+
self.params << ""
|
53
|
+
|
54
|
+
# end of link
|
55
|
+
when current_char == ']' && ((previous_char == ']' && self.internal_link == true) || self.internal_link == false) && @in_quotes == false
|
56
|
+
self.data.chop! if self.internal_link == true
|
57
|
+
self.current_param = self.data
|
58
|
+
self.data = ""
|
59
|
+
return false
|
60
|
+
|
61
|
+
else
|
62
|
+
self.data += current_char unless current_char == ' ' && self.data.blank?
|
63
|
+
end
|
64
|
+
|
65
|
+
return true
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
module WikiCloth
|
2
|
+
|
3
|
+
class WikiBuffer::Table < WikiBuffer
|
4
|
+
|
5
|
+
def initialize(data="",options={})
|
6
|
+
super(data,options)
|
7
|
+
self.buffer_type = "table"
|
8
|
+
@start_table = true
|
9
|
+
@start_row = false
|
10
|
+
@start_caption = false
|
11
|
+
@in_quotes = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def table_caption
|
15
|
+
@caption ||= ""
|
16
|
+
return @caption.kind_of?(Hash) ? @caption[:value] : @caption
|
17
|
+
end
|
18
|
+
|
19
|
+
def table_caption_attributes
|
20
|
+
@caption.kind_of?(Hash) ? @caption[:style] : ""
|
21
|
+
end
|
22
|
+
|
23
|
+
def rows
|
24
|
+
@rows ||= [ [] ]
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
row_count = 0
|
29
|
+
ret = "<table" + (params[0].blank? ? "" : " #{params[0].strip}") + ">"
|
30
|
+
ret += "<caption" + (self.table_caption_attributes.blank? ? "" : " #{table_caption_attributes.strip}") +
|
31
|
+
">#{table_caption.strip}</caption>" unless self.table_caption.blank?
|
32
|
+
for row in rows
|
33
|
+
row_count += 1
|
34
|
+
ret += "<tr" + (params[row_count].nil? || params[row_count].blank? ? "" : " #{params[row_count].strip}") + ">"
|
35
|
+
for cell in row
|
36
|
+
cell_attributes = cell[:style].blank? ? "" : " #{cell[:style].strip}"
|
37
|
+
ret += "<#{cell[:type]}#{cell_attributes}>\n#{cell[:value].strip}\n</#{cell[:type]}>"
|
38
|
+
end
|
39
|
+
ret += "</tr>"
|
40
|
+
end
|
41
|
+
ret += "</table>"
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
def rows=(val)
|
46
|
+
@rows = val
|
47
|
+
end
|
48
|
+
|
49
|
+
def table_caption_attributes=(val)
|
50
|
+
@caption = { :style => val, :value => self.table_caption } unless @caption.kind_of?(Hash)
|
51
|
+
@caption[:style] = val if @caption.kind_of?(Hash)
|
52
|
+
end
|
53
|
+
|
54
|
+
def table_caption=(val)
|
55
|
+
@caption = val unless @caption.kind_of?(Hash)
|
56
|
+
@caption[:value] = val if @caption.kind_of?(Hash)
|
57
|
+
end
|
58
|
+
|
59
|
+
def next_row()
|
60
|
+
self.params << ""
|
61
|
+
self.rows << []
|
62
|
+
end
|
63
|
+
|
64
|
+
def next_cell(type="td")
|
65
|
+
if self.rows[-1].size == 0
|
66
|
+
self.rows[-1] = [ { :type => type, :value => "", :style => "" } ]
|
67
|
+
else
|
68
|
+
self.rows[-1][-1][:value] = self.data
|
69
|
+
self.rows[-1] << { :type => type, :value => "", :style => "" }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def new_char()
|
74
|
+
if @check_cell_data == 1
|
75
|
+
case
|
76
|
+
when current_char != '|' && @start_caption == false && self.rows[-1][-1][:style].blank?
|
77
|
+
self.rows[-1][-1][:style] = self.data
|
78
|
+
self.data = ""
|
79
|
+
when current_char != '|' && @start_caption == true && self.table_caption_attributes.blank?
|
80
|
+
self.table_caption_attributes = self.data
|
81
|
+
self.data = ""
|
82
|
+
end
|
83
|
+
@check_cell_data = 0
|
84
|
+
end
|
85
|
+
|
86
|
+
case
|
87
|
+
# Next table cell in row (TD)
|
88
|
+
when current_char == "|" && (previous_char == "\n" || previous_char == "|") && @in_quotes == false
|
89
|
+
self.data.chop!
|
90
|
+
self.next_cell() unless self.data.blank? && previous_char == "|"
|
91
|
+
self.data = ""
|
92
|
+
|
93
|
+
# Next table cell in row (TH)
|
94
|
+
when current_char == "!" && (previous_char == "\n" || previous_char == "!") && @in_quotes == false
|
95
|
+
self.data.chop!
|
96
|
+
self.next_cell('th')
|
97
|
+
self.data = ""
|
98
|
+
|
99
|
+
# End of a table
|
100
|
+
when current_char == '}' && previous_char == '|'
|
101
|
+
self.data = ""
|
102
|
+
self.rows[-1].pop
|
103
|
+
return false
|
104
|
+
|
105
|
+
# Start table caption
|
106
|
+
when current_char == '+' && previous_char == '|' && @in_quotes == false
|
107
|
+
self.data = ""
|
108
|
+
self.rows[-1].pop
|
109
|
+
@start_caption = true
|
110
|
+
|
111
|
+
# Table cell might have attributes
|
112
|
+
when current_char == '|' && previous_char != "\n" && @in_quotes == false
|
113
|
+
@check_cell_data = 1
|
114
|
+
|
115
|
+
# End table caption
|
116
|
+
when current_char == "\n" && @start_caption == true && @in_quotes == false
|
117
|
+
@start_caption = false
|
118
|
+
self.table_caption = self.data
|
119
|
+
self.data = ""
|
120
|
+
|
121
|
+
# in quotes
|
122
|
+
when current_char == '"' && previous_char != '\\'
|
123
|
+
@in_quotes = !@in_quotes
|
124
|
+
self.data += '"'
|
125
|
+
|
126
|
+
# Table params
|
127
|
+
when current_char == "\n" && @start_table == true && @in_quotes == false
|
128
|
+
@start_table = false
|
129
|
+
unless self.data.blank?
|
130
|
+
self.current_param = self.data
|
131
|
+
self.params << ""
|
132
|
+
end
|
133
|
+
self.data = ""
|
134
|
+
|
135
|
+
# Table row params
|
136
|
+
when current_char == "\n" && @start_row == true && @in_quotes == false
|
137
|
+
@start_row = false
|
138
|
+
unless self.data.blank?
|
139
|
+
self.current_param = self.data
|
140
|
+
end
|
141
|
+
self.data = ""
|
142
|
+
|
143
|
+
# Start new table row
|
144
|
+
when current_char == '-' && previous_char == '|' && @in_quotes == false
|
145
|
+
self.data.chop!
|
146
|
+
self.rows[-1].pop
|
147
|
+
self.next_row()
|
148
|
+
@start_row = true
|
149
|
+
|
150
|
+
else
|
151
|
+
self.data += current_char
|
152
|
+
end
|
153
|
+
|
154
|
+
return true
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module WikiCloth
|
2
|
+
|
3
|
+
class WikiBuffer::Var < WikiBuffer
|
4
|
+
|
5
|
+
def initialize(data="",options={})
|
6
|
+
super(data,options)
|
7
|
+
self.buffer_type = "var"
|
8
|
+
@in_quotes = false
|
9
|
+
end
|
10
|
+
|
11
|
+
def skip_html?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def function_name
|
16
|
+
@fname
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
if self.is_function?
|
21
|
+
ret = "#{buffer_type}"
|
22
|
+
ret += " function #{function_name}"
|
23
|
+
ret += "(#{params.inspect})"
|
24
|
+
ret += " [#{data}]"
|
25
|
+
else
|
26
|
+
ret = @options[:link_handler].include_resource("#{params[0]}".strip,params[1..-1])
|
27
|
+
end
|
28
|
+
ret ||= "<!-- TEMPLATE[#{params[0]}] NOT FOUND -->"
|
29
|
+
ret
|
30
|
+
end
|
31
|
+
|
32
|
+
def is_function?
|
33
|
+
self.function_name.nil? || self.function_name.blank? ? false : true
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
def function_name=(val)
|
38
|
+
@fname = val
|
39
|
+
end
|
40
|
+
|
41
|
+
def new_char()
|
42
|
+
case
|
43
|
+
when current_char == '|' && @in_quotes == false
|
44
|
+
self.current_param = self.data
|
45
|
+
self.data = ""
|
46
|
+
self.params << ""
|
47
|
+
|
48
|
+
# Start of either a function or a namespace change
|
49
|
+
when current_char == ':' && @in_quotes == false && self.params.size <= 1
|
50
|
+
self.function_name = self.data
|
51
|
+
self.data = ""
|
52
|
+
puts "[found var function (#{function_name})"
|
53
|
+
|
54
|
+
# Dealing with variable names within functions
|
55
|
+
# and variables
|
56
|
+
when current_char == '=' && @in_quotes == false
|
57
|
+
self.current_param = self.data
|
58
|
+
self.data = ""
|
59
|
+
self.name_current_param()
|
60
|
+
|
61
|
+
# End of a template, variable, or function
|
62
|
+
when current_char == '}' && previous_char == '}'
|
63
|
+
self.data.chop!
|
64
|
+
self.current_param = self.data
|
65
|
+
self.data = ""
|
66
|
+
return false
|
67
|
+
|
68
|
+
else
|
69
|
+
self.data += current_char
|
70
|
+
end
|
71
|
+
|
72
|
+
return true
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|