Module: Waves::Helpers::Formatting
- Defined in:
- lib/helpers/formatting.rb
Overview
Formatting helpers are used to convert specialized content, like Markaby or Textile, into valid HTML. It also provides common escaping functions.
Instance Method Summary collapse
-
#escape_html(s) ⇒ Object
Escape a string as HTML content.
-
#escape_uri(s) ⇒ Object
Escape a URI, converting quotes and spaces and so on.
-
#markaby(content) ⇒ Object
Treat content as Markaby and evaluate (only works within a Markaby template).
-
#textile(content) ⇒ Object
Treat content as Textile.
Instance Method Details
#escape_html(s) ⇒ Object
Escape a string as HTML content.
10 |
# File 'lib/helpers/formatting.rb', line 10 def escape_html(s); Rack::Utils.escape_html(s); end |
#escape_uri(s) ⇒ Object
Escape a URI, converting quotes and spaces and so on.
13 |
# File 'lib/helpers/formatting.rb', line 13 def escape_uri(s); Rack::Utils.escape(s); end |
#markaby(content) ⇒ Object
Treat content as Markaby and evaluate (only works within a Markaby template). Used to pull Markaby content from a file or database into a Markaby template.
17 |
# File 'lib/helpers/formatting.rb', line 17 def markaby( content ); self << eval( content ); end |
#textile(content) ⇒ Object
Treat content as Textile.
20 21 22 23 24 25 26 |
# File 'lib/helpers/formatting.rb', line 20 def textile( content ) return if content.nil? or content.empty? ( ::RedCloth::TEXTILE_TAGS << [ 96.chr, '&8216;'] ).each do |pat,ent| content.gsub!( pat, ent.gsub('&','&#') ) end self << ::RedCloth.new( content ).to_html end |