Class: BBCoder::Tag
- Inherits:
-
Object
- Object
- BBCoder::Tag
- Extended by:
- ClassMethods
- Defined in:
- lib/bbcoder/tag.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #content_valid?(content) ⇒ Boolean
-
#initialize(name, options = {}) ⇒ Tag
constructor
A new instance of Tag.
- #parents ⇒ Object
- #to_html(meta, content) ⇒ Object
Methods included from ClassMethods
reform, reform_end, reform_open
Constructor Details
#initialize(name, options = {}) ⇒ Tag
Returns a new instance of Tag.
5 6 7 8 |
# File 'lib/bbcoder/tag.rb', line 5 def initialize(name, = {}) @name = name @options = .merge(:as => ([:as] || name)) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/bbcoder/tag.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/bbcoder/tag.rb', line 3 def @options end |
Instance Method Details
#content_valid?(content) ⇒ Boolean
25 26 27 28 29 |
# File 'lib/bbcoder/tag.rb', line 25 def content_valid?(content) return true if [:match].nil? return !content.match([:match]).nil? end |
#parents ⇒ Object
31 32 33 |
# File 'lib/bbcoder/tag.rb', line 31 def parents [:parents] || [] end |
#to_html(meta, content) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bbcoder/tag.rb', line 10 def to_html(, content) return self.class.reform(name, , content) unless content_valid?(content) if [:block].nil? "<#{[:as]}>#{content}</#{[:as]}>" else [:block].binding.eval <<-EOS @meta = %Q{#{Regexp.escape(.to_s)}} @content = %Q{#{Regexp.escape(content.to_s)}} EOS [:block].call end end |