forked from sendgrid/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfo_warning.rb
More file actions
87 lines (73 loc) · 2.22 KB
/
Copy pathinfo_warning.rb
File metadata and controls
87 lines (73 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
43
44
45
46
47
48
49
50
51
52
53
54
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
require 'kramdown'
module Jekyll
class InfoBlock < Liquid::Block
def initialize(tag_name, markup, tokens)
super
end
def render(context)
contents = super
source = '<div class="callout callout-info">'
source += "#{Kramdown::Document.new(contents).to_html}"
source += '</div>'
source
end
end
class WarningBlock < Liquid::Block
def initialize(tag_name, markup, tokens)
super
end
def render(context)
contents = super
source = '<div class="callout callout-warning">'
source += "#{Kramdown::Document.new(contents).to_html}"
source += '</div>'
source
end
end
class DeveloperBlock < Liquid::Block
def initialize(tag_name, markup, tokens)
super
end
def render(context)
contents = super
source = '<div class="callout callout-developer">'
source += "#{Kramdown::Document.new(contents).to_html}"
source += '</div>'
source
end
end
class GithubBlock < Liquid::Block
def initialize(tag_name, markup, tokens)
args = markup.split(/\s+/)
@path = args[0]
@lang = args[1]
info = @path.match(/^([\w\-.%]+?)\/([\w\-.%]+)(.+)$/)
@author = info[1]
@name = info[2]
super
end
def render(context)
contents = super
source = '<div class="callout callout-github" itemscope itemtype="http://schema.org/Code">'
source += contents
if @name
source += '<meta itemprop="name" content="' + @name + '">'
end
if @author
source += '<meta itemprop="author" content="' + @author + '">'
end
if @lang
source += '<meta itemprop="programmingLanguage" content="' + @lang + '">'
end
url = 'https://github.com/' + @path
source += '<meta itemprop="codeRepository" content="' + url + '">'
source += '<p class="link"><a href="' + url + '">View on Github »</a></p>'
source += '</div>'
source
end
end
end
Liquid::Template.register_tag('warning', Jekyll::WarningBlock)
Liquid::Template.register_tag('info', Jekyll::InfoBlock)
Liquid::Template.register_tag('developer', Jekyll::DeveloperBlock)
Liquid::Template.register_tag('github', Jekyll::GithubBlock)