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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/shi/jekyll/images/image.rb', line 39
def render context
args = Shi::Args::Params::parse context, @markup
= context['extra_args'] || {}
source = args[:src] || args[:source]
if source == nil && Jekyll::StaticFile === args[0]
source = args[0]
end
if !Jekyll::StaticFile === source
raise ArgumentError, "Invalid source: #{source.inspect}!"
end
link = args[:link]
link = false if args[:no_link]
link = true if link == nil
site = context.registers[:site]
page_path = clean_path(context['page.path'])
if page_path == nil
p context.registers[:page]
end
page = site.documents.find { |d| d.relative_path == page_path }
page ||= site.pages.find { |p| p.relative_path == page_path }
gen_big = false
href = if link == false
nil
elsif Jekyll::StaticFile === link && !link.write?
bounds = args[:bounds] || [:bounds]
Jekyll::PathManager::join '', Shi::Jekyll::Images::File::create(page, link, bounds, nil).url
elsif link.respond_to?(:url) && link.url
Jekyll::PathManager::join '', link.url
elsif String === link
link
elsif link == true
gen_big = true
bounds = args[:bounds] || [:bounds]
Jekyll::PathManager::join '', Shi::Jekyll::Images::File::create(page, source, bounds, nil).url
else
raise ArgumentError, "Invalid link: #{link.inspect}!"
end
thumb = args[:thumb]
thumb = false if args[:no_thumb]
thumb = true if thumb == nil
if !gen_big && !thumb
raise ArgumentError, "You can't disable large image and thumbnail at the same time!"
end
src = if thumb
bounds = thumb_bounds context, args,
crop = args[:crop] || [:crop]
Shi::Jekyll::Images::File::create(page, source, bounds, crop).url
else
href
end
src = Jekyll::PathManager::join '', src
cls = '__image'
cls += ' ' + args[:class] if args[:class]
cls += ' ' + [:class] if [:class]
width = args[:width] || [:width] || DEFAULT_WIDTH
style = ""
style += [:style] if [:style]
style += args[:style] if args[:style]
shape = args[:shape] || [:shape]
case shape
when Jekyll::StaticFile
shape_url = if shape.write?
shape.url
else
bounds = thumb_bounds context, args,
crop = args[:crop] || [:crop]
Jekyll::PathManager::join '', Shi::Jekyll::Images::File::create(page, shape, bounds, crop).url
end
style += "shape-outside:url(#{shape_url});"
when String
cls += " __shape_#{shape}"
when true
style += "shape-outside:url(#{src});"
end
caption = args[:caption]
title = args[:title] || caption
alt = args[:alt] || title
id = args[:id]
attrs = "class=\"#{cls}\""
attrs += " style=\"#{style}\"" if style && !style.empty?
attrs += " alt=\"#{alt}\"" if alt
attrs += " title=\"#{title}\"" if title
attrs += " id=\"#{id}\""
figure = args[:figure]
if figure && !.empty?
raise ArgumentError, 'Nested figures not allowed!'
end
result = ''
if figure
fig_class = '__figure __implicit_figure'
place = args[:place]
if place == 'right' || args[:right]
fig_class += ' __right'
elsif place == 'left' || args[:left]
fig_class += ' __left'
else
fig_class += ' __center'
end
fig_class += ' ' + args[:fig_class] if args[:fig_class]
fig_style = "max-width:#{width.value};"
fig_style += args[:fig_style] if args[:fig_style]
case shape
when Jekyll::StaticFile
shape_url = if shape.write?
shape.url
else
bounds = thumb_bounds context, args,
crop = args[:crop] || [:crop]
Jekyll::PathManager::join '', Shi::Jekyll::Images::File::create(page, shape, bounds, crop).url
end
fig_style += "shape-outside:url(#{shape_url});"
when String
fig_class += " __shape_#{shape}"
when true
fig_style += "shape-outside:url(#{src});"
end
result += "<figure class=\"#{fig_class}\" style=\"#{fig_style}\" markdown=\"0\">"
end
if link != false
if gen_big
result += "<a href=\"#{href}\" class=\"__image_link\">"
else
result += "<a href=\"#{href}\">"
end
end
result += "<img src=\"#{src}\" #{attrs}>"
if link != false
result += '</a>'
end
if figure
if caption
result += "<figcaption markdown=\"span\">#{caption}</figcaption>"
end
result += '</figure>'
end
result
end
|