sinatra-s3 0.98 → 0.99
Sign up to get free protection for your applications and to get access to all the features.
- data/README +36 -18
- data/bin/sinatra-s3 +47 -15
- data/examples/wiki.rb +13 -13
- data/lib/sinatra-s3/admin.rb +1 -1
- data/lib/sinatra-s3/base.rb +1 -5
- data/lib/sinatra-s3/models/bit.rb +2 -2
- data/lib/sinatra-s3/s3.rb +11 -4
- data/public/js/wiki.js +35 -0
- data/s3.yml.example +6 -3
- metadata +63 -67
- data/examples/README +0 -9
- data/examples/wikicloth/MIT-LICENSE +0 -20
- data/examples/wikicloth/README +0 -81
- data/examples/wikicloth/Rakefile +0 -23
- data/examples/wikicloth/init.rb +0 -1
- data/examples/wikicloth/install.rb +0 -0
- data/examples/wikicloth/lib/core_ext.rb +0 -43
- data/examples/wikicloth/lib/wiki_buffer.rb +0 -279
- data/examples/wikicloth/lib/wiki_buffer/html_element.rb +0 -237
- data/examples/wikicloth/lib/wiki_buffer/link.rb +0 -70
- data/examples/wikicloth/lib/wiki_buffer/table.rb +0 -159
- data/examples/wikicloth/lib/wiki_buffer/var.rb +0 -77
- data/examples/wikicloth/lib/wiki_cloth.rb +0 -61
- data/examples/wikicloth/lib/wiki_link_handler.rb +0 -138
- data/examples/wikicloth/lib/wikicloth.rb +0 -5
- data/examples/wikicloth/run_tests.rb +0 -48
- data/examples/wikicloth/sample_documents/air_force_one.wiki +0 -170
- data/examples/wikicloth/sample_documents/cheatsheet.wiki +0 -205
- data/examples/wikicloth/sample_documents/default.css +0 -34
- data/examples/wikicloth/sample_documents/elements.wiki +0 -7
- data/examples/wikicloth/sample_documents/george_washington.wiki +0 -526
- data/examples/wikicloth/sample_documents/images.wiki +0 -15
- data/examples/wikicloth/sample_documents/lists.wiki +0 -421
- data/examples/wikicloth/sample_documents/pipe_trick.wiki +0 -68
- data/examples/wikicloth/sample_documents/random.wiki +0 -55
- data/examples/wikicloth/sample_documents/tv.wiki +0 -312
- data/examples/wikicloth/sample_documents/wiki.png +0 -0
- data/examples/wikicloth/sample_documents/wiki_tables.wiki +0 -410
- data/examples/wikicloth/tasks/wikicloth_tasks.rake +0 -0
- data/examples/wikicloth/test/test_helper.rb +0 -3
- data/examples/wikicloth/test/wiki_cloth_test.rb +0 -8
- data/examples/wikicloth/uninstall.rb +0 -0
- data/examples/wikicloth/wikicloth-0.1.3.gem +0 -0
- data/examples/wikicloth/wikicloth.gemspec +0 -69
- data/public/test.html +0 -8
@@ -1,237 +0,0 @@
|
|
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
|
@@ -1,70 +0,0 @@
|
|
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
|
@@ -1,159 +0,0 @@
|
|
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
|