Created
May 14, 2010 18:48
-
-
Save marugoshi/401485 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Ext | |
| module String | |
| def self.included(base) | |
| base.class_eval do | |
| include InstanceMethods | |
| end | |
| end | |
| module InstanceMethods | |
| def br_to_return | |
| self.gsub(/<(BR|br|BR \/|br \/)>/, "\n") | |
| end | |
| def br_to_return! | |
| self.gsub!(/<(BR|br|BR \/|br \/)>/, "\n") | |
| end | |
| def return_to_br | |
| self.gsub(/\r\n/, "\n").gsub(/\r/, "\n").gsub(/\n/, "<br />") | |
| end | |
| def return_to_br! | |
| self.gsub!(/\r\n/, "\n") | |
| self.gsub!(/\r/, "\n") | |
| self.gsub!(/\n/, "<br />") | |
| end | |
| def strip_html_tag | |
| self.gsub(/<[^<>]*>/,"") while /<[^<>]*>/ =~ self | |
| end | |
| def strip_html_tag! | |
| self.gsub!(/<[^<>]*>/,"") while /<[^<>]*>/ =~ self | |
| end | |
| def strip_return | |
| self.gsub(/\r\n/, "\n").gsub(/\r/, "\n").gsub(/\n/, "") | |
| end | |
| def strip_return! | |
| self.gsub!(/\r\n/, "\n") | |
| self.gsub!(/\r/, "\n") | |
| self.gsub!(/\n/, "") | |
| end | |
| end | |
| end | |
| end | |
| String.send :include, Ext::String |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment