convert 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/convert.rb +55 -47
  3. metadata +87 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eefc419abd4caaa5de0f2b5bf89e7a57a3b01578
4
- data.tar.gz: 7cff0bdb81b275bee194be33ce0bcc5d9b6f38b6
3
+ metadata.gz: 0f8038d316910757119756d12f77bfa2894ddd42
4
+ data.tar.gz: 4f3935f05c5cec5ac6e1af0cab3a31871570881b
5
5
  SHA512:
6
- metadata.gz: d7dca0451caabeb8e094bc25d640fb00a72730e6634f68181f46a14ea5954281f01abd4215795c96913d4c459bb6b3a4d13981107254baf3faed1c6e4a9e6557
7
- data.tar.gz: fc10fc1f89a5f7f1ef8c3ffcc81acc99fd548c7550e8c083ba0d0be0fc1dac634f591e95e23a72ef7d7af8d587dade883d95afe525ba5f9c9bc86b9afc9ca0b6
6
+ metadata.gz: b186341f0a93f93eb59f4a60753d80bb3104e91683c93f29fb0356ecbec8e12dc5ed6faeae76a922a7f936fd3584f93b6604cf05c3d29710fbb45b19f2e4c801
7
+ data.tar.gz: 24eae3560e9e575339c3289b476be9eda4b8e28f9ffa943f12169265bdb28a6a25518aaaed1dff8f2b2891793e8785b40a5912cd27640cf6c059d73082294e84
data/lib/convert.rb CHANGED
@@ -1,56 +1,64 @@
1
- module Convert
1
+ # Require the converters
2
+ Dir['./lib/converters/*.rb'].each{|f| require f}
3
+
4
+ # Require the sanitizers
5
+ Dir['./lib/sanitizers/*.rb'].each{|f| require f}
6
+
7
+ # Autoload for faster loading
8
+
9
+ module Converters
10
+ autoload :Redcarpet, 'redcarpet'
11
+ autoload :Kramdown, 'kramdown'
12
+ autoload :Rinku, 'rinku'
13
+ autoload :Sanitize, 'sanitize'
14
+ autoload :HTMLEntities, 'htmlentities'
15
+ end
16
+ autoload :Nokogiri, 'nokogiri'
17
+
18
+ # # # # # #
19
+ # The Convert module is responsible for converting strings
20
+ #
21
+ class Convert
2
22
 
3
23
  # # # # # #
4
- # Convert strings and HTML from a long list of providers
24
+ # Convert strings and HTML from a long list of converters
5
25
  # @homepage: https://github.com/fugroup/convert
6
26
  # @author: Vidar <vidar@fugroup.net>, Fugroup Ltd.
7
27
  # @license: MIT, contributions are welcome.
8
28
  # # # # # #
9
29
 
10
- class << self; attr_accessor :converters; end
11
-
12
- # Set which converters to run: Convert.converters = [:markdown, :auto_html]
13
- # Default is all
14
-
15
- @converters = [
16
- :auto_link,
17
- :iframe_embed,
18
- :dailymotion,
19
- :email_escape,
20
- :flickr,
21
- :gist,
22
- :google_maps,
23
- :hashtag,
24
- :html_escape,
25
- :image_tag,
26
- :instagram,
27
- :kramdown,
28
- :liveleak,
29
- :markdown,
30
- :metacafe,
31
- :redcarpet,
32
- :simple_format,
33
- :soundcloud,
34
- :ted,
35
- :twitter,
36
- :unescape_html,
37
- :video_embed,
38
- :vimeo,
39
- :vimeo_embed,
40
- :worldstar,
41
- :youtube,
42
- :youtube_embed,
43
- :youtube_image,
44
- :youtube_js_api
45
- ]
46
-
47
- # Only run the ones set in Convert.converters, see above.
48
- Convert.converters.each do |c|
49
-
50
- # Require
51
- require_relative "converters/#{c}"
52
-
53
- # Extend
54
- extend Object.const_get("Convert::#{c.to_s.split('_').map(&:capitalize).join}")
30
+ # Some of the matchers are taken from https://github.com/dejan/auto_html
31
+
32
+ CONVERTERS = [:iframe_embed, :dailymotion, :email_escape, :flickr, :gist, :google_maps, :hashtag, :html_escape, :image_tag, :instagram, :liveleak, :markdown, :metacafe, :redcarpet, :soundcloud, :ted, :twitter, :video_embed, :vimeo, :vimeo_embed, :worldstar, :youtube, :youtube_embed, :youtube_js_api, :auto_link, :encode, :decode, :strip_params, :sanitize, :nokogiri]
33
+
34
+ DEFAULT = [:dailymotion, :flickr, :gist, :google_maps, :instagram, :liveleak, :metacafe, :soundcloud, :ted, :twitter, :vimeo, :worldstar, :youtube, :auto_link]
35
+
36
+ # Include converters
37
+ extend Converters
38
+
39
+ # Run all the converters or the ones you sent to the initializers
40
+ def self.run(string, options = {})
41
+ return '' if !string
42
+
43
+ # Setup
44
+ options = {:markdown => true, :config => :custom, :converters => DEFAULT}.merge(options)
45
+
46
+ # Include
47
+ options[:converters] += options[:include] if options[:include]
48
+
49
+ # Exclude
50
+ options[:converters] -= options[:exclude] if options[:exclude]
51
+
52
+ # Markdown
53
+ string = markdown(string, :autolink => false) if options[:markdown]
54
+
55
+ # Scan
56
+ string = scan(string, options)
57
+
58
+ # Sanitize
59
+ string = sanitize(string, :config => options[:config])
60
+
61
+ string
55
62
  end
63
+
56
64
  end
metadata CHANGED
@@ -1,15 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fugroup Limited
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-29 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2016-12-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redcarpet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: kramdown
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rinku
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sanitize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: htmlentities
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
13
97
  description: Easily convert any string and replace with links and embedded content
14
98
  from a long list of providers and libraries.
15
99
  email: mail@fugroup.net