texttube 6.0.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGES.md +9 -0
- data/README.md +84 -71
- data/lib/texttube/version.rb +1 -1
- metadata +3 -6
- data/lib/ext/blank.rb +0 -17
- data/lib/ext/to_constant.rb +0 -26
- data/lib/texttube.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 610f0fe430a90ce6e8de9b697d41e81029cdd82c
|
4
|
+
data.tar.gz: a334d2477567f2be643d05076866fb4fd6f41e1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb605ac48e32f2cb5066fddeaab12be996435e5517d205f774f4957e7530b2fd174ec0e7b64e092907f69e2418470762de03a63f0a059ff3b8cd2cbf8009ab1a
|
7
|
+
data.tar.gz: c9df73120109399f0efd543c46f5c521c76f05a42bb6fde52b75e91321012d2c6cf75c8369dc2ff455abc5066b4a3e332d43fb0045e15292520f532fd805072c
|
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# CH CH CH CHANGES! #
|
2
2
|
|
3
|
+
|
4
|
+
## Friday the 12th of June 2015, v6.1.0 ##
|
5
|
+
|
6
|
+
* Got rid of some ext methods that weren't needed or used.
|
7
|
+
* Updated the docs for Github with the syntax highlighting hints.
|
8
|
+
|
9
|
+
----
|
10
|
+
|
11
|
+
|
3
12
|
## Friday the 17th of October 2014, v6.0.0 ##
|
4
13
|
|
5
14
|
* Moved extra filters into TextTubeBaby to make the library lighter and easier to install.
|
data/README.md
CHANGED
@@ -26,79 +26,90 @@ You want to filter/transform a string. You also want to run several filters acro
|
|
26
26
|
|
27
27
|
In practice this means:
|
28
28
|
|
29
|
+
```ruby
|
30
|
+
require 'texttube/filterable'
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
module BFil
|
45
|
-
extend TextTube::Filterable
|
46
|
-
|
47
|
-
filter_with :spacial do |current,options|
|
48
|
-
current.split(//).join " "
|
49
|
-
end
|
50
|
-
end
|
32
|
+
module AFilter
|
33
|
+
extend TextTube::Filterable
|
34
|
+
|
35
|
+
filter_with :double do |text|
|
36
|
+
text * 2
|
37
|
+
end
|
38
|
+
|
39
|
+
filter_with :triple do |text|
|
40
|
+
text * 3
|
41
|
+
end
|
42
|
+
end
|
51
43
|
|
52
|
-
|
44
|
+
module BFil
|
45
|
+
extend TextTube::Filterable
|
53
46
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
47
|
+
filter_with :spacial do |current,options|
|
48
|
+
current.split(//).join " "
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
require 'texttube/base'
|
53
|
+
|
54
|
+
class NeuS < TextTube::Base
|
55
|
+
register BFil
|
56
|
+
register AFilter
|
57
|
+
register do # on the fly
|
58
|
+
filter_with :dashes do |text|
|
59
|
+
"---#{text}---"
|
62
60
|
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
63
64
|
|
64
65
|
Now there is a class `NeuS` which will run filters `:spacial`, `:double`, `:triple`, and `:dashes` in that order, on a given string. For example:
|
65
66
|
|
66
|
-
|
67
|
+
```ruby
|
68
|
+
n = NeuS.new "abc"
|
69
|
+
```
|
67
70
|
|
68
71
|
Running all of the filters:
|
69
72
|
|
70
|
-
|
71
|
-
|
73
|
+
```ruby
|
74
|
+
n.filter
|
75
|
+
# => "---a b ca b ca b ca b ca b ca b c---"
|
76
|
+
```
|
72
77
|
|
73
78
|
Or just some of the filters:
|
74
79
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
80
|
+
```
|
81
|
+
n.filter :spacial
|
82
|
+
# => "a b c"
|
83
|
+
n.filter :spacial, :dashes
|
84
|
+
# => "---a b c---"
|
85
|
+
```
|
79
86
|
|
80
87
|
Run them more than once:
|
81
|
-
|
82
|
-
|
83
|
-
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
n.filter :double, :triple, :double
|
91
|
+
# => "abcabcabcabcabcabcabcabcabcabcabcabc"
|
92
|
+
```
|
84
93
|
|
85
94
|
### Creating a filter ###
|
86
95
|
|
87
96
|
Make something _filterable_:
|
88
97
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
```ruby
|
99
|
+
require 'texttube/filterable'
|
100
|
+
|
101
|
+
module AnotherFilter
|
102
|
+
extend TextTube::Filterable
|
103
|
+
|
104
|
+
filter_with :copyright do |text|
|
105
|
+
text << " ©#{Time.now.year}. "
|
106
|
+
end
|
107
|
+
|
108
|
+
filter_with :number do |text,options|
|
109
|
+
text * options[:times].to_i
|
110
|
+
end
|
111
|
+
end
|
112
|
+
```
|
102
113
|
|
103
114
|
That's all there is to creating a filter.
|
104
115
|
|
@@ -106,34 +117,36 @@ That's all there is to creating a filter.
|
|
106
117
|
|
107
118
|
The class picks which filters to use, and can add filters on the fly, by using `register`:
|
108
119
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
120
|
+
```ruby
|
121
|
+
require 'texttube/base'
|
122
|
+
|
123
|
+
class MyString < TextTube::Base
|
124
|
+
register AnotherFilter
|
125
|
+
register do
|
126
|
+
filter_with :my_name do |text|
|
127
|
+
text.gsub "Iain Barnett", %q!<a href="iainbarnett.me.uk" title="My blog">Iain Barnett</a>!
|
118
128
|
end
|
119
|
-
|
120
|
-
|
121
|
-
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
s = MyString.new "Let me introduce Iain Barnett. He writes Ruby code."
|
133
|
+
# => "Let me introduce Iain Barnett. He writes Ruby code."
|
122
134
|
|
123
|
-
|
124
|
-
|
135
|
+
MyString.options.merge! :number => {times: 2}
|
136
|
+
# => {:number=>{:times=>2}}
|
125
137
|
|
126
|
-
|
127
|
-
|
138
|
+
s.filter
|
139
|
+
# => "Let me introduce <a href="iainbarnett.me.uk" title="My blog">Iain Barnett</a>. He writes Ruby code. ©2013. Let me introduce <a href="iainbarnett.me.uk" title="My blog">Iain Barnett</a>. He writes Ruby code. ©2013. "
|
140
|
+
```
|
128
141
|
|
129
142
|
### Ready made filters ###
|
130
143
|
|
131
|
-
They used to come with this library, but sometimes they caused problems with installation (things like Nokogiri can be painful to install at times) so I spun them off into their own library - TextTubeBaby!
|
144
|
+
They used to come with this library, but sometimes they caused problems with installation (things like Nokogiri can be painful to install at times) so I spun them off into their own library - [TextTubeBaby](https://github.com/yb66/TextTubeBaby)!
|
132
145
|
|
133
146
|
|
134
147
|
### Contributors ###
|
135
148
|
|
136
|
-
Many thanks to Eleni Karinou and [Annette Smith](https://twitter.com/moosecatear) for brainsplatting a new name for the library, and after many unusable and clearly disturbing suggestions, to Annette for the final name (and its spin off, TextTubeBaby).
|
149
|
+
Many thanks to Eleni Karinou and [Annette Smith](https://twitter.com/moosecatear) for brainsplatting a new name for the library, and after many unusable and clearly disturbing suggestions, to Annette for the final name (and its spin off, [TextTubeBaby](https://github.com/yb66/TextTubeBaby)).
|
137
150
|
|
138
151
|
|
139
152
|
### Licence ###
|
data/lib/texttube/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: texttube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iain Barnett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Create chainable filters with ease.
|
14
14
|
email: iainspeed @nospam@ gmail.com
|
@@ -22,9 +22,6 @@ files:
|
|
22
22
|
- Gemfile
|
23
23
|
- README.md
|
24
24
|
- Rakefile
|
25
|
-
- lib/ext/blank.rb
|
26
|
-
- lib/ext/to_constant.rb
|
27
|
-
- lib/texttube.rb
|
28
25
|
- lib/texttube/base.rb
|
29
26
|
- lib/texttube/filterable.rb
|
30
27
|
- lib/texttube/version.rb
|
@@ -51,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
48
|
version: '0'
|
52
49
|
requirements: []
|
53
50
|
rubyforge_project:
|
54
|
-
rubygems_version: 2.
|
51
|
+
rubygems_version: 2.4.5
|
55
52
|
signing_key:
|
56
53
|
specification_version: 4
|
57
54
|
summary: Create chainable filters with ease.
|
data/lib/ext/blank.rb
DELETED
data/lib/ext/to_constant.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module TextTube
|
2
|
-
|
3
|
-
# Core lib extensions reside here.
|
4
|
-
module CoreExtensions
|
5
|
-
# to_constant tries to find a declared constant with the name specified
|
6
|
-
# in the string. It raises a NameError when the name is not in CamelCase
|
7
|
-
# or is not initialized.
|
8
|
-
#
|
9
|
-
# Examples
|
10
|
-
# "Module".to_constant #=> Module
|
11
|
-
# "Class".to_constant #=> Class
|
12
|
-
def to_constant
|
13
|
-
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
|
14
|
-
fail NameError, "#{self.inspect} is not a valid constant name!"
|
15
|
-
end
|
16
|
-
|
17
|
-
Object.module_eval("::#{$1}", __FILE__, __LINE__)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
# Standard lib String class gets some extras.
|
24
|
-
class String
|
25
|
-
include TextTube::CoreExtensions
|
26
|
-
end
|
data/lib/texttube.rb
DELETED