Class: Convert

Inherits:
Object
  • Object
show all
Extended by:
Converters
Defined in:
lib/convert.rb

Overview

# # # # # The Convert module is responsible for converting strings

Constant Summary collapse

CONVERTERS =

Some of the matchers are taken from github.com/dejan/auto_html

[: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]
DEFAULT =
[:dailymotion, :flickr, :gist, :google_maps, :instagram, :liveleak, :metacafe, :soundcloud, :ted, :twitter, :vimeo, :worldstar, :youtube, :auto_link]

Class Method Summary collapse

Class Method Details

.run(string, options = {}) ⇒ Object

Run all the converters or the ones you sent to the initializers



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/convert.rb', line 40

def self.run(string, options = {})
  return '' if !string

  # Setup
  options = {:markdown => true, :config => :custom, :converters => DEFAULT}.merge(options)

  # Include
  options[:converters] += options[:include] if options[:include]

  # Exclude
  options[:converters] -= options[:exclude] if options[:exclude]

  # Markdown
  string = markdown(string, :autolink => false) if options[:markdown]

  # Scan
  string = scan(string, options)

  # Sanitize
  string = sanitize(string, :config => options[:config])

  string
end