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
53 54 55 56 57 58 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 53 def initialize(node) @node = node @tag_definition = node.definition # tag_definition @opening_html = node.definition[:html_open].dup @closing_html = node.definition[:html_close].dup end |
Instance Attribute Details
#closing_html ⇒ Object
Returns the value of attribute closing_html.
51 52 53 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 51 def closing_html @closing_html end |
#opening_html ⇒ Object
Returns the value of attribute opening_html.
51 52 53 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 51 def opening_html @opening_html end |
Instance Method Details
#inlay_between_text! ⇒ Object
60 61 62 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 60 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
81 82 83 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 81 def inlay_closing_html! @closing_html.gsub!('%between%',@node[:between]) if @tag_definition[:require_between] end |
#inlay_inline_params! ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 64 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
85 86 87 88 89 |
# File 'lib/ruby-bbcode/tag_collection.rb', line 85 def remove_unused_tokens! @tag_definition[:tag_param_tokens].each do |token| @opening_html.gsub!("%#{token[:token]}%", '') end end |