middlemac-extras 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +18 -0
- data/LICENSE.md +22 -0
- data/README.md +70 -0
- data/Rakefile +10 -0
- data/bin/middlemac-extras +80 -0
- data/documentation_project/.gitignore +25 -0
- data/documentation_project/Gemfile +17 -0
- data/documentation_project/README.md +13 -0
- data/documentation_project/config.rb +77 -0
- data/documentation_project/source/archives/about.html.md.erb +29 -0
- data/documentation_project/source/archives/index.html.md.erb +78 -0
- data/documentation_project/source/archives/past_far/about.html.md.erb +29 -0
- data/documentation_project/source/archives/past_far/index.html.md.erb +35 -0
- data/documentation_project/source/archives/past_near/about.html.md.erb +29 -0
- data/documentation_project/source/archives/past_near/index.html.md.erb +35 -0
- data/documentation_project/source/books/about.html.md.erb +29 -0
- data/documentation_project/source/books/index.html.md.erb +30 -0
- data/documentation_project/source/books/science fiction/about.html.md.erb +29 -0
- data/documentation_project/source/books/science fiction/index.html.md.erb +35 -0
- data/documentation_project/source/books/science fiction/past_science_fiction/about.html.md.erb +29 -0
- data/documentation_project/source/books/science fiction/past_science_fiction/index.html.md.erb +35 -0
- data/documentation_project/source/books/science fiction/past_science_fiction/past_far/about.html.md.erb +29 -0
- data/documentation_project/source/books/science fiction/past_science_fiction/past_far/index.html.md.erb +35 -0
- data/documentation_project/source/books/science fiction/past_science_fiction/past_near/about.html.md.erb +29 -0
- data/documentation_project/source/books/science fiction/past_science_fiction/past_near/index.html.md.erb +35 -0
- data/documentation_project/source/config_rb.html.md.erb +72 -0
- data/documentation_project/source/css_image_sizes.html.md.erb +65 -0
- data/documentation_project/source/image_tag.html.md.erb +83 -0
- data/documentation_project/source/images/middlemac-extras-small.png +0 -0
- data/documentation_project/source/images/middlemac-extras-small@2x.png +0 -0
- data/documentation_project/source/images/middlemac-extras.png +0 -0
- data/documentation_project/source/images/middlemac-extras@2x.png +0 -0
- data/documentation_project/source/images/sub_images/middlemac-extras-small.png +0 -0
- data/documentation_project/source/images/sub_images/middlemac-extras-small@2x.png +0 -0
- data/documentation_project/source/images/sub_images/middlemac-extras.png +0 -0
- data/documentation_project/source/images/sub_images/middlemac-extras@2x.png +0 -0
- data/documentation_project/source/index.html.md.erb +53 -0
- data/documentation_project/source/javascripts/all.js +1 -0
- data/documentation_project/source/layouts/layout.haml +10 -0
- data/documentation_project/source/layouts/template-logo-large.haml +22 -0
- data/documentation_project/source/layouts/template-logo-medium.haml +20 -0
- data/documentation_project/source/layouts/template-logo-small.haml +18 -0
- data/documentation_project/source/license.html.md.erb +42 -0
- data/documentation_project/source/md_images.html.md.erb +72 -0
- data/documentation_project/source/md_links.html.md.erb +73 -0
- data/documentation_project/source/stylesheets/_github.scss +61 -0
- data/documentation_project/source/stylesheets/_middlemac_minimal.scss +516 -0
- data/documentation_project/source/stylesheets/_normalize.scss +374 -0
- data/documentation_project/source/stylesheets/css_image_sizes.css.erb +1 -0
- data/documentation_project/source/stylesheets/style.css.scss +3 -0
- data/lib/middlemac-extras/extension.rb +261 -0
- data/lib/middlemac-extras/version.rb +5 -0
- data/lib/middlemac-extras.rb +6 -0
- data/middlemac-extras.gemspec +27 -0
- metadata +162 -0
@@ -0,0 +1,374 @@
|
|
1
|
+
/*! normalize.css v2.0.1 | MIT License | git.io/normalize */
|
2
|
+
|
3
|
+
/* ==========================================================================
|
4
|
+
HTML5 display definitions
|
5
|
+
========================================================================== */
|
6
|
+
|
7
|
+
/*
|
8
|
+
* Corrects `block` display not defined in IE 8/9.
|
9
|
+
*/
|
10
|
+
|
11
|
+
article,
|
12
|
+
aside,
|
13
|
+
details,
|
14
|
+
figcaption,
|
15
|
+
figure,
|
16
|
+
footer,
|
17
|
+
header,
|
18
|
+
nav,
|
19
|
+
section,
|
20
|
+
summary {
|
21
|
+
display: block;
|
22
|
+
}
|
23
|
+
|
24
|
+
/*
|
25
|
+
* Corrects `inline-block` display not defined in IE 8/9.
|
26
|
+
*/
|
27
|
+
|
28
|
+
audio,
|
29
|
+
canvas,
|
30
|
+
video {
|
31
|
+
display: inline-block;
|
32
|
+
}
|
33
|
+
|
34
|
+
/*
|
35
|
+
* Prevents modern browsers from displaying `audio` without controls.
|
36
|
+
* Remove excess height in iOS 5 devices.
|
37
|
+
*/
|
38
|
+
|
39
|
+
audio:not([controls]) {
|
40
|
+
display: none;
|
41
|
+
height: 0;
|
42
|
+
}
|
43
|
+
|
44
|
+
/*
|
45
|
+
* Addresses styling for `hidden` attribute not present in IE 8/9.
|
46
|
+
*/
|
47
|
+
|
48
|
+
[hidden] {
|
49
|
+
display: none;
|
50
|
+
}
|
51
|
+
|
52
|
+
/* ==========================================================================
|
53
|
+
Base
|
54
|
+
========================================================================== */
|
55
|
+
|
56
|
+
/*
|
57
|
+
* 1. Sets default font family to sans-serif.
|
58
|
+
* 2. Prevents iOS text size adjust after orientation change, without disabling
|
59
|
+
* user zoom.
|
60
|
+
*/
|
61
|
+
|
62
|
+
html {
|
63
|
+
font-family: sans-serif; /* 1 */
|
64
|
+
-webkit-text-size-adjust: 100%; /* 2 */
|
65
|
+
-ms-text-size-adjust: 100%; /* 2 */
|
66
|
+
}
|
67
|
+
|
68
|
+
/*
|
69
|
+
* Removes default margin.
|
70
|
+
*/
|
71
|
+
|
72
|
+
body {
|
73
|
+
margin: 0;
|
74
|
+
}
|
75
|
+
|
76
|
+
/* ==========================================================================
|
77
|
+
Links
|
78
|
+
========================================================================== */
|
79
|
+
|
80
|
+
/*
|
81
|
+
* Addresses `outline` inconsistency between Chrome and other browsers.
|
82
|
+
*/
|
83
|
+
|
84
|
+
a:focus {
|
85
|
+
outline: thin dotted;
|
86
|
+
}
|
87
|
+
|
88
|
+
/*
|
89
|
+
* Improves readability when focused and also mouse hovered in all browsers.
|
90
|
+
*/
|
91
|
+
|
92
|
+
a:active,
|
93
|
+
a:hover {
|
94
|
+
outline: 0;
|
95
|
+
}
|
96
|
+
|
97
|
+
/* ==========================================================================
|
98
|
+
Typography
|
99
|
+
========================================================================== */
|
100
|
+
|
101
|
+
/*
|
102
|
+
* Addresses `h1` font sizes within `section` and `article` in Firefox 4+,
|
103
|
+
* Safari 5, and Chrome.
|
104
|
+
*/
|
105
|
+
|
106
|
+
h1 {
|
107
|
+
font-size: 2em;
|
108
|
+
}
|
109
|
+
|
110
|
+
/*
|
111
|
+
* Addresses styling not present in IE 8/9, Safari 5, and Chrome.
|
112
|
+
*/
|
113
|
+
|
114
|
+
abbr[title] {
|
115
|
+
border-bottom: 1px dotted;
|
116
|
+
}
|
117
|
+
|
118
|
+
/*
|
119
|
+
* Addresses style set to `bolder` in Firefox 4+, Safari 5, and Chrome.
|
120
|
+
*/
|
121
|
+
|
122
|
+
b,
|
123
|
+
strong {
|
124
|
+
font-weight: bold;
|
125
|
+
}
|
126
|
+
|
127
|
+
/*
|
128
|
+
* Addresses styling not present in Safari 5 and Chrome.
|
129
|
+
*/
|
130
|
+
|
131
|
+
dfn {
|
132
|
+
font-style: italic;
|
133
|
+
}
|
134
|
+
|
135
|
+
/*
|
136
|
+
* Addresses styling not present in IE 8/9.
|
137
|
+
*/
|
138
|
+
|
139
|
+
mark {
|
140
|
+
background: #ff0;
|
141
|
+
color: #000;
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
/*
|
146
|
+
* Corrects font family set oddly in Safari 5 and Chrome.
|
147
|
+
*/
|
148
|
+
|
149
|
+
code,
|
150
|
+
kbd,
|
151
|
+
pre,
|
152
|
+
samp {
|
153
|
+
font-family: monospace, serif;
|
154
|
+
font-size: 1em;
|
155
|
+
}
|
156
|
+
|
157
|
+
/*
|
158
|
+
* Improves readability of pre-formatted text in all browsers.
|
159
|
+
*/
|
160
|
+
|
161
|
+
pre {
|
162
|
+
white-space: pre;
|
163
|
+
white-space: pre-wrap;
|
164
|
+
word-wrap: break-word;
|
165
|
+
}
|
166
|
+
|
167
|
+
/*
|
168
|
+
* Sets consistent quote types.
|
169
|
+
*/
|
170
|
+
|
171
|
+
q {
|
172
|
+
quotes: "\201C" "\201D" "\2018" "\2019";
|
173
|
+
}
|
174
|
+
|
175
|
+
/*
|
176
|
+
* Addresses inconsistent and variable font size in all browsers.
|
177
|
+
*/
|
178
|
+
|
179
|
+
small {
|
180
|
+
font-size: 80%;
|
181
|
+
}
|
182
|
+
|
183
|
+
/*
|
184
|
+
* Prevents `sub` and `sup` affecting `line-height` in all browsers.
|
185
|
+
*/
|
186
|
+
|
187
|
+
sub,
|
188
|
+
sup {
|
189
|
+
font-size: 75%;
|
190
|
+
line-height: 0;
|
191
|
+
position: relative;
|
192
|
+
vertical-align: baseline;
|
193
|
+
}
|
194
|
+
|
195
|
+
sup {
|
196
|
+
top: -0.5em;
|
197
|
+
}
|
198
|
+
|
199
|
+
sub {
|
200
|
+
bottom: -0.25em;
|
201
|
+
}
|
202
|
+
|
203
|
+
/* ==========================================================================
|
204
|
+
Embedded content
|
205
|
+
========================================================================== */
|
206
|
+
|
207
|
+
/*
|
208
|
+
* Removes border when inside `a` element in IE 8/9.
|
209
|
+
*/
|
210
|
+
|
211
|
+
img {
|
212
|
+
border: 0;
|
213
|
+
}
|
214
|
+
|
215
|
+
/*
|
216
|
+
* Corrects overflow displayed oddly in IE 9.
|
217
|
+
*/
|
218
|
+
|
219
|
+
svg:not(:root) {
|
220
|
+
overflow: hidden;
|
221
|
+
}
|
222
|
+
|
223
|
+
/* ==========================================================================
|
224
|
+
Figures
|
225
|
+
========================================================================== */
|
226
|
+
|
227
|
+
/*
|
228
|
+
* Addresses margin not present in IE 8/9 and Safari 5.
|
229
|
+
*/
|
230
|
+
|
231
|
+
figure {
|
232
|
+
margin: 0;
|
233
|
+
}
|
234
|
+
|
235
|
+
/* ==========================================================================
|
236
|
+
Forms
|
237
|
+
========================================================================== */
|
238
|
+
|
239
|
+
/*
|
240
|
+
* Define consistent border, margin, and padding.
|
241
|
+
*/
|
242
|
+
|
243
|
+
fieldset {
|
244
|
+
border: 1px solid #c0c0c0;
|
245
|
+
margin: 0 2px;
|
246
|
+
padding: 0.35em 0.625em 0.75em;
|
247
|
+
}
|
248
|
+
|
249
|
+
/*
|
250
|
+
* 1. Corrects color not being inherited in IE 8/9.
|
251
|
+
* 2. Remove padding so people aren't caught out if they zero out fieldsets.
|
252
|
+
*/
|
253
|
+
|
254
|
+
legend {
|
255
|
+
border: 0; /* 1 */
|
256
|
+
padding: 0; /* 2 */
|
257
|
+
}
|
258
|
+
|
259
|
+
/*
|
260
|
+
* 1. Corrects font family not being inherited in all browsers.
|
261
|
+
* 2. Corrects font size not being inherited in all browsers.
|
262
|
+
* 3. Addresses margins set differently in Firefox 4+, Safari 5, and Chrome
|
263
|
+
*/
|
264
|
+
|
265
|
+
button,
|
266
|
+
input,
|
267
|
+
select,
|
268
|
+
textarea {
|
269
|
+
font-family: inherit; /* 1 */
|
270
|
+
font-size: 100%; /* 2 */
|
271
|
+
margin: 0; /* 3 */
|
272
|
+
}
|
273
|
+
|
274
|
+
/*
|
275
|
+
* Addresses Firefox 4+ setting `line-height` on `input` using `!important` in
|
276
|
+
* the UA stylesheet.
|
277
|
+
*/
|
278
|
+
|
279
|
+
button,
|
280
|
+
input {
|
281
|
+
line-height: normal;
|
282
|
+
}
|
283
|
+
|
284
|
+
/*
|
285
|
+
* 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
|
286
|
+
* and `video` controls.
|
287
|
+
* 2. Corrects inability to style clickable `input` types in iOS.
|
288
|
+
* 3. Improves usability and consistency of cursor style between image-type
|
289
|
+
* `input` and others.
|
290
|
+
*/
|
291
|
+
|
292
|
+
button,
|
293
|
+
html input[type="button"], /* 1 */
|
294
|
+
input[type="reset"],
|
295
|
+
input[type="submit"] {
|
296
|
+
-webkit-appearance: button; /* 2 */
|
297
|
+
cursor: pointer; /* 3 */
|
298
|
+
}
|
299
|
+
|
300
|
+
/*
|
301
|
+
* Re-set default cursor for disabled elements.
|
302
|
+
*/
|
303
|
+
|
304
|
+
button[disabled],
|
305
|
+
input[disabled] {
|
306
|
+
cursor: default;
|
307
|
+
}
|
308
|
+
|
309
|
+
/*
|
310
|
+
* 1. Addresses box sizing set to `content-box` in IE 8/9.
|
311
|
+
* 2. Removes excess padding in IE 8/9.
|
312
|
+
*/
|
313
|
+
|
314
|
+
input[type="checkbox"],
|
315
|
+
input[type="radio"] {
|
316
|
+
box-sizing: border-box; /* 1 */
|
317
|
+
padding: 0; /* 2 */
|
318
|
+
}
|
319
|
+
|
320
|
+
/*
|
321
|
+
* 1. Addresses `appearance` set to `searchfield` in Safari 5 and Chrome.
|
322
|
+
* 2. Addresses `box-sizing` set to `border-box` in Safari 5 and Chrome
|
323
|
+
* (include `-moz` to future-proof).
|
324
|
+
*/
|
325
|
+
|
326
|
+
input[type="search"] {
|
327
|
+
-webkit-appearance: textfield; /* 1 */
|
328
|
+
-moz-box-sizing: content-box;
|
329
|
+
-webkit-box-sizing: content-box; /* 2 */
|
330
|
+
box-sizing: content-box;
|
331
|
+
}
|
332
|
+
|
333
|
+
/*
|
334
|
+
* Removes inner padding and search cancel button in Safari 5 and Chrome
|
335
|
+
* on OS X.
|
336
|
+
*/
|
337
|
+
|
338
|
+
input[type="search"]::-webkit-search-cancel-button,
|
339
|
+
input[type="search"]::-webkit-search-decoration {
|
340
|
+
-webkit-appearance: none;
|
341
|
+
}
|
342
|
+
|
343
|
+
/*
|
344
|
+
* Removes inner padding and border in Firefox 4+.
|
345
|
+
*/
|
346
|
+
|
347
|
+
button::-moz-focus-inner,
|
348
|
+
input::-moz-focus-inner {
|
349
|
+
border: 0;
|
350
|
+
padding: 0;
|
351
|
+
}
|
352
|
+
|
353
|
+
/*
|
354
|
+
* 1. Removes default vertical scrollbar in IE 8/9.
|
355
|
+
* 2. Improves readability and alignment in all browsers.
|
356
|
+
*/
|
357
|
+
|
358
|
+
textarea {
|
359
|
+
overflow: auto; /* 1 */
|
360
|
+
vertical-align: top; /* 2 */
|
361
|
+
}
|
362
|
+
|
363
|
+
/* ==========================================================================
|
364
|
+
Tables
|
365
|
+
========================================================================== */
|
366
|
+
|
367
|
+
/*
|
368
|
+
* Remove most spacing between table cells.
|
369
|
+
*/
|
370
|
+
|
371
|
+
table {
|
372
|
+
border-collapse: collapse;
|
373
|
+
border-spacing: 0;
|
374
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= css_image_sizes %>
|
@@ -0,0 +1,261 @@
|
|
1
|
+
################################################################################
|
2
|
+
# extension.rb
|
3
|
+
# This file constitutes the framework for the bulk of this extension.
|
4
|
+
################################################################################
|
5
|
+
require 'middleman-core'
|
6
|
+
require 'pathname'
|
7
|
+
require 'fastimage'
|
8
|
+
|
9
|
+
class MiddlemacExtras < ::Middleman::Extension
|
10
|
+
|
11
|
+
############################################################
|
12
|
+
# Define the options that are to be set within `config.rb`
|
13
|
+
# as extension options.
|
14
|
+
############################################################
|
15
|
+
option :retina_srcset, true, 'If true then the image_tag helper will be extended to include automatic @2x images.'
|
16
|
+
option :img_auto_extensions, true, 'If true then `image_tag` will work without filename extensions.'
|
17
|
+
option :img_auto_extensions_order, %w(.svg .png .jpg .jpeg .gif .tiff .tif), 'Specifies the order to support automatic image extensions.'
|
18
|
+
|
19
|
+
|
20
|
+
############################################################
|
21
|
+
# initialize
|
22
|
+
############################################################
|
23
|
+
def initialize(app, options_hash={}, &block)
|
24
|
+
|
25
|
+
super
|
26
|
+
|
27
|
+
@md_links_b = nil
|
28
|
+
@md_images_b = nil
|
29
|
+
@md_sizes_b = nil
|
30
|
+
|
31
|
+
end # initialize
|
32
|
+
|
33
|
+
|
34
|
+
############################################################
|
35
|
+
# after_configuration
|
36
|
+
# Callback occurs before `before_build`.
|
37
|
+
#############################################################
|
38
|
+
def after_configuration
|
39
|
+
|
40
|
+
# Reset the helpers' buffers when the configuration
|
41
|
+
# changes. For speed we don't want to recalculate everything
|
42
|
+
# every time a helper is used, but only the first time.
|
43
|
+
@md_links_b = nil
|
44
|
+
@md_images_b = nil
|
45
|
+
@md_sizes_b = nil
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
############################################################
|
51
|
+
# Helpers
|
52
|
+
# Methods defined in this helpers block are available in
|
53
|
+
# templates.
|
54
|
+
############################################################
|
55
|
+
|
56
|
+
helpers do
|
57
|
+
|
58
|
+
#--------------------------------------------------------
|
59
|
+
# md_links
|
60
|
+
# Adds simple markdown links where needed.
|
61
|
+
#--------------------------------------------------------
|
62
|
+
def md_links
|
63
|
+
extensions[:MiddlemacExtras].md_links_b
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
#--------------------------------------------------------
|
68
|
+
# md_images
|
69
|
+
# Adds simple markdown image links where needed.
|
70
|
+
#--------------------------------------------------------
|
71
|
+
def md_images
|
72
|
+
extensions[:MiddlemacExtras].md_images_b
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
#--------------------------------------------------------
|
77
|
+
# css_image_sizes
|
78
|
+
# Generates image size CSS information for all images.
|
79
|
+
#--------------------------------------------------------
|
80
|
+
def css_image_sizes
|
81
|
+
extensions[:MiddlemacExtras].md_sizes_b
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
#--------------------------------------------------------
|
86
|
+
# image_tag(path, params={})
|
87
|
+
# Add automatic srcset if an @2x image is present and
|
88
|
+
# no srcset is already specified. Also support the
|
89
|
+
# use of extension-less images.
|
90
|
+
#--------------------------------------------------------
|
91
|
+
def image_tag(path, params={})
|
92
|
+
params.symbolize_keys!
|
93
|
+
ext_options = extensions[:MiddlemacExtras].options
|
94
|
+
|
95
|
+
img_auto_extensions = ext_options[:img_auto_extensions]
|
96
|
+
img_auto_extensions = params.delete(:img_auto_extensions) if params[:img_auto_extensions]
|
97
|
+
|
98
|
+
retina_srcset = ext_options[:retina_srcset]
|
99
|
+
retina_srcset = params.delete(:retina_srcset) if params[:retina_srcset]
|
100
|
+
|
101
|
+
automatic_alt_tags = @app.extensions[:automatic_alt_tags]
|
102
|
+
automatic_alt_tags = params.delete(:automatic_alt_tags) if params[:automatic_alt_tags]
|
103
|
+
|
104
|
+
|
105
|
+
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
106
|
+
# Support images without extensions. If an image with the
|
107
|
+
# specified name + :img_auto_extensions_order is found,
|
108
|
+
# use that instead.
|
109
|
+
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
110
|
+
if File.extname(path) == '' && img_auto_extensions
|
111
|
+
ext_options[:img_auto_extensions_order].reverse.each do |ext|
|
112
|
+
real_path = "#{path.dup}#{ext}"
|
113
|
+
real_path = if path.start_with?('/')
|
114
|
+
File.expand_path(File.join(@app.config[:source], real_path))
|
115
|
+
else
|
116
|
+
File.expand_path(File.join(@app.config[:source], @app.config[:images_dir], real_path))
|
117
|
+
end
|
118
|
+
|
119
|
+
file = app.files.find(:source, real_path)
|
120
|
+
if file && file[:full_path].exist?
|
121
|
+
path = "#{path.dup}#{ext}"
|
122
|
+
end
|
123
|
+
end # each
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
128
|
+
# Support automatic @2x image srcset.
|
129
|
+
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
130
|
+
if retina_srcset
|
131
|
+
test_path = path.sub(/#{File.extname(path)}/i, "@2x#{File.extname(path)}")
|
132
|
+
real_path = if path.start_with?('/')
|
133
|
+
File.expand_path(File.join(@app.config[:source], test_path))
|
134
|
+
else
|
135
|
+
File.expand_path(File.join(@app.config[:source], @app.config[:images_dir], test_path))
|
136
|
+
end
|
137
|
+
|
138
|
+
file = app.files.find(:source, real_path)
|
139
|
+
if file && file[:full_path].exist?
|
140
|
+
params[:srcset] ||= "#{test_path} 2x"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
146
|
+
# Support automatic alt tags for absolute locations, too.
|
147
|
+
# Only do this for absolute paths; let the extension do its
|
148
|
+
# own thing otherwise.
|
149
|
+
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
150
|
+
if automatic_alt_tags && path.start_with?('/')
|
151
|
+
alt_text = File.basename(path, '.*')
|
152
|
+
alt_text.capitalize!
|
153
|
+
params[:alt] ||= alt_text
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
super(path, params)
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
end #helpers
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
############################################################
|
166
|
+
# Instance Methods
|
167
|
+
############################################################
|
168
|
+
|
169
|
+
#--------------------------------------------------------
|
170
|
+
# md_links_b
|
171
|
+
# Adds simple markdown links where needed.
|
172
|
+
#--------------------------------------------------------
|
173
|
+
def md_links_b
|
174
|
+
unless @md_links_b
|
175
|
+
@md_links_b = get_link_data('text/html', 'application/xhtml')
|
176
|
+
.collect { |l| "[#{l[:reference]}]: #{l[:link]} \"#{l[:title]}\"" }
|
177
|
+
.join("\n")
|
178
|
+
end
|
179
|
+
|
180
|
+
@md_links_b
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
#--------------------------------------------------------
|
185
|
+
# md_images_b
|
186
|
+
#--------------------------------------------------------
|
187
|
+
def md_images_b
|
188
|
+
unless @md_images_b
|
189
|
+
@md_images_b = get_link_data('image/')
|
190
|
+
.collect { |l| "[#{l[:reference]}]: #{l[:link]}" }
|
191
|
+
.join("\n")
|
192
|
+
end
|
193
|
+
@md_images_b
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
#--------------------------------------------------------
|
198
|
+
# get_link_data( *types )
|
199
|
+
# Get all of the required link data for generating
|
200
|
+
# markdown shortcuts.
|
201
|
+
# @param types should be the content_type to check.
|
202
|
+
# @return an array of hashes with file data.
|
203
|
+
#--------------------------------------------------------
|
204
|
+
def get_link_data( *types )
|
205
|
+
all_links = []
|
206
|
+
# We'll include a sort by number of path components in this chain so
|
207
|
+
# that we can improve the chances of higher-level items not having
|
208
|
+
# naming conflicts. For example, the topmost index.html file should
|
209
|
+
# not require a prefix!
|
210
|
+
app.sitemap.resources
|
211
|
+
.select { |r| r.content_type && r.content_type.start_with?( *types ) }
|
212
|
+
.sort { |a, b| Pathname(a.destination_path).each_filename.to_a.count <=> Pathname(b.destination_path).each_filename.to_a.count }
|
213
|
+
.each do |r|
|
214
|
+
reference_path = Pathname(r.destination_path).each_filename.to_a.reverse
|
215
|
+
reference_path.shift
|
216
|
+
reference = File.basename(r.destination_path, '.*').gsub(%r{ }, '_')
|
217
|
+
link = r.url
|
218
|
+
title = r.data.title ? r.data.title.gsub(%r{</?[^>]+?>}, '') : nil
|
219
|
+
|
220
|
+
i = 0
|
221
|
+
while all_links.find { |link| link[:reference] == reference }
|
222
|
+
next_piece = reference_path[i].gsub(%r{ }, '_')
|
223
|
+
reference = "#{next_piece}-#{reference}"
|
224
|
+
i += 1
|
225
|
+
end
|
226
|
+
|
227
|
+
all_links << {:reference => reference, :link => link, :title => title}
|
228
|
+
end # .each
|
229
|
+
|
230
|
+
all_links
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
#--------------------------------------------------------
|
235
|
+
# md_sizes_b
|
236
|
+
# For every image resource, try to build the size.
|
237
|
+
#--------------------------------------------------------
|
238
|
+
def md_sizes_b
|
239
|
+
unless @md_sizes_b
|
240
|
+
@md_sizes_b = []
|
241
|
+
app.sitemap.resources
|
242
|
+
.select { |r| r.content_type && r.content_type.start_with?('image/') }
|
243
|
+
.each do |r|
|
244
|
+
|
245
|
+
file = r.file_descriptor.full_path
|
246
|
+
base_name = File.basename(r.destination_path, '.*')
|
247
|
+
factor = 1
|
248
|
+
factor = 2 if base_name.end_with?('@2x')
|
249
|
+
factor = 3 if base_name.end_with?('@3x')
|
250
|
+
if FastImage.size(file)
|
251
|
+
width = (FastImage.size(file)[0] / factor).to_i.to_s
|
252
|
+
height = (FastImage.size(file)[1] / factor).to_i.to_s
|
253
|
+
@md_sizes_b << "img[src$='#{r.url}'] { max-width: #{width}px; max-height: #{height}px; }"
|
254
|
+
end
|
255
|
+
end # each
|
256
|
+
end
|
257
|
+
|
258
|
+
@md_sizes_b.join("\n")
|
259
|
+
end
|
260
|
+
|
261
|
+
end # class MiddlemacExtras
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'middlemac-extras/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'middlemac-extras'
|
7
|
+
s.version = Middleman::MiddlemacExtras::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Jim Derry']
|
10
|
+
s.email = ['balthisar@gmail.com']
|
11
|
+
s.homepage = 'https://github.com/middlemac/middlemac-extras'
|
12
|
+
s.summary = 'Implements several useful developer conveniences for Middleman projects.'
|
13
|
+
s.description = 'Implements several useful developer conveniences for Middleman projects.'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
|
21
|
+
# The version of middleman-core your extension depends on
|
22
|
+
s.add_runtime_dependency('middleman-core', ['~> 4.1', '>= 4.1.6'])
|
23
|
+
|
24
|
+
# Additional dependencies
|
25
|
+
s.add_runtime_dependency('middleman-cli', ['~> 4.1', '>= 4.1.6'])
|
26
|
+
s.add_runtime_dependency('fastimage', ['~> 1.9', '>= 1.9.0'])
|
27
|
+
end
|