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.
@@ -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"
@@ -3,7 +3,7 @@ module Useful
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 15
6
+ TINY = 16
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-useful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelredd