Module: RubyBBCode
- Includes:
- Tags
- Defined in:
- lib/tags/tags.rb,
lib/ruby-bbcode-to-md.rb,
lib/ruby-bbcode-to-md/bbtree.rb,
lib/ruby-bbcode-to-md/tag_info.rb,
lib/ruby-bbcode-to-md/tag_node.rb,
lib/ruby-bbcode-to-md/debugging.rb,
lib/ruby-bbcode-to-md/tag_sifter.rb,
lib/ruby-bbcode-to-md/tag_collection.rb
Defined Under Namespace
Modules: DebugBBTree, Tags
Classes: BBTree, TagCollection, TagInfo, TagNode, TagSifter
Class Method Summary
collapse
Methods included from Tags
tag_list
Class Method Details
.clear_log_file_at_beginning_of_execution(clear_file) ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'lib/ruby-bbcode-to-md/debugging.rb', line 10
def self.clear_log_file_at_beginning_of_execution(clear_file)
return if !clear_file
if defined?(@@cleared_file).nil?
@@cleared_file = true
File.open('/tmp/ruby-bbcode.log', 'w+') do |f|
puts ''
end
end
end
|
.disable_validation ⇒ Object
15
16
17
|
# File 'lib/ruby-bbcode-to-md.rb', line 15
def self.disable_validation
@ignore_validation = true
end
|
.enable_validation ⇒ Object
19
20
21
|
# File 'lib/ruby-bbcode-to-md.rb', line 19
def self.enable_validation
@ignore_validation = false
end
|
.log(string, clear_file = true) ⇒ Object
2
3
4
5
6
7
8
|
# File 'lib/ruby-bbcode-to-md/debugging.rb', line 2
def self.log(string, clear_file = true)
clear_log_file_at_beginning_of_execution clear_file
File.open('/tmp/ruby-bbcode.log', 'a') do |f|
f.puts string
end
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 paramter 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/ruby-bbcode-to-md.rb', line 31
def self.to_html(text, escape_html = true, additional_tags = {}, method = :disable, *tags)
text = text.clone
use_tags = determine_applicable_tags(additional_tags, method, *tags)
@tag_sifter = TagSifter.new(text, use_tags, escape_html)
@tag_sifter.process_text
if @tag_sifter.invalid?
raise @tag_sifter.errors.join(', ')
else
@tag_sifter.bbtree.to_html(use_tags)
end
end
|
.validation_enabled ⇒ Object
23
24
25
|
# File 'lib/ruby-bbcode-to-md.rb', line 23
def self.validation_enabled
!@ignore_validation.nil? and !@ignore_validation
end
|
.validity_check(text, additional_tags = {}) ⇒ Object
Returns true when valid, else returns array with error(s)
49
50
51
52
53
54
55
|
# File 'lib/ruby-bbcode-to-md.rb', line 49
def self.validity_check(text, additional_tags = {})
@tag_sifter = TagSifter.new(text, @@tags.merge(additional_tags))
@tag_sifter.process_text
return @tag_sifter.errors if @tag_sifter.invalid?
true
end
|