quesadilla 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,235 @@
1
+ # encoding: UTF-8
2
+ require 'test_helper'
3
+
4
+ module Quesadilla
5
+ class MarkdownTest < TestCase
6
+ def test_that_it_extracts_links
7
+ extraction = extract('Read [my resume](http://samsoff.es/resume) if you want')
8
+ assert_equal extraction, {
9
+ display_text: 'Read my resume if you want',
10
+ display_html: 'Read <a href="http://samsoff.es/resume" rel="external nofollow" class="link">my resume</a> if you want',
11
+ entities: [
12
+ {
13
+ type: 'link',
14
+ text: '[my resume](http://samsoff.es/resume)',
15
+ display_text: 'my resume',
16
+ url: 'http://samsoff.es/resume',
17
+ indices: [5, 42],
18
+ display_indices: [5, 14]
19
+ }
20
+ ]
21
+ }
22
+ end
23
+
24
+ def test_that_it_extracts_links_with_titles
25
+ extraction = extract('Read [my resume](http://samsoff.es/resume "Sam\'s Resume") if you want')
26
+ assert_equal extraction, {
27
+ display_text: 'Read my resume if you want',
28
+ display_html: 'Read <a href="http://samsoff.es/resume" rel="external nofollow" class="link" title="Sam&#x27;s Resume">my resume</a> if you want',
29
+ entities: [
30
+ {
31
+ type: 'link',
32
+ text: '[my resume](http://samsoff.es/resume "Sam\'s Resume")',
33
+ display_text: 'my resume',
34
+ url: 'http://samsoff.es/resume',
35
+ title: 'Sam\'s Resume',
36
+ indices: [5, 57],
37
+ display_indices: [5, 14]
38
+ }
39
+ ]
40
+ }
41
+ end
42
+
43
+ def test_that_it_extracts_links_with_brackets
44
+ extraction = extract('Something with a link: <http://samsoff.es/posts/hire-sam>')
45
+ assert_equal extraction, {
46
+ display_text: 'Something with a link: samsoff.es/posts/hire-sam',
47
+ display_html: 'Something with a link: <a href="http://samsoff.es/posts/hire-sam" rel="external nofollow" class="link">samsoff.es&#x2F;posts&#x2F;hire-sam</a>',
48
+ entities: [
49
+ {
50
+ type: 'link',
51
+ text: '<http://samsoff.es/posts/hire-sam>',
52
+ display_text: 'samsoff.es/posts/hire-sam',
53
+ url: 'http://samsoff.es/posts/hire-sam',
54
+ indices: [23, 57],
55
+ display_indices: [23, 48]
56
+ }
57
+ ]
58
+ }
59
+ end
60
+
61
+ def test_that_it_extracts_email_addresses_with_brackets
62
+ extraction = extract('Email <support@cheddarapp.com>')
63
+ assert_equal extraction, {
64
+ display_text: 'Email support@cheddarapp.com',
65
+ display_html: 'Email <a href="mailto:support@cheddarapp.com" rel="external nofollow" class="link">support@cheddarapp.com</a>',
66
+ entities: [
67
+ {
68
+ type: 'link',
69
+ text: '<support@cheddarapp.com>',
70
+ display_text: 'support@cheddarapp.com',
71
+ url: 'mailto:support@cheddarapp.com',
72
+ indices: [6, 30],
73
+ display_indices: [6, 28]
74
+ }
75
+ ]
76
+ }
77
+ end
78
+
79
+ # it 'should extract plain email addresses'
80
+
81
+ def test_that_it_extracts_emphasis
82
+ extraction = extract('Something *cool* is awesome')
83
+ assert_equal extraction, {
84
+ display_text: 'Something cool is awesome',
85
+ display_html: 'Something <em>cool</em> is awesome',
86
+ entities: [
87
+ {
88
+ type: 'emphasis',
89
+ text: '*cool*',
90
+ display_text: 'cool',
91
+ indices: [10, 16],
92
+ display_indices: [10, 14]
93
+ }
94
+ ]
95
+ }
96
+
97
+ extraction = extract('Something _cool_ is awesome')
98
+ assert_equal extraction, {
99
+ display_text: 'Something cool is awesome',
100
+ display_html: 'Something <em>cool</em> is awesome',
101
+ entities: [
102
+ {
103
+ type: 'emphasis',
104
+ text: '_cool_',
105
+ display_text: 'cool',
106
+ indices: [10, 16],
107
+ display_indices: [10, 14]
108
+ }
109
+ ]
110
+ }
111
+ end
112
+
113
+ def test_that_it_extracts_double_emphasis
114
+ extraction = extract('Something **cool** is awesome')
115
+ assert_equal extraction, {
116
+ display_text: 'Something cool is awesome',
117
+ display_html: 'Something <strong>cool</strong> is awesome',
118
+ entities: [
119
+ {
120
+ type: 'double_emphasis',
121
+ text: '**cool**',
122
+ display_text: 'cool',
123
+ indices: [10, 18],
124
+ display_indices: [10, 14]
125
+ }
126
+ ]
127
+ }
128
+
129
+ extraction = extract('Something __cool__ is awesome')
130
+ assert_equal extraction, {
131
+ display_text: 'Something cool is awesome',
132
+ display_html: 'Something <strong>cool</strong> is awesome',
133
+ entities: [
134
+ {
135
+ type: 'double_emphasis',
136
+ text: '__cool__',
137
+ display_text: 'cool',
138
+ indices: [10, 18],
139
+ display_indices: [10, 14]
140
+ }
141
+ ]
142
+ }
143
+ end
144
+
145
+ def test_that_it_extracts_triple_emphasis
146
+ extraction = extract('Something ***cool*** is awesome')
147
+ assert_equal extraction, {
148
+ display_text: 'Something cool is awesome',
149
+ display_html: 'Something <strong><em>cool</em></strong> is awesome',
150
+ entities: [
151
+ {
152
+ type: 'triple_emphasis',
153
+ text: '***cool***',
154
+ display_text: 'cool',
155
+ indices: [10, 20],
156
+ display_indices: [10, 14]
157
+ }
158
+ ]
159
+ }
160
+
161
+ extraction = extract('Something ___cool___ is awesome')
162
+ assert_equal extraction, {
163
+ display_text: 'Something cool is awesome',
164
+ display_html: 'Something <strong><em>cool</em></strong> is awesome',
165
+ entities: [
166
+ {
167
+ type: 'triple_emphasis',
168
+ text: '___cool___',
169
+ display_text: 'cool',
170
+ indices: [10, 20],
171
+ display_indices: [10, 14]
172
+ }
173
+ ]
174
+ }
175
+ end
176
+
177
+ def test_that_it_extracts_strikethrough
178
+ extraction = extract('Something ~~cool~~ awesome')
179
+ assert_equal extraction, {
180
+ display_text: 'Something cool awesome',
181
+ display_html: 'Something <del>cool</del> awesome',
182
+ entities: [
183
+ {
184
+ type: 'strikethrough',
185
+ text: '~~cool~~',
186
+ display_text: 'cool',
187
+ indices: [10, 18],
188
+ display_indices: [10, 14]
189
+ }
190
+ ]
191
+ }
192
+ end
193
+
194
+ def test_that_it_extracts_multiple_strikethroughs
195
+ extraction = extract('Something ~~cool~~ awesome ~~foo~~')
196
+ assert_equal extraction, {
197
+ display_text: 'Something cool awesome foo',
198
+ display_html: 'Something <del>cool</del> awesome <del>foo</del>',
199
+ entities: [
200
+ {
201
+ type: 'strikethrough',
202
+ text: '~~cool~~',
203
+ display_text: 'cool',
204
+ indices: [10, 18],
205
+ display_indices: [10, 14]
206
+ },
207
+ {
208
+ type: 'strikethrough',
209
+ text: '~~foo~~',
210
+ display_text: 'foo',
211
+ indices: [27, 34],
212
+ display_indices: [23, 26]
213
+ }
214
+ ]
215
+ }
216
+ end
217
+
218
+ def test_that_it_extracts_code
219
+ extraction = extract('Something with `code` is awesome')
220
+ assert_equal extraction, {
221
+ display_text: 'Something with code is awesome',
222
+ display_html: 'Something with <code>code</code> is awesome',
223
+ entities: [
224
+ {
225
+ type: 'code',
226
+ text: '`code`',
227
+ display_text: 'code',
228
+ indices: [15, 21],
229
+ display_indices: [15, 19]
230
+ }
231
+ ]
232
+ }
233
+ end
234
+ end
235
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: UTF-8
2
+ require 'test_helper'
3
+
4
+ module Quesadilla
5
+ class MultiTest < TestCase
6
+ def test_that_it_extracts_links_and_tags
7
+ extraction = extract('Something #tagged with a link http://samsoff.es/posts/hire-sam')
8
+ assert_equal extraction, {
9
+ display_text: 'Something #tagged with a link samsoff.es/posts/hire-sam',
10
+ display_html: 'Something <a href="#hashtag-tagged" class="hashtag">#tagged</a> with a link <a href="http://samsoff.es/posts/hire-sam" rel="external nofollow" class="link">samsoff.es&#x2F;posts&#x2F;hire-sam</a>',
11
+ entities: [
12
+ {
13
+ type: 'hashtag',
14
+ text: '#tagged',
15
+ display_text: '#tagged',
16
+ hashtag: 'tagged',
17
+ indices: [10, 17],
18
+ display_indices: [10, 17]
19
+ },
20
+ {
21
+ type: 'link',
22
+ text: 'http://samsoff.es/posts/hire-sam',
23
+ display_text: 'samsoff.es/posts/hire-sam',
24
+ url: 'http://samsoff.es/posts/hire-sam',
25
+ indices: [30, 62],
26
+ display_indices: [30, 55]
27
+ }
28
+ ]
29
+ }
30
+ end
31
+
32
+ def test_that_it_doesnt_lose_the_last_character
33
+ extraction = extract('Something that is **bold**?')
34
+ assert_equal extraction, {
35
+ display_text: 'Something that is bold?',
36
+ display_html: 'Something that is <strong>bold</strong>?',
37
+ entities: [
38
+ {
39
+ type: 'double_emphasis',
40
+ text: '**bold**',
41
+ display_text: 'bold',
42
+ indices: [18, 26],
43
+ display_indices: [18, 22]
44
+ }
45
+ ]
46
+ }
47
+
48
+ extraction = extract('Something that is **bold**')
49
+ assert_equal extraction, {
50
+ display_text: 'Something that is bold',
51
+ display_html: 'Something that is <strong>bold</strong>',
52
+ entities: [
53
+ {
54
+ type: 'double_emphasis',
55
+ text: '**bold**',
56
+ display_text: 'bold',
57
+ indices: [18, 26],
58
+ display_indices: [18, 22]
59
+ }
60
+ ]
61
+ }
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module Quesadilla
4
+ class QuesadillaTest < TestCase
5
+ def test_that_it_has_a_version_number
6
+ refute_nil VERSION
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module ExtractorMacros
2
+ def extract(text, options = {})
3
+ Quesadilla.extract(text, options)
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require :test
4
+
5
+ require 'simplecov'
6
+ SimpleCov.start
7
+
8
+ require 'minitest/autorun'
9
+ require 'quesadilla'
10
+
11
+ # Support files
12
+ Dir["#{File.expand_path(File.dirname(__FILE__))}/support/*.rb"].each do |file|
13
+ require file
14
+ end
15
+
16
+ class Quesadilla::TestCase < MiniTest::Unit::TestCase
17
+ include ExtractorMacros
18
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quesadilla
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam Soffes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: twitter-text
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: named_emoji
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.1
41
+ description: Entity-style text parsing
42
+ email:
43
+ - sam@soff.es
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .travis.yml
50
+ - Contributing.markdown
51
+ - Gemfile
52
+ - LICENSE
53
+ - Rakefile
54
+ - Readme.markdown
55
+ - lib/quesadilla.rb
56
+ - lib/quesadilla/core_ext/string.rb
57
+ - lib/quesadilla/extractor.rb
58
+ - lib/quesadilla/extractor/autolinks.rb
59
+ - lib/quesadilla/extractor/emoji.rb
60
+ - lib/quesadilla/extractor/hashtags.rb
61
+ - lib/quesadilla/extractor/html.rb
62
+ - lib/quesadilla/extractor/markdown.rb
63
+ - lib/quesadilla/html_renderer.rb
64
+ - lib/quesadilla/version.rb
65
+ - quesadilla.gemspec
66
+ - test/quesadilla/autolink_test.rb
67
+ - test/quesadilla/emoji_test.rb
68
+ - test/quesadilla/hashtags_test.rb
69
+ - test/quesadilla/html_test.rb
70
+ - test/quesadilla/markdown_test.rb
71
+ - test/quesadilla/multi_test.rb
72
+ - test/quesadilla_test.rb
73
+ - test/support/extractor_macros.rb
74
+ - test/test_helper.rb
75
+ homepage: https://github.com/soffes/quesadilla
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: 1.9.3
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.0
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Entity-style text parsing
99
+ test_files:
100
+ - test/quesadilla/autolink_test.rb
101
+ - test/quesadilla/emoji_test.rb
102
+ - test/quesadilla/hashtags_test.rb
103
+ - test/quesadilla/html_test.rb
104
+ - test/quesadilla/markdown_test.rb
105
+ - test/quesadilla/multi_test.rb
106
+ - test/quesadilla_test.rb
107
+ - test/support/extractor_macros.rb
108
+ - test/test_helper.rb
109
+ has_rdoc: