blob: 7a885175b1e72a54d62c9aa291d87a45a38c7b5f (
plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#
# Author: Josediaz Gonzalez - https://github.com/josegonzalez
# Source URL: https://github.com/josegonzalez/josediazgonzalez.com/blob/master/_plugins/blockquote.rb
# Modified by Brandon Mathis
#
require './_plugins/titlecase.rb'
module Jekyll
# Outputs a string with a given attribution as a quote
#
# {% blockquote John Paul Jones %}
# Monkeys!
# {% endblockquote %}
# ...
# <blockquote>
# Monkeys!
# <br />
# John Paul Jones
# </blockquote>
#
class Blockquote < Liquid::Block
FullCiteWithTitle = /([\w\s]+)(https?:\/\/)(\S+\s)([\w\s]+)/i
FullCite = /([\w\s]+)(https?:\/\/)(\S+)/i
Author = /([\w\s]+)/
def initialize(tag_name, markup, tokens)
@by = nil
@source = nil
@title = nil
if markup =~ FullCiteWithTitle
@by = $1
@source = $2 + $3
@title = $4.titlecase
elsif markup =~ FullCite
@by = $1
@source = $2 + $3
elsif markup =~ Author
@by = $1
end
super
end
def render(context)
output = super
if @by.nil?
'<blockquote><p>' + output.join + '</p></blockquote>'
elsif !@title.nil?
'<blockquote><p>' + output.join + '</p></blockquote>' + '<p><cite><strong>' + @by + '</strong>' + '<a class="source" href="' + @source + '">' + @title + '</a></cite></p>'
elsif !@source.nil?
'<blockquote><p>' + output.join + '</p></blockquote>' + '<p><cite><strong>' + @by + '</strong>' + '<a class="source" href="' + @source + '">source</a></cite></p>'
else
'<blockquote><p>' + output.join + '</p></blockquote>' + '<p><cite><strong>' + @by + '</strong></cite></p>'
end
end
end
# Outputs a string with a given attribution as a pullquote
#
# {% blockquote John Paul Jones %}
# Monkeys!
# {% endblockquote %}
# ...
# <blockquote class="pullquote">
# Monkeys!
# <br />
# John Paul Jones
# </blockquote>
#
class Pullquote < Liquid::Block
FullCiteWithTitle = /([\w\s]+)(http:\/\/|https:\/\/)(\S+)([\w\s]+)/i
FullCite = /([\w\s]+)(http:\/\/|https:\/\/)(\S+)/i
Author = /([\w\s]+)/
def initialize(tag_name, markup, tokens)
@by = nil
@source = nil
@title = nil
if markup =~ FullCiteWithTitle
@by = $1
@source = $2 + $3
@title = $4
elsif markup =~ FullCite
@by = $1
@source = $2 + $3
elsif markup =~ Author
@by = $1
end
super
end
def render(context)
output = super
if @by.nil?
'<blockquote class="pullquote"><p>' + output.join + '</p></blockquote>'
elsif @title
'<blockquote class="pullquote"><p>' + output.join + '</p></blockquote>' + '<p><cite><strong>' + @by + '</strong>' + ' <a class="source" href="' + @source + '">' + @title + '</a></cite></p>'
elsif @source
'<blockquote class="pullquote"><p>' + output.join + '</p></blockquote>' + '<p><cite><strong>' + @by + '</strong>' + ' <a class="source" href="' + @source + '">source</a></cite></p>'
elsif @by
'<blockquote class="pullquote"><p>' + output.join + '</p></blockquote>' + '<p><cite><strong>' + @by + '</strong></cite></p>'
end
end
end
end
Liquid::Template.register_tag('blockquote', Jekyll::Blockquote)
Liquid::Template.register_tag('pullquote', Jekyll::Pullquote)
|