require 'singleton' require 'redcloth' require 'glue/property' require 'glue/sanitize' module Nitro #-- # Override the default PropertyUtils implementation to # add markup support. #++ =begin 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 = Nitro::Markup if true == markup code = %{ def #{s}=(val) } if Property.type_checking code << %{ unless String == val.class raise "Invalid type, expected '#{prop.klass}', is '\#\{val.class\}'." end } end code << %{ @#{s} = #{markup}.expand(val) end def compact_#{s} #{markup}.compact(@#{s}) end } return code else return %{ def #{s}=(val) @#{s} = val end } end end end =end # 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 # # Define your custom markup methods like this: # # module Markup # def markup_simple # ... # end # def markup_special # ... # end # # # maps the {{..}} macro # alias_method :sanitize, :markup_simple # # maps the {|..|} macro # alias_method :markup, :markup_special # end # # here comes the #{obj.body} # => prints the expanded version. # # obj.body = markup(@params['body']) module Markup private # The default markup method. You should override this method # in your application to call your custom markup # methods. def expand(str) if str xstr = str.dup xstr.gsub!(//, '>') return String.sanitize(xstr) end return nil end alias_method :sanitize, :expand # ... def expand_redcloth(str) if str return RedCloth.new(expand(str)).to_html end return nil end alias_method :markup, :expand_redcloth # Compact (reverse) the content to the origial markup # code. Not all markup transformations are reversible. # You should override this method in your application # to call your custom markup methods. # # NOT IMPLEMENTED. def compact(str, meth = nil) end # Remove markup code from the input string. # # NOT IMPLEMENTED. def clear(str) end end # An abstract Markup class. class Markuper include Singleton include Markup end end # * George Moschovitis