ubbparser 0.1.6 → 0.1.7
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.
- checksums.yaml +8 -8
- data/lib/ubbparser.rb +97 -90
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjVmZTQ5NWE1Y2FkMzRhNDE5ODRmMjMzYzVkYmRlZjA5MzgyYzYyZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmY0MzIwNjkxYzQxYjBmNjA5NzcxMDMwMjNiMTQ5MDg2NmE5Yzk3Zg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDQ1Y2ZmODc1MmNmZmNlNzdlMGIyOTllZDczZDkxN2U1YzQyY2VjNTk3NzU5
|
10
|
+
NDkxNWU3YmY1OGM5MGVlNTA5ZTdjYmZlYmQwOWQzMTNlMDBhMzliNmY3MDIx
|
11
|
+
ZTVlYjMwZGRkOTlhZmRjOTg3NDkyNmI2MGNmMjgwNGZlZmYyNTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGY2N2ExOGYzNmEwMzUxOTYxYzljYjc2ZmYwZTEwODJjOWFlNmU3MzI1MzUw
|
14
|
+
YWFiZDY1MmQ0ZTlmMzQ5YjVkMWI0ZTYxYjA1MzBhZDkzNDBhMjYxM2NjZTAw
|
15
|
+
YjdjOTFkZDg1NTM1NzdkNjdkYTVmYTJmMTIyNTJkNDMxNGYxN2E=
|
data/lib/ubbparser.rb
CHANGED
@@ -27,19 +27,25 @@ require 'cgi'
|
|
27
27
|
#noinspection RubyUnusedLocalVariable RubyTooManyMethods
|
28
28
|
module UBBParser
|
29
29
|
|
30
|
+
extend self
|
31
|
+
|
32
|
+
def inline_elements
|
33
|
+
%w(b big i small tt abbr acronym cite code dfn em kbd strong samp var a bdo br img map object q script span sub sup button input label select textarea)
|
34
|
+
end
|
35
|
+
|
30
36
|
# Mapping can be used to allow simplified use of files
|
31
37
|
# [img]123123[/img] would have the same effect as [img]files/download/123123[/img]
|
32
38
|
#noinspection RubyClassVariableUsageInspection
|
33
|
-
def
|
39
|
+
def set_file_url_convert_method(callback_method)
|
34
40
|
@@file_url_convert_method = callback_method
|
35
41
|
end
|
36
42
|
|
37
43
|
#noinspection RubyClassVariableUsageInspection
|
38
44
|
@@file_url_convert_method = nil
|
39
45
|
|
40
|
-
# Converts a strings containing key-value-list into a hash. This function is mostly used by the parser
|
46
|
+
# Converts a strings containing key-value-list into a hash. This function is mostly used by the parser it
|
41
47
|
# Attributes are given to the render methods as a hash.
|
42
|
-
def
|
48
|
+
def attrib_str_to_hash(attrib_str)
|
43
49
|
result = {:class_attrib_str => attrib_str.gsub(/^=/, '')}
|
44
50
|
|
45
51
|
attrib_str.insert(0, 'default') if (attrib_str[0] == '=')
|
@@ -54,7 +60,7 @@ module UBBParser
|
|
54
60
|
# [:denied_keys] An array of keys that are denied
|
55
61
|
# ===Example:
|
56
62
|
# UBBParser.hash_to_attrib_str({}, {:allowed_keys => [:class, :src, :width]})
|
57
|
-
def
|
63
|
+
def hash_to_attrib_str(hash, options = {})
|
58
64
|
hash.delete_if { |k, _| !options[:allowed_keys].include?(k) } if options[:allowed_keys].is_a?(Array)
|
59
65
|
hash.delete_if { |k, _| options[:denied_keys].include?(k) } if options[:denied_keys].is_a?(Array)
|
60
66
|
return hash.map { |k, v| v = v.to_s.gsub(/\\|'/) { |c| "\\#{c}" }; "#{k}='#{v}'" }.join(' ')
|
@@ -69,7 +75,7 @@ module UBBParser
|
|
69
75
|
# {:class_code: "prettify linenums"} => <pre class='prettify linenums'>...</pre>
|
70
76
|
#
|
71
77
|
# When developing your own tags, you can also define your own parse_options.
|
72
|
-
def
|
78
|
+
def parse(text, parse_options = {})
|
73
79
|
result = ''
|
74
80
|
scnr = StringScanner.new(text)
|
75
81
|
parse_options.each { |k, v| v.to_s.gsub(/-/, '_').gsub(/[^\w]+/, '') if (k.to_s.start_with?('class_')); v }
|
@@ -94,10 +100,10 @@ module UBBParser
|
|
94
100
|
scnr.skip(/\[/)
|
95
101
|
code = scnr.scan(/[\w-]*/)
|
96
102
|
method_name = ('render_' + code.to_s.gsub(/-/, '_')).to_sym
|
97
|
-
if ((scnr.eos?) || (code == "") || (!
|
103
|
+
if ((scnr.eos?) || (code == "") || (!respond_to?(method_name)))
|
98
104
|
result << '[' + code
|
99
105
|
else
|
100
|
-
attributes =
|
106
|
+
attributes = attrib_str_to_hash(scnr.scan(/[^\]]*/))
|
101
107
|
scnr.skip(/]/)
|
102
108
|
inner_text = scnr.scan_until(/\[\/#{code}\]/)
|
103
109
|
if inner_text.nil? #no closing tag found
|
@@ -106,9 +112,10 @@ module UBBParser
|
|
106
112
|
else
|
107
113
|
inner_text.chomp!("[/#{code}]")
|
108
114
|
end
|
109
|
-
method_result =
|
115
|
+
method_result = send(method_name, inner_text, attributes, parse_options).to_s
|
110
116
|
result << method_result
|
111
|
-
|
117
|
+
last_html_tag = method_result.match('</\w+>$').to_s
|
118
|
+
scnr.skip(/\n?/) unless (inline_elements.include?(last_html_tag)) # Skip next newline if last tag was not inline element
|
112
119
|
end
|
113
120
|
end
|
114
121
|
end
|
@@ -117,95 +124,95 @@ module UBBParser
|
|
117
124
|
|
118
125
|
# Returns true if the given value matches the given regular expression.
|
119
126
|
# :category: Validation methods
|
120
|
-
def
|
127
|
+
def matches_regexp?(value, regexp)
|
121
128
|
return !value.to_s.match(regexp).nil?
|
122
129
|
end
|
123
130
|
|
124
131
|
# Returns true if the given value is a valid email address
|
125
132
|
# :category: Validation methods
|
126
|
-
def
|
133
|
+
def is_email?(value)
|
127
134
|
return false unless value.is_a?(String)
|
128
|
-
return
|
135
|
+
return matches_regexp?(value, /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i)
|
129
136
|
end
|
130
137
|
|
131
138
|
# Returns true if the given value is a valid url
|
132
139
|
# :category: Validation methods
|
133
|
-
def
|
134
|
-
return
|
140
|
+
def is_url?(value)
|
141
|
+
return matches_regexp?(value, /^(http|https)\:\/\/([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$/)
|
135
142
|
end
|
136
143
|
|
137
144
|
# Converts the [anchor=myname]...[/anchor] tag into <a name='myname'>...</a>. Use the :class_anchor parse option to define html classes.
|
138
145
|
# :category: Render methods
|
139
|
-
def
|
146
|
+
def render_anchor(inner_text, attributes = {}, parse_options = {})
|
140
147
|
name = attributes[:default] || ''
|
141
148
|
inner_text.gsub!(/\\|'/) { |c| "\\#{c}" }
|
142
149
|
css_class = parse_options[:class_anchor] || 'ubb-anchor'
|
143
|
-
"<a name='#{name}' class='#{css_class}'>#{
|
150
|
+
"<a name='#{name}' class='#{css_class}'>#{parse(inner_text, parse_options)}</a>"
|
144
151
|
end
|
145
152
|
|
146
153
|
# Converts the url in the inner_text into a webplayer, playing the audio file.
|
147
154
|
# :category: Render methods
|
148
|
-
def
|
155
|
+
def render_audio(inner_text, attributes = {}, parse_options = {})
|
149
156
|
# Not yet implemented
|
150
157
|
end
|
151
158
|
|
152
159
|
# Renders the inner_text bold (using <strong>).
|
153
160
|
# :category: Render methods
|
154
|
-
def
|
155
|
-
"<strong>#{
|
161
|
+
def render_b(inner_text, attributes = {}, parse_options = {})
|
162
|
+
"<strong>#{parse(inner_text, parse_options)}</strong>"
|
156
163
|
end
|
157
164
|
|
158
165
|
# Converts [br] into a <br />.
|
159
166
|
# :category: Render methods
|
160
|
-
def
|
161
|
-
"<br />#{
|
167
|
+
def render_br(inner_text, attributes = {}, parse_options = {})
|
168
|
+
"<br />#{parse(inner_text, parse_options)}"
|
162
169
|
end
|
163
170
|
|
164
171
|
# Converts all lines in the inner_text as a bullet list. Each line represents one list item. Empty lines are ignored. Use the :class_bullet parse option to define html classes.
|
165
172
|
# :category: Render methods
|
166
|
-
def
|
173
|
+
def render_bullets(inner_text, attributes = {}, parse_options = {})
|
167
174
|
items = inner_text.split(/\n/)
|
168
175
|
items.delete_if { |item| item.strip == '' }
|
169
|
-
items.map! { |item| '<li>' +
|
176
|
+
items.map! { |item| '<li>' + parse(item, parse_options) + '</li>' }
|
170
177
|
css_class = parse_options[:class_list] || 'ubb-list'
|
171
178
|
return (items.empty?) ? '' : "<ul class='#{css_class}'>" + items.join('') + '</ul>'
|
172
179
|
end
|
173
180
|
|
174
181
|
# Centers the inner_text.
|
175
182
|
# :category: Render methods
|
176
|
-
def
|
177
|
-
"<div style='text-align: center'>#{
|
183
|
+
def render_center(inner_text, attributes = {}, parse_options = {})
|
184
|
+
"<div style='text-align: center'>#{parse(inner_text, parse_options)}</div>"
|
178
185
|
end
|
179
186
|
|
180
187
|
# Assures the inner_text is rendered below floating elements.
|
181
188
|
# :category: Render methods
|
182
|
-
def
|
189
|
+
def render_class(inner_text, attributes = {}, parse_options = {})
|
183
190
|
classes = attributes[:class_attrib_str].to_s.gsub(/'/, "\\'")
|
184
|
-
"<div class='#{classes}'>#{
|
191
|
+
"<div class='#{classes}'>#{parse(inner_text, parse_options)}</div>"
|
185
192
|
end
|
186
193
|
|
187
194
|
# Assures the inner_text is rendered below floating elements.
|
188
195
|
# :category: Render methods
|
189
|
-
def
|
196
|
+
def render_clear(inner_text, attributes = {}, parse_options = {})
|
190
197
|
"<div style='clear: both'></div>"
|
191
198
|
end
|
192
199
|
|
193
200
|
# Changes the font color of the inner_text
|
194
201
|
# :category: Render methods
|
195
|
-
def
|
202
|
+
def render_color(inner_text, attributes = {}, parse_options = {})
|
196
203
|
color = attributes[:default].gsub(/'/, "\\'")
|
197
|
-
"<div style='color:#{color}'>#{
|
204
|
+
"<div style='color:#{color}'>#{parse(inner_text, parse_options)}</div>"
|
198
205
|
end
|
199
206
|
|
200
207
|
# Ignores all the inner_text
|
201
208
|
# :category: Render methods
|
202
|
-
def
|
209
|
+
def render_comment(inner_text, attributes = {}, parse_options = {})
|
203
210
|
''
|
204
211
|
end
|
205
212
|
|
206
213
|
# Places the inner_text in a fixed font type. Also adds the classes prettify and linenums for styling purposes. Use the :class_code parse option to define html classes.
|
207
214
|
# :category: Render methods
|
208
|
-
def
|
215
|
+
def render_code(inner_text, attributes = {}, parse_options = {})
|
209
216
|
css_class = parse_options[:class_code] || 'ubb-code'
|
210
217
|
"<pre class='#{css_class}'>#{inner_text}</pre>"
|
211
218
|
end
|
@@ -213,7 +220,7 @@ module UBBParser
|
|
213
220
|
# Renders csv-data into a html table. You can use the following attributes:
|
214
221
|
# [:has_header] The first row should be rendered as header cells (using th).
|
215
222
|
# :category: Render methods
|
216
|
-
def
|
223
|
+
def render_csv(inner_text, attributes = {}, parse_options = {})
|
217
224
|
head_cells = body_cells = ''
|
218
225
|
cell_tag = (attributes[:has_header]) ? 'th' : 'td'
|
219
226
|
lines = inner_text.gsub(/(^\n|\n*$)/, '').split(/\n/)
|
@@ -248,11 +255,11 @@ module UBBParser
|
|
248
255
|
# [email=info@osingasoftware.nl]Osinga Software[/email]
|
249
256
|
# By default the email address is protected against spoofing, using JavaScript. Use the email parse option to define html classes.
|
250
257
|
# :category: Render methods
|
251
|
-
def
|
258
|
+
def render_email(inner_text, attributes = {}, parse_options = {})
|
252
259
|
css_class = (parse_options[:class_email] || 'ubb-email').to_s.strip
|
253
|
-
inner_text =
|
260
|
+
inner_text = parse(inner_text, parse_options) if !attributes[:default].nil?
|
254
261
|
email = (attributes[:default] || inner_text)
|
255
|
-
if (!
|
262
|
+
if (!is_email?(email))
|
256
263
|
result = "<span class='#{css_class} ubbparser-error'>UBB error: invalid email address #{email}</span>"
|
257
264
|
elsif ((parse_options.has_key?(:protect_email) && !parse_options[:protect_email]) || (attributes[:protected] == "false"))
|
258
265
|
result = "<a href='mailto:#{email}' class='#{css_class}'>#{inner_text}</a>"
|
@@ -276,87 +283,87 @@ module UBBParser
|
|
276
283
|
|
277
284
|
# Renders the inner_text in a H1 heading.
|
278
285
|
# :category: Render methods
|
279
|
-
def
|
280
|
-
"<h1>#{
|
286
|
+
def render_h1(inner_text, attributes = {}, parse_options = {})
|
287
|
+
"<h1>#{parse(inner_text, parse_options)}</h1>"
|
281
288
|
end
|
282
289
|
|
283
290
|
# Renders the inner_text in a H2 heading.
|
284
291
|
# :category: Render methods
|
285
|
-
def
|
286
|
-
"<h2>#{
|
292
|
+
def render_h2(inner_text, attributes = {}, parse_options = {})
|
293
|
+
"<h2>#{parse(inner_text, parse_options)}</h2>"
|
287
294
|
end
|
288
295
|
|
289
296
|
# Renders the inner_text in a H3 heading.
|
290
297
|
# :category: Render methods
|
291
|
-
def
|
292
|
-
"<h3>#{
|
298
|
+
def render_h3(inner_text, attributes = {}, parse_options = {})
|
299
|
+
"<h3>#{parse(inner_text, parse_options)}</h3>"
|
293
300
|
end
|
294
301
|
|
295
302
|
# Renders the inner_text in a H4 heading.
|
296
303
|
# :category: Render methods
|
297
|
-
def
|
298
|
-
"<h4>#{
|
304
|
+
def render_h4(inner_text, attributes = {}, parse_options = {})
|
305
|
+
"<h4>#{parse(inner_text, parse_options)}</h4>"
|
299
306
|
end
|
300
307
|
|
301
308
|
# Renders the inner_text in a H5 heading.
|
302
309
|
# :category: Render methods
|
303
|
-
def
|
304
|
-
"<h5>#{
|
310
|
+
def render_h5(inner_text, attributes = {}, parse_options = {})
|
311
|
+
"<h5>#{parse(inner_text, parse_options)}</h5>"
|
305
312
|
end
|
306
313
|
|
307
314
|
# Renders the inner_text in a H6 heading.
|
308
315
|
# :category: Render methods
|
309
|
-
def
|
310
|
-
"<h6>#{
|
316
|
+
def render_h6(inner_text, attributes = {}, parse_options = {})
|
317
|
+
"<h6>#{parse(inner_text, parse_options)}</h6>"
|
311
318
|
end
|
312
319
|
|
313
320
|
# Renders a horizontal ruler.
|
314
321
|
# :category: Render methods
|
315
|
-
def
|
316
|
-
"<hr />#{
|
322
|
+
def render_hr(inner_text, attributes = {}, parse_options = {})
|
323
|
+
"<hr />#{parse(inner_text, parse_options)}"
|
317
324
|
end
|
318
325
|
|
319
326
|
# Renders the inner_text in italic.
|
320
327
|
# :category: Render methods
|
321
|
-
def
|
322
|
-
"<em>#{
|
328
|
+
def render_i(inner_text, attributes = {}, parse_options = {})
|
329
|
+
"<em>#{parse(inner_text, parse_options)}</em>"
|
323
330
|
end
|
324
331
|
|
325
332
|
# Renders an iframe. Use the inner_text as source. Use the :class_iframe parse option to define html classes.
|
326
333
|
# :category: Render methods
|
327
|
-
def
|
334
|
+
def render_iframe(inner_text, attributes = {}, parse_options = {})
|
328
335
|
src = inner_text
|
329
336
|
src = 'http://' + src if (src.match(/^www\./))
|
330
337
|
src.gsub!(/\\|'/) { |c| "\\#{c}" }
|
331
338
|
attributes[:src] = inner_text
|
332
339
|
attributes[:class] = attributes[:class] || parse_options[:class_iframe] || 'ubb-iframe'
|
333
|
-
attrib_str =
|
340
|
+
attrib_str = hash_to_attrib_str(attributes, :allowed_keys => [:src, :class, :frameborder, :marginwidth, :marginheight, :width, :height])
|
334
341
|
return "<iframe #{attrib_str}></iframe>"
|
335
342
|
end
|
336
343
|
|
337
344
|
# Doesn't render the ubb code in the inner_text. It does strip all html-tags from the inner_text
|
338
345
|
# :category: Render methods
|
339
|
-
def
|
346
|
+
def render_ignore(inner_text, attributes = {}, parse_options = {})
|
340
347
|
inner_text
|
341
348
|
end
|
342
349
|
|
343
350
|
# Renders an image. Use the :class_img parse option to define html classes.
|
344
351
|
# :category: Render methods
|
345
352
|
#noinspection RubyClassVariableUsageInspection
|
346
|
-
def
|
353
|
+
def render_img(inner_text, attributes = {}, parse_options = {})
|
347
354
|
url = inner_text
|
348
355
|
url = @@file_url_convert_method.call(url) unless @@file_url_convert_method.nil?
|
349
356
|
attributes[:src] = url.gsub(/\\|'/) { |c| "\\#{c}" }
|
350
357
|
attributes[:alt] ||= ''
|
351
358
|
|
352
359
|
attributes[:class] = attributes[:class] || parse_options[:class] || 'ubb-img'
|
353
|
-
attrib_str =
|
360
|
+
attrib_str = hash_to_attrib_str(attributes, :allowed_keys => [:src, :alt, :styles, :class])
|
354
361
|
return "<img #{attrib_str} />"
|
355
362
|
end
|
356
363
|
|
357
364
|
# Renders an image, floated on the left side of the text frame. Use the :class_img_left parse option to define html classes.
|
358
365
|
# :category: Render methods
|
359
|
-
def
|
366
|
+
def render_img_left(inner_text, attributes = {}, parse_options = {})
|
360
367
|
attributes[:styles] = 'float: left; margin: 0px 10px 10px 0px'
|
361
368
|
attributes[:class] = parse_options[:class_img_left] || 'ubb-img-left'
|
362
369
|
render_img(inner_text, attributes, parse_options)
|
@@ -364,7 +371,7 @@ module UBBParser
|
|
364
371
|
|
365
372
|
# Renders an image, floated on the right side of the text frame. Use the :class_img_right parse option to define html classes.
|
366
373
|
# :category: Render methods
|
367
|
-
def
|
374
|
+
def render_img_right(inner_text, attributes = {}, parse_options = {})
|
368
375
|
attributes[:styles] = 'float: left; margin: 0px 0px 10px 10px'
|
369
376
|
attributes[:class] = parse_options[:class_img_right] || 'ubb-img-right'
|
370
377
|
render_img(inner_text, attributes, parse_options)
|
@@ -372,75 +379,75 @@ module UBBParser
|
|
372
379
|
|
373
380
|
# Renders the inner_text with a justified text alignment.
|
374
381
|
# :category: Render methods
|
375
|
-
def
|
376
|
-
"<div style='text-align: justify'>#{
|
382
|
+
def render_justify(inner_text, attributes = {}, parse_options = {})
|
383
|
+
"<div style='text-align: justify'>#{parse(inner_text, parse_options)}</div>"
|
377
384
|
end
|
378
385
|
|
379
386
|
# Renders the inner_text with a left text alignment.
|
380
387
|
# :category: Render methods
|
381
|
-
def
|
382
|
-
"<div style='text-align: left'>#{
|
388
|
+
def render_left(inner_text, attributes = {}, parse_options = {})
|
389
|
+
"<div style='text-align: left'>#{parse(inner_text, parse_options)}</div>"
|
383
390
|
end
|
384
391
|
|
385
392
|
# Renders the inner_text as an ordered list. Each line represents a list item. Use the :class_list parse option to define html classes.
|
386
393
|
# :category: Render methods
|
387
|
-
def
|
394
|
+
def render_list(inner_text, attributes = {}, parse_options = {})
|
388
395
|
items = inner_text.split(/\n/)
|
389
396
|
items.delete_if { |item| item.strip == '' }
|
390
|
-
items.map! { |item| '<li>' +
|
397
|
+
items.map! { |item| '<li>' + parse(item, parse_options) + '</li>' }
|
391
398
|
return (items.empty?) ? '' : "<ol class='#{parse_options[:class_list].to_s.strip}'>" + items.join('') + '</ol>'
|
392
399
|
end
|
393
400
|
|
394
401
|
# Renders the inner_text as a paragraph. Use the :class_p parse option to define html classes.
|
395
402
|
# :category: Render methods
|
396
|
-
def
|
403
|
+
def render_p(inner_text, attributes = {}, parse_options = {})
|
397
404
|
css_class = parse_options[:class_p] || 'ubb-p'
|
398
|
-
"<p class='#{css_class}'>#{
|
405
|
+
"<p class='#{css_class}'>#{parse(inner_text, parse_options)}</p>"
|
399
406
|
end
|
400
407
|
|
401
408
|
# Renders the inner_text with a right text alignment.
|
402
409
|
# :category: Render methods
|
403
|
-
def
|
404
|
-
"<div style='text-align: right'>#{
|
410
|
+
def render_right(inner_text, attributes = {}, parse_options = {})
|
411
|
+
"<div style='text-align: right'>#{parse(inner_text, parse_options)}</div>"
|
405
412
|
end
|
406
413
|
|
407
414
|
# Renders the inner_text in a <div> block with inline CSS styles, i.e.:
|
408
415
|
# [style color: red; border: 1px solid green]...[/style]
|
409
416
|
# :category: Render methods
|
410
|
-
def
|
417
|
+
def render_style(inner_text, attributes = {}, parse_options = {})
|
411
418
|
styles = attributes[:class_attrib_str].to_s.gsub(/'/, "\\'")
|
412
|
-
"<div style='#{styles}'>#{
|
419
|
+
"<div style='#{styles}'>#{parse(inner_text, parse_options)}</div>"
|
413
420
|
end
|
414
421
|
|
415
422
|
# Converts the [table] to a <table>. Always use this in combination with [tr] and [td] or [th]. Use the :class_table parse option to define html classes.
|
416
423
|
# :category: Render methods
|
417
|
-
def
|
424
|
+
def render_table(inner_text, attributes = {}, parse_options = {})
|
418
425
|
css_class = parse_options[:class_table] || 'ubb-table'
|
419
|
-
"<table class='#{css_class}'>#{
|
426
|
+
"<table class='#{css_class}'>#{parse(inner_text.gsub(/(^\n+)|(\n+$)/, ''), parse_options)}</table>"
|
420
427
|
end
|
421
428
|
|
422
429
|
# Converts the [td] to a <td>. Always use this in combination with [table] and [tr].
|
423
430
|
# :category: Render methods
|
424
|
-
def
|
425
|
-
"<td>#{
|
431
|
+
def render_td(inner_text, attributes = {}, parse_options = {})
|
432
|
+
"<td>#{parse(inner_text, parse_options)}</td>"
|
426
433
|
end
|
427
434
|
|
428
435
|
# Converts the [th] to a <th>. Always use this in combination with [table] and [tr].
|
429
436
|
# :category: Render methods
|
430
|
-
def
|
431
|
-
"<th>#{
|
437
|
+
def render_th(inner_text, attributes = {}, parse_options = {})
|
438
|
+
"<th>#{parse(inner_text, parse_options)}</th>"
|
432
439
|
end
|
433
440
|
|
434
441
|
# Converts the [tr] to a <tr>. Always use this in combination with [table] and [td] or [th].
|
435
442
|
# :category: Render methods
|
436
|
-
def
|
437
|
-
"<tr>#{
|
443
|
+
def render_tr(inner_text, attributes = {}, parse_options = {})
|
444
|
+
"<tr>#{parse(inner_text.gsub(/(^\n+)|(\n+$)/, ''), parse_options)}</tr>"
|
438
445
|
end
|
439
446
|
|
440
447
|
# Renders the inner_text underline. Use this with caution, since underline text is associated with hyperlinks.
|
441
448
|
# :category: Render methods
|
442
|
-
def
|
443
|
-
"<u>#{
|
449
|
+
def render_u(inner_text, attributes = {}, parse_options = {})
|
450
|
+
"<u>#{parse(inner_text, parse_options)}</u>"
|
444
451
|
end
|
445
452
|
|
446
453
|
# Renders a web addres. There are two options to define:
|
@@ -449,8 +456,8 @@ module UBBParser
|
|
449
456
|
# Use the :class_url parse option to define html classes.
|
450
457
|
# :category: Render methods
|
451
458
|
#noinspection RubyClassVariableUsageInspection
|
452
|
-
def
|
453
|
-
inner_text =
|
459
|
+
def render_url(inner_text, attributes = {}, parse_options = {})
|
460
|
+
inner_text = parse(inner_text, parse_options) if !attributes[:default].nil?
|
454
461
|
url = (attributes[:default] || inner_text)
|
455
462
|
url = 'http://' + url if (url.start_with?('www.'))
|
456
463
|
target = (url.start_with?('http://')) ? " target='_blank'" : ''
|
@@ -462,7 +469,7 @@ module UBBParser
|
|
462
469
|
|
463
470
|
# Renders a YouTube video using the video id or url in the inner_text.
|
464
471
|
# :category: Render methods
|
465
|
-
def
|
472
|
+
def render_vimeo(inner_text, attributes = {}, parse_options = {})
|
466
473
|
attributes[:width] ||= 500
|
467
474
|
attributes[:height] ||= 281
|
468
475
|
attributes[:class] = parse_options[:class_vimeo] || 'ubb-vimeo'
|
@@ -473,7 +480,7 @@ module UBBParser
|
|
473
480
|
|
474
481
|
# Renders a YouTube video using the video id or url in the inner_text.
|
475
482
|
# :category: Render methods
|
476
|
-
def
|
483
|
+
def render_youtube(inner_text, attributes = {}, parse_options = {})
|
477
484
|
attributes[:width] ||= 560
|
478
485
|
attributes[:height] ||= 315
|
479
486
|
attributes[:class] = parse_options[:class_youtube] || 'ubb-youtube'
|
@@ -485,15 +492,15 @@ module UBBParser
|
|
485
492
|
# Renders a Youtube, Vimeo or Zideo video using the video id or url in the inner_text.
|
486
493
|
# It automatically determines which video renderer should be used based on the given url.
|
487
494
|
# :category: Render methods
|
488
|
-
def
|
495
|
+
def render_video(inner_text, attributes = {}, parse_options = {})
|
489
496
|
attributes[:class] = "#{attributes[:class]} #{parse_options[:class_zideo]}"
|
490
497
|
url = inner_text
|
491
498
|
if !url.match(/zideo\.nl/).nil?
|
492
|
-
return
|
499
|
+
return render_zideo(inner_text, attributes, parse_options)
|
493
500
|
elsif (!url.match(/[0-9]{5,}/).nil?) || (!url.match(/vimeo/).nil?)
|
494
|
-
return
|
501
|
+
return render_vimeo(inner_text, attributes, parse_options)
|
495
502
|
elsif (!url.match(/youtu/).nil?) || (!url.match(/^[^\?&]+\{11}$/).nil?)
|
496
|
-
return
|
503
|
+
return render_youtube(inner_text, attributes, parse_options)
|
497
504
|
else
|
498
505
|
return 'Unknown video'
|
499
506
|
end
|
@@ -501,7 +508,7 @@ module UBBParser
|
|
501
508
|
|
502
509
|
# Renders a zideo.nl video using the video id or url in the inner_text.
|
503
510
|
# :category: Render methods
|
504
|
-
def
|
511
|
+
def render_zideo(inner_text, attributes = {}, parse_options = {})
|
505
512
|
attributes[:width] ||= 480
|
506
513
|
attributes[:height] ||= :auto
|
507
514
|
attributes[:class] = parse_options[:class_zideo] || 'ubb-zideo'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ubbparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taco Jan Osinga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple and flexibel ubb parser.
|
14
14
|
email: info@osingasoftware.nl
|