Module: RubyBBCode
- Includes:
- Tags
- Defined in:
- lib/ruby-bbcode.rb,
lib/tags/tags.rb,
lib/ruby-bbcode/bbtree.rb,
lib/ruby-bbcode/version.rb,
lib/ruby-bbcode/tag_info.rb,
lib/ruby-bbcode/tag_node.rb,
lib/ruby-bbcode/tag_sifter.rb,
lib/ruby-bbcode/tag_collection.rb
Overview
RubyBBCode adds support for BBCode to Ruby. The BBCode is parsed by a parser before converted to HTML, allowing to convert nested BBCode tags in strings to their correct HTML equivalent. The used parser also checks whether the BBCode is valid and gives errors for incorrect BBCode texts.
Defined Under Namespace
Modules: Tags, Templates Classes: BBTree, TagCollection, TagInfo, TagNode, TagSifter
Constant Summary collapse
- VERSION =
Version of RubyBBCode
Follows semantic versioning: semver.org/
'2.1.0'.freeze
Class Attribute Summary collapse
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
- .reset ⇒ Object
-
.to_bbcode(text, additional_tags = {}, method = :disable, *tags) ⇒ Object
This method converts the given text (with BBCode tags) into a HTML representation The additional_tags parameter is used to add additional BBCode tags that should be accepted The method parameter determines whether the tags parameter needs to be used to blacklist (when set to :disable) or whitelist (when not set to :disable) the list of BBCode tags The method raises an exception when the text could not be parsed due to errors.
-
.to_html(text, escape_html = true, additional_tags = {}, method = :disable, *tags) ⇒ Object
This method converts the given text (with BBCode tags) into a HTML representation The escape_html parameter (default: true) escapes HTML tags that were present in the given text and therefore blocking (mallicious) HTML in the original text The additional_tags parameter is used to add additional BBCode tags that should be accepted The method parameter determines whether the tags parameter needs to be used to blacklist (when set to :disable) or whitelist (when not set to :disable) the list of BBCode tags The method raises an exception when the text could not be parsed due to errors.
-
.validity_check(text, additional_tags = {}, method = :disable, *tags) ⇒ Object
Returns true when valid, else returns array with error(s).
Methods included from Tags
Class Attribute Details
.configuration ⇒ Object
19 20 21 |
# File 'lib/ruby-bbcode.rb', line 19 def self.configuration @configuration ||= Configuration.new end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
27 28 29 |
# File 'lib/ruby-bbcode.rb', line 27 def self.configure yield(configuration) end |
.reset ⇒ Object
23 24 25 |
# File 'lib/ruby-bbcode.rb', line 23 def self.reset @configuration = Configuration.new end |
.to_bbcode(text, additional_tags = {}, method = :disable, *tags) ⇒ Object
This method converts the given text (with BBCode tags) into a HTML representation The additional_tags parameter is used to add additional BBCode tags that should be accepted The method parameter determines whether the tags parameter needs to be used to blacklist (when set to :disable) or whitelist (when not set to :disable) the list of BBCode tags The method raises an exception when the text could not be parsed due to errors
50 51 52 53 54 |
# File 'lib/ruby-bbcode.rb', line 50 def self.to_bbcode(text, = {}, method = :disable, *) parse(text, true, , method, *) = (, method, *) @tag_sifter.bbtree.to_bbcode() end |
.to_html(text, escape_html = true, additional_tags = {}, method = :disable, *tags) ⇒ Object
This method converts the given text (with BBCode tags) into a HTML representation The escape_html parameter (default: true) escapes HTML tags that were present in the given text and therefore blocking (mallicious) HTML in the original text The additional_tags parameter is used to add additional BBCode tags that should be accepted The method parameter determines whether the tags parameter needs to be used to blacklist (when set to :disable) or whitelist (when not set to :disable) the list of BBCode tags The method raises an exception when the text could not be parsed due to errors
36 37 38 39 40 41 42 43 44 |
# File 'lib/ruby-bbcode.rb', line 36 def self.to_html(text, escape_html = true, = {}, method = :disable, *) parse(text, escape_html, , method, *) = (, method, *) # We cannot convert to HTML if the BBCode is not valid! raise @tag_sifter.errors.join(', ') unless @tag_sifter.valid? @tag_sifter.bbtree.to_html() end |
.validity_check(text, additional_tags = {}, method = :disable, *tags) ⇒ Object
Returns true when valid, else returns array with error(s)
57 58 59 60 61 62 63 64 65 |
# File 'lib/ruby-bbcode.rb', line 57 def self.validity_check(text, = {}, method = :disable, *) = (, method, *) @tag_sifter = TagSifter.new(text, ) @tag_sifter.process_text return @tag_sifter.errors unless @tag_sifter.valid? true end |