Class: MarkupEmail::Render

Inherits:
Object
  • Object
show all
Includes:
HTML
Defined in:
lib/markup_email/convert.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, sanitize = false) ⇒ Render

Returns a new instance of Render.



13
14
15
16
# File 'lib/markup_email/convert.rb', line 13

def initialize file, sanitize=false
  @file = file
  @sanitize = sanitize
end

Instance Method Details

#bodyObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/markup_email/convert.rb', line 18

def body
  exit 1 unless package_tester
  unfiltered = File.read(@file) #GitHub::Markup.render @file, File.read(@file) # Use me :'(
  # ^^^^^ IN THE FUTURE, WHEN `HTML::Pipeline` HAS FIXED THEIR SHIT AND DON'T
  # ^^^^^ A HUNDRED YEAR OLD VERSION OF `github-linguist` I WILL BE ABLE TO
  # ^^^^^ ALL THE MARKUPS LISTED IN THE `--help` SECTION...
  context = {
    :asset_root => "https://assets-cdn.github.com/images/icons",
    :gfm => true
  }
  filters = [
    Pipeline::MarkdownFilter,
    Pipeline::SanitizationFilter,
    Pipeline::TableOfContentsFilter,
    #Pipeline::CamoFilter,
    TaskList::Filter,
    Pipeline::EmojiFilter,
    Pipeline::AutolinkFilter,
    Pipeline::SyntaxHighlightFilter
  ]
  filters.delete(Pipeline::SanitizationFilter) unless @sanitize

  pipeline = Pipeline.new filters, context
  return pipeline.call(unfiltered)[:output].to_s
end

#package_testerObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/markup_email/convert.rb', line 55

def package_tester
  if %w(.markdown .md .mdown .mkdn).include? File.extname(@file)
    require_test 'commonmarker'
    return true
  end
  if File.extname(@file) == '.textile'
    require_test 'RedCloth'
    return true
  end
  if File.extname(@file) == '.rdoc'
    require_test 'rdoc'
    return true
  end
  if File.extname(@file) == '.org'
    require_test 'org-ruby'
    return true
  end
  if File.extname(@file) == '.creole'
    require_test 'org-ruby'
    return true
  end
  if %w(.mediawiki .wiki).include? File.extname(@file)
    require_test 'wikicloth'
    return true
  end
  if File.extname(@file) == '.rst'
    begin
      %x(python3 --version)
    rescue
      puts "python3 (Python version 3) not installed, please install python3!"
      exit 1
    end
    unless %x(python3 -c "import sphinx" 2>&1).empty?
      puts "python3 `sphinx` module not installed for .rst markup!\nSee `--help` for more information on installing the package."
      exit 1
    end
    return true
  end
  if %w(.asciidoc .adoc .asc).include? File.extname(@file)
    require_test 'asciidoctor'
    return true
  end
  if File.extname(@file) == '.pod'
    begin
      %x(perl -v)
    rescue
      puts "Perl not installed! Please install Perl"
      exit 1
    end
    unless %x(perl -v)[%x(perl -v).index('(v') + 2, 4].to_f >= 5.10
      puts "Your perl version is not up to date (Perl must be >= 5.10)."
      puts "your perl version is #{%x(perl -v)[%x(perl -v).index('(v'), 9]}."
      exit 1
    end
    return true # comes with perl
  end
  return true
end

#require_test(package) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/markup_email/convert.rb', line 44

def require_test(package)
  begin
    require "#{package}"
  rescue LoadError
    puts "`#{package}` not installed for you chosen markup!\nSee `--help` for more information on installing the package."
    exit 1
  else
    return "`#{package}` installed!"
  end
end