ubbparser 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/ubbparser.rb +43 -0
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yjc5Y2ExZTk1ZTFlNWE4ZDIzMjkxODUwOTE1ZWQzNmVlZGY1ZjQxZA==
4
+ OTBjNDUzMDNhMzY4YmY1YTg3YTYyMjk2ZTE4ZjM1NWFlMWI2YWZlOQ==
5
5
  data.tar.gz: !binary |-
6
- YWZiMTI5YmQ4MzM1MmU2N2Q4YWQzNTI4NzNmZWMyMGE5ZDRmYjU1ZA==
6
+ M2FlY2RjODJmM2IzZjJiMTI2YzcwNDcyMGI4NTExNDczNzc3YjdhYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- M2RjOTg3MDhlZTZlNjk4YWVlZmJjYjBkNWNlODkwZGMxZmEzZmUzN2Q0Nzk2
10
- ODE4MmY1YTc2NWJjZWIzMWI4M2IwZGFjNTM4MjJiMzQ1ZmViYzhkNThmMmQ5
11
- Y2Y3NTYxMmM1NWZhZTY5MzE1OTAxOGVmN2I2YjM0ZjgyZmIwODU=
9
+ NGEyMWIyMmNiYTEzZDFjYmVlZGJiZWJlM2UzNjg3MWUxM2U1YWY0MGVkMWQ4
10
+ ZTE4YzQzNGI0NjFhYzJiZTgzNWRmZmM1NjVjZTUzYmQxNzFmY2NlMDg5NjQ5
11
+ MmM1ZTg3NmM5NzlhMzQ2NjFjN2E3ZjQ3MmNhNjQ3OTExMjY0MTQ=
12
12
  data.tar.gz: !binary |-
13
- MGQyMTc2NWFiNDAyYWFlZGQwMWE0YTFiYTE4NGY2NmEzMjA2MjZjZmVmYjkx
14
- ZjQ5ZmY2ZmY2N2U5YWY4OWI3ZTdlOTBiMGNjOGRjMGMxZmQzYjc0OTMyOWNi
15
- YmU0YmIzNGI1NzIyMmI0MTNjYjNjMmQ1MmY5ZjBkYTFhZjMyOTA=
13
+ YjhkMjQwMzA4YzUwNjMwM2NmNTQzZDQ5MjJmMGFhOWI1YzhhMGEyOTg5NTA5
14
+ OGI4ZDEzNGEyNWQ4ZTQ0NjQ5MzY3ZDdhZjZlNTYxNjgyNjI2NGRhY2MwN2Nj
15
+ NmNlYWZjMzFmMzIzNGM1Yjc5NzM3YmMxZDcwN2MxNmY2NjNhNzI=
data/lib/ubbparser.rb CHANGED
@@ -70,6 +70,7 @@ module UBBParser
70
70
  # Parses the given text with ubb code into html. Use parse_options to specify a hash of options:
71
71
  # [:convert_newlines] A boolean whether newlines should be convert into <br /> tags (default: true).
72
72
  # [:protect_email] A boolean whether email addresses should be protected from spoofing using embedded JavaScript.
73
+ # [:strip_ubb] A boolean whether the parse should return all data without html. Default: false.
73
74
  # [:class_xxx] A string with css class(es) that is embedded in the html for the tag xxx. Not all tags supports this.
74
75
  # Replace a dash in a tag with underscore (i.e. the class for img-left is defined in :class_img_left).
75
76
  # ===Example:
@@ -77,6 +78,7 @@ module UBBParser
77
78
  #
78
79
  # When developing your own tags, you can also define your own parse_options.
79
80
  def parse(text, parse_options = {})
81
+ parse_options[:strip_ubb] ||= false
80
82
  result = ''
81
83
  scnr = StringScanner.new(text)
82
84
  parse_options.each { |k, v| v.to_s.gsub(/-/, '_').gsub(/[^\w]+/, '') if (k.to_s.start_with?('class_')); v }
@@ -123,6 +125,11 @@ module UBBParser
123
125
  return result
124
126
  end
125
127
 
128
+ def strip_ubb(text, parse_options = {})
129
+ parse_options[:strip_ubb] = true
130
+ return parse(text, parse_options)
131
+ end
132
+
126
133
  # Returns true if the given value matches the given regular expression.
127
134
  # :category: Validation methods
128
135
  def matches_regexp?(value, regexp)
@@ -160,18 +167,21 @@ module UBBParser
160
167
  # Renders the inner_text bold (using <strong>).
161
168
  # :category: Render methods
162
169
  def render_b(inner_text, attributes = {}, parse_options = {})
170
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
163
171
  "<strong>#{parse(inner_text, parse_options)}</strong>"
164
172
  end
165
173
 
166
174
  # Converts [br] into a <br />.
167
175
  # :category: Render methods
168
176
  def render_br(inner_text, attributes = {}, parse_options = {})
177
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
169
178
  "<br />#{parse(inner_text, parse_options)}"
170
179
  end
171
180
 
172
181
  # 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.
173
182
  # :category: Render methods
174
183
  def render_bullets(inner_text, attributes = {}, parse_options = {})
184
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
175
185
  items = inner_text.split(/\n/)
176
186
  items.delete_if { |item| item.strip == '' }
177
187
  items.map! { |item| '<li>' + parse(item, parse_options) + '</li>' }
@@ -182,12 +192,14 @@ module UBBParser
182
192
  # Centers the inner_text.
183
193
  # :category: Render methods
184
194
  def render_center(inner_text, attributes = {}, parse_options = {})
195
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
185
196
  "<div style='text-align: center'>#{parse(inner_text, parse_options)}</div>"
186
197
  end
187
198
 
188
199
  # Assures the inner_text is rendered below floating elements.
189
200
  # :category: Render methods
190
201
  def render_class(inner_text, attributes = {}, parse_options = {})
202
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
191
203
  classes = attributes[:class_attrib_str].to_s.gsub(/'/, "\\'")
192
204
  "<div class='#{classes}'>#{parse(inner_text, parse_options)}</div>"
193
205
  end
@@ -195,12 +207,14 @@ module UBBParser
195
207
  # Assures the inner_text is rendered below floating elements.
196
208
  # :category: Render methods
197
209
  def render_clear(inner_text, attributes = {}, parse_options = {})
210
+ return "" if parse_options[:strip_ubb]
198
211
  "<div style='clear: both'></div>"
199
212
  end
200
213
 
201
214
  # Changes the font color of the inner_text
202
215
  # :category: Render methods
203
216
  def render_color(inner_text, attributes = {}, parse_options = {})
217
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
204
218
  color = attributes[:default].gsub(/'/, "\\'")
205
219
  "<div style='color:#{color}'>#{parse(inner_text, parse_options)}</div>"
206
220
  end
@@ -214,6 +228,7 @@ module UBBParser
214
228
  # 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.
215
229
  # :category: Render methods
216
230
  def render_code(inner_text, attributes = {}, parse_options = {})
231
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
217
232
  css_class = parse_options[:class_code] || 'ubb-code'
218
233
  "<pre class='#{css_class}'>#{inner_text}</pre>"
219
234
  end
@@ -222,6 +237,7 @@ module UBBParser
222
237
  # [:has_header] The first row should be rendered as header cells (using th).
223
238
  # :category: Render methods
224
239
  def render_csv(inner_text, attributes = {}, parse_options = {})
240
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
225
241
  head_cells = body_cells = ''
226
242
  cell_tag = (attributes[:has_header]) ? 'th' : 'td'
227
243
  lines = inner_text.gsub(/(^\n|\n*$)/, '').split(/\n/)
@@ -257,6 +273,7 @@ module UBBParser
257
273
  # By default the email address is protected against spoofing, using JavaScript. Use the email parse option to define html classes.
258
274
  # :category: Render methods
259
275
  def render_email(inner_text, attributes = {}, parse_options = {})
276
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
260
277
  css_class = (parse_options[:class_email] || 'ubb-email').to_s.strip
261
278
  inner_text = parse(inner_text, parse_options) if !attributes[:default].nil?
262
279
  email = (attributes[:default] || inner_text)
@@ -285,54 +302,63 @@ module UBBParser
285
302
  # Renders the inner_text in a H1 heading.
286
303
  # :category: Render methods
287
304
  def render_h1(inner_text, attributes = {}, parse_options = {})
305
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
288
306
  "<h1>#{parse(inner_text, parse_options)}</h1>"
289
307
  end
290
308
 
291
309
  # Renders the inner_text in a H2 heading.
292
310
  # :category: Render methods
293
311
  def render_h2(inner_text, attributes = {}, parse_options = {})
312
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
294
313
  "<h2>#{parse(inner_text, parse_options)}</h2>"
295
314
  end
296
315
 
297
316
  # Renders the inner_text in a H3 heading.
298
317
  # :category: Render methods
299
318
  def render_h3(inner_text, attributes = {}, parse_options = {})
319
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
300
320
  "<h3>#{parse(inner_text, parse_options)}</h3>"
301
321
  end
302
322
 
303
323
  # Renders the inner_text in a H4 heading.
304
324
  # :category: Render methods
305
325
  def render_h4(inner_text, attributes = {}, parse_options = {})
326
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
306
327
  "<h4>#{parse(inner_text, parse_options)}</h4>"
307
328
  end
308
329
 
309
330
  # Renders the inner_text in a H5 heading.
310
331
  # :category: Render methods
311
332
  def render_h5(inner_text, attributes = {}, parse_options = {})
333
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
312
334
  "<h5>#{parse(inner_text, parse_options)}</h5>"
313
335
  end
314
336
 
315
337
  # Renders the inner_text in a H6 heading.
316
338
  # :category: Render methods
317
339
  def render_h6(inner_text, attributes = {}, parse_options = {})
340
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
318
341
  "<h6>#{parse(inner_text, parse_options)}</h6>"
319
342
  end
320
343
 
321
344
  # Renders a horizontal ruler.
322
345
  # :category: Render methods
323
346
  def render_hr(inner_text, attributes = {}, parse_options = {})
347
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
324
348
  "<hr />#{parse(inner_text, parse_options)}"
325
349
  end
326
350
 
327
351
  # Renders the inner_text in italic.
328
352
  # :category: Render methods
329
353
  def render_i(inner_text, attributes = {}, parse_options = {})
354
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
330
355
  "<em>#{parse(inner_text, parse_options)}</em>"
331
356
  end
332
357
 
333
358
  # Renders an iframe. Use the inner_text as source. Use the :class_iframe parse option to define html classes.
334
359
  # :category: Render methods
335
360
  def render_iframe(inner_text, attributes = {}, parse_options = {})
361
+ return inner_text if parse_options[:strip_ubb]
336
362
  src = inner_text
337
363
  src = 'http://' + src if (src.match(/^www\./))
338
364
  src.gsub!(/\\|'/) { |c| "\\#{c}" }
@@ -352,6 +378,7 @@ module UBBParser
352
378
  # :category: Render methods
353
379
  #noinspection RubyClassVariableUsageInspection
354
380
  def render_img(inner_text, attributes = {}, parse_options = {})
381
+ return inner_text if parse_options[:strip_ubb]
355
382
  url = inner_text
356
383
  url = @@file_url_convert_method.call(url) unless @@file_url_convert_method.nil?
357
384
  attributes[:src] = url.gsub(/\\|'/) { |c| "\\#{c}" }
@@ -365,6 +392,7 @@ module UBBParser
365
392
  # Renders an image, floated on the left side of the text frame. Use the :class_img_left parse option to define html classes.
366
393
  # :category: Render methods
367
394
  def render_img_left(inner_text, attributes = {}, parse_options = {})
395
+ return inner_text if parse_options[:strip_ubb]
368
396
  attributes[:styles] = 'float: left; margin: 0px 10px 10px 0px'
369
397
  attributes[:class] = parse_options[:class_img_left] || 'ubb-img-left'
370
398
  render_img(inner_text, attributes, parse_options)
@@ -373,6 +401,7 @@ module UBBParser
373
401
  # Renders an image, floated on the right side of the text frame. Use the :class_img_right parse option to define html classes.
374
402
  # :category: Render methods
375
403
  def render_img_right(inner_text, attributes = {}, parse_options = {})
404
+ return inner_text if parse_options[:strip_ubb]
376
405
  attributes[:styles] = 'float: left; margin: 0px 0px 10px 10px'
377
406
  attributes[:class] = parse_options[:class_img_right] || 'ubb-img-right'
378
407
  render_img(inner_text, attributes, parse_options)
@@ -381,18 +410,21 @@ module UBBParser
381
410
  # Renders the inner_text with a justified text alignment.
382
411
  # :category: Render methods
383
412
  def render_justify(inner_text, attributes = {}, parse_options = {})
413
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
384
414
  "<div style='text-align: justify'>#{parse(inner_text, parse_options)}</div>"
385
415
  end
386
416
 
387
417
  # Renders the inner_text with a left text alignment.
388
418
  # :category: Render methods
389
419
  def render_left(inner_text, attributes = {}, parse_options = {})
420
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
390
421
  "<div style='text-align: left'>#{parse(inner_text, parse_options)}</div>"
391
422
  end
392
423
 
393
424
  # Renders the inner_text as an ordered list. Each line represents a list item. Use the :class_list parse option to define html classes.
394
425
  # :category: Render methods
395
426
  def render_list(inner_text, attributes = {}, parse_options = {})
427
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
396
428
  items = inner_text.split(/\n/)
397
429
  items.delete_if { |item| item.strip == '' }
398
430
  items.map! { |item| '<li>' + parse(item, parse_options) + '</li>' }
@@ -402,6 +434,7 @@ module UBBParser
402
434
  # Renders the inner_text as a paragraph. Use the :class_p parse option to define html classes.
403
435
  # :category: Render methods
404
436
  def render_p(inner_text, attributes = {}, parse_options = {})
437
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
405
438
  css_class = parse_options[:class_p] || 'ubb-p'
406
439
  "<p class='#{css_class}'>#{parse(inner_text, parse_options)}</p>"
407
440
  end
@@ -409,6 +442,7 @@ module UBBParser
409
442
  # Renders the inner_text with a right text alignment.
410
443
  # :category: Render methods
411
444
  def render_right(inner_text, attributes = {}, parse_options = {})
445
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
412
446
  "<div style='text-align: right'>#{parse(inner_text, parse_options)}</div>"
413
447
  end
414
448
 
@@ -416,6 +450,7 @@ module UBBParser
416
450
  # [style color: red; border: 1px solid green]...[/style]
417
451
  # :category: Render methods
418
452
  def render_style(inner_text, attributes = {}, parse_options = {})
453
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
419
454
  styles = attributes[:class_attrib_str].to_s.gsub(/'/, "\\'")
420
455
  "<div style='#{styles}'>#{parse(inner_text, parse_options)}</div>"
421
456
  end
@@ -423,6 +458,7 @@ module UBBParser
423
458
  # 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.
424
459
  # :category: Render methods
425
460
  def render_table(inner_text, attributes = {}, parse_options = {})
461
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
426
462
  css_class = parse_options[:class_table] || 'ubb-table'
427
463
  "<table class='#{css_class}'>#{parse(inner_text.gsub(/(^\n+)|(\n+$)/, ''), parse_options)}</table>"
428
464
  end
@@ -430,18 +466,21 @@ module UBBParser
430
466
  # Converts the [td] to a <td>. Always use this in combination with [table] and [tr].
431
467
  # :category: Render methods
432
468
  def render_td(inner_text, attributes = {}, parse_options = {})
469
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
433
470
  "<td>#{parse(inner_text, parse_options)}</td>"
434
471
  end
435
472
 
436
473
  # Converts the [th] to a <th>. Always use this in combination with [table] and [tr].
437
474
  # :category: Render methods
438
475
  def render_th(inner_text, attributes = {}, parse_options = {})
476
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
439
477
  "<th>#{parse(inner_text, parse_options)}</th>"
440
478
  end
441
479
 
442
480
  # Converts the [tr] to a <tr>. Always use this in combination with [table] and [td] or [th].
443
481
  # :category: Render methods
444
482
  def render_tr(inner_text, attributes = {}, parse_options = {})
483
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
445
484
  "<tr>#{parse(inner_text.gsub(/(^\n+)|(\n+$)/, ''), parse_options)}</tr>"
446
485
  end
447
486
 
@@ -458,6 +497,7 @@ module UBBParser
458
497
  # :category: Render methods
459
498
  #noinspection RubyClassVariableUsageInspection
460
499
  def render_url(inner_text, attributes = {}, parse_options = {})
500
+ return parse(inner_text, parse_options) if parse_options[:strip_ubb]
461
501
  inner_text = parse(inner_text, parse_options) if !attributes[:default].nil?
462
502
  url = (attributes[:default] || inner_text)
463
503
  url = 'http://' + url if (url.start_with?('www.'))
@@ -471,6 +511,7 @@ module UBBParser
471
511
  # Renders a YouTube video using the video id or url in the inner_text.
472
512
  # :category: Render methods
473
513
  def render_vimeo(inner_text, attributes = {}, parse_options = {})
514
+ return inner_text if parse_options[:strip_ubb]
474
515
  attributes[:width] ||= 500
475
516
  attributes[:height] ||= 281
476
517
  attributes[:class] = parse_options[:class_vimeo] || 'ubb-vimeo'
@@ -482,6 +523,7 @@ module UBBParser
482
523
  # Renders a YouTube video using the video id or url in the inner_text.
483
524
  # :category: Render methods
484
525
  def render_youtube(inner_text, attributes = {}, parse_options = {})
526
+ return inner_text if parse_options[:strip_ubb]
485
527
  attributes[:width] ||= 560
486
528
  attributes[:height] ||= 315
487
529
  attributes[:class] = parse_options[:class_youtube] || 'ubb-youtube'
@@ -510,6 +552,7 @@ module UBBParser
510
552
  # Renders a zideo.nl video using the video id or url in the inner_text.
511
553
  # :category: Render methods
512
554
  def render_zideo(inner_text, attributes = {}, parse_options = {})
555
+ return inner_text if parse_options[:strip_ubb]
513
556
  attributes[:width] ||= 480
514
557
  attributes[:height] ||= :auto
515
558
  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.9
4
+ version: 0.2.0
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-19 00:00:00.000000000 Z
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple and flexibel ubb parser.
14
14
  email: info@osingasoftware.nl