Sha256: 15888bcc67669646f299055e00d290aee1729349817474236f57f32f78d39a0c

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

require 'bbcoder/base'
require 'bbcoder/configuration'
require 'bbcoder/tag'
require 'bbcoder/buffer'
require 'bbcoder/buffer_tags'
require 'bbcoder/string'

BBCoder.configure do
  tag :p
  tag :b, :as => :strong
  tag :i, :as => :em
  tag :u
  tag :s, :as => :strike
  tag :del
  tag :ins
  tag :ol
  tag :ul
  tag :li, :parents => [:ol, :ul]
  tag :dl
  tag :dt, :parents => [:dl]
  tag :dd, :parents => [:dl]

  tag :quote do
    quoted = meta.empty? ? '' : "\n  <legend>#{meta} says</legend>"

    <<-EOS
<fieldset>#{quoted}
  <blockquote>
    #{content}
  </blockquote>
</fieldset>
    EOS
  end

  tag :code do
    <<-EOS
<div class="bbcode-code #{meta}">
  <pre>#{content}</pre>
</div>
    EOS
  end

  tag :spoiler do
    <<-EOS
<fieldset class="bbcode-spoiler">
  <legend>Spoiler</legend>
  <div>#{content}</div>
</fieldset>
    EOS
  end

  tag :url, :match_link => /^https?:\/\// do
    if meta.nil? || meta.empty?
      %(<a href="#{content}">#{content}</a>)
    else
      %(<a href="#{meta}">#{content}</a>)
    end
  end

  tag :img, :match => /^https?:\/\/.*(png|bmp|jpe?g|gif)$/, :singular => true do
    %(<a href="#{singular? ? meta : content}"><img src="#{singular? ? meta : content}" /></a>)
  end

  tag :youtube do
    <<-EOS
<iframe width="560" height="349" src="http://www.youtube.com/embed/#{content}" frameborder="0" allowfullscreen></iframe>
    EOS
  end

  tag :sub, :singular => true do
    %(<sub>#{singular? ? meta : content}</sub>)
  end

  tag :sup, :singular => true do
    %(<sup>#{singular? ? meta : content}</sup>)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bbcoder-1.1.0 lib/bbcoder.rb
bbcoder-1.0.1 lib/bbcoder.rb