Module: BBCoder::Tag::ClassMethods

Included in:
BBCoder::Tag
Defined in:
lib/bbcoder/tag.rb

Instance Method Summary collapse

Instance Method Details

#handle(tag, depth, meta, content = nil, force_end = false) ⇒ Object

need #handle so we don’t get into a reform loop from to_html checking content validity



89
90
91
92
93
94
95
96
# File 'lib/bbcoder/tag.rb', line 89

def handle(tag, depth, meta, content = nil, force_end = false)
  if BBCoder.configuration[tag] && BBCoder.configuration[tag].singular?
    to_html(tag, depth, meta, content, true)
  else
    # reform doesn't really care about depth, so we don't pass it in.
    reform(tag, meta, content, force_end)
  end
end

#reform(tag, meta, content = nil, singularity = false, force_end = false) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/bbcoder/tag.rb', line 98

def reform(tag, meta, content = nil, singularity = false, force_end = false)
  if (content.nil? && !force_end) || singularity
    %(#{reform_open(tag, meta)})
  else
    %(#{reform_open(tag, meta)}#{content}#{reform_end(tag)})
  end
end

#reform_end(tag) ⇒ Object



114
115
116
# File 'lib/bbcoder/tag.rb', line 114

def reform_end(tag)
  "[/#{tag}]"
end

#reform_open(tag, meta) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/bbcoder/tag.rb', line 106

def reform_open(tag, meta)
  if meta.nil? || meta.empty?
    "[#{tag}]"
  else
    "[#{tag}=#{meta}]"
  end
end

#to_html(tag, depth, meta, content, singularity = false) ⇒ Object



83
84
85
# File 'lib/bbcoder/tag.rb', line 83

def to_html(tag, depth, meta, content, singularity = false)
  BBCoder.configuration[tag].to_html(depth, meta, content, singularity)
end