kelredd-useful 0.1.15 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/useful/sinatra_helpers/erb/tags.rb +11 -0
- data/lib/useful/version.rb +1 -1
- metadata +1 -1
@@ -26,8 +26,19 @@ module Useful
|
|
26
26
|
tag(options.delete(:tag), options) { '' }
|
27
27
|
end
|
28
28
|
|
29
|
+
# helpers to escape tag text content
|
29
30
|
include Rack::Utils
|
30
31
|
alias_method :h, :escape_html
|
32
|
+
|
33
|
+
# escape tag text content and format for text like display
|
34
|
+
def h_text(text, opts={})
|
35
|
+
h(text.to_s).
|
36
|
+
gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
|
37
|
+
split("\n").collect do |line|
|
38
|
+
line.nil? ? '': line.sub(/(\s+)?\S*/) {|lead| lead.gsub(/\s/,' ')}
|
39
|
+
end.join("\n"). # change any leading white spaces on a line to ' '
|
40
|
+
gsub(/\n/,'\1<br />') # newlines -> br added
|
41
|
+
end
|
31
42
|
|
32
43
|
# emulator for 'tag'
|
33
44
|
# EX : tag :h1, "shizam", :title => "shizam"
|
data/lib/useful/version.rb
CHANGED