texttube 5.1.1 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/CHANGES.md +8 -0
- data/Gemfile +1 -0
- data/README.md +3 -216
- data/lib/texttube/version.rb +1 -1
- data/lib/texttube.rb +1 -20
- data/spec/base_spec.rb +33 -0
- data/spec/examples_spec.rb +63 -0
- data/spec/spec_helper.rb +2 -3
- data/texttube.gemspec +2 -6
- metadata +27 -94
- data/lib/texttube/filters/coderay.rb +0 -68
- data/lib/texttube/filters/embedding_audio.rb +0 -61
- data/lib/texttube/filters/embedding_video.rb +0 -111
- data/lib/texttube/filters/inside_block.rb +0 -35
- data/lib/texttube/filters/link_reffing.rb +0 -144
- data/lib/texttube/filters/spiffing.rb +0 -42
- data/spec/coderay_spec.rb +0 -87
- data/spec/embedding_audio_spec.rb +0 -42
- data/spec/inside_block_spec.rb +0 -35
- data/spec/link_reffing_spec.rb +0 -97
- data/spec/markdownfilters_spec.rb +0 -280
- data/spec/spiffing_spec.rb +0 -45
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d2fd3b516b75ad314db454507278459173618f6e
|
4
|
+
data.tar.gz: 33b727194070771ecb3e32517204f376c1ec468c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 114c1141b316a4e5ad05f92487ceb4a014fb542794fe150d348c1bb9527e9c90e11f86db33bc44889495a34396999be68999c99ea116675c310bd1ed89224384
|
7
|
+
data.tar.gz: 6216d74f04173b226bcebaa5de1ba673e09d52822ffba0e4c09f2ece08c2c1c40365191f5837fc08369bab7a754b1004b14255b8785a39fbba1e841184a49067
|
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# CH CH CH CHANGES! #
|
2
2
|
|
3
|
+
## Friday the 17th of October 2014, v6.0.0 ##
|
4
|
+
|
5
|
+
* Moved extra filters into TextTubeBaby to make the library lighter and easier to install.
|
6
|
+
* Updated specs to check core lib now filter specs have gone.
|
7
|
+
|
8
|
+
----
|
9
|
+
|
10
|
+
|
3
11
|
## Wednesday the 30th of July 2014, v5.1.1 ##
|
4
12
|
|
5
13
|
* Updated info in the README about Spiffing CSS website, since it's gone.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,10 +2,6 @@
|
|
2
2
|
|
3
3
|
Pass a string through filters to transform it.
|
4
4
|
|
5
|
-
### Note! ###
|
6
|
-
|
7
|
-
If you're having a problem with the TextTube::InsideBlock filter on Heroku it could be because of the version of Libxml2 it uses, as [the problem given here states](http://stackoverflow.com/q/8598958/335847), which means Nokogiri won't always work properly on Heroku. When using the InsideBlock filter this can be a problem, so use the `hpricot` branch instead.
|
8
|
-
|
9
5
|
### Build status ###
|
10
6
|
|
11
7
|
Master branch:
|
@@ -130,223 +126,14 @@ The class picks which filters to use, and can add filters on the fly, by using `
|
|
130
126
|
s.filter
|
131
127
|
# => "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. "
|
132
128
|
|
129
|
+
### Ready made filters ###
|
133
130
|
|
134
|
-
|
135
|
-
|
136
|
-
Here are some ready built filters to use.
|
137
|
-
|
138
|
-
### LinkReffing ###
|
139
|
-
|
140
|
-
If you'd don't want your links inline and would prefer to have them at the bottom of the document, then you can use this:
|
141
|
-
|
142
|
-
require 'texttube/base'
|
143
|
-
require 'texttube/filters/link_reffing'
|
144
|
-
|
145
|
-
class TextWithLinks < TextTube::Base
|
146
|
-
register TextTube::LinkReffing
|
147
|
-
end
|
148
|
-
|
149
|
-
s = TextWithLinks.new %q!Iain's blog[[http://iainbarnett.me.uk|My blog]] is good. Erik Hollensbe's blog[[http://erik.hollensbe.org/|Holistic Engineering]] is also good, as is James Coglan's blog[[http://blog.jcoglan.com/|The If Works]]!
|
150
|
-
|
151
|
-
s.filter
|
152
|
-
|
153
|
-
and it will produce this:
|
154
|
-
|
155
|
-
# => "Iain's blog[⁰](#0 "Jump to reference") is good. Erik Hollensbe's blog[¹](#1 "Jump to reference") is also good, as is James Coglan's blog[²](#2 "Jump to reference")\n<div markdown='1' id='reflinks'>\n<a name="0"></a>[0] [http://iainbarnett.me.uk](http://iainbarnett.me.uk "http://iainbarnett.me.uk") My blog\n\n\n<a name="1"></a>[1] [http://erik.hollensbe.org/](http://erik.hollensbe.org/ "http://erik.hollensbe.org/") Holistic Engineering\n\n\n<a name="2"></a>[2] [http://blog.jcoglan.com/](http://blog.jcoglan.com/ "http://blog.jcoglan.com/") The If Works\n\n</div>"
|
156
|
-
|
157
|
-
Run that through a markdown parser and you get:
|
158
|
-
|
159
|
-
<p>Iain's blog<a href="#0" title="Jump to reference">⁰</a> is good. Erik Hollensbe's blog<a href="#1" title="Jump to reference">¹</a> is also good, as is James Coglan's blog<a href="#2" title="Jump to reference">²</a></p>
|
160
|
-
|
161
|
-
<div markdown='1' id='reflinks'>
|
162
|
-
<a name="0"></a>[0] [http://iainbarnett.me.uk](http://iainbarnett.me.uk "http://iainbarnett.me.uk") My blog
|
163
|
-
|
164
|
-
|
165
|
-
<a name="1"></a>[1] [http://erik.hollensbe.org/](http://erik.hollensbe.org/ "http://erik.hollensbe.org/") Holistic Engineering
|
166
|
-
|
167
|
-
|
168
|
-
<a name="2"></a>[2] [http://blog.jcoglan.com/](http://blog.jcoglan.com/ "http://blog.jcoglan.com/") The If Works
|
169
|
-
|
170
|
-
</div>
|
171
|
-
|
172
|
-
Using this will probably end up with also using InsideBlock, to transform the markdown inside the div.
|
173
|
-
|
174
|
-
### InsideBlock ###
|
175
|
-
|
176
|
-
Sometimes it'd be useful to wrap some markdown with HTML, for example:
|
177
|
-
|
178
|
-
<div id="notes">
|
179
|
-
|
180
|
-
* first
|
181
|
-
* second
|
182
|
-
* third
|
183
|
-
|
184
|
-
</div>
|
185
|
-
|
186
|
-
If you put this through a markdown parser the markdown won't get parsed:
|
187
|
-
|
188
|
-
require 'rdiscount'
|
189
|
-
s = "<div id="notes">\n\n* first\n* second\n* third\n\n</div>\n"
|
190
|
-
puts RDiscount.new(s).to_html
|
191
|
-
|
192
|
-
This is the output:
|
193
|
-
|
194
|
-
<div id="notes">
|
195
|
-
|
196
|
-
* first
|
197
|
-
* second
|
198
|
-
* third
|
199
|
-
|
200
|
-
</div>
|
201
|
-
|
202
|
-
My brilliant idea to get around this is to add an HTML attribute of `markdown='1'` to HTML tags that you want the markdown parser to look inside:
|
203
|
-
|
204
|
-
<div id="notes" markdown='1'>
|
205
|
-
|
206
|
-
* first
|
207
|
-
* second
|
208
|
-
* third
|
209
|
-
|
210
|
-
</div>
|
211
|
-
|
212
|
-
Trying this with `InsideBlock` gives:
|
213
|
-
|
214
|
-
puts TextTube::InsideBlock.run s
|
215
|
-
|
216
|
-
<div id="notes">
|
217
|
-
<ul>
|
218
|
-
<li>first</li>
|
219
|
-
<li>second</li>
|
220
|
-
<li>third</li>
|
221
|
-
</ul>
|
222
|
-
|
223
|
-
</div>
|
224
|
-
|
225
|
-
To use it as a filter:
|
226
|
-
|
227
|
-
require 'texttube/base'
|
228
|
-
|
229
|
-
class MyFilter < TextTube::Base
|
230
|
-
register TextTube::InsideBlock
|
231
|
-
end
|
232
|
-
|
233
|
-
myf = MyFilter.new(s)
|
234
|
-
# => "<div id="notes" markdown='1'>\n\n* first\n* second\n* third\n\n</div>\n"
|
235
|
-
|
236
|
-
puts myf.filter
|
237
|
-
|
238
|
-
Gives:
|
239
|
-
|
240
|
-
<div id="notes">
|
241
|
-
<ul>
|
242
|
-
<li>first</li>
|
243
|
-
<li>second</li>
|
244
|
-
<li>third</li>
|
245
|
-
</ul>
|
246
|
-
|
247
|
-
</div>
|
248
|
-
|
249
|
-
### Coderay ###
|
250
|
-
|
251
|
-
Filters an HTML code block and marks it up with [coderay](http://coderay.rubychan.de/):
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
require 'texttube/base'
|
256
|
-
require 'texttube/filters/coderay'
|
257
|
-
require 'rdiscount' # a markdown parser
|
258
|
-
|
259
|
-
class TextWithCode < TextTube::Base
|
260
|
-
register do
|
261
|
-
filter_with :rdiscount do |text|
|
262
|
-
RDiscount.new(text).to_html
|
263
|
-
end
|
264
|
-
end
|
265
|
-
register TextTube::Coderay
|
266
|
-
end
|
267
|
-
|
268
|
-
s = TextWithCode.new <<'STR'
|
269
|
-
# FizzBuzz #
|
270
|
-
|
271
|
-
::::ruby
|
272
|
-
(1..100).each do |n|
|
273
|
-
out = "#{n}: "
|
274
|
-
out << "Fizz" if n % 3 == 0
|
275
|
-
out << "Buzz" if n % 5 == 0
|
276
|
-
puts out
|
277
|
-
end
|
278
|
-
|
279
|
-
That's all folks!
|
280
|
-
STR
|
281
|
-
# => "# FizzBuzz #\n\n ::::ruby\n (1..100).each do |n| \n out = "\#{n}: "\n out << "Fizz" if n % 3 == 0\n out << "Buzz" if n % 5 == 0\n puts out\n end\n\nThat's all folks!\n"
|
282
|
-
|
283
|
-
|
284
|
-
puts s.filter
|
285
|
-
|
286
|
-
Produces:
|
287
|
-
|
288
|
-
<h1>FizzBuzz</h1>
|
289
|
-
|
290
|
-
<pre><code class="CodeRay">(<span class="integer">1</span>..<span class="integer">100</span>).each <span class="keyword">do</span> |n|
|
291
|
-
out = <span class="string"><span class="delimiter">"</span><span class="inline"><span class="inline-delimiter">#{</span>n<span class="inline-delimiter">}</span></span><span class="content">: </span><span class="delimiter">"</span></span>
|
292
|
-
out << <span class="string"><span class="delimiter">"</span><span class="content">Fizz</span><span class="delimiter">"</span></span> <span class="keyword">if</span> n % <span class="integer">3</span> == <span class="integer">0</span>
|
293
|
-
out << <span class="string"><span class="delimiter">"</span><span class="content">Buzz</span><span class="delimiter">"</span></span> <span class="keyword">if</span> n % <span class="integer">5</span> == <span class="integer">0</span>
|
294
|
-
puts out
|
295
|
-
<span class="keyword">end</span></code></pre>
|
296
|
-
|
297
|
-
<p>That's all folks!</p>
|
298
|
-
|
299
|
-
The language was specified with a leading `::::ruby`. It didn't have to be as the default is to use Ruby, but if you want to use any other of the [coderay supported languages](http://coderay.rubychan.de/doc/CodeRay/Scanners.html), that's how to do it.
|
300
|
-
|
301
|
-
### Spiffing ###
|
302
|
-
|
303
|
-
Transforms CSS written in British English into its ugly sister from across the pond. Inspired by [visualidiot's SpiffingCSS](https://github.com/visualidiot/Spiffing).
|
304
|
-
|
305
|
-
content = <<CSS
|
306
|
-
body {
|
307
|
-
background-colour: darkgrey;
|
308
|
-
background-photograph: url(logo.gif);
|
309
|
-
transparency: .7;
|
310
|
-
|
311
|
-
font: 72px "Comic Sans", cursive !please;
|
312
|
-
font-weight: plump;
|
313
|
-
p { text-align: centre }
|
314
|
-
fieldset input {
|
315
|
-
text-transform: capitalise;
|
316
|
-
}
|
317
|
-
}
|
318
|
-
CSS
|
319
|
-
|
320
|
-
require 'texttube/base'
|
321
|
-
require 'texttube/filters/spiffing'
|
322
|
-
|
323
|
-
class CssString < TextTube::Base
|
324
|
-
register TextTube::Spiffing
|
325
|
-
end
|
326
|
-
|
327
|
-
puts CssString.new(content).filter
|
328
|
-
|
329
|
-
# output:
|
330
|
-
|
331
|
-
body {
|
332
|
-
background-color: darkgray;
|
333
|
-
background-image: url(logo.gif);
|
334
|
-
opacity: .7;
|
335
|
-
|
336
|
-
font: 72px "Comic Sans", cursive !important;
|
337
|
-
font-weight: bold;
|
338
|
-
p { text-align: center }
|
339
|
-
fieldset input {
|
340
|
-
text-transform: capitalize;
|
341
|
-
}
|
342
|
-
}
|
343
|
-
|
344
|
-
God save the Queen!
|
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!
|
345
132
|
|
346
133
|
|
347
134
|
### Contributors ###
|
348
135
|
|
349
|
-
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
|
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).
|
350
137
|
|
351
138
|
|
352
139
|
### Licence ###
|
data/lib/texttube/version.rb
CHANGED
data/lib/texttube.rb
CHANGED
@@ -1,23 +1,4 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require_relative "./ext/blank.rb"
|
4
|
-
require_relative "./ext/to_constant.rb"
|
5
|
-
|
6
|
-
# The original. Maybe. I haven't checked.
|
7
|
-
module TextTube
|
8
|
-
|
9
|
-
# Require all the filters.
|
10
|
-
# The `map` is there to show the result of this and
|
11
|
-
# show which libs were required (if so desired).
|
12
|
-
# @return [Array<String,TrueClass>]
|
13
|
-
def self.load_all_filters
|
14
|
-
Dir.glob( File.join File.dirname(__FILE__), "/texttube/filters/*.rb" )
|
15
|
-
.reject{|name| name.end_with? "version.rb" }
|
16
|
-
.map{|filter|
|
17
|
-
tf = require filter
|
18
|
-
[File.basename(filter, ".rb").gsub("_",""), tf]
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
end
|
4
|
+
require_relative "./ext/to_constant.rb"
|
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec/its'
|
3
|
+
require_relative "../lib/texttube/base.rb"
|
4
|
+
|
5
|
+
module TextTube # for convenience
|
6
|
+
|
7
|
+
describe Base do
|
8
|
+
|
9
|
+
context "Checking the basics" do
|
10
|
+
context "Instances" do
|
11
|
+
subject { Base.new "anything" }
|
12
|
+
it { should be_a_kind_of String }
|
13
|
+
it { should respond_to :options }
|
14
|
+
its(:options) { should respond_to :empty? }
|
15
|
+
its(:options) { should be_empty }
|
16
|
+
end
|
17
|
+
context "Class methods and their defaults" do
|
18
|
+
subject { Base }
|
19
|
+
it { should respond_to :options }
|
20
|
+
its(:options) { should respond_to :empty? }
|
21
|
+
its(:options) { should be_empty }
|
22
|
+
it { should respond_to :reset! }
|
23
|
+
it { should respond_to :filters }
|
24
|
+
its(:filters) { should respond_to :empty? }
|
25
|
+
its(:filters) { should be_empty }
|
26
|
+
it { should respond_to :register }
|
27
|
+
it { should respond_to :inherited }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec/its'
|
3
|
+
require_relative "../lib/texttube/base.rb"
|
4
|
+
require_relative "../lib/texttube/filterable.rb"
|
5
|
+
|
6
|
+
module TextTube # for convenience
|
7
|
+
|
8
|
+
describe "Example usage" do
|
9
|
+
before :all do
|
10
|
+
module AFilter
|
11
|
+
extend TextTube::Filterable
|
12
|
+
|
13
|
+
filter_with :double do |text|
|
14
|
+
text * 2
|
15
|
+
end
|
16
|
+
|
17
|
+
filter_with :triple do |text|
|
18
|
+
text * 3
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module BFil
|
23
|
+
extend TextTube::Filterable
|
24
|
+
|
25
|
+
filter_with :spacial do |current,options|
|
26
|
+
current.split(//).join " "
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class NeuS < TextTube::Base
|
31
|
+
register BFil
|
32
|
+
register AFilter
|
33
|
+
register do
|
34
|
+
filter_with :dashes do |text|
|
35
|
+
"---#{text}---"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end # before
|
40
|
+
|
41
|
+
context "Instantiation" do
|
42
|
+
let(:n) { NeuS.new "abc" }
|
43
|
+
subject { n }
|
44
|
+
it { should == "abc" }
|
45
|
+
|
46
|
+
context "filtering" do
|
47
|
+
context "With no arguments" do
|
48
|
+
subject { n.filter }
|
49
|
+
it { should == "---a b ca b ca b ca b ca b ca b c---" }
|
50
|
+
end
|
51
|
+
context "Given a specific filter" do
|
52
|
+
subject { n.filter :spacial }
|
53
|
+
it { should == "a b c" }
|
54
|
+
end
|
55
|
+
context "Given several specific filters" do
|
56
|
+
subject { n.filter :spacial, :dashes, :spacial }
|
57
|
+
it { should == "- - - a b c - - -" }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end # inconvenient
|
data/spec/spec_helper.rb
CHANGED
data/texttube.gemspec
CHANGED
@@ -4,17 +4,13 @@ require "texttube/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "texttube"
|
7
|
-
s.summary = "
|
8
|
-
s.description
|
9
|
-
Some markdown filters I find useful.
|
10
|
-
EOF
|
7
|
+
s.summary = "Create chainable filters with ease."
|
8
|
+
s.description = s.summary
|
11
9
|
s.version = TextTube::VERSION
|
12
10
|
s.platform = Gem::Platform::RUBY
|
13
11
|
s.required_ruby_version = ">= 1.9.1"
|
14
12
|
s.author = "Iain Barnett"
|
15
13
|
s.files = `git ls-files`.split("\n")
|
16
|
-
s.add_dependency("nokogiri", '~>1.5.9' )
|
17
|
-
s.add_dependency("coderay", '~>1.0' )
|
18
14
|
s.email = "iainspeed @nospam@ gmail.com"
|
19
15
|
s.test_files = `git ls-files -- {test,spec,features}`.split("\n")
|
20
16
|
s.homepage = "https://github.com/yb66/TextTube"
|
metadata
CHANGED
@@ -1,64 +1,23 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: texttube
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 5
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 5.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 6.0.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Iain Barnett
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
name: nokogiri
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
|
-
requirements:
|
26
|
-
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 17
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 5
|
32
|
-
- 9
|
33
|
-
version: 1.5.9
|
34
|
-
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: coderay
|
38
|
-
prerelease: false
|
39
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
|
-
requirements:
|
42
|
-
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 15
|
45
|
-
segments:
|
46
|
-
- 1
|
47
|
-
- 0
|
48
|
-
version: "1.0"
|
49
|
-
type: :runtime
|
50
|
-
version_requirements: *id002
|
51
|
-
description: " Some markdown filters I find useful.\n"
|
11
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Create chainable filters with ease.
|
52
14
|
email: iainspeed @nospam@ gmail.com
|
53
15
|
executables: []
|
54
|
-
|
55
16
|
extensions: []
|
56
|
-
|
57
17
|
extra_rdoc_files: []
|
58
|
-
|
59
|
-
|
60
|
-
- .
|
61
|
-
- .travis.yml
|
18
|
+
files:
|
19
|
+
- ".gitignore"
|
20
|
+
- ".travis.yml"
|
62
21
|
- CHANGES.md
|
63
22
|
- Gemfile
|
64
23
|
- README.md
|
@@ -68,61 +27,35 @@ files:
|
|
68
27
|
- lib/texttube.rb
|
69
28
|
- lib/texttube/base.rb
|
70
29
|
- lib/texttube/filterable.rb
|
71
|
-
- lib/texttube/filters/coderay.rb
|
72
|
-
- lib/texttube/filters/embedding_audio.rb
|
73
|
-
- lib/texttube/filters/embedding_video.rb
|
74
|
-
- lib/texttube/filters/inside_block.rb
|
75
|
-
- lib/texttube/filters/link_reffing.rb
|
76
|
-
- lib/texttube/filters/spiffing.rb
|
77
30
|
- lib/texttube/version.rb
|
78
|
-
- spec/
|
79
|
-
- spec/
|
80
|
-
- spec/inside_block_spec.rb
|
81
|
-
- spec/link_reffing_spec.rb
|
82
|
-
- spec/markdownfilters_spec.rb
|
31
|
+
- spec/base_spec.rb
|
32
|
+
- spec/examples_spec.rb
|
83
33
|
- spec/spec_helper.rb
|
84
|
-
- spec/spiffing_spec.rb
|
85
34
|
- texttube.gemspec
|
86
35
|
homepage: https://github.com/yb66/TextTube
|
87
36
|
licenses: []
|
88
|
-
|
37
|
+
metadata: {}
|
89
38
|
post_install_message:
|
90
39
|
rdoc_options: []
|
91
|
-
|
92
|
-
require_paths:
|
40
|
+
require_paths:
|
93
41
|
- lib
|
94
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
-
|
96
|
-
requirements:
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
97
44
|
- - ">="
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
hash: 49
|
100
|
-
segments:
|
101
|
-
- 1
|
102
|
-
- 9
|
103
|
-
- 1
|
45
|
+
- !ruby/object:Gem::Version
|
104
46
|
version: 1.9.1
|
105
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
-
|
107
|
-
requirements:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
108
49
|
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
|
111
|
-
segments:
|
112
|
-
- 0
|
113
|
-
version: "0"
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
114
52
|
requirements: []
|
115
|
-
|
116
53
|
rubyforge_project:
|
117
|
-
rubygems_version:
|
54
|
+
rubygems_version: 2.2.2
|
118
55
|
signing_key:
|
119
|
-
specification_version:
|
120
|
-
summary:
|
121
|
-
test_files:
|
122
|
-
- spec/
|
123
|
-
- spec/
|
124
|
-
- spec/inside_block_spec.rb
|
125
|
-
- spec/link_reffing_spec.rb
|
126
|
-
- spec/markdownfilters_spec.rb
|
56
|
+
specification_version: 4
|
57
|
+
summary: Create chainable filters with ease.
|
58
|
+
test_files:
|
59
|
+
- spec/base_spec.rb
|
60
|
+
- spec/examples_spec.rb
|
127
61
|
- spec/spec_helper.rb
|
128
|
-
- spec/spiffing_spec.rb
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
module TextTube
|
3
|
-
|
4
|
-
require 'nokogiri'
|
5
|
-
require_relative "../../ext/blank.rb"
|
6
|
-
require 'coderay'
|
7
|
-
require_relative "../filterable.rb"
|
8
|
-
|
9
|
-
# a filter for Coderay
|
10
|
-
module Coderay
|
11
|
-
extend Filterable
|
12
|
-
|
13
|
-
filter_with :coderay do |text|
|
14
|
-
TextTube::Coderay.run text
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
# @param [String] content
|
19
|
-
# @param [Hash] options
|
20
|
-
# @return [String]
|
21
|
-
def self.run(content, options={})
|
22
|
-
options = {lang: :ruby } if options.blank?
|
23
|
-
doc = Nokogiri::HTML::fragment(content)
|
24
|
-
|
25
|
-
code_blocks = doc.xpath("pre/code").map do |code_block|
|
26
|
-
#un-escape as Coderay will escape it again
|
27
|
-
inner_html = code_block.inner_html
|
28
|
-
|
29
|
-
# following the convention of Rack::Codehighlighter
|
30
|
-
if inner_html.start_with?("::::")
|
31
|
-
lines = inner_html.split("\n")
|
32
|
-
options[:lang] = lines.shift.match(%r{::::(\w+)})[1].to_sym
|
33
|
-
inner_html = lines.join("\n")
|
34
|
-
end
|
35
|
-
|
36
|
-
if (options[:lang] == :skip) || (! options.has_key? :lang )
|
37
|
-
code_block.inner_html = inner_html
|
38
|
-
else
|
39
|
-
code = Coderay.codify(Coderay.html_unescape(inner_html), options[:lang])
|
40
|
-
code_block.inner_html = code
|
41
|
-
code_block["class"] = "CodeRay"
|
42
|
-
end
|
43
|
-
end#block
|
44
|
-
|
45
|
-
doc.to_s
|
46
|
-
end#def
|
47
|
-
|
48
|
-
# @private
|
49
|
-
# Unescape the HTML as the Coderay scanner won't work otherwise.
|
50
|
-
def self.html_unescape(a_string)
|
51
|
-
a_string.gsub('&', '&').gsub('<', '<').gsub('>',
|
52
|
-
'>').gsub('"', '"')
|
53
|
-
end#def
|
54
|
-
|
55
|
-
# Run the Coderay scanner.
|
56
|
-
# @private
|
57
|
-
# @param [String] str
|
58
|
-
# @param [String] lang
|
59
|
-
# @example
|
60
|
-
# self.class.codify "x = 2", "ruby"
|
61
|
-
def self.codify(str, lang)
|
62
|
-
CodeRay.scan(str, lang).html
|
63
|
-
end#def
|
64
|
-
|
65
|
-
end#class
|
66
|
-
|
67
|
-
|
68
|
-
end#module
|