Class: RubyBBCode::Templates::BBCodeErrorsTemplate
- Inherits:
-
Object
- Object
- RubyBBCode::Templates::BBCodeErrorsTemplate
- Defined in:
- lib/ruby-bbcode/templates/bbcode_errors_template.rb
Overview
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]'
Instance Attribute Summary collapse
-
#opening_part ⇒ Object
Returns the value of attribute opening_part.
Class Method Summary collapse
Instance Method Summary collapse
- #closing_part ⇒ Object
-
#initialize(node) ⇒ BBCodeErrorsTemplate
constructor
A new instance of BBCodeErrorsTemplate.
- #inlay_between_text! ⇒ Object
- #inlay_closing_part! ⇒ Object
- #inlay_params! ⇒ Object
- #remove_unused_tokens! ⇒ Object
Constructor Details
#initialize(node) ⇒ BBCodeErrorsTemplate
Returns a new instance of BBCodeErrorsTemplate.
14 15 16 17 18 19 20 21 22 |
# 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%' : ''}]" unless @node[:errors].empty? @opening_part = "<span class='bbcode_error' #{BBCodeErrorsTemplate.error_attribute(@node[:errors])}>#{@opening_part}</span>" end @closing_part = "[/#{node[:tag]}]" end |
Instance Attribute Details
#opening_part ⇒ Object
Returns the value of attribute opening_part.
12 13 14 |
# File 'lib/ruby-bbcode/templates/bbcode_errors_template.rb', line 12 def opening_part @opening_part end |
Class Method Details
.convert_text(node) ⇒ Object
24 25 26 27 28 |
# File 'lib/ruby-bbcode/templates/bbcode_errors_template.rb', line 24 def self.convert_text(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 |
Instance Method Details
#closing_part ⇒ Object
51 52 53 |
# File 'lib/ruby-bbcode/templates/bbcode_errors_template.rb', line 51 def closing_part @node[:closed] == false ? '' : @closing_part end |
#inlay_between_text! ⇒ Object
30 31 32 33 |
# File 'lib/ruby-bbcode/templates/bbcode_errors_template.rb', line 30 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! ⇒ Object
44 45 |
# File 'lib/ruby-bbcode/templates/bbcode_errors_template.rb', line 44 def inlay_closing_part! end |
#inlay_params! ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/ruby-bbcode/templates/bbcode_errors_template.rb', line 35 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! ⇒ Object
47 48 49 |
# File 'lib/ruby-bbcode/templates/bbcode_errors_template.rb', line 47 def remove_unused_tokens! @opening_part.gsub!('%param%', '') end |