middlemac-extras 1.0.6 → 1.0.11
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 +5 -5
- data/.gitattributes +4 -0
- data/.gitignore +8 -1
- data/.yardopts +7 -0
- data/CHANGELOG.md +55 -9
- data/Rakefile +206 -7
- data/documentation_project/Gemfile +3 -3
- data/documentation_project/config.rb +2 -6
- data/documentation_project/source/api_reference.html.md.erb +38 -0
- data/documentation_project/source/cli.html.md.erb +4 -3
- data/documentation_project/source/config_rb.html.md.erb +1 -2
- data/documentation_project/source/css_image_sizes.html.md.erb +2 -3
- data/documentation_project/source/image_tag.html.md.erb +1 -2
- data/documentation_project/source/index.html.md.erb +8 -7
- data/documentation_project/source/license.html.md.erb +1 -2
- data/documentation_project/source/md_images.html.md.erb +1 -2
- data/documentation_project/source/md_links.html.md.erb +1 -2
- data/documentation_project/source/partials/_yard_config.erb +200 -0
- data/documentation_project/source/partials/_yard_helpers.erb +192 -0
- data/documentation_project/source/partials/_yard_helpers_extended.erb +135 -0
- data/documentation_project/source/stylesheets/_middlemac_minimal.scss +281 -0
- data/features/helpers.feature +39 -0
- data/features/support/env.rb +20 -0
- data/fixtures/middlemac_extras_app/config.rb +7 -0
- data/fixtures/middlemac_extras_app/source/images/middlemac-extras-small.png +0 -0
- data/fixtures/middlemac_extras_app/source/images/middlemac-extras-small@2x.png +0 -0
- data/fixtures/middlemac_extras_app/source/images/middlemac-extras-smaller.png +0 -0
- data/fixtures/middlemac_extras_app/source/index.html.md.erb +31 -0
- data/lib/middlemac-extras/extension.rb +187 -61
- data/lib/middlemac-extras/version.rb +1 -1
- data/middlemac-extras.gemspec +44 -17
- data/yard/readme.md +6 -0
- data/yard/template-grouped/default/module/html/method_details_list.erb +11 -0
- data/yard/template-partials/default/method_details/setup.rb +4 -0
- data/yard/template-partials/default/module/html/attribute_details.erb +9 -0
- data/yard/template-partials/default/module/html/method_details_list.erb +10 -0
- data/yard/template-partials/default/module/setup.rb +6 -0
- data/yard/template-partials/default/onefile/html/layout.erb +1 -0
- data/yard/template-partials/default/onefile/html/setup.rb +4 -0
- data/yard/yard_extensions.rb +109 -0
- metadata +118 -23
@@ -0,0 +1,20 @@
|
|
1
|
+
PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
|
2
|
+
ENV['TEST'] = 'true'
|
3
|
+
|
4
|
+
require 'middleman'
|
5
|
+
require 'middleman-core/step_definitions'
|
6
|
+
require File.join(PROJECT_ROOT_PATH, 'lib', 'middlemac-extras')
|
7
|
+
|
8
|
+
|
9
|
+
require 'cucumber/formatter/pretty'
|
10
|
+
class QuietFormatter < Cucumber::Formatter::Pretty
|
11
|
+
def initialize(runtime, io, options)
|
12
|
+
$stderr = File.new( '/dev/null', 'w' )
|
13
|
+
super(runtime, io, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def after_features(features)
|
17
|
+
$stderr = STDOUT
|
18
|
+
super(features)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
title: Fixture for middlemac-extras
|
3
|
+
---
|
4
|
+
# css_image_sizes
|
5
|
+
|
6
|
+
~~~
|
7
|
+
<%= css_image_sizes %>
|
8
|
+
~~~
|
9
|
+
|
10
|
+
# md_images
|
11
|
+
|
12
|
+
~~~
|
13
|
+
<%= md_images %>
|
14
|
+
~~~
|
15
|
+
|
16
|
+
# md_links
|
17
|
+
|
18
|
+
~~~
|
19
|
+
<%= md_links %>
|
20
|
+
~~~
|
21
|
+
|
22
|
+
# extended image_tag
|
23
|
+
|
24
|
+
~~~
|
25
|
+
<%= image_tag 'middlemac-extras-small' %>
|
26
|
+
~~~
|
27
|
+
|
28
|
+
~~~
|
29
|
+
<%= image_tag 'middlemac-extras-smaller' %>
|
30
|
+
~~~
|
31
|
+
|
@@ -1,11 +1,12 @@
|
|
1
|
-
################################################################################
|
2
|
-
# extension.rb
|
3
|
-
# This file constitutes the framework for the bulk of this extension.
|
4
|
-
################################################################################
|
5
1
|
require 'middleman-core'
|
6
2
|
require 'pathname'
|
7
3
|
require 'fastimage'
|
8
4
|
|
5
|
+
################################################################################
|
6
|
+
# This extension provides Middleman several useful helpers and extends some of
|
7
|
+
# its built-in helpers to offer more features.
|
8
|
+
# @author Jim Derry <balthisar@gmail.com>
|
9
|
+
################################################################################
|
9
10
|
class MiddlemacExtras < ::Middleman::Extension
|
10
11
|
|
11
12
|
############################################################
|
@@ -17,14 +18,46 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
17
18
|
option :img_auto_extensions_order, %w(.svg .png .jpg .jpeg .gif .tiff .tif), 'Specifies the order to support automatic image extensions.'
|
18
19
|
|
19
20
|
|
21
|
+
# @!group Extension Configuration
|
22
|
+
|
23
|
+
# @!attribute [rw] options[:retina_srcset]=
|
24
|
+
# This option determines whether or not the enhanced `image_tag` helper will
|
25
|
+
# be used to include an @2x `srcset` attribute automatically. This automatic
|
26
|
+
# behavior will only be applied if the image asset exists on disk and this
|
27
|
+
# option is set to `true`.
|
28
|
+
# @param [Boolean] value `true` or `false` to enable or disable this feature.
|
29
|
+
# @return [Boolean] Returns the current value of this option.
|
30
|
+
|
31
|
+
# @!attribute [rw] options[:img_auto_extensions]=
|
32
|
+
# This option determines whether or not to support specifying images without
|
33
|
+
# using a file name extension. If set to `true` then the `image_tag` helper
|
34
|
+
# will work for images even if you don’t specify an extension, but only if a
|
35
|
+
# file exists on disk that has one of the extensions in
|
36
|
+
# `:img_auto_extensions_order`.
|
37
|
+
# @param [Boolean] value `true` or `false` to enable or disable this feature.
|
38
|
+
# @return [Boolean] Returns the current value of this option.
|
39
|
+
|
40
|
+
# @!attribute [rw] options[:img_auto_extensions_order]=
|
41
|
+
# This option defines the eligible file name extensions and their precedence
|
42
|
+
# when you specify an image without an extension using the `image_tag` helper.
|
43
|
+
# Set this to an array of image file extensions in your desired order of
|
44
|
+
# of precedence.
|
45
|
+
# @param [Array<String>] value Set to an array of image extensions.
|
46
|
+
# @return [Array<String>] Returns the current value of this option.
|
47
|
+
|
48
|
+
# @!endgroup
|
49
|
+
|
50
|
+
|
20
51
|
############################################################
|
21
52
|
# initialize
|
53
|
+
# @visibility private
|
22
54
|
############################################################
|
23
55
|
def initialize(app, options_hash={}, &block)
|
24
56
|
|
25
57
|
super
|
26
58
|
|
27
59
|
@md_links_b = nil
|
60
|
+
@md_links_modern_b = nil
|
28
61
|
@md_images_b = nil
|
29
62
|
@md_sizes_b = nil
|
30
63
|
|
@@ -33,7 +66,8 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
33
66
|
|
34
67
|
############################################################
|
35
68
|
# after_configuration
|
36
|
-
#
|
69
|
+
# Callback occurs before `before_build`.
|
70
|
+
# @visibility private
|
37
71
|
#############################################################
|
38
72
|
def after_configuration
|
39
73
|
|
@@ -41,6 +75,7 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
41
75
|
# changes. For speed we don't want to recalculate everything
|
42
76
|
# every time a helper is used, but only the first time.
|
43
77
|
@md_links_b = nil
|
78
|
+
@md_links_modern_b = nil
|
44
79
|
@md_images_b = nil
|
45
80
|
@md_sizes_b = nil
|
46
81
|
|
@@ -56,8 +91,13 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
56
91
|
helpers do
|
57
92
|
|
58
93
|
#--------------------------------------------------------
|
59
|
-
#
|
60
|
-
#
|
94
|
+
# This helper provides access to `middlemac-extras`’
|
95
|
+
# index of links in Markdown reference format, enabling
|
96
|
+
# you to use reference-style links in documents. Because
|
97
|
+
# this helper includes literal Markdown, it’s only useful
|
98
|
+
# in Markdown documents.
|
99
|
+
# @return [String] Returns a string with the Markdown
|
100
|
+
# index of every page in your project.
|
61
101
|
#--------------------------------------------------------
|
62
102
|
def md_links
|
63
103
|
extensions[:MiddlemacExtras].md_links_b
|
@@ -65,8 +105,29 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
65
105
|
|
66
106
|
|
67
107
|
#--------------------------------------------------------
|
68
|
-
#
|
69
|
-
#
|
108
|
+
# This helper provides access to `middlemac-extras`’
|
109
|
+
# index of links in Markdown reference format, enabling
|
110
|
+
# you to use reference-style links in documents. Because
|
111
|
+
# this helper includes literal Markdown, it’s only useful
|
112
|
+
# in Markdown documents. This is only useful when using
|
113
|
+
# Middlemac 3.0.0 or newer, which includes support for
|
114
|
+
# helpbook style links.
|
115
|
+
# @return [String] Returns a string with the Markdown
|
116
|
+
# index of every page in your project.
|
117
|
+
#--------------------------------------------------------
|
118
|
+
def md_hblinks
|
119
|
+
extensions[:MiddlemacExtras].md_links_modern_b
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
#--------------------------------------------------------
|
124
|
+
# This helper provides access to `middlemac-extras`’
|
125
|
+
# index of images in Markdown reference format, enabling
|
126
|
+
# you to use reference-style images in documents. Because
|
127
|
+
# this helper includes literal Markdown, it’s only useful
|
128
|
+
# in Markdown documents.
|
129
|
+
# @return [String] Returns a string with the Markdown
|
130
|
+
# index of every image in your project.
|
70
131
|
#--------------------------------------------------------
|
71
132
|
def md_images
|
72
133
|
extensions[:MiddlemacExtras].md_images_b
|
@@ -74,8 +135,14 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
74
135
|
|
75
136
|
|
76
137
|
#--------------------------------------------------------
|
77
|
-
#
|
78
|
-
#
|
138
|
+
# This helper provides CSS for every image in your
|
139
|
+
# project. Each image will have a declaration that sets
|
140
|
+
# `max-width` and `max-height` to the actual size of the
|
141
|
+
# image. Proper @2x image support is included. It’s most
|
142
|
+
# useful to use this helper in a `some_file.css.erb`
|
143
|
+
# file.
|
144
|
+
# @return [String] Returns a string with the CSS markup
|
145
|
+
# for every image found in your project.
|
79
146
|
#--------------------------------------------------------
|
80
147
|
def css_image_sizes
|
81
148
|
extensions[:MiddlemacExtras].md_sizes_b
|
@@ -83,10 +150,25 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
83
150
|
|
84
151
|
|
85
152
|
#--------------------------------------------------------
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
153
|
+
# With the proper options enabled this helper extends
|
154
|
+
# the built-in functionality of **Middleman**’s helpers
|
155
|
+
# in a couple of ways. With `:retina_srcset` enabled,
|
156
|
+
# automatic `srcset` attributes will be applied to
|
157
|
+
# `<img>` tags if an @2x version of the specified image
|
158
|
+
# is found. With `:img_auto_extensions` it’s possible to
|
159
|
+
# specify image names without the file name extension.
|
160
|
+
# @param [String] path Specify path to the image file.
|
161
|
+
# @param [Hash] params Optional parameters to pass to
|
162
|
+
# the helper. **Middleman** (and other extensions)
|
163
|
+
# provide other parameters in addition to these.
|
164
|
+
# @option params [Boolean] :img_auto_extensions Allows
|
165
|
+
# control of the automatic image extensions option
|
166
|
+
# on a per-use basis.
|
167
|
+
# @option params [Boolean] :retina_srcset Allows control
|
168
|
+
# of the automatic @2x images feature on a per-use
|
169
|
+
# basis.
|
170
|
+
# @return [String] Returns an HTML `<img>` tag.
|
171
|
+
# @group Extended Helpers
|
90
172
|
#--------------------------------------------------------
|
91
173
|
def image_tag(path, params={})
|
92
174
|
params.symbolize_keys!
|
@@ -100,9 +182,6 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
100
182
|
retina_srcset = ext_options[:retina_srcset]
|
101
183
|
retina_srcset = params.delete(:retina_srcset) if params[:retina_srcset]
|
102
184
|
|
103
|
-
automatic_alt_tags = @app.extensions[:automatic_alt_tags]
|
104
|
-
automatic_alt_tags = params.delete(:automatic_alt_tags) if params[:automatic_alt_tags]
|
105
|
-
|
106
185
|
|
107
186
|
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
108
187
|
# Support images without extensions. If an image with the
|
@@ -154,19 +233,6 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
154
233
|
end
|
155
234
|
end
|
156
235
|
|
157
|
-
|
158
|
-
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
159
|
-
# Support automatic alt tags for absolute locations, too.
|
160
|
-
# Only do this for absolute paths; let the extension do its
|
161
|
-
# own thing otherwise.
|
162
|
-
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
163
|
-
if automatic_alt_tags && path.start_with?('/')
|
164
|
-
alt_text = File.basename(path, '.*')
|
165
|
-
alt_text.capitalize!
|
166
|
-
params[:alt] ||= alt_text
|
167
|
-
end
|
168
|
-
|
169
|
-
|
170
236
|
super(path, params)
|
171
237
|
end
|
172
238
|
|
@@ -176,17 +242,28 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
176
242
|
|
177
243
|
|
178
244
|
############################################################
|
179
|
-
#
|
245
|
+
# Instance Methods
|
246
|
+
# @!group Instance Methods
|
180
247
|
############################################################
|
181
248
|
|
182
|
-
|
183
|
-
|
184
|
-
#
|
185
|
-
|
249
|
+
|
250
|
+
#########################################################
|
251
|
+
# This accessor for @md_links_b lazily populates the
|
252
|
+
# backing variable and buffers it for repeated use. In
|
253
|
+
# the event of file changes, a server restart is needed.
|
254
|
+
# @returns [String] Returns the Markdown reference list.
|
255
|
+
# @!visibility private
|
256
|
+
#########################################################
|
186
257
|
def md_links_b
|
187
258
|
unless @md_links_b
|
188
259
|
@md_links_b = get_link_data('text/html', 'application/xhtml')
|
189
|
-
.collect { |l|
|
260
|
+
.collect { |l|
|
261
|
+
if l[:title]
|
262
|
+
"[#{l[:reference]}]: #{l[:link]} \"#{l[:title]}\""
|
263
|
+
else
|
264
|
+
"[#{l[:reference]}]: #{l[:link]}"
|
265
|
+
end
|
266
|
+
}
|
190
267
|
.join("\n")
|
191
268
|
end
|
192
269
|
|
@@ -194,9 +271,38 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
194
271
|
end
|
195
272
|
|
196
273
|
|
197
|
-
|
198
|
-
#
|
199
|
-
|
274
|
+
#########################################################
|
275
|
+
# This accessor for @md_links_modern_b lazily populates
|
276
|
+
# the backing variable and buffers it for repeated use.
|
277
|
+
# In the event of file changes, a server restart is
|
278
|
+
# needed.
|
279
|
+
# @returns [String] Returns the Markdown reference list.
|
280
|
+
# @!visibility private
|
281
|
+
#########################################################
|
282
|
+
def md_links_modern_b
|
283
|
+
unless @md_links_modern_b
|
284
|
+
@md_links_modern_b = get_link_data('text/html', 'application/xhtml')
|
285
|
+
.collect { |l|
|
286
|
+
if l[:title]
|
287
|
+
"[#{l[:reference]}]: #{l[:hb_link]} \"#{l[:title]}\""
|
288
|
+
else
|
289
|
+
"[#{l[:reference]}]: #{l[:hb_link]}"
|
290
|
+
end
|
291
|
+
}
|
292
|
+
.join("\n")
|
293
|
+
end
|
294
|
+
|
295
|
+
@md_links_modern_b
|
296
|
+
end
|
297
|
+
|
298
|
+
|
299
|
+
#########################################################
|
300
|
+
# This accessor for @md_images_b lazily populates the
|
301
|
+
# backing variable and buffers it for repeated use. In
|
302
|
+
# the event of file changes, a server restart is needed.
|
303
|
+
# @returns [String] Returns the Markdown reference list.
|
304
|
+
# @!visibility private
|
305
|
+
#########################################################
|
200
306
|
def md_images_b
|
201
307
|
unless @md_images_b
|
202
308
|
@md_images_b = get_link_data('image/')
|
@@ -207,13 +313,15 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
207
313
|
end
|
208
314
|
|
209
315
|
|
210
|
-
|
211
|
-
#
|
212
|
-
#
|
213
|
-
#
|
214
|
-
#
|
215
|
-
# @return
|
216
|
-
|
316
|
+
#########################################################
|
317
|
+
# Get all of the required link data for generating
|
318
|
+
# markdown shortcuts for the two property accessors.
|
319
|
+
# @param [va_list<String>] types One or more MIME types
|
320
|
+
# specifying the file types for which to build links.
|
321
|
+
# @return [Array<Hash>] An array of hashes containing
|
322
|
+
# the file data.
|
323
|
+
# @!visibility private
|
324
|
+
#########################################################
|
217
325
|
def get_link_data( *types )
|
218
326
|
all_links = []
|
219
327
|
# We'll include a sort by number of path components in this chain so
|
@@ -228,6 +336,7 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
228
336
|
reference_path.shift
|
229
337
|
reference = File.basename(r.destination_path, '.*').gsub(%r{ }, '_')
|
230
338
|
link = r.url
|
339
|
+
hb_link = defined?(r.hb_NavId) ? "#/#{r.hb_NavId}" : nil
|
231
340
|
title = r.data.title ? r.data.title.gsub(%r{</?[^>]+?>}, '') : nil
|
232
341
|
|
233
342
|
i = 0
|
@@ -237,17 +346,21 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
237
346
|
i += 1
|
238
347
|
end
|
239
348
|
|
240
|
-
all_links << {:reference => reference, :link => link, :title => title}
|
349
|
+
all_links << {:reference => reference, :link => link, :title => title, :hb_link => hb_link}
|
241
350
|
end # .each
|
242
351
|
|
243
352
|
all_links
|
244
353
|
end
|
245
354
|
|
246
355
|
|
247
|
-
|
248
|
-
#
|
249
|
-
#
|
250
|
-
|
356
|
+
#########################################################
|
357
|
+
# For every image resource in the project, attempt to
|
358
|
+
# build the CSS rules. Only bitmap images are supported,
|
359
|
+
# as vectors (e.g., SVG) don’t have a specific size.
|
360
|
+
# @returns [String] Returns the CSS stylesheet with the
|
361
|
+
# maximum width and height for each image.
|
362
|
+
# @!visibility private
|
363
|
+
#########################################################
|
251
364
|
def md_sizes_b
|
252
365
|
unless @md_sizes_b
|
253
366
|
@md_sizes_b = []
|
@@ -282,11 +395,19 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
282
395
|
end
|
283
396
|
|
284
397
|
|
285
|
-
|
286
|
-
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
|
398
|
+
#########################################################
|
399
|
+
# Returns a file with an extension if found; otherwise
|
400
|
+
# it returns the original file. This is used to search
|
401
|
+
# for images for which no file name extension has been
|
402
|
+
# provided.
|
403
|
+
# @param [String] path Specifies the image without an
|
404
|
+
# extension, which is to be checked.
|
405
|
+
# @param [String] ext Specifies the extension to check.
|
406
|
+
# @returns [String] Returns the path of the image with
|
407
|
+
# an extension (if found), or returns the original
|
408
|
+
# `path` parameter.
|
409
|
+
# @!visibility private
|
410
|
+
#########################################################
|
290
411
|
def with_extension_proposal( path, ext )
|
291
412
|
return path unless File.extname(path) == '' && app.extensions[:MiddlemacExtras].options[:img_auto_extensions]
|
292
413
|
|
@@ -311,10 +432,15 @@ class MiddlemacExtras < ::Middleman::Extension
|
|
311
432
|
end
|
312
433
|
|
313
434
|
|
314
|
-
|
315
|
-
#
|
316
|
-
#
|
317
|
-
|
435
|
+
#########################################################
|
436
|
+
# Output colored messages using ANSI codes.
|
437
|
+
# @param [String] message The message to output to the
|
438
|
+
# console.
|
439
|
+
# @param [Symbol] color The color in which to display
|
440
|
+
# the message.
|
441
|
+
# @returns [Void]
|
442
|
+
# @!visibility private
|
443
|
+
#########################################################
|
318
444
|
def say(message = '', color = :reset)
|
319
445
|
colors = { :blue => "\033[34m",
|
320
446
|
:cyan => "\033[36m",
|