• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 16 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

BBCode implementation for Ruby

BBRuby

Description:

BBRuby is a BBCode implementation for Ruby. It will convert strings with BBCode markup to their HTML equivalent.

Installation:

gem install bb-ruby

Usage:

require 'bb-ruby'

BBRuby has been included directly into the String class for use on any string object:

text = "[b]Here is some bold text[/b] followed by some [u]underlined text[/u]"
output = text.bbcode_to_html
text.bbcode_to_html!

BBRuby will auto-escape HTML tags. To prevent this just pass false as the second param:

output = text.bbcode_to_html({}, false)

Only allow certain tags:

output = text.bbcode_to_html({}, true, :enable, :image, :bold, :quote)

Disable certain tags:

output = text.bbcode_to_html({}, true, :disable, :image, :bold, :quote)

Alternative Direct usage:

output = BBRuby.to_html(bbcode_markup)

Define your own translation, in order to be more flexible:

my_blockquote = {
  'Quote' => [
    /\[quote(:.*)?=(.*?)\](.*?)\[\/quote\1?\]/mi,
    '<div class="quote"><p><cite>\2</cite></p><blockquote>\3</blockquote></div>',
    'Quote with citation',
    '[quote=mike]please quote me[/quote]',
    :quote
  ],
}

text.bbcode_to_html(my_blockquote)

Define Proc as replacement:

module BBRuby
  @@tags = @@tags.merge({
      'File' => [
        /\[file(:.*)?=(.*?)\](.*?)\[\/file\1?\]/mi,
        lambda{ |e| "<div class="file"><p><cite>#{e[3]}</cite></p><blockquote>#{file_read_method(e[2])}</blockquote></div>"},
        'File content with citation',
        '[file=script.rb]Script Caption[/file]',
        :file
      ],
    })
end

You can also use the simple_format method of ActionPack by using the *_with_formatting methods:

output = text.bbcode_to_html_with_formatting
output = text.bbcode_to_html_with_formatting!

TAGS PROCESSED:

The following is the list of BBCode tags processed by BBRuby and their associated symbol for enabling/disabling them

[b]               :bold
[i]               :italics
[u]               :underline
[s]               :strikeout
[del]             :delete
[ins]             :insert
[code]            :code
[size]            :size
[color]           :color
[ol]              :orderedlist
[ul]              :unorderedlist
[li]              :listitem
[*]               :listitem
[list]            :listitem
[list=1]          :listitem
[list=a]          :listitem
[dl]              :definelist
[dt]              :defineterm
[dd]              :definition
[quote]           :quote
[quote=source]    :quote
[url=link]        :link
[url]             :link
[img size=]       :image
[img align=]      :image
[img=]            :image
[img]             :image
[youtube]         :video
[gvideo]          :video
[vimeo]           :video
[email]           :email
[align]           :align
[left]            :left
[center]          :center
[right]           :right
[br]              :br

More Repositories

1

cerberus

A lightweight, Continuous Integration tool written in Ruby
Ruby
81
star
2

mojo-database

ActiveRecord-like ORM interface for Sqlite in Objective-C for use in iOS applications
Objective-C
56
star
3

guard-annotate

NOTE: Please use and leave issues/pull requests on the official guard version of this repo - https://github.com/guard/guard-annotate
Ruby
19
star
4

echowaves-notifier-osx

OS X Statusbar update notifier for Echowaves.com
Objective-C
8
star
5

cerberusweb

A web front-end to the Cerberus CI gem
Ruby
6
star
6

vizio-via-plex

Vizio VIA Plex app
6
star
7

feedcache

FeedCache wordpress plugin for caching and displaying multiple RSS feeds on a Wordpress blog
PHP
5
star
8

parsehtml

parseHTML is a HTML parser which works with Ruby 1.8 and above
Ruby
4
star
9

jgcharts

jQuery Google Charts
4
star
10

echowaves-update-notifier

A simple script that notifies you of updated EchoWaves convos that you follow
Ruby
4
star
11

coinbase-cli

Coinbase command line tool
Shell
4
star
12

prototypegrowl

Prototype & Scriptaculous implementation of the OS X growl notification bubbles
JavaScript
4
star
13

tmux-go

bash shell tmux session launcher pre-configured for rails development
Shell
3
star
14

fluxion

An exploratory attempt at a Flux dispatcher for MarionetteJS
CoffeeScript
3
star
15

pollyanna

SVG to CSS Polygon converter
Go
3
star
16

clothblue

BlueCloth's evil twin - convert HTML into Markdown
PHP
3
star
17

merc_convert

Easily convert mercator meters to latitude/longitude (and vice versa)
Ruby
3
star
18

tumblr_theme

My current tumblr theme
3
star
19

greenbacks

Greenbacks is an open-source, rails-based invoicing platform
2
star
20

slicehost

Capistrano recipes for setting up and deploying to Slicehost
Ruby
2
star
21

redisearch

REDIS backed full-text search for Ruby
Ruby
2
star
22

ghost

A simple, vanilla static file server written in Go
Go
1
star
23

cerberus-stats

Download stats collection for the Cerberus CI gem
Ruby
1
star