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
@@ -1,61 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require_relative "../filterable.rb"
|
3
|
-
|
4
|
-
module TextTube
|
5
|
-
|
6
|
-
# Embed some audio via [audio[link|name]]
|
7
|
-
module EmbeddingAudio
|
8
|
-
extend TextTube::Filterable
|
9
|
-
|
10
|
-
filter_with :embeddingaudio do |text|
|
11
|
-
TextTube::EmbeddingAudio.run text
|
12
|
-
end
|
13
|
-
|
14
|
-
# default attributes
|
15
|
-
DEFAULTS = {
|
16
|
-
src_base: "/streams/",
|
17
|
-
preload: "metadata",
|
18
|
-
fallback_text: "Your browser does not support HTML5, update your browser you fool!",
|
19
|
-
controls: "controls",
|
20
|
-
}
|
21
|
-
|
22
|
-
# [audio[link|name]]
|
23
|
-
R_link = / # [audio[url|description]]
|
24
|
-
\[audio\[ # opening square brackets
|
25
|
-
([^\|]+) # link
|
26
|
-
\| # separator
|
27
|
-
([^\[]+) # description
|
28
|
-
\]\] # closing square brackets
|
29
|
-
/x
|
30
|
-
|
31
|
-
|
32
|
-
# @param [String] content
|
33
|
-
# @param [Hash] options
|
34
|
-
# @return [String]
|
35
|
-
def self.run(content, options={})
|
36
|
-
options ||= {}
|
37
|
-
attributes = DEFAULTS.merge options
|
38
|
-
|
39
|
-
content.gsub( R_link ) { |m|
|
40
|
-
url,desc = $1,$2
|
41
|
-
EmbeddingAudio::render_tag(url,desc,attributes)
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
# Does the grunt work of rendering the tag.
|
47
|
-
# @private
|
48
|
-
# @param [String] link
|
49
|
-
# @param [String] desc
|
50
|
-
# @param [Hash] attributes
|
51
|
-
def self.render_tag(link,desc,attributes)
|
52
|
-
fallback_text = attributes.delete(:fallback_text)
|
53
|
-
src_base = attributes.delete(:src_base)
|
54
|
-
make_inner = ->(lnk){%Q!<source src='#{src_base}#{lnk}' type='audio/#{File.extname(lnk)[1..-1]}' />!}
|
55
|
-
inner = make_inner.( link )
|
56
|
-
inner += make_inner.( link.sub(/m4a$/, "ogg") ) if File.extname(link) == ".m4a"
|
57
|
-
%Q!<div class='audio'><h3>#{desc}</h3><audio #{attributes.map{|(k,v)| "#{k}='#{v}'" }.join(" ")}>#{inner}#{fallback_text}</audio></div>!.strip.gsub /\s+/, " "
|
58
|
-
end
|
59
|
-
|
60
|
-
end # class
|
61
|
-
end # module
|
@@ -1,111 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require_relative "../filterable.rb"
|
3
|
-
|
4
|
-
module TextTube
|
5
|
-
|
6
|
-
# Embed video via [embed_SIZE[url|description]]
|
7
|
-
module EmbeddingVideo
|
8
|
-
extend TextTube::Filterable
|
9
|
-
|
10
|
-
filter_with :embeddingvideo do |text|
|
11
|
-
TextTube::EmbeddingVideo.run text
|
12
|
-
end
|
13
|
-
|
14
|
-
# List of available sites.
|
15
|
-
SITES = {
|
16
|
-
# "video.google".to_sym => ['http://www.video.google.com/',->(w,h,url){ %Q!! }],
|
17
|
-
# :brightcove => ['http://www.brightcove.com/',->(w,h,url){ %Q!! }],
|
18
|
-
# :photobucket => ['http://www.photobucket.com/',->(w,h,url){ %Q!! }],
|
19
|
-
:youtube => {
|
20
|
-
name: 'http://www.youtube.com/',
|
21
|
-
html: ->(w,h,url){ %Q!<iframe title="YouTube video player" class="youtube-player" type="text/html" width="#{w}" height="#{h}" src="#{url}" frameborder="0"></iframe>!.strip},
|
22
|
-
url_morph: ->(orig){ orig.sub( %r{watch\?v=}, 'embed/') }
|
23
|
-
},
|
24
|
-
# :dailymotion => ['http://dailymotion.com/',->(w,h,url){ %Q!! }],
|
25
|
-
# :ifilm => ['http://ifilm.com/',->(w,h,url){ %Q!! }],
|
26
|
-
# :break => ['http://break.com/',->(w,h,url){ %Q!! }],
|
27
|
-
# :blip => ['http://blip.tv/',->(w,h,url){ %Q!! }],
|
28
|
-
# :grindtv => ['http://www.grindtv.com/',->(w,h,url){ %Q!! }],
|
29
|
-
# :metacafe => ['http://metacafe.com/',->(w,h,url){ %Q!! }],
|
30
|
-
# :myspace => ['http://vids.myspace.com/',->(w,h,url){ %Q!! }],
|
31
|
-
# :vimeo => ['http://vimeo.com/',->(w,h,url){ %Q!! }],
|
32
|
-
# :buzznet => ['http://buzznet.com/',->(w,h,url){ %Q!! }],
|
33
|
-
# :liveleak => ['http://www.liveleak.com/',->(w,h,url){ %Q!! }],
|
34
|
-
# :stupidvideos => ['http://stupidvideos.com/',->(w,h,url){ %Q!! }],
|
35
|
-
# :flixya => ['http://www.flixya.com/',->(w,h,url){ %Q!! }],
|
36
|
-
# :gofish => ['http://gofish.com/',->(w,h,url){ %Q!! }],
|
37
|
-
# :kewego => ['http://kewego.com/',->(w,h,url){ %Q!! }],
|
38
|
-
# :lulu => ['http://lulu.tv/',->(w,h,url){ %Q!! }],
|
39
|
-
# :pandora => ['http://pandora.tv/',->(w,h,url){ %Q!! }],
|
40
|
-
# :viddler => ['http://www.viddler.com/',->(w,h,url){ %Q!! }],
|
41
|
-
# :myheavy => ['http://myheavy.com/',->(w,h,url){ %Q!! }],
|
42
|
-
# :putfile => ['http://putfile.com/',->(w,h,url){ %Q!! }],
|
43
|
-
# :stupidvideos => ['http://stupidvideos.com/',->(w,h,url){ %Q!! }],
|
44
|
-
# :vmix => ['http://vmix.com/',->(w,h,url){ %Q!! }],
|
45
|
-
# :zippyvideos => ['http://zippyvideos.com/',->(w,h,url){ %Q!! }],
|
46
|
-
# :castpost => ['http://castpost.com/',->(w,h,url){ %Q!! }],
|
47
|
-
# :dotv => ['http://dotv.com/',->(w,h,url){ %Q!! }],
|
48
|
-
# :famster => ['http://famster.com/',->(w,h,url){ %Q!! }],
|
49
|
-
# :gawkk => ['http://gawkk.com/',->(w,h,url){ %Q!! }],
|
50
|
-
# :tubetorial => ['http://tubetorial.com/',->(w,h,url){ %Q!! }],
|
51
|
-
# :MeraVideo => ['http://MeraVideo.com/',->(w,h,url){ %Q!! }],
|
52
|
-
# :Porkolt => ['http://Porkolt.com/',->(w,h,url){ %Q!! }],
|
53
|
-
# :VideoWebTown => ['http://VideoWebTown.com/',->(w,h,url){ %Q!! }],
|
54
|
-
# :Vidmax => ['http://Vidmax.com/',->(w,h,url){ %Q!! }],
|
55
|
-
# :clipmoon => ['http://www.clipmoon.com/',->(w,h,url){ %Q!! }],
|
56
|
-
# :motorsportmad => ['http://motorsportmad.com/',->(w,h,url){ %Q!! }],
|
57
|
-
# :thatshow => ['http://www.thatshow.com/',->(w,h,url){ %Q!! }],
|
58
|
-
# :clipchef => ['http://clipchef.com/',->(w,h,url){ %Q!! }],
|
59
|
-
}
|
60
|
-
|
61
|
-
# Some standard player sizes.
|
62
|
-
SIZES = {
|
63
|
-
small: [560,345],
|
64
|
-
medium: [640,390],
|
65
|
-
large: [853,510],
|
66
|
-
largest: [1280,750] }
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
# r_url = %r{
|
71
|
-
# http(?:s)?\:// #http https ://
|
72
|
-
# (?:(?:www|vids)\.)? # www. vids.
|
73
|
-
# (.+?) # domain name (hopefully)
|
74
|
-
# \.(?:com|tv) # .com .tv
|
75
|
-
# /? # optional trailing slash
|
76
|
-
# }x
|
77
|
-
|
78
|
-
# Pattern for deconstructing [embed_SIZE[url|description]]
|
79
|
-
R_link = / # [embed_SIZE[url|description]]
|
80
|
-
\[embed\_?([a-z]+)?\[ # opening square brackets
|
81
|
-
(\S+) # link
|
82
|
-
\| # separator
|
83
|
-
([^\[]+) # description
|
84
|
-
\]\] # closing square brackets
|
85
|
-
/x
|
86
|
-
|
87
|
-
|
88
|
-
# @param [String] content
|
89
|
-
# @param [Hash] options
|
90
|
-
# @return [String]
|
91
|
-
def self.run(content, options={})
|
92
|
-
options ||= {}
|
93
|
-
content.gsub( R_link ) { |m|
|
94
|
-
size,url,desc = $1,$2,$3
|
95
|
-
|
96
|
-
unless size.nil?
|
97
|
-
res = SIZES[size.to_sym] || SIZES[:medium] #resolution
|
98
|
-
else
|
99
|
-
res = SIZES[:medium]
|
100
|
-
end
|
101
|
-
|
102
|
-
#"res: #{res.inspect} size: #{size}, url:#{url}, desc:#{desc}"
|
103
|
-
|
104
|
-
emb_url = SITES[:youtube][:url_morph].(url)
|
105
|
-
SITES[:youtube][:html].(res.first, res.last, emb_url )
|
106
|
-
}
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
end # class
|
111
|
-
end # module
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'nokogiri'
|
3
|
-
require_relative "../filterable.rb"
|
4
|
-
|
5
|
-
module TextTube
|
6
|
-
|
7
|
-
# This finds html tags with "markdown='1'" as an attribute, runs markdown over the contents, then removes the markdown attribute, allowing markdown within html blocks
|
8
|
-
module InsideBlock
|
9
|
-
extend TextTube::Filterable
|
10
|
-
|
11
|
-
filter_with :insideblock do |text|
|
12
|
-
TextTube::InsideBlock.run text
|
13
|
-
end
|
14
|
-
|
15
|
-
# @param [String] content
|
16
|
-
# @param [Hash] options
|
17
|
-
# @option options [Constant] The markdown parser to use. I'm not sure this bit really works for other parsers than RDiscount.
|
18
|
-
def self.run( content, options={})
|
19
|
-
options ||= {}
|
20
|
-
if options[:markdown_parser].nil?
|
21
|
-
require 'rdiscount'
|
22
|
-
markdown_parser=RDiscount
|
23
|
-
end
|
24
|
-
doc = Nokogiri::HTML::fragment(content)
|
25
|
-
|
26
|
-
(doc/"*[@markdown='1']").each do |ele|
|
27
|
-
ele.inner_html = markdown_parser.new(ele.inner_html).to_html
|
28
|
-
ele.remove_attribute("markdown")
|
29
|
-
end
|
30
|
-
|
31
|
-
doc.to_s
|
32
|
-
end # run
|
33
|
-
|
34
|
-
end # class
|
35
|
-
end # module
|
@@ -1,144 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require_relative "../filterable.rb"
|
3
|
-
|
4
|
-
module TextTube
|
5
|
-
|
6
|
-
# @author Iain Barnett
|
7
|
-
# A class to take links in the format `[[link|description]]` and give them a number reference, then output them in markdown format. Note: this is not the same as reference links in markdown, this is more akin to the way books will refer to references or footnotes with a number.
|
8
|
-
#P.S. I don't like to make functions private, we're all adults, so to use this call Link_reffing#run, #format_links is for internal use.
|
9
|
-
module LinkReffing
|
10
|
-
extend Filterable
|
11
|
-
|
12
|
-
filter_with :linkreffing do |text, options|
|
13
|
-
TextTube::LinkReffing.run text, options
|
14
|
-
end
|
15
|
-
|
16
|
-
# These are the html codes for superscript 0 - 9
|
17
|
-
UNITS = ['⁰', '¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹'] #unicode superscript numbers
|
18
|
-
|
19
|
-
# Matches [[link|description]]
|
20
|
-
Pattern = /
|
21
|
-
\[\[ # opening square brackets
|
22
|
-
(?<link>\S+)
|
23
|
-
\s*\|\s* # separator
|
24
|
-
(?<description>[^\[]+)
|
25
|
-
\]\] # closing square brackets
|
26
|
-
/x
|
27
|
-
|
28
|
-
# a lambda function to transform a link and a number into a markdown reference link.
|
29
|
-
# @param [String] lnk The url.
|
30
|
-
# @param [String] num The reference number.
|
31
|
-
Reffer = ->(lnk, num){ %Q![#{lnk}](##{num} "Jump to reference")!}
|
32
|
-
|
33
|
-
# A lambda to transform a link and a number to a HTML reference link.
|
34
|
-
RefHTMLer = ->(lnk, num){ %Q!<a href="##{num}" title="Jump to reference">#{lnk}</a>! }
|
35
|
-
|
36
|
-
# A lambda to transform a href and a description into an HTML link.
|
37
|
-
HTMLer = ->(lnk, desc){ %Q! <a href="#{lnk}">#{desc}</a>! }
|
38
|
-
|
39
|
-
# A lambda to transform a link and a description into an inline Markdown link.
|
40
|
-
Markdowner = ->(lnk, desc){ %Q! [#{desc}](#{lnk})! }
|
41
|
-
|
42
|
-
# Noner = ->(_,_) { "" } # this isn't needed but will sit here as a reminder.
|
43
|
-
|
44
|
-
|
45
|
-
# Takes markdown content with ref links and turns it into 100% markdown.
|
46
|
-
# @param [String] content The markdown content with links to ref.
|
47
|
-
# @option options [#to_s] :format The format of the link you want added. The options are :html, :markdown. The default is :markdown
|
48
|
-
# @option options [#to_s] :kind The kind of link you want added. The options are :reference, :inline, :none. The default is :reference
|
49
|
-
# @option options [String,nil] :div_id ID of the div to wrap reference links in. Defaults to "reflinks". Set to nil or false for no div.
|
50
|
-
# @return [String] The string formatted as markdown e.g. `[http://cheat.errtheblog.com/s/yard/more/and/m...](http://cheat.errtheblog.com/s/yard/more/and/more/and/more/ "http://cheat.errtheblog.com/s/yard/more/and/more/and/more/")`
|
51
|
-
def self.run(content, options={})
|
52
|
-
return content if content.blank?
|
53
|
-
text = content.dup
|
54
|
-
options ||= {}
|
55
|
-
kind = options.fetch :kind, :reference
|
56
|
-
format = options.fetch( :format, :markdown )
|
57
|
-
formatter = if kind == :inline
|
58
|
-
if format == :html
|
59
|
-
HTMLer
|
60
|
-
else
|
61
|
-
Markdowner
|
62
|
-
end
|
63
|
-
elsif kind == :none
|
64
|
-
nil # none is needed
|
65
|
-
else # kind == :reference
|
66
|
-
if format == :html
|
67
|
-
RefHTMLer
|
68
|
-
else
|
69
|
-
Reffer
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
div_id = options.has_key?(:div_id) ?
|
74
|
-
options[:div_id] :
|
75
|
-
:reflinks
|
76
|
-
|
77
|
-
cur = 0 #current number
|
78
|
-
|
79
|
-
# if there are no reflinks found
|
80
|
-
# this will remain false
|
81
|
-
# and `divit` won't be run.
|
82
|
-
has_reflinks = false
|
83
|
-
|
84
|
-
links = [] #to store the matches
|
85
|
-
|
86
|
-
text.gsub! Pattern do |md| #block to pass to gsub
|
87
|
-
has_reflinks = true
|
88
|
-
if kind == :inline
|
89
|
-
formatter.($1,$2)
|
90
|
-
elsif kind == :none
|
91
|
-
""
|
92
|
-
else # kind == :reference
|
93
|
-
mags = cur.divmod(10) #get magnitude of number
|
94
|
-
ref_tag = mags.first >= 1 ?
|
95
|
-
UNITS[mags.first] :
|
96
|
-
'' #sort out tens
|
97
|
-
|
98
|
-
ref_tag += UNITS[mags.last] #units
|
99
|
-
retval = formatter.(ref_tag,cur)
|
100
|
-
|
101
|
-
links << [$1, $2, cur] # add to the words list
|
102
|
-
cur += 1 #increase current number
|
103
|
-
retval
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
if !links.empty?
|
108
|
-
if has_reflinks && div_id
|
109
|
-
"#{text}\n#{LinkReffing.divit( div_id ) { format_links(links) }}"
|
110
|
-
else
|
111
|
-
"#{text}\n#{format_links(links)}"
|
112
|
-
end
|
113
|
-
else
|
114
|
-
text
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
|
119
|
-
# This func outputs the link as valid markdown.
|
120
|
-
# @param [Array<String,String,Integer>] links A list of 2-length arrays containing the url and the description and the reference number.
|
121
|
-
def self.format_links( links )
|
122
|
-
links.map{ |(link, description, cur)|
|
123
|
-
display_link = link.length >= 45 ?
|
124
|
-
link[0,45] + "..." :
|
125
|
-
link
|
126
|
-
%Q!\n<a name="#{cur}"></a>#{LeftSq}#{cur}#{RightSq} [#{display_link}](#{link} "#{link}") #{description}\n\n!
|
127
|
-
}.join
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
# Wraps things in a div. If no id given, no div.
|
132
|
-
# @param [#to_s] id The ID attribute for the div.
|
133
|
-
def self.divit( id )
|
134
|
-
"<div markdown='1' id='#{id}'>#{ yield }</div>"
|
135
|
-
end
|
136
|
-
|
137
|
-
# HTML code for [
|
138
|
-
LeftSq = "["
|
139
|
-
# HTML code for ]
|
140
|
-
RightSq = "]"
|
141
|
-
|
142
|
-
end#class
|
143
|
-
|
144
|
-
end#module
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require_relative "../filterable.rb"
|
3
|
-
|
4
|
-
module TextTube
|
5
|
-
|
6
|
-
# Will transform the Queen's English into American English for use in CSS, as the current CSS standards prefer ugly words.
|
7
|
-
# Inspired by visualidiot's SpiffingCSS (see http://spiffingcss.com/)
|
8
|
-
module Spiffing
|
9
|
-
extend TextTube::Filterable
|
10
|
-
|
11
|
-
filter_with :spiffing do |text|
|
12
|
-
TextTube::Spiffing.run text
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
# The dictionary.
|
17
|
-
DICTIONARY = {
|
18
|
-
# Queen's English # Primitive English from our stateside
|
19
|
-
# friends from across the pond.
|
20
|
-
'colour' => 'color',
|
21
|
-
'grey' => 'gray',
|
22
|
-
'!please' => '!important',
|
23
|
-
'transparency' => 'opacity',
|
24
|
-
'centre' => 'center',
|
25
|
-
'plump' => 'bold',
|
26
|
-
'photograph' => 'image',
|
27
|
-
'capitalise' => 'capitalize'
|
28
|
-
}
|
29
|
-
|
30
|
-
# @param [String] content
|
31
|
-
# @param [Hash] options
|
32
|
-
def self.run( content, options={})
|
33
|
-
ugly_child = content.dup
|
34
|
-
# warn ugly_child
|
35
|
-
DICTIONARY.each do |english, ugly|
|
36
|
-
ugly_child.sub! english, ugly
|
37
|
-
# warn ugly_child
|
38
|
-
end
|
39
|
-
ugly_child
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/spec/coderay_spec.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require_relative "../lib/texttube.rb"
|
5
|
-
require_relative "../lib/texttube/filters/coderay.rb"
|
6
|
-
|
7
|
-
module TextTube
|
8
|
-
describe TextTube do
|
9
|
-
|
10
|
-
let(:coderayed){
|
11
|
-
%Q!<h2>Hello</h2>\n\n<p>This is some code:</p>\n\n<pre><code class="CodeRay">[<span class="integer">1</span>,<span class="integer">2</span>,<span class="integer">3</span>].map{|x| + <span class="integer">1</span> }\n</code></pre>\n\n<p>And this is the result:\n [2,3,4]</p>\n\n<p>Thankyou</p>\n!
|
12
|
-
}
|
13
|
-
|
14
|
-
let(:notrayed) {
|
15
|
-
"<h2>Hello</h2>\n\n<p>This is some code:</p>\n\n<pre><code>[1,2,3].map{|x| + 1 }\n</code></pre>\n\n<p>And this is the result:\n [2,3,4]</p>\n\n<p>Thankyou</p>\n"
|
16
|
-
}
|
17
|
-
|
18
|
-
describe Coderay do
|
19
|
-
context "Given some text" do
|
20
|
-
context "With some code to be rayed in it" do
|
21
|
-
context "That has a language hint" do
|
22
|
-
let(:content) { <<CODE
|
23
|
-
<pre><code>::::ruby
|
24
|
-
{"one" => 1 }
|
25
|
-
</code></pre>
|
26
|
-
CODE
|
27
|
-
}
|
28
|
-
let(:expected) { <<HTML
|
29
|
-
<pre><code class="CodeRay">{<span class="string"><span class="delimiter">"</span><span class="content">one</span><span class="delimiter">"</span></span> => <span class="integer">1</span> }</code></pre>
|
30
|
-
HTML
|
31
|
-
}
|
32
|
-
let(:wrong) { <<CODE
|
33
|
-
<pre><code>::::json
|
34
|
-
{"one" => 1 }
|
35
|
-
</code></pre>
|
36
|
-
CODE
|
37
|
-
}
|
38
|
-
|
39
|
-
subject { TextTube::Coderay.run content }
|
40
|
-
it { should_not be_nil }
|
41
|
-
it { should == expected }
|
42
|
-
it { should_not == TextTube::Coderay.run(wrong) }
|
43
|
-
end
|
44
|
-
context "That has no language hint" do
|
45
|
-
let(:content) { notrayed }
|
46
|
-
let(:expected) { coderayed }
|
47
|
-
|
48
|
-
subject { TextTube::Coderay.run content }
|
49
|
-
it { should_not be_nil }
|
50
|
-
it { should == expected }
|
51
|
-
end
|
52
|
-
context "That has a 'skip' language hint" do
|
53
|
-
let(:content) { <<CODE
|
54
|
-
<pre><code>::::skip
|
55
|
-
{"one" => 1 }
|
56
|
-
</code></pre>
|
57
|
-
CODE
|
58
|
-
}
|
59
|
-
let(:expected) { <<CODE
|
60
|
-
<pre><code>{"one" => 1 }</code></pre>
|
61
|
-
CODE
|
62
|
-
}
|
63
|
-
|
64
|
-
subject { TextTube::Coderay.run content }
|
65
|
-
it { should_not be_nil }
|
66
|
-
it { should == expected }
|
67
|
-
end
|
68
|
-
end # context
|
69
|
-
|
70
|
-
context "With no code to be rayed in it" do
|
71
|
-
let(:content) { %Q$The[UtterFAIL website](http://utterfail.info/ "UtterFAIL!") is good.$ }
|
72
|
-
let(:expected) { content }
|
73
|
-
subject { TextTube::Coderay.run content }
|
74
|
-
it { should_not be_nil }
|
75
|
-
it { should == expected }
|
76
|
-
end # context
|
77
|
-
end # context
|
78
|
-
|
79
|
-
context "Given no text" do
|
80
|
-
subject { TextTube::Coderay.run "" }
|
81
|
-
it { should_not be_nil }
|
82
|
-
it { should == "" }
|
83
|
-
end # context
|
84
|
-
|
85
|
-
end # describe Coderay
|
86
|
-
end # describe TextTube
|
87
|
-
end # module
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require_relative "../lib/texttube.rb"
|
5
|
-
require_relative "../lib/texttube/filters/embedding_audio.rb"
|
6
|
-
|
7
|
-
|
8
|
-
module TextTube
|
9
|
-
describe TextTube do
|
10
|
-
|
11
|
-
describe EmbeddingAudio do
|
12
|
-
context "Given some text" do
|
13
|
-
let(:content) { "[audio[a24.m4a|A24]]" }
|
14
|
-
let(:expected) {
|
15
|
-
%q[<div class='audio'><h3>A24</h3><audio preload='metadata' controls='controls'><source src='/streams/a24.m4a' type='audio/m4a' /><source src='/streams/a24.ogg' type='audio/ogg' />Your browser does not support HTML5, update your browser you fool!</audio></div>]
|
16
|
-
}
|
17
|
-
context "containing valid extended markdown for audio" do
|
18
|
-
context "with no options" do
|
19
|
-
subject { TextTube::EmbeddingAudio.run content }
|
20
|
-
it { should_not be_nil }
|
21
|
-
it { should be == expected }
|
22
|
-
end
|
23
|
-
context "with src_base given as an option" do
|
24
|
-
subject { TextTube::EmbeddingAudio.run content, {src_base: "/files/" } }
|
25
|
-
it { should_not be_nil }
|
26
|
-
it { should_not == expected }
|
27
|
-
it { should match(%r{^.+\ssrc\='/files/\S+?'\s.+$}) }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
context "containing invalid extended markdown for audio" do
|
31
|
-
let(:content) { "audio[a24.m4a|A24]]" }
|
32
|
-
subject { TextTube::EmbeddingAudio.run content }
|
33
|
-
it { should_not be_nil }
|
34
|
-
it { should_not be == expected }
|
35
|
-
it { should == content }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end # describe
|
40
|
-
|
41
|
-
end # describe TextTube
|
42
|
-
end
|
data/spec/inside_block_spec.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require_relative "../lib/texttube.rb"
|
3
|
-
require_relative "../lib/texttube/filters/inside_block.rb"
|
4
|
-
|
5
|
-
describe "InsideBlock" do
|
6
|
-
let(:content) { <<HTML
|
7
|
-
<div class='wrapper' id='sidebar' markdown='1'>
|
8
|
-
## This is a sidebar ##
|
9
|
-
|
10
|
-
* Written
|
11
|
-
* in
|
12
|
-
* markdown
|
13
|
-
|
14
|
-
Sometimes this is useful.
|
15
|
-
</div>
|
16
|
-
HTML
|
17
|
-
}
|
18
|
-
let(:expected) { <<HTML
|
19
|
-
<div class="wrapper" id="sidebar">
|
20
|
-
<h2>This is a sidebar</h2>
|
21
|
-
|
22
|
-
<ul>
|
23
|
-
<li>Written</li>
|
24
|
-
<li>in</li>
|
25
|
-
<li>markdown</li>
|
26
|
-
</ul>
|
27
|
-
|
28
|
-
|
29
|
-
<p>Sometimes this is useful.</p>
|
30
|
-
</div>
|
31
|
-
HTML
|
32
|
-
}
|
33
|
-
subject { TextTube::InsideBlock.run content }
|
34
|
-
it { should == expected }
|
35
|
-
end
|
data/spec/link_reffing_spec.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require_relative "../lib/texttube.rb"
|
5
|
-
require_relative "../lib/texttube/filters/link_reffing.rb"
|
6
|
-
|
7
|
-
module TextTube
|
8
|
-
describe LinkReffing do
|
9
|
-
context "Given some text" do
|
10
|
-
context "With a link to be reffed in it" do
|
11
|
-
shared_examples "outputting links" do
|
12
|
-
it { should_not be_nil }
|
13
|
-
it { should == expected }
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:content) { "The UtterFAIL website[[http://utterfail.info|UtterFAIL!]] is good. My blog[[http://iainbarnett.me.uk|My blog]] is also good." }
|
17
|
-
|
18
|
-
context "and no options" do
|
19
|
-
subject { TextTube::LinkReffing.run content }
|
20
|
-
let(:expected) { s = <<HTML
|
21
|
-
The UtterFAIL website[⁰](#0 "Jump to reference") is good. My blog[¹](#1 "Jump to reference") is also good.
|
22
|
-
<div markdown='1' id='reflinks'>
|
23
|
-
<a name="0"></a>[0] [http://utterfail.info](http://utterfail.info "http://utterfail.info") UtterFAIL!
|
24
|
-
|
25
|
-
|
26
|
-
<a name="1"></a>[1] [http://iainbarnett.me.uk](http://iainbarnett.me.uk "http://iainbarnett.me.uk") My blog
|
27
|
-
|
28
|
-
</div>
|
29
|
-
HTML
|
30
|
-
s.strip
|
31
|
-
}
|
32
|
-
include_examples "outputting links"
|
33
|
-
end
|
34
|
-
context "and an option not to ref the link (i.e. inline)" do
|
35
|
-
let(:expected) {
|
36
|
-
"The UtterFAIL website [UtterFAIL!](http://utterfail.info) is good. My blog [My blog](http://iainbarnett.me.uk) is also good."
|
37
|
-
}
|
38
|
-
subject {
|
39
|
-
TextTube::LinkReffing.run content, kind: :inline
|
40
|
-
}
|
41
|
-
include_examples "outputting links"
|
42
|
-
context "and use HTML" do
|
43
|
-
let(:expected) {
|
44
|
-
%Q$The UtterFAIL website <a href="http://utterfail.info">UtterFAIL!</a> is good. My blog <a href="http://iainbarnett.me.uk">My blog</a> is also good.$
|
45
|
-
}
|
46
|
-
subject {
|
47
|
-
TextTube::LinkReffing.run content, kind: :inline, format: :html
|
48
|
-
}
|
49
|
-
include_examples "outputting links"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
context "and an option to output a link as HTML" do
|
53
|
-
let(:expected) { s = <<HTML
|
54
|
-
The UtterFAIL website<a href="#0" title="Jump to reference">⁰</a> is good. My blog<a href="#1" title="Jump to reference">¹</a> is also good.
|
55
|
-
<div markdown='1' id='reflinks'>
|
56
|
-
<a name="0"></a>[0] [http://utterfail.info](http://utterfail.info "http://utterfail.info") UtterFAIL!
|
57
|
-
|
58
|
-
|
59
|
-
<a name="1"></a>[1] [http://iainbarnett.me.uk](http://iainbarnett.me.uk "http://iainbarnett.me.uk") My blog
|
60
|
-
|
61
|
-
</div>
|
62
|
-
HTML
|
63
|
-
s.strip
|
64
|
-
}
|
65
|
-
subject { TextTube::LinkReffing.run content, format: :html }
|
66
|
-
include_examples "outputting links"
|
67
|
-
end
|
68
|
-
context "and an option to not show the link at all" do
|
69
|
-
let(:expected) { s = <<HTML
|
70
|
-
The UtterFAIL website is good. My blog is also good.
|
71
|
-
HTML
|
72
|
-
s.strip
|
73
|
-
}
|
74
|
-
subject {
|
75
|
-
TextTube::LinkReffing.run content, kind: :none
|
76
|
-
}
|
77
|
-
include_examples "outputting links"
|
78
|
-
end
|
79
|
-
end # context
|
80
|
-
|
81
|
-
context "With no link to be reffed in it" do
|
82
|
-
let(:content) { %Q$The [UtterFAIL website](http://utterfail.info/ "UtterFAIL!") is good.$ }
|
83
|
-
let(:expected) { content }
|
84
|
-
subject { TextTube::LinkReffing.run content }
|
85
|
-
it { should_not be_nil }
|
86
|
-
it { should == expected }
|
87
|
-
end # context
|
88
|
-
end # context
|
89
|
-
|
90
|
-
context "Given no text" do
|
91
|
-
subject { TextTube::LinkReffing.run "" }
|
92
|
-
it { should_not be_nil }
|
93
|
-
it { should == "" }
|
94
|
-
end # context
|
95
|
-
|
96
|
-
end # describe LinkReffing
|
97
|
-
end # module
|