string_master 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/Gemfile.lock +28 -28
- data/VERSION +1 -1
- data/lib/string_master/string_master.rb +19 -8
- data/spec/lib/string_master/string_master_spec.rb +2 -4
- data/string_master.gemspec +1 -4
- metadata +2 -18
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,22 +1,21 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
actionpack (3.
|
5
|
-
activemodel (= 3.
|
6
|
-
activesupport (= 3.
|
4
|
+
actionpack (3.2.4)
|
5
|
+
activemodel (= 3.2.4)
|
6
|
+
activesupport (= 3.2.4)
|
7
7
|
builder (~> 3.0.0)
|
8
8
|
erubis (~> 2.7.0)
|
9
|
-
|
10
|
-
rack (~> 1.
|
11
|
-
rack-cache (~> 1.
|
12
|
-
rack-mount (~> 0.8.2)
|
9
|
+
journey (~> 1.0.1)
|
10
|
+
rack (~> 1.4.0)
|
11
|
+
rack-cache (~> 1.2)
|
13
12
|
rack-test (~> 0.6.1)
|
14
|
-
sprockets (~> 2.
|
15
|
-
activemodel (3.
|
16
|
-
activesupport (= 3.
|
13
|
+
sprockets (~> 2.1.3)
|
14
|
+
activemodel (3.2.4)
|
15
|
+
activesupport (= 3.2.4)
|
17
16
|
builder (~> 3.0.0)
|
17
|
+
activesupport (3.2.4)
|
18
18
|
i18n (~> 0.6)
|
19
|
-
activesupport (3.1.3)
|
20
19
|
multi_json (~> 1.0)
|
21
20
|
builder (3.0.0)
|
22
21
|
diff-lcs (1.1.3)
|
@@ -24,29 +23,31 @@ GEM
|
|
24
23
|
git (1.2.5)
|
25
24
|
hike (1.2.1)
|
26
25
|
i18n (0.6.0)
|
27
|
-
jeweler (1.
|
26
|
+
jeweler (1.8.3)
|
28
27
|
bundler (~> 1.0)
|
29
28
|
git (>= 1.2.5)
|
30
29
|
rake
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
rdoc
|
31
|
+
journey (1.0.3)
|
32
|
+
json (1.7.3)
|
33
|
+
multi_json (1.3.6)
|
34
|
+
rack (1.4.1)
|
35
|
+
rack-cache (1.2)
|
34
36
|
rack (>= 0.4)
|
35
|
-
rack-mount (0.8.3)
|
36
|
-
rack (>= 1.0.0)
|
37
37
|
rack-test (0.6.1)
|
38
38
|
rack (>= 1.0)
|
39
39
|
rake (0.9.2.2)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
rspec-
|
44
|
-
rspec-
|
45
|
-
|
46
|
-
rspec-
|
47
|
-
|
48
|
-
|
49
|
-
|
40
|
+
rdoc (3.12)
|
41
|
+
json (~> 1.4)
|
42
|
+
rspec (2.10.0)
|
43
|
+
rspec-core (~> 2.10.0)
|
44
|
+
rspec-expectations (~> 2.10.0)
|
45
|
+
rspec-mocks (~> 2.10.0)
|
46
|
+
rspec-core (2.10.1)
|
47
|
+
rspec-expectations (2.10.0)
|
48
|
+
diff-lcs (~> 1.1.3)
|
49
|
+
rspec-mocks (2.10.1)
|
50
|
+
sprockets (2.1.3)
|
50
51
|
hike (~> 1.2)
|
51
52
|
rack (~> 1.0)
|
52
53
|
tilt (~> 1.1, != 1.3.0)
|
@@ -59,5 +60,4 @@ DEPENDENCIES
|
|
59
60
|
actionpack
|
60
61
|
bundler
|
61
62
|
jeweler
|
62
|
-
rcov
|
63
63
|
rspec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.6
|
@@ -101,19 +101,30 @@ class StringMaster
|
|
101
101
|
|
102
102
|
# Finds lines of text that satisfy a 'regexp' and wraps them into an
|
103
103
|
# opening and closing 'tag'. Best example of usage is #wrap_code.
|
104
|
-
|
105
|
-
|
104
|
+
#
|
105
|
+
# Also receives an option :remove_newlines (default is false)
|
106
|
+
# which removes \n around the tag that wraps the lines of text. Useful if
|
107
|
+
# you're using this method with #newlines_to_br to avoid extra space that may or
|
108
|
+
# may not be in the user's input.
|
109
|
+
def wrap_lines(tag, regexp, options={remove_newlines: false})
|
110
|
+
code_tag = nil; result = ""
|
106
111
|
@modified_string.each_line do |line|
|
107
112
|
if line =~ regexp
|
108
|
-
|
109
|
-
|
113
|
+
unless code_tag == :opened
|
114
|
+
result.chomp! if options[:remove_newlines]
|
115
|
+
result += "<#{tag}>"
|
116
|
+
code_tag = :opened
|
117
|
+
end
|
110
118
|
result += line.sub(regexp, '')
|
111
119
|
else
|
112
|
-
if
|
120
|
+
if code_tag == :opened
|
121
|
+
code_tag = :closed
|
113
122
|
result.chomp!
|
114
|
-
result += "</#{tag}
|
123
|
+
result += "</#{tag}>"
|
124
|
+
elsif code_tag == :closed
|
125
|
+
code_tag = nil
|
126
|
+
result.chomp! if options[:remove_newlines]
|
115
127
|
end
|
116
|
-
code_open = false
|
117
128
|
result += line
|
118
129
|
end
|
119
130
|
end
|
@@ -125,7 +136,7 @@ class StringMaster
|
|
125
136
|
# It also transforms each occurence of 2 or more spaces into an entity,
|
126
137
|
# which is available as a standalone method #preserve_whitespace
|
127
138
|
def wrap_code
|
128
|
-
wrap_lines("code", /\A\s{4}
|
139
|
+
wrap_lines("code", /\A\s{4}/, remove_newlines: true)
|
129
140
|
preserve_whitespace_within("code") # already returns `self`
|
130
141
|
end
|
131
142
|
|
@@ -44,12 +44,10 @@ I have a piece of code
|
|
44
44
|
and here's what my code looks like.
|
45
45
|
CODE
|
46
46
|
StringMaster.new(code).wrap_code.to_s.should == <<WRAPPED_CODE
|
47
|
-
I have a piece of code
|
48
|
-
<code>def say_hello
|
47
|
+
I have a piece of code<code>def say_hello
|
49
48
|
puts "hello world"
|
50
49
|
return true
|
51
|
-
end</code>
|
52
|
-
and here's what my code looks like.
|
50
|
+
end</code>and here's what my code looks like.
|
53
51
|
WRAPPED_CODE
|
54
52
|
end
|
55
53
|
|
data/string_master.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "string_master"
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.6"
|
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"]
|
@@ -47,20 +47,17 @@ Gem::Specification.new do |s|
|
|
47
47
|
s.add_runtime_dependency(%q<actionpack>, [">= 0"])
|
48
48
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
49
49
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
50
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
51
50
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
52
51
|
else
|
53
52
|
s.add_dependency(%q<actionpack>, [">= 0"])
|
54
53
|
s.add_dependency(%q<bundler>, [">= 0"])
|
55
54
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
56
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
57
55
|
s.add_dependency(%q<rspec>, [">= 0"])
|
58
56
|
end
|
59
57
|
else
|
60
58
|
s.add_dependency(%q<actionpack>, [">= 0"])
|
61
59
|
s.add_dependency(%q<bundler>, [">= 0"])
|
62
60
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
63
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
64
61
|
s.add_dependency(%q<rspec>, [">= 0"])
|
65
62
|
end
|
66
63
|
end
|
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.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -59,22 +59,6 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: rcov
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :development
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
62
|
- !ruby/object:Gem::Dependency
|
79
63
|
name: rspec
|
80
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
117
|
version: '0'
|
134
118
|
segments:
|
135
119
|
- 0
|
136
|
-
hash: -
|
120
|
+
hash: -1937837215791656684
|
137
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
122
|
none: false
|
139
123
|
requirements:
|