Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ begin
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
require 'rdoc/task'
require 'rdoc/task'
RDoc::Task = Rake::RDocTask
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-bbcode-to-md.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def self.validation_enabled
# 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
# 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
def self.to_html(text, escape_html = true, additional_tags = {}, method = :disable, *tags)
text = text.clone

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-bbcode-to-md/bbtree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ def to_html(tags = {})
end

end
end
end
44 changes: 22 additions & 22 deletions lib/ruby-bbcode-to-md/debugging.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module RubyBBCode
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

def self.clear_log_file_at_beginning_of_execution(clear_file)
return if !clear_file
if defined?(@@cleared_file).nil?
Expand All @@ -16,16 +16,16 @@ def self.clear_log_file_at_beginning_of_execution(clear_file)
end
end
end


# This module can be included in the BBTree and TagNode to give them debugging features
module DebugBBTree
# For Debugging/ visualization purposes.
# This can be used to render the #nodes array in a pretty manor, showing the hirarchy.
# This can be used to render the #nodes array in a pretty manor, showing the hierarchy.
def to_v
tree = self
visual_string = ''

walk_tree(tree) do |node, depth|
indentation = ' ' * depth
case node[:is_tag]
Expand All @@ -35,11 +35,11 @@ def to_v
visual_string += "#{indentation}\"#{node[:text]}\"\n"
end
end

visual_string
end


# this blocky method counts how many children are
# in the TagNode.children, recursively walking the tree
def count_child_nodes(hash = self)
Expand All @@ -50,13 +50,13 @@ def count_child_nodes(hash = self)
count
end

# For BBTree, teh to_s method shows the count of the children plus a graphical
# depiction of the tree, and the relation of the nodes.
# For TagNodes, the root-most tag is displayed, and the children are counted.
# For BBTree, the to_s method shows the count of the children plus a graphical
# depiction of the tree, and the relation of the nodes.
# For TagNodes, the root-most tag is displayed, and the children are counted.
def to_s
object_identifier = "#<#{self.class.to_s}:0x#{'%x' % (self.object_id << 1)}\n"
close_object = ">\n"

case self
when RubyBBCode::BBTree
object_identifier + "Children: #{count_child_nodes}\n" + self.to_v + close_object
Expand All @@ -68,26 +68,26 @@ def to_s
end
end
end

private
# This function is used by to_v and anything else that needs to iterate through the

# This function is used by to_v and anything else that needs to iterate through the
# @bbtree
def walk_tree(tree, depth = -1, &blk)
return enum_for(:walk_tree) unless blk # ignore me for now, I'm a convention for being versatile

# Perform the block action specified at top level!!!
yield tree, depth unless depth == -1

# next if we're a text node
return if tree.type == :text

# Enter into recursion (including block action) for each child node in this node
tree.children.each do |node|
walk_tree(node, depth + 1, &blk)
end
end

end
end

end
2 changes: 1 addition & 1 deletion lib/ruby-bbcode-to-md/tag_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ def between_text_goes_into_html_output_as_param?
end

end
end
end
2 changes: 1 addition & 1 deletion lib/ruby-bbcode-to-md/tag_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def tag_param=(param)
end

end
end
end
2 changes: 1 addition & 1 deletion lib/tags/tags.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module RubyBBCode
module Tags
# tagname => tag, HTML open tag, HTML close tag, description, example
# All of these entrys are represented as @dictionary in the classes (or as the variable tags)
# All of these entries are represented as @dictionary in the classes (or as the variable tags)
# A single item from this file (eg the :b entry) is refered to as a @definition
@@tags = {
:b => {
Expand Down
2 changes: 1 addition & 1 deletion test/ruby_bbcode_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_stack_level_too_deep

end

def test_mulit_tag
def test_multi_tag
input1 = "[media]https://www.youtube.com/watch?v=cSohjlYQI2A[/media]"
input2 = "[media]http://vimeo.com/46141955[/media]"

Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'ruby-bbcode-to-md'
require 'minitest/autorun'

# This hack allows us to make all the private methods of a class public.
# This hack allows us to make all the private methods of a class public.
class Class
def publicize_methods
saved_private_instance_methods = self.private_instance_methods
Expand Down
22 changes: 11 additions & 11 deletions test/unit/debugging_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class RubyBbcodeTest < MiniTest::Unit::TestCase
include ::RubyBBCode::Tags

def test_bbtree_to_v
text = "[i][b]a[/b][b]a[/b][b]a[/b][b]a[/b]item 1[/i][i]item 2[/i]"
visual = <<eos
Expand All @@ -19,29 +19,29 @@ def test_bbtree_to_v
i
"item 2"
eos

tags = @@tags
@tag_sifter = RubyBBCode::TagSifter.new(text, tags)
@tag_sifter.process_text

# manually include the debugging methods if they've been disabled for cleanliness purposes
@tag_sifter.bbtree.extend(::RubyBBCode::DebugBBTree) unless @tag_sifter.bbtree.respond_to? :to_v

assert_equal visual, @tag_sifter.bbtree.to_v
end

def test_bbtree_counting_nodes
text = "[ol][li][b][/b][b][/b][b][/b][b][/b]item 1[/li][li]item 2[/li][/ol]"
tags = @@tags

@tag_sifter = RubyBBCode::TagSifter.new(text, tags)

@tag_sifter.process_text
# manually include debugging methods if needed.

# manually include debugging methods if needed.
@tag_sifter.bbtree.extend(::RubyBBCode::DebugBBTree) unless @tag_sifter.bbtree.respond_to? :count_child_nodes

assert_equal 9, @tag_sifter.bbtree.count_child_nodes
end

end
48 changes: 24 additions & 24 deletions test/unit/tag_sifter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@ def test_youtube_parser
url_without_www = "youtube.com/watch?v=E4Fbk52Mk1w"
url_with_feature = "http://www.youtube.com/watch?feature=player_embedded&v=E4Fbk52Mk1w"
mock_regex_matches = [/youtube.com.*[v]=([^&]*)/, /youtu.be\/([^&]*)/, /y2u.be\/([^&]*)/]

expected_output = 'E4Fbk52Mk1w'

RubyBBCode::TagSifter.publicize_methods do
ts = RubyBBCode::TagSifter.new "", ""
assert_equal expected_output,
assert_equal expected_output,
ts.conduct_special_formatting(url1, mock_regex_matches)
assert_equal expected_output,

assert_equal expected_output,
ts.conduct_special_formatting(just_an_id, mock_regex_matches)
assert_equal expected_output,

assert_equal expected_output,
ts.conduct_special_formatting(url_without_http, mock_regex_matches)
assert_equal expected_output,

assert_equal expected_output,
ts.conduct_special_formatting(url_without_www, mock_regex_matches)
assert_equal expected_output,

assert_equal expected_output,
ts.conduct_special_formatting(url_with_feature, mock_regex_matches)
end

end

# I think the answer to this is creating a new tag named [youtube]
# but that captures specifically the .be or .com and treats them differently...
def test_youtubes_via_there_url_shortener
url_from_shortener = "http://youtu.be/E4Fbk52Mk1w"
directory_format = "http://youtube.googleapis.com/v/E4Fbk52Mk1w"
# I think the answer to this is creating a new tag named [youtube]
# but that captures specifically the .be or .com and treats them differently...
def test_youtubes_via_there_url_shortener
url_from_shortener = "http://youtu.be/E4Fbk52Mk1w"
directory_format = "http://youtube.googleapis.com/v/E4Fbk52Mk1w"
expected_output = 'E4Fbk52Mk1w'
mock_regex_matches = [/youtube.com.*[v]=([^&]*)/, /youtu.be\/([^&]*)/, /y2u.be\/([^&]*)/]


RubyBBCode::TagSifter.publicize_methods do
ts = RubyBBCode::TagSifter.new "", ""
assert_equal expected_output,
ts.conduct_special_formatting(url_from_shortener, mock_regex_matches) # this test is now hopelessly broken because generating an ID from a link requires that @bbtree.current_node.definition be properly populated with regex matches...
end
end


assert_equal expected_output,
ts.conduct_special_formatting(url_from_shortener, mock_regex_matches) # this test is now hopelessly broken because generating an ID from a link requires that @bbtree.current_node.definition be properly populated with regex matches...
end
end
end