lib/nitro/mixin/markup.rb in nitro-0.21.0 vs lib/nitro/mixin/markup.rb in nitro-0.21.2

- old
+ new

@@ -1,60 +1,13 @@ require 'singleton' require 'redcloth' +require 'cgi' -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 @@ -66,11 +19,11 @@ # # === Examples # # Define your custom markup methods like this: # -# module Markup +# module MarkupMixin # def markup_simple # ... # end # def markup_special # ... @@ -128,15 +81,39 @@ # # NOT IMPLEMENTED. def clear(str) end + + def escape(str) + CGI.escape(str.gsub(/ /, '_')) + end + + def unescape(str) + CGI.unescape(str.gsub(/_/, ' ')) + end + + class << self + # Helper method for manipulating the sanitize transformation. + + def setup_sanitize_transform(&block) + self.send :define_method, :sanitize, block + end + alias_method :setup_sanitize_transformation, :setup_sanitize_transform + + # Helper method for manipulating the markup transformation. + + def setup_markup_transform(&block) + self.send :define_method, :markup, block + end + alias_method :setup_markup_transformation, :setup_markup_transform + end end # An abstract Markup class. -class Markuper - include Singleton +class MarkupKit + extend Markup include Markup end end