bb-ruby 0.8.2 → 0.8.3
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/History.txt +4 -0
- data/lib/bb-ruby.rb +117 -36
- metadata +2 -2
data/History.txt
CHANGED
data/lib/bb-ruby.rb
CHANGED
@@ -2,9 +2,12 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
module BBRuby
|
5
|
-
VERSION = '0.8.
|
5
|
+
VERSION = '0.8.3'
|
6
6
|
|
7
|
+
# allowable image formats
|
7
8
|
@@imageformats = 'png|bmp|jpg|gif|jpeg'
|
9
|
+
|
10
|
+
# built-in BBCode tabs that will be processed
|
8
11
|
@@tags = {
|
9
12
|
# tag name => [regex, replace, description, example, enable/disable symbol]
|
10
13
|
'Bold' => [
|
@@ -198,50 +201,128 @@ module BBRuby
|
|
198
201
|
:email]
|
199
202
|
}
|
200
203
|
|
201
|
-
|
202
|
-
|
203
|
-
#
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
204
|
+
class << self
|
205
|
+
# Convert a string with BBCode markup into its corresponding HTML markup
|
206
|
+
#
|
207
|
+
# === Basic Usage
|
208
|
+
#
|
209
|
+
# The first parameter is the string off BBCode markup to be processed
|
210
|
+
#
|
211
|
+
# text = "[b]some bold text to markup[/b]"
|
212
|
+
# output = BBRuby.to_html(text)
|
213
|
+
# # output => "<strong>some bold text to markup</strong>"
|
214
|
+
#
|
215
|
+
# === Custom BBCode translations
|
216
|
+
#
|
217
|
+
# You can supply your own BBCode markup translations to create your own custom markup
|
218
|
+
# or override the default BBRuby translations (parameter is a hash of custom translations).
|
219
|
+
#
|
220
|
+
# The hash takes the following format: "name" => [regexp, replacement, description, example, enable_symbol]
|
221
|
+
#
|
222
|
+
# custom_blockquote = {
|
223
|
+
# 'Quote' => [
|
224
|
+
# /\[quote(:.*)?=(.*?)\](.*?)\[\/quote\1?\]/mi,
|
225
|
+
# '<div class="quote"><p><cite>\2</cite></p><blockquote>\3</blockquote></div>',
|
226
|
+
# 'Quote with citation',
|
227
|
+
# '[quote=mike]please quote me[/quote]',
|
228
|
+
# :quote
|
229
|
+
# ]
|
230
|
+
# }
|
231
|
+
#
|
232
|
+
# === Enable and Disable specific tags
|
233
|
+
#
|
234
|
+
# BBRuby will allow you to only enable certain BBCode tags, or to explicitly disable certain tags.
|
235
|
+
# Pass in either :disable or :enable to set your method, followed by the comma-separated list of tags
|
236
|
+
# you wish to disable or enable
|
237
|
+
#
|
238
|
+
# BBRuby.to_html(text, {}, true, :enable, :image, :bold, :quote)
|
239
|
+
# BBRuby.to_html(text, {}, true, :disable, :image, :video, :color)
|
240
|
+
#
|
241
|
+
def to_html(text, tags_alternative_definition = {}, escape_html=true, method=:disable, *tags)
|
242
|
+
text = text.clone
|
243
|
+
# escape < and > to remove any html
|
244
|
+
if escape_html
|
245
|
+
text.gsub!( '<', '<' )
|
246
|
+
text.gsub!( '>', '>' )
|
247
|
+
end
|
248
|
+
|
249
|
+
tags_definition = @@tags.merge(tags_alternative_definition)
|
210
250
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
251
|
+
# parse bbcode tags
|
252
|
+
case method
|
253
|
+
when :enable
|
254
|
+
tags_definition.each_value { |t| text.gsub!(t[0], t[1]) if tags[0].include?(t[4]) }
|
255
|
+
when :disable
|
256
|
+
# this works nicely because the default is disable and the default set of tags is [] (so none disabled) :)
|
257
|
+
tags_definition.each_value { |t| text.gsub!(t[0], t[1]) unless tags[0].include?(t[4]) }
|
258
|
+
end
|
219
259
|
|
220
|
-
|
221
|
-
|
222
|
-
|
260
|
+
# parse spacing
|
261
|
+
text.gsub!( /\r\n?/, "\n" )
|
262
|
+
text.gsub!( /\n/, "<br />" )
|
223
263
|
|
224
|
-
|
225
|
-
|
226
|
-
|
264
|
+
# return markup
|
265
|
+
text
|
266
|
+
end
|
227
267
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
def self.tag_list
|
236
|
-
@@tags
|
237
|
-
end
|
238
|
-
end
|
268
|
+
# Returns the list of tags processed by BBRuby in a Hash object
|
269
|
+
def tag_list
|
270
|
+
@@tags
|
271
|
+
end
|
272
|
+
end # class << self
|
273
|
+
|
274
|
+
end # class BBRuby
|
239
275
|
|
240
276
|
class String
|
277
|
+
# Convert a string with BBCode markup into its corresponding HTML markup
|
278
|
+
#
|
279
|
+
# === Basic Usage
|
280
|
+
#
|
281
|
+
# text = "[b]some bold text to markup[/b]"
|
282
|
+
# output = text.bbcode_to_html
|
283
|
+
# # output => "<strong>some bold text to markup</strong>"
|
284
|
+
#
|
285
|
+
# === Custom BBCode translations
|
286
|
+
#
|
287
|
+
# You can supply your own BBCode markup translations to create your own custom markup
|
288
|
+
# or override the default BBRuby translations (parameter is a hash of custom translations).
|
289
|
+
#
|
290
|
+
# The hash takes the following format: "name" => [regexp, replacement, description, example, enable_symbol]
|
291
|
+
#
|
292
|
+
# custom_blockquote = {
|
293
|
+
# 'Quote' => [
|
294
|
+
# /\[quote(:.*)?=(.*?)\](.*?)\[\/quote\1?\]/mi,
|
295
|
+
# '<div class="quote"><p><cite>\2</cite></p><blockquote>\3</blockquote></div>',
|
296
|
+
# 'Quote with citation',
|
297
|
+
# '[quote=mike]please quote me[/quote]',
|
298
|
+
# :quote
|
299
|
+
# ]
|
300
|
+
# }
|
301
|
+
#
|
302
|
+
# output = text.bbcode_to_html(custom_blockquote)
|
303
|
+
#
|
304
|
+
# === Enable and Disable specific tags
|
305
|
+
#
|
306
|
+
# BBRuby will allow you to only enable certain BBCode tags, or to explicitly disable certain tags.
|
307
|
+
# Pass in either :disable or :enable to set your method, followed by the comma-separated list of tags
|
308
|
+
# you wish to disable or enable
|
309
|
+
#
|
310
|
+
# output = text.bbcode_to_html({}, true, :enable, :image, :bold, :quote)
|
311
|
+
# output = text.bbcode_to_html({}, true, :disable, :image, :video, :color)
|
312
|
+
#
|
313
|
+
# === HTML auto-escaping
|
314
|
+
#
|
315
|
+
# By default, BBRuby will auto-escape HTML. You can prevent this by passing in false as the second
|
316
|
+
# parameter
|
317
|
+
#
|
318
|
+
# output = text.bbcode_to_html({}, false)
|
319
|
+
#
|
241
320
|
def bbcode_to_html(tags_alternative_definition = {}, escape_html=true, method=:disable, *tags)
|
242
321
|
BBRuby.to_html(self, tags_alternative_definition, escape_html, method, tags)
|
243
322
|
end
|
323
|
+
|
324
|
+
# Replace the string contents with the HTML-converted markup
|
244
325
|
def bbcode_to_html!(tags_alternative_definition = {}, escape_html=true, method=:disable, *tags)
|
245
326
|
self.replace(BBRuby.to_html(self, tags_alternative_definition, escape_html, method, tags))
|
246
327
|
end
|
247
|
-
end
|
328
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bb-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig P Jolicoeur
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.1
|
23
|
+
version: 1.2.1
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hoe
|