middleman-more 3.0.0.beta.2 → 3.0.0.beta.3
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.
- data/features/asset_hash.feature +24 -24
- data/features/ignore_already_minified.feature +39 -4
- data/features/markdown.feature +3 -12
- data/features/markdown_redcarpet.feature +37 -0
- data/features/minify_css.feature +72 -10
- data/features/minify_javascript.feature +108 -10
- data/features/slim.feature +15 -1
- data/fixtures/markdown-app/config.rb +0 -9
- data/lib/middleman-more.rb +1 -74
- data/lib/middleman-more/core_extensions/compass.rb +49 -48
- data/lib/middleman-more/core_extensions/sprockets.rb +10 -2
- data/lib/middleman-more/extensions/asset_hash.rb +9 -23
- data/lib/middleman-more/extensions/cache_buster.rb +51 -53
- data/lib/middleman-more/extensions/gzip.rb +14 -0
- data/lib/middleman-more/extensions/minify_css.rb +60 -70
- data/lib/middleman-more/extensions/minify_javascript.rb +70 -77
- data/lib/middleman-more/extensions/relative_assets.rb +47 -47
- data/lib/middleman-more/register_extensions.rb +82 -0
- data/lib/middleman-more/renderers/coffee_script.rb +22 -0
- data/lib/middleman-more/renderers/haml.rb +24 -19
- data/lib/middleman-more/renderers/liquid.rb +28 -23
- data/lib/middleman-more/renderers/markdown.rb +50 -42
- data/lib/middleman-more/renderers/sass.rb +70 -63
- data/lib/middleman-more/renderers/slim.rb +27 -19
- data/middleman-more.gemspec +6 -7
- metadata +34 -43
- data/fixtures/already-minified-app/config.rb +0 -2
- data/fixtures/already-minified-app/source/javascripts/test.min.js +0 -10
- data/fixtures/already-minified-app/source/stylesheets/test.min.css +0 -10
- data/fixtures/minify-css-app/config.rb +0 -0
- data/fixtures/passthrough-app/config.rb +0 -17
- data/fixtures/slim-app/config.rb +0 -1
- data/fixtures/slim-app/source/slim.html.slim +0 -7
@@ -1,92 +1,82 @@
|
|
1
1
|
# Extensions namespace
|
2
|
-
module Middleman
|
2
|
+
module Middleman
|
3
|
+
module Extensions
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
# Minify CSS Extension
|
6
|
+
module MinifyCss
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
# Setup extension
|
9
|
+
class << self
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
# Once registered
|
12
|
+
def registered(app, options={})
|
13
|
+
app.set :css_compressor, false
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
ignore = Array(options[:ignore]) << /\.min\./
|
16
|
+
inline = options[:inline] || false
|
17
|
+
|
18
|
+
app.after_configuration do
|
19
|
+
chosen_compressor = css_compressor || options[:compressor] || begin
|
20
|
+
require "middleman-more/extensions/minify_css/rainpress"
|
21
|
+
::Rainpress
|
22
|
+
end
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
# Setup Rack middleware to minify CSS
|
25
|
+
use Rack, :compressor => chosen_compressor,
|
26
|
+
:ignore => ignore,
|
27
|
+
:inline => inline
|
28
|
+
end
|
22
29
|
end
|
30
|
+
alias :included :registered
|
23
31
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
# Rack middleware to look for JS in HTML and compress it
|
29
|
-
class InlineCSSRack
|
30
|
-
|
31
|
-
# Init
|
32
|
-
# @param [Class] app
|
33
|
-
# @param [Hash] options
|
34
|
-
def initialize(app, options={})
|
35
|
-
@app = app
|
36
|
-
@compressor = options[:compressor]
|
37
|
-
end
|
38
|
-
|
39
|
-
# Rack interface
|
40
|
-
# @param [Rack::Environmemt] env
|
41
|
-
# @return [Array]
|
42
|
-
def call(env)
|
43
|
-
status, headers, response = @app.call(env)
|
32
|
+
|
33
|
+
# Rack middleware to look for CSS and compress it
|
34
|
+
class Rack
|
44
35
|
|
45
|
-
|
36
|
+
# Init
|
37
|
+
# @param [Class] app
|
38
|
+
# @param [Hash] options
|
39
|
+
def initialize(app, options={})
|
40
|
+
@app = app
|
41
|
+
@compressor = options[:compressor]
|
42
|
+
@ignore = options[:ignore]
|
43
|
+
@inline = options[:inline]
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
46
|
+
# Rack interface
|
47
|
+
# @param [Rack::Environmemt] env
|
48
|
+
# @return [Array]
|
49
|
+
def call(env)
|
50
|
+
status, headers, response = @app.call(env)
|
49
51
|
|
50
|
-
|
51
|
-
first = $1
|
52
|
-
css = $2
|
53
|
-
last = $3
|
52
|
+
path = env["PATH_INFO"]
|
54
53
|
|
55
|
-
|
54
|
+
if (path.end_with?('.html') || path.end_with?('.php')) && @inline
|
55
|
+
uncompressed_source = ::Middleman::Util.extract_response_text(response)
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
minified = uncompressed_source.gsub(/(<style[^>]*>\s*(?:\/\*<!\[CDATA\[\*\/\n)?)(.*?)((?:(?:\n\s*)?\/\*\]\]>\*\/)?\s*<\/style>)/m) do |match|
|
58
|
+
first = $1
|
59
|
+
css = $2
|
60
|
+
last = $3
|
59
61
|
|
60
|
-
|
61
|
-
response = [minified]
|
62
|
-
elsif path.end_with?('.css') && path !~ /\.min\./
|
63
|
-
uncompressed_source = extract_response_text(response)
|
64
|
-
minified_css = @compressor.compress(uncompressed_source)
|
62
|
+
minified_css = @compressor.compress(css)
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
end
|
64
|
+
first << minified_css << last
|
65
|
+
end
|
69
66
|
|
70
|
-
|
71
|
-
|
67
|
+
headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
|
68
|
+
response = [minified]
|
69
|
+
elsif path.end_with?('.css') && @ignore.none? {|ignore| path =~ ignore }
|
70
|
+
uncompressed_source = ::Middleman::Util.extract_response_text(response)
|
71
|
+
minified_css = @compressor.compress(uncompressed_source)
|
72
72
|
|
73
|
-
|
73
|
+
headers["Content-Length"] = ::Rack::Utils.bytesize(minified_css).to_s
|
74
|
+
response = [minified_css]
|
75
|
+
end
|
74
76
|
|
75
|
-
|
76
|
-
|
77
|
-
when String
|
78
|
-
response
|
79
|
-
when Array
|
80
|
-
response.join
|
81
|
-
when Rack::Response
|
82
|
-
response.body.join
|
83
|
-
when Rack::File
|
84
|
-
File.read(response.path)
|
85
|
-
else
|
86
|
-
response.to_s
|
77
|
+
[status, headers, response]
|
78
|
+
end
|
87
79
|
end
|
88
80
|
end
|
89
81
|
end
|
90
|
-
# Register extension
|
91
|
-
# register :minify_css, MinifyCss
|
92
82
|
end
|
@@ -1,101 +1,94 @@
|
|
1
1
|
# Extension namespace
|
2
|
-
module Middleman
|
2
|
+
module Middleman
|
3
|
+
module Extensions
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
# Minify Javascript Extension
|
6
|
+
module MinifyJavascript
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
# Setup extension
|
9
|
+
class << self
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
# Once registered
|
12
|
+
def registered(app, options={})
|
13
|
+
app.set :js_compressor, false
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
ignore = Array(options[:ignore]) << /\.min\./
|
16
|
+
inline = options[:inline] || false
|
17
|
+
|
18
|
+
# Once config is parsed
|
19
|
+
app.after_configuration do
|
20
|
+
chosen_compressor = js_compressor || options[:compressor] || begin
|
21
|
+
require 'uglifier'
|
22
|
+
::Uglifier.new
|
23
|
+
end
|
20
24
|
|
21
|
-
|
22
|
-
|
25
|
+
# Setup Rack middlware to minify JS
|
26
|
+
use Rack, :compressor => chosen_compressor,
|
27
|
+
:ignore => ignore,
|
28
|
+
:inline => inline
|
29
|
+
end
|
23
30
|
end
|
31
|
+
alias :included :registered
|
24
32
|
end
|
25
|
-
alias :included :registered
|
26
|
-
end
|
27
33
|
|
28
|
-
|
29
|
-
|
34
|
+
# Rack middleware to look for JS and compress it
|
35
|
+
class Rack
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
# @param [Rack::Environmemt] env
|
41
|
-
# @return [Array]
|
42
|
-
def call(env)
|
43
|
-
status, headers, response = @app.call(env)
|
44
|
-
|
45
|
-
path = env["PATH_INFO"]
|
37
|
+
# Init
|
38
|
+
# @param [Class] app
|
39
|
+
# @param [Hash] options
|
40
|
+
def initialize(app, options={})
|
41
|
+
@app = app
|
42
|
+
@compressor = options[:compressor]
|
43
|
+
@ignore = options[:ignore]
|
44
|
+
@inline = options[:inline]
|
45
|
+
end
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
# Rack interface
|
48
|
+
# @param [Rack::Environmemt] env
|
49
|
+
# @return [Array]
|
50
|
+
def call(env)
|
51
|
+
status, headers, response = @app.call(env)
|
49
52
|
|
50
|
-
|
51
|
-
first = $1
|
52
|
-
javascript = $2
|
53
|
-
last = $3
|
53
|
+
path = env["PATH_INFO"]
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
if first =~ /<script>/ || first.include?('text/javascript')
|
59
|
-
minified_js = @compressor.compress(javascript)
|
55
|
+
begin
|
56
|
+
if (path.end_with?('.html') || path.end_with?('.php')) && @inline
|
57
|
+
uncompressed_source = ::Middleman::Util.extract_response_text(response)
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
59
|
+
minified = uncompressed_source.gsub(/(<script[^>]*>\s*(?:\/\/(?:(?:<!--)|(?:<!\[CDATA\[))\n)?)(.*?)((?:(?:\n\s*)?\/\/(?:(?:-->)|(?:\]\]>)))?\s*<\/script>)/m) do |match|
|
60
|
+
first = $1
|
61
|
+
javascript = $2
|
62
|
+
last = $3
|
66
63
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
64
|
+
# Only compress script tags that contain JavaScript (as opposed
|
65
|
+
# to something like jQuery templates, identified with a "text/html"
|
66
|
+
# type.
|
67
|
+
if first =~ /<script>/ || first.include?('text/javascript')
|
68
|
+
minified_js = @compressor.compress(javascript)
|
72
69
|
|
73
|
-
|
74
|
-
|
75
|
-
|
70
|
+
first << minified_js << last
|
71
|
+
else
|
72
|
+
match
|
73
|
+
end
|
74
|
+
end
|
76
75
|
|
77
|
-
|
78
|
-
|
76
|
+
headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
|
77
|
+
response = [minified]
|
78
|
+
elsif path.end_with?('.js') && @ignore.none? {|ignore| path =~ ignore }
|
79
|
+
uncompressed_source = ::Middleman::Util.extract_response_text(response)
|
80
|
+
minified_js = @compressor.compress(uncompressed_source)
|
79
81
|
|
80
|
-
|
82
|
+
headers["Content-Length"] = ::Rack::Utils.bytesize(minified_js).to_s
|
83
|
+
response = [minified_js]
|
84
|
+
end
|
85
|
+
rescue ExecJS::ProgramError => e
|
86
|
+
warn "WARNING: Couldn't compress JavaScript in #{path}: #{e.message}"
|
87
|
+
end
|
81
88
|
|
82
|
-
|
83
|
-
case(response)
|
84
|
-
when String
|
85
|
-
response
|
86
|
-
when Array
|
87
|
-
response.join
|
88
|
-
when Rack::Response
|
89
|
-
response.body.join
|
90
|
-
when Rack::File
|
91
|
-
File.read(response.path)
|
92
|
-
else
|
93
|
-
response.to_s
|
89
|
+
[status, headers, response]
|
94
90
|
end
|
95
91
|
end
|
96
92
|
end
|
97
93
|
end
|
98
|
-
|
99
|
-
# Register extension
|
100
|
-
# register :minify_javascript, MinifyJavascript
|
101
94
|
end
|
@@ -1,63 +1,63 @@
|
|
1
1
|
# Extension namespace
|
2
|
-
module Middleman
|
2
|
+
module Middleman
|
3
|
+
module Extensions
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
# Relative Assets extension
|
6
|
+
module RelativeAssets
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
# Setup extension
|
9
|
+
class << self
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
# Once registered
|
12
|
+
def registered(app)
|
13
|
+
# Tell compass to use relative assets
|
14
|
+
app.compass_config do |config|
|
15
|
+
config.relative_assets = true
|
16
|
+
end
|
17
|
+
|
18
|
+
# Include instance methods
|
19
|
+
app.send :include, InstanceMethods
|
15
20
|
end
|
16
21
|
|
17
|
-
|
18
|
-
app.send :include, InstanceMethods
|
22
|
+
alias :included :registered
|
19
23
|
end
|
20
|
-
|
21
|
-
alias :included :registered
|
22
|
-
end
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
# Relative Assets instance method
|
26
|
+
module InstanceMethods
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if path.include?("://")
|
38
|
-
super(path, prefix)
|
39
|
-
elsif path[0,1] == "/"
|
40
|
-
path
|
41
|
-
else
|
42
|
-
path = File.join(prefix, path) if prefix.length > 0
|
43
|
-
request_path = @request_path.dup
|
44
|
-
request_path << index_file if path.match(%r{/$})
|
45
|
-
request_path.gsub!(%r{^/}, '')
|
46
|
-
parts = request_path.split('/')
|
28
|
+
# asset_url override for relative assets
|
29
|
+
# @param [String] path
|
30
|
+
# @param [String] prefix
|
31
|
+
# @return [String]
|
32
|
+
def asset_url(path, prefix="")
|
33
|
+
begin
|
34
|
+
prefix = images_dir if prefix == http_images_path
|
35
|
+
rescue
|
36
|
+
end
|
47
37
|
|
48
|
-
if
|
49
|
-
|
50
|
-
|
51
|
-
arry << path
|
52
|
-
File.join(*arry)
|
53
|
-
else
|
38
|
+
if path.include?("://")
|
39
|
+
super(path, prefix)
|
40
|
+
elsif path[0,1] == "/"
|
54
41
|
path
|
42
|
+
else
|
43
|
+
path = File.join(prefix, path) if prefix.length > 0
|
44
|
+
|
45
|
+
request_path = current_path.dup
|
46
|
+
request_path << index_file if path.match(%r{/$})
|
47
|
+
|
48
|
+
parts = request_path.gsub(%r{^/}, '').split('/')
|
49
|
+
|
50
|
+
if parts.length > 1
|
51
|
+
arry = []
|
52
|
+
(parts.length - 1).times { arry << ".." }
|
53
|
+
arry << path
|
54
|
+
File.join(*arry)
|
55
|
+
else
|
56
|
+
path
|
57
|
+
end
|
55
58
|
end
|
56
59
|
end
|
57
60
|
end
|
58
61
|
end
|
59
62
|
end
|
60
|
-
|
61
|
-
# Register extension
|
62
|
-
# register :relative_assets, RelativeAssets
|
63
|
-
end
|
63
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
###
|
2
|
+
# Setup renderers
|
3
|
+
###
|
4
|
+
|
5
|
+
# CoffeeScript Support
|
6
|
+
require "middleman-more/renderers/coffee_script"
|
7
|
+
Middleman::Application.register Middleman::Renderers::CoffeeScript
|
8
|
+
|
9
|
+
# Haml Support
|
10
|
+
require "middleman-more/renderers/haml"
|
11
|
+
Middleman::Application.register Middleman::Renderers::Haml
|
12
|
+
|
13
|
+
# Sass Support
|
14
|
+
require "middleman-more/renderers/sass"
|
15
|
+
Middleman::Application.register Middleman::Renderers::Sass
|
16
|
+
|
17
|
+
# Markdown Support
|
18
|
+
require "middleman-more/renderers/markdown"
|
19
|
+
Middleman::Application.register Middleman::Renderers::Markdown
|
20
|
+
|
21
|
+
# Liquid Support
|
22
|
+
require "middleman-more/renderers/liquid"
|
23
|
+
Middleman::Application.register Middleman::Renderers::Liquid
|
24
|
+
|
25
|
+
# Slim Support
|
26
|
+
require "middleman-more/renderers/slim"
|
27
|
+
Middleman::Application.register Middleman::Renderers::Slim
|
28
|
+
|
29
|
+
###
|
30
|
+
# Setup Core Extensions
|
31
|
+
###
|
32
|
+
|
33
|
+
# Compass framework
|
34
|
+
require "middleman-more/core_extensions/compass"
|
35
|
+
Middleman::Application.register Middleman::CoreExtensions::Compass
|
36
|
+
|
37
|
+
# Sprockets asset handling
|
38
|
+
require "middleman-more/core_extensions/sprockets"
|
39
|
+
Middleman::Application.register Middleman::CoreExtensions::Sprockets
|
40
|
+
|
41
|
+
###
|
42
|
+
# Setup Optional Extensions
|
43
|
+
###
|
44
|
+
|
45
|
+
# CacheBuster adds a query string to assets in dynamic templates to avoid
|
46
|
+
# browser caches failing to update to your new content.
|
47
|
+
Middleman::Extensions.register(:cache_buster) do
|
48
|
+
require "middleman-more/extensions/cache_buster"
|
49
|
+
Middleman::Extensions::CacheBuster
|
50
|
+
end
|
51
|
+
|
52
|
+
# MinifyCss compresses CSS
|
53
|
+
Middleman::Extensions.register(:minify_css) do
|
54
|
+
require "middleman-more/extensions/minify_css"
|
55
|
+
Middleman::Extensions::MinifyCss
|
56
|
+
end
|
57
|
+
|
58
|
+
# MinifyJavascript compresses JS
|
59
|
+
Middleman::Extensions.register(:minify_javascript) do
|
60
|
+
require "middleman-more/extensions/minify_javascript"
|
61
|
+
Middleman::Extensions::MinifyJavascript
|
62
|
+
end
|
63
|
+
|
64
|
+
# RelativeAssets allow any asset path in dynamic templates to be either
|
65
|
+
# relative to the root of the project or use an absolute URL.
|
66
|
+
Middleman::Extensions.register(:relative_assets) do
|
67
|
+
require "middleman-more/extensions/relative_assets"
|
68
|
+
Middleman::Extensions::RelativeAssets
|
69
|
+
end
|
70
|
+
|
71
|
+
# GZIP assets and pages during build
|
72
|
+
Middleman::Extensions.register(:gzip) do
|
73
|
+
require "middleman-more/extensions/gzip"
|
74
|
+
Middleman::Extensions::Gzip
|
75
|
+
end
|
76
|
+
|
77
|
+
# AssetHash appends a hash of the file contents to the assets filename
|
78
|
+
# to avoid browser caches failing to update to your new content.
|
79
|
+
Middleman::Extensions.register(:asset_hash) do
|
80
|
+
require "middleman-more/extensions/asset_hash"
|
81
|
+
Middleman::Extensions::AssetHash
|
82
|
+
end
|