Skip to content
This repository was archived by the owner on Aug 27, 2021. It is now read-only.

Commit c3123bc

Browse files
committed
Merge pull request #1886 from sendgrid/formatting_plugins
Formatting plugins
2 parents f8b71a9 + e595496 commit c3123bc

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

plugins/boostrap_column_nop.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# Author: Matt Bernier
3+
# Make a bootstrap column
4+
#
5+
# Outputs the HTML for a bootstrap column of size 4 with id "best_column"
6+
#
7+
# {% html_column md-4 best_column %}
8+
# Some content
9+
# {% endhtml_column %}
10+
# ...
11+
# <div id="best_column" class="col-md-4">
12+
# <p>Some content</p>
13+
# </div>
14+
#
15+
module Jekyll
16+
17+
class Bootstrap_Column_Nop < Liquid::Block
18+
19+
def initialize(tag_name, markup, tokens)
20+
parameters = markup.shellsplit
21+
22+
@size = "col-#{parameters[0]}"
23+
24+
@class = defined?(parameters[1]) ? " #{parameters[1]}" : ""
25+
26+
@id = parameters[2];
27+
28+
if defined?(parameters[2].to_str)
29+
if !empty?(parameters[2].to_str)
30+
@id = "id=\"#{parameters[2]}\""
31+
end
32+
end
33+
34+
35+
super
36+
end
37+
def render(context)
38+
output = super
39+
output = <<HTML
40+
<div #{@id} class="#{@size}#{@class}">#{output}</div>
41+
HTML
42+
43+
#html = Kramdown::Document.new(output).to_html
44+
return Liquid::Template.parse(output).render context
45+
end
46+
end
47+
end
48+
Liquid::Template.register_tag('html_column_nop', Jekyll::Bootstrap_Column_Nop)

plugins/bootstrap_column.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# Author: Matt Bernier
3+
# Make a bootstrap column
4+
#
5+
# Outputs the HTML for a bootstrap column of size 4 with id "best_column"
6+
#
7+
# {% html_column md-4 best_column %}
8+
# Some content
9+
# {% endhtml_column %}
10+
# ...
11+
# <div id="best_column" class="col-md-4">
12+
# <p>Some content</p>
13+
# </div>
14+
#
15+
module Jekyll
16+
17+
class Bootstrap_Column < Liquid::Block
18+
19+
def initialize(tag_name, markup, tokens)
20+
parameters = markup.shellsplit
21+
22+
@size = "col-#{parameters[0]}"
23+
24+
@class = defined?(parameters[1]) ? " #{parameters[1]}" : ""
25+
26+
@id = parameters[2];
27+
28+
if defined?(parameters[2].to_str)
29+
if !empty?(parameters[2].to_str)
30+
@id = "id=\"#{parameters[2]}\""
31+
end
32+
end
33+
34+
35+
super
36+
end
37+
def render(context)
38+
output = super
39+
output = <<HTML
40+
<div #{@id} class="#{@size}#{@class}"><p>#{output}</p></div>
41+
HTML
42+
43+
#html = Kramdown::Document.new(output).to_html
44+
return Liquid::Template.parse(output).render context
45+
end
46+
end
47+
end
48+
Liquid::Template.register_tag('html_column', Jekyll::Bootstrap_Column)

plugins/bootstrap_row.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# Author: Matt Bernier
3+
# Make a bootstrap row
4+
#
5+
# Outputs the HTML for a bootstrap row with id "best_row"
6+
#
7+
# {% html_row md-4 best_row %}
8+
# Wheeee!
9+
# {% endhtml_row %}
10+
# ...
11+
# <div id="best_row" class="row">
12+
# Wheeee!
13+
# </div>
14+
#
15+
# Use with html_column to output a proper bootstrap row and column pairing
16+
#
17+
# {% html_row md-4 best_row %}
18+
# {% html_column md-4 best_column %}
19+
# Some content
20+
# {% endhtml_column %}
21+
# {% html_column md-4 best_column2 %}
22+
# Some content
23+
# {% endhtml_column %}
24+
# {% html_column md-4 best_column3 %}
25+
# Some content
26+
# {% endhtml_column %}
27+
# {% endhtml_row %}
28+
# ...
29+
# <div id="best_row" class="row">
30+
# <div id="best_column" class="col-md-4">
31+
# <p>Some content</p>
32+
# </div>
33+
# <div id="best_column2" class="col-md-4">
34+
# <p>Some content</p>
35+
# </div>
36+
# <div id="best_column3" class="col-md-4">
37+
# <p>Some content</p>
38+
# </div>
39+
# </div>
40+
#
41+
module Jekyll
42+
43+
class Bootstrap_Row < Liquid::Block
44+
45+
def initialize(tag_name, markup, tokens)
46+
parameters = markup.shellsplit
47+
48+
@class = defined?(parameters[0]) ? " #{parameters[1]}" : ""
49+
50+
@id = defined?(parameters[1]) ? "id=\"#{parameters[0]}\"" : ""
51+
52+
super
53+
end
54+
def render(context)
55+
output = super
56+
output = <<HTML
57+
<div #{@id} class="row#{@class}">#{output}</div>
58+
HTML
59+
60+
#html = Kramdown::Document.new(output).to_html
61+
return Liquid::Template.parse(output).render context
62+
end
63+
end
64+
end
65+
Liquid::Template.register_tag('html_row', Jekyll::Bootstrap_Row)

0 commit comments

Comments
 (0)