Sha256: 8ed70e8e4eea425a1f971bc0cecb8f8c80591b740c1cac5c2e1617bdcccea665
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
class BBCoder class Tag attr_reader :name, :options def initialize(name, options = {}) @name = name @options = options.merge(:as => (options[:as] || name)) end def to_html(meta, content) return self.class.reform(name, meta, content) unless content_valid?(content) if options[:block].nil? "<#{options[:as]}>#{content}</#{options[:as]}>" else options[:block].binding.eval <<-EOS @meta = %Q{#{meta}} @content = %Q{#{content}} EOS options[:block].call end end def content_valid?(content) return true if options[:match].nil? return !content.match(options[:match]).nil? end def parents options[:parents] || [] end module ClassMethods def to_html(tag, meta, content) BBCoder.configuration[tag].to_html(meta, content) end def reform(tag, meta, content = nil) if content.nil? %(#{reform_open(tag, meta)}) else %(#{reform_open(tag, meta)}#{content}#{reform_end(tag)}) end end def reform_open(tag, meta) if meta.nil? || meta.empty? "[#{tag}]" else "[#{tag}=#{meta}]" end end def reform_end(tag) "[/#{tag}]" end end extend ClassMethods end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bbcoder-0.1.1 | lib/bbcoder/tag.rb |