string_master 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/string_master/string_master.rb +13 -1
- data/spec/lib/string_master/string_master_spec.rb +8 -6
- data/string_master.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
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 entity,
|
124
|
+
# which is available as a standalone method #preserve_whitespace
|
123
125
|
def wrap_code
|
124
|
-
wrap_lines("code", /\A\s{4}/)
|
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 entities.
|
132
|
+
def preserve_whitespace_within(tag)
|
133
|
+
@modified_string.gsub!(/<#{tag}>.+?<\/#{tag}>/) do |match|
|
134
|
+
match.gsub(/\s\s+/) { |m| " "*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
|
-
|
41
|
-
|
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>
|
47
|
-
|
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
|
data/string_master.gemspec
CHANGED
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.
|
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:
|
136
|
+
hash: 2244729625638070014
|
137
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|