class RubyBBCode::Templates::BBCodeErrorsTemplate
This class is designed to help us build up the (original) BBCode annotated with the error information. It starts out as a template such as…
@opening_part = '[url=%param%] @closing_part = '[/url]'
and then slowly turns into…
@opening_part = '[url=http://www.blah.com"]cool beans' @closing_part = '[/url]'
Attributes
opening_part[RW]
Public Class Methods
convert_text(node, _parent_node)
click to toggle source
# File lib/ruby-bbcode/templates/bbcode_errors_template.rb, line 22 def self.convert_text(node, _parent_node) # Keep the text as it was return "<span class='bbcode_error' #{error_attribute(node[:errors])}>#{node[:text]}</span>" unless node[:errors].empty? node[:text] end
new(node)
click to toggle source
# File lib/ruby-bbcode/templates/bbcode_errors_template.rb, line 14 def initialize(node) @node = node @tag_definition = node.definition # tag_definition @opening_part = "[#{node[:tag]}#{node.allow_params? ? '%param%' : ''}]" + add_whitespace(node[:opening_whitespace]) @opening_part = "<span class='bbcode_error' #{BBCodeErrorsTemplate.error_attribute(@node[:errors])}>#{@opening_part}</span>" unless @node[:errors].empty? @closing_part = "[/#{node[:tag]}]" + add_whitespace(node[:closing_whitespace]) end
Private Class Methods
error_attribute(errors)
click to toggle source
# File lib/ruby-bbcode/templates/bbcode_errors_template.rb, line 65 def self.error_attribute(errors) # Escape (double) quotes so the JSON can be generated properly (and parsed properly by JavaScript) escapedErrors = errors.map { |error| error.gsub('"', '"').gsub("'", ''') } "data-bbcode-errors='#{JSON.fast_generate(escapedErrors)}'" end
Public Instance Methods
closing_part()
click to toggle source
# File lib/ruby-bbcode/templates/bbcode_errors_template.rb, line 49 def closing_part @node[:closed] == false ? '' : @closing_part end
inlay_between_text!()
click to toggle source
# File lib/ruby-bbcode/templates/bbcode_errors_template.rb, line 29 def inlay_between_text! # Set the between text between the tags again, if required to do so... @opening_part << get_between end
inlay_closing_part!()
click to toggle source
# File lib/ruby-bbcode/templates/bbcode_errors_template.rb, line 43 def inlay_closing_part!; end
inlay_params!()
click to toggle source
# File lib/ruby-bbcode/templates/bbcode_errors_template.rb, line 34 def inlay_params! # Iterate over known tokens and fill in their values, if provided @tag_definition[:param_tokens].each do |token| # Use %param% to insert the parameters and their values (and re-add %param%) param_value = @node[:params][token[:token]] @opening_part.gsub!('%param%', " #{token[:token]}=#{param_value}%param%") unless param_value.nil? end end
remove_unused_tokens!()
click to toggle source
# File lib/ruby-bbcode/templates/bbcode_errors_template.rb, line 45 def remove_unused_tokens! @opening_part.gsub!('%param%', '') end
Private Instance Methods
add_whitespace(whitespace)
click to toggle source
# File lib/ruby-bbcode/templates/bbcode_errors_template.rb, line 55 def add_whitespace(whitespace) whitespace || '' end
get_between()
click to toggle source
# File lib/ruby-bbcode/templates/bbcode_errors_template.rb, line 59 def get_between return @node[:between] if @tag_definition[:require_between] && @node[:between] '' end