string_master 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
@@ -120,8 +120,20 @@ class StringMaster
120
120
  end
121
121
 
122
122
  # Finds all lines that start with 4 spaces and wraps them into <code> tags.
123
+ # It also transforms each occurence of 2 or more spaces into an &nbsp; entity,
124
+ # which is available as a standalone method #preserve_whitespace
123
125
  def wrap_code
124
- wrap_lines("code", /\A\s{4}/) # wrap lines already returns `self`
126
+ wrap_lines("code", /\A\s{4}/)
127
+ preserve_whitespace_within("code") # already returns `self`
128
+ end
129
+
130
+ # Preserves whitespace within a given tag. Each occurence of 2 or more spaces
131
+ # is transformed into a &nbsp; entities.
132
+ def preserve_whitespace_within(tag)
133
+ @modified_string.gsub!(/<#{tag}>.+?<\/#{tag}>/) do |match|
134
+ match.gsub(/\s\s+/) { |m| "&nbsp;"*m.length }
135
+ end
136
+ self
125
137
  end
126
138
 
127
139
  def wrap_inline_code(opening_tag="<span class=\"inlineCode\">", closing_tag="</span>")
@@ -37,14 +37,18 @@ describe StringMaster do
37
37
  it "wraps code in <code> tags" do
38
38
  code = <<CODE
39
39
  I have a piece of code
40
- puts "hello world"
41
- exit
40
+ def say_hello
41
+ puts "hello world"
42
+ return true
43
+ end
42
44
  and here's what my code looks like.
43
45
  CODE
44
46
  StringMaster.new(code).wrap_code.to_s.should == <<WRAPPED_CODE
45
47
  I have a piece of code
46
- <code>puts "hello world"
47
- exit</code>
48
+ <code>def say_hello
49
+ puts "hello world"
50
+ return true
51
+ end</code>
48
52
  and here's what my code looks like.
49
53
  WRAPPED_CODE
50
54
  end
@@ -87,6 +91,4 @@ WRAPPED_CODE
87
91
  "<img src=\"http://images.com/image.jpg\" alt=\"\" /> <b>Hello <a href=\"http://url.com\" target=\"_blank\">http://url.com</a> </b>"
88
92
  end
89
93
 
90
-
91
-
92
94
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "string_master"
8
- s.version = "0.3.2"
8
+ s.version = "0.3.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roman Snitko"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -133,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  segments:
135
135
  - 0
136
- hash: 2478903722703068135
136
+ hash: 2244729625638070014
137
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements: