quesadilla 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46c4870ebc2332f165ba715f3765a9407f22f247
4
- data.tar.gz: fc7da4a6eba9dc99ac253abaefe6434f955ec6dd
3
+ metadata.gz: 70dc2e9472fde307002d6826fc06e0d2d316e00b
4
+ data.tar.gz: f8ef3bceef62a578e65a846b03cdb4d3348d71ee
5
5
  SHA512:
6
- metadata.gz: 9dfada0f0d96994a6228a6e416ecb588d77075ea9cf2b5d098d065f130abc390968de9c9e62e7cad94c0f79b809243f54a0a24de2082568461cfc621bbfdd767
7
- data.tar.gz: 4609a722036391bec45d1d24590c76a47bd72dc8dbaa76ae788b98dbc888e34ef2b18f30a6fe277e342f90cb5565bed83c550e98fc11aa1e561026842775f875
6
+ metadata.gz: a325502695825843f55530bc6b61e72b9428103b45a5d75a1a1b098e84b5bdf525a9d330ddc09db60baafa41dd11f912d85dc74f2001eafe01fe6378c8020640
7
+ data.tar.gz: e9fafa4a7fd9d679e192286beaa837dd9ec9d2c1de64beeebdcada523a3bcf6d5a20135c8f7d50fa1bb72d41eb02abc487d7bb2def1d9d9baeebebb733caa9ca
data/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  language: ruby
2
2
  bundler_args: --without development
3
3
  rvm:
4
+ - 1.9.2
4
5
  - 1.9.3
5
6
  - 2.0.0
6
7
  - jruby-19mode
8
+ - rbx-19mode
data/Readme.markdown CHANGED
@@ -60,6 +60,7 @@ Option | Description
60
60
  `:markdown_emphasis` | Markdown italic
61
61
  `:markdown_strikethrough` | Markdown Extra strikethrough
62
62
  `:hashtags` | Hashtags
63
+ `:hashtags_validator` | Callable object to validate hashtags
63
64
  `:autolinks` | Automatically detect links
64
65
  `:emoji` | GitHub-style named emoji
65
66
  `:users` | User mentions
@@ -93,7 +94,7 @@ extraction = Quesadilla.extract('Some #awesome text', html_renderer: CustomRende
93
94
  extraction[:display_html] #=> 'Some <a href="http://example.com/tags/awesome" class="tag">#awesome</a> text'
94
95
  ```
95
96
 
96
- Take a look at [Quesadilla::HTMLRenderer](lib/quesadilla/html_renderer.html) for more details on creating a custom renderer.
97
+ Take a look at [Quesadilla::HTMLRenderer](lib/quesadilla/html_renderer.rb) for more details on creating a custom renderer.
97
98
 
98
99
  ### Users
99
100
 
@@ -112,7 +113,7 @@ Assuming there is a user named `soffes` in your database, it would extract `@sof
112
113
 
113
114
  ## Supported Ruby Versions
114
115
 
115
- Quesadilla is tested under 1.9.3, 2.0.0, and JRuby (1.9 mode).
116
+ Quesadilla is tested under 1.9.2, 1.9.3, 2.0.0, JRuby 1.7.2 (1.9 mode), and Rubinius 2.0.0 (1.9 mode).
116
117
 
117
118
  [![Build Status](https://travis-ci.org/soffes/quesadilla.png?branch=master)](https://travis-ci.org/soffes/quesadilla)
118
119
 
data/lib/quesadilla.rb CHANGED
@@ -31,7 +31,7 @@ module Quesadilla
31
31
  module_function
32
32
 
33
33
  # Extract entities from text
34
- # @param text the text to extract
34
+ # @param text [String] the text to extract
35
35
  # @option options markdown_code [Boolean] Should extract Markdown code. Defaults to `true`.
36
36
  # @option options markdown_links [Boolean] Should extract Markdown links. Defaults to `true`.
37
37
  # @option options markdown_triple_emphasis [Boolean] Should extract Markdown triple emphasis (bold italic). Defaults to `true`.
@@ -39,8 +39,11 @@ module_function
39
39
  # @option options markdown_emphasis [Boolean] Should extract Markdown emphasis (italic). Defaults to `true`.
40
40
  # @option options markdown_strikethrough [Boolean] Should extract Markdown strikethrough. Defaults to `true`.
41
41
  # @option options hashtags [Boolean] Should extract hashtags. Defaults to `true`.
42
+ # @option options hashtag_validator A callable object to validate a hashtag. This should return `true` or `false`. Invalid hashtags will be left as plain text. If the validator is `nil`, all hashtags will be extracted. Defaults to `nil`.
42
43
  # @option options autolinks [Boolean] Should automatically detect links. Defaults to `true`.
43
44
  # @option options emoji [Boolean] Should extract named emoji. Defaults to `true`.
45
+ # @option options users [Boolean] Should extract user mentions. Defaults to `false`.
46
+ # @option options user_validator A callable object to validate a username. This should return the user ID of the user or nil if it is invalid. Invalid users will be left as plain text. If the validator is nil, all usernames will be extracted. Defaults to `nil`.
44
47
  # @option options html [Boolean] Should generate HTML. Defaults to `true`.
45
48
  # @option options html_renderer [Class] class to use as HTML renderer. Defaults to `Quesadilla::HTMLRenderer`.
46
49
  # @return [Hash] hash containing the display text, html text, and entities
@@ -24,6 +24,7 @@ module Quesadilla
24
24
  markdown_emphasis: true,
25
25
  markdown_strikethrough: true,
26
26
  hashtags: true,
27
+ hashtag_validator: nil,
27
28
  autolinks: true,
28
29
  emoji: true,
29
30
  users: false,
@@ -42,10 +43,11 @@ module Quesadilla
42
43
  # @option options markdown_emphasis [Boolean] Should extract Markdown emphasis (italic). Defaults to `true`.
43
44
  # @option options markdown_strikethrough [Boolean] Should extract Markdown strikethrough. Defaults to `true`.
44
45
  # @option options hashtags [Boolean] Should extract hashtags. Defaults to `true`.
46
+ # @option options hashtag_validator A callable object to validate a hashtag. This should return `true` or `false`. Invalid hashtags will be left as plain text. If the validator is `nil`, all hashtags will be extracted. Defaults to `nil`.
45
47
  # @option options autolinks [Boolean] Should automatically detect links. Defaults to `true`.
46
48
  # @option options emoji [Boolean] Should extract named emoji. Defaults to `true`.
47
49
  # @option options users [Boolean] Should extract user mentions. Defaults to `false`.
48
- # @option options user_validator A callable object to validate a username. This should return the user ID of the user or nil if it is invalid. Invalid users will be left as plain text. If the validator is nil, all usernames will be extracted. Defaults to `nil`.
50
+ # @option options user_validator A callable object to validate a username. This should return the user ID of the user or nil if it is invalid. Invalid users will be left as plain text. If the validator is `nil`, all usernames will be extracted. Defaults to `nil`.
49
51
  # @option options html [Boolean] Should generate HTML. Defaults to `true`.
50
52
  # @option options html_renderer [Class] class to use as HTML renderer. Defaults to `Quesadilla::HTMLRenderer`.
51
53
  def initialize(options = {})
@@ -54,10 +56,10 @@ module Quesadilla
54
56
  end
55
57
 
56
58
  # Extract entities from text
57
- # @param original_text the text to extract from
59
+ # @param text [String] the text to extract from
58
60
  # @return [Hash] hash containing the display text, html text, and entities
59
- def extract(original_text)
60
- @original_text = original_text.dup
61
+ def extract(text)
62
+ @original_text = text.dup
61
63
 
62
64
  # Emoji colon-syntax
63
65
  replace_emoji if @options[:emoji]
@@ -12,15 +12,22 @@ module Quesadilla
12
12
 
13
13
  def extract_hashtags
14
14
  Twitter::Extractor::extract_hashtags_with_indices(@working_text).each do |entity|
15
- entity_text = "##{entity[:hashtag]}"
15
+ hashtag = entity[:hashtag]
16
+
17
+ # Validate
18
+ if validator = @options[:hashtag_validator]
19
+ next unless validator.call(hashtag)
20
+ end
21
+
22
+ display_text = "##{hashtag}"
16
23
  @entities << {
17
24
  type: ENTITY_TYPE_HASHTAG,
18
- text: entity_text,
19
- display_text: entity_text,
25
+ text: display_text,
26
+ display_text: display_text,
20
27
  indices: entity[:indices],
21
- hashtag: entity[:hashtag].downcase
28
+ hashtag: hashtag.downcase
22
29
  }
23
- @working_text.sub!(entity_text, REPLACE_TOKEN * entity_text.length)
30
+ @working_text.sub!(display_text, REPLACE_TOKEN * display_text.length)
24
31
  end
25
32
  end
26
33
  end
@@ -1,4 +1,4 @@
1
1
  module Quesadilla
2
2
  # Version of the Quesadilla gem
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
data/quesadilla.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.authors = ['Sam Soffes']
10
10
  gem.email = ['sam@soff.es']
11
11
  gem.description = 'Entity-style text parsing'
12
- gem.summary = gem.description
12
+ gem.summary = 'Entity-style text parsing extracted from Cheddar'
13
13
  gem.homepage = 'https://github.com/soffes/quesadilla'
14
14
  gem.license = 'MIT'
15
15
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ['lib']
20
20
 
21
- gem.required_ruby_version = '>= 1.9.3'
21
+ gem.required_ruby_version = '>= 1.9.2'
22
22
 
23
23
  # Hashtag and autolink parsing
24
24
  gem.add_dependency 'twitter-text', '~> 1.5.0'
@@ -48,5 +48,27 @@ module Quesadilla
48
48
  }
49
49
  assert_equal expected, extraction
50
50
  end
51
+
52
+ def test_that_it_validates
53
+ validator = lambda do |hashtag|
54
+ hashtag == 'awesome'
55
+ end
56
+ extraction = extract('A task with some #tags that are #awesome', hashtag_validator: validator)
57
+ expected = {
58
+ display_text: 'A task with some #tags that are #awesome',
59
+ display_html: 'A task with some #tags that are <a href="#hashtag-awesome" class="hashtag">#awesome</a>',
60
+ entities: [
61
+ {
62
+ type: 'hashtag',
63
+ text: '#awesome',
64
+ display_text: '#awesome',
65
+ hashtag: 'awesome',
66
+ indices: [32, 40],
67
+ display_indices: [32, 40]
68
+ }
69
+ ]
70
+ }
71
+ assert_equal expected, extraction
72
+ end
51
73
  end
52
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quesadilla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Soffes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-02 00:00:00.000000000 Z
11
+ date: 2013-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter-text
@@ -85,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - '>='
87
87
  - !ruby/object:Gem::Version
88
- version: 1.9.3
88
+ version: 1.9.2
89
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  requirements:
91
91
  - - '>='
@@ -96,7 +96,7 @@ rubyforge_project:
96
96
  rubygems_version: 2.0.0
97
97
  signing_key:
98
98
  specification_version: 4
99
- summary: Entity-style text parsing
99
+ summary: Entity-style text parsing extracted from Cheddar
100
100
  test_files:
101
101
  - test/quesadilla/autolink_test.rb
102
102
  - test/quesadilla/emoji_test.rb