# code: # * George Moschovitis # # (c) 2004 Navel, all rights reserved. # $Id$ require 'glue/property' module G #-- # Override the default PropertyUtils implementation to # add markup support. #++ module PropertyUtils # Override to add markup code. # def self.prop_setter(prop) s = prop.symbol if markup = prop.meta[:markup] # if true, set to default Markup markup = N::Markup if true == markup return %{ def #{s}=(val) @#{s} = #{markup}.expand(val) end def compact_#{s} #{markup}.compact(@#{s}) end } else return %{ def #{s}=(val) @#{s} = val end } end end end end # module module N # = Markup # # Generalised Markup transformations. # # The expand methods evaluate (expand) the markup # code to produce the final content. The compact # methods reverse this process to create the original # markup code. Not all markup transformations are # reversible. # # When this library is included, the default PropertyUtils # implementation is overriden to add markup support. # # === Examples # # here comes the #{obj.body} # => prints the expanded version. # # obj.body = N::Markup.expand(@params['body']) # module Markup def self.expand_html!(str) return unless str str.gsub!(/"/, '"') str.gsub!(/'/, ''') str.gsub!(/\r\n/, '
') return str end def self.compact_html!(str) return unless str str.gsub!(/"/, '"') str.gsub!(/'/, "'") # gmosx: SOS! double quotes ARE needed for \r\n!! str.gsub!(/\s
/, "\r\n") return str end # Expand the markup code to produce the # actual content. # def self.expand(str) if str xstr = str.dup expand_html!(xstr) expand_wiki!(xstr) return xstr else return str end end # Compact (reverse) the content to the origial markup # code. Not all markup transformations are reversible. # def self.compact(str) if str xstr = str.dup compact_html!(xstr) compact_wiki!(xstr) return xstr else return str end end # Remove markup code from the input string. # NOT IMPLEMENTED. # def self.clear(str) end end end # module