projects
/
rails.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
6039aac
)
Add a simple "text" format to the RichText module
author
Tom Hughes
<tom@compton.nu>
Fri, 16 Mar 2012 17:00:59 +0000
(17:00 +0000)
committer
Tom Hughes
<tom@compton.nu>
Sat, 17 Mar 2012 16:37:00 +0000
(16:37 +0000)
lib/rich_text.rb
patch
|
blob
|
history
diff --git
a/lib/rich_text.rb
b/lib/rich_text.rb
index f2a558e6af8dcc92aae9aa588ce8216edb0ab248..9c4a24fd54a11c18e7d50d3b65e8b137e768dc24 100644
(file)
--- a/
lib/rich_text.rb
+++ b/
lib/rich_text.rb
@@
-3,6
+3,7
@@
module RichText
case format
when "html"; HTML.new(text || "")
when "markdown"; Markdown.new(text || "")
case format
when "html"; HTML.new(text || "")
when "markdown"; Markdown.new(text || "")
+ when "text"; Text.new(text || "")
else; nil
end
end
else; nil
end
end
@@
-27,6
+28,16
@@
module RichText
return [link_proportion - 0.2, 0.0].max * 200 + link_count * 20
end
return [link_proportion - 0.2, 0.0].max * 200 + link_count * 20
end
+
+ protected
+
+ def linkify(text)
+ if text.html_safe?
+ Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow")).html_safe
+ else
+ Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow"))
+ end
+ end
end
class HTML < Base
end
class HTML < Base
@@
-46,14
+57,6
@@
module RichText
def sanitize(text)
Sanitize.clean(text, Sanitize::Config::OSM).html_safe
end
def sanitize(text)
Sanitize.clean(text, Sanitize::Config::OSM).html_safe
end
-
- def linkify(text)
- if text.html_safe?
- Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow")).html_safe
- else
- Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow"))
- end
- end
end
class Markdown < Base
end
class Markdown < Base
@@
-76,4
+79,16
@@
module RichText
})
end
end
})
end
end
+
+ class Text < Base
+ include ActionView::Helpers::TextHelper
+
+ def to_html
+ linkify(simple_format(ERB::Util.html_escape(self)))
+ end
+
+ def to_text
+ self
+ end
+ end
end
end