Class: RubyBBCode::TagCollection::HtmlTemplate
- Inherits:
-
Object
- Object
- RubyBBCode::TagCollection::HtmlTemplate
- Defined in:
- lib/ruby-bbcode/tag_collection.rb
Overview
This class is designed to help us build up the HTML data. It starts out as a template such as…
@opening_html = '<a href="%url%">%between%'
@closing_html = '</a>'
and then slowly turns into…
@opening_html = '<a href="http://www.blah.com">cool beans'
@closing_html = '</a>'
TODO: Think about creating a separate file for this or something… maybe look into folder structures cause this project got huge when I showed up.
Instance Attribute Summary collapse
-
#closing_html ⇒ Object
Returns the value of attribute closing_html.
-
#opening_html ⇒ Object
Returns the value of attribute opening_html.
Instance Method Summary collapse
-
#initialize(node) ⇒ HtmlTemplate
constructor
A new instance of HtmlTemplate.
- #inlay_between_text! ⇒ Object
- #inlay_closing_html! ⇒ Object
- #inlay_inline_params! ⇒ Object
- #remove_unused_tokens! ⇒ Object
Constructor Details
#initialize(node) ⇒ HtmlTemplate
Returns a new instance of HtmlTemplate.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 48 def initialize(node) @node = node @tag_definition = node.definition # tag_definition @opening_html = "" @closing_html = "" # if this is a nested tag, then don't prefix first_html_open if !node.definition[:first_html_open].nil? && node.type != node.parent_type then @opening_html << node.definition[:first_html_open] end if node.definition[:html_open].is_a?(Hash) then @opening_html << node.definition[:html_open][node.parent_type].dup else @opening_html << node.definition[:html_open].dup end if node.definition[:html_close].is_a?(Hash) then @closing_html << node.definition[:html_close][node.parent_type].dup else @closing_html << node.definition[:html_close].dup end if !node.definition[:last_html_close].nil? && node.type != node.parent_type then @closing_html << node.definition[:last_html_close] end end |
Instance Attribute Details
#closing_html ⇒ Object
Returns the value of attribute closing_html.
46 47 48 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 46 def closing_html @closing_html end |
#opening_html ⇒ Object
Returns the value of attribute opening_html.
46 47 48 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 46 def opening_html @opening_html end |
Instance Method Details
#inlay_between_text! ⇒ Object
77 78 79 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 77 def inlay_between_text! @opening_html.gsub!('%between%',@node[:between]) if between_text_goes_into_html_output_as_param? # set the between text to where it goes if required to do so... end |
#inlay_closing_html! ⇒ Object
98 99 100 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 98 def inlay_closing_html! @closing_html.gsub!('%between%',@node[:between]) if @tag_definition[:require_between] end |
#inlay_inline_params! ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 81 def inlay_inline_params! # Get list of paramaters to feed match_array = @node[:params][:tag_param].scan(@tag_definition[:tag_param])[0] # for each parameter to feed match_array.each.with_index do |match, i| if i < @tag_definition[:tag_param_tokens].length # Substitute the %param% keyword for the appropriate data specified @opening_html.gsub!("%#{@tag_definition[:tag_param_tokens][i][:token].to_s}%", @tag_definition[:tag_param_tokens][i][:prefix].to_s + match + @tag_definition[:tag_param_tokens][i][:postfix].to_s) end end end |
#remove_unused_tokens! ⇒ Object
102 103 104 105 106 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 102 def remove_unused_tokens! @tag_definition[:tag_param_tokens].each do |token| @opening_html.gsub!("%#{token[:token]}%", '') end end |