middleman-condenser 0.0.1
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 +5 -0
- data/Gemfile +15 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +4 -0
- data/features/support/env.rb +4 -0
- data/lib/middleman-condenser.rb +9 -0
- data/lib/middleman/condenser.rb +129 -0
- data/middleman-condenser.gemspec +24 -0
- metadata +81 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d428a136b39ccaee166aa2d702ef46615c46be98deaa678246ae3c2c8e3be7e1
|
|
4
|
+
data.tar.gz: d0a5dbb4c04fd5c2282cd4f5d5df70515cb473b13a8aace529f03781287adede
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4ee37263f4b03ad434b6f3181579a21ff62585f9f67a6515049838323f4730311d86f4798517d229559023c993d1d0831c187dac02d8ec9bf526e1f8cf3cacf3
|
|
7
|
+
data.tar.gz: fbbe24bf5f15ad31486d9feed91224ae92704728d147ab521aae5ed963d30e0d26f0dc288ce4dcdfe8959df241374e256154a09b2902bb2fd59044e42074c17e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# If you do not have OpenSSL installed, update
|
|
2
|
+
# the following line to use "http://" instead
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
|
|
5
|
+
# Specify your gem's dependencies in middleman-condenser.gemspec
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
group :development do
|
|
9
|
+
gem 'rake'
|
|
10
|
+
gem 'rdoc'
|
|
11
|
+
gem 'yard'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
group :test do
|
|
15
|
+
end
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Jon Bracy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require "middleman-core"
|
|
2
|
+
|
|
3
|
+
::Middleman::Extensions.register :condenser do
|
|
4
|
+
require "middleman/condenser"
|
|
5
|
+
::Middleman::Condenser
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
puts ::Middleman::Extensions.instance_variable_get(:@auto_activate)[:before_configuration].delete_if { |i| i.name == :sass_renderer}
|
|
9
|
+
puts ::Middleman::Extensions.registered.delete(:sass_renderer)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
require 'middleman-core'
|
|
2
|
+
|
|
3
|
+
class Middleman::Condenser < ::Middleman::Extension
|
|
4
|
+
|
|
5
|
+
class Middleware
|
|
6
|
+
def initialize(app, middleman)
|
|
7
|
+
@app = app
|
|
8
|
+
@middleman = middleman
|
|
9
|
+
@condenser = Condenser::Server.new(@middleman.instance_variable_get(:@condenser))
|
|
10
|
+
@prefix = middleman.extensions[:condenser].options[:prefix]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call(env)
|
|
14
|
+
if env['PATH_INFO'].start_with?(@prefix)
|
|
15
|
+
env['PATH_INFO'].delete_prefix!(@prefix)
|
|
16
|
+
@condenser.call(env)
|
|
17
|
+
else
|
|
18
|
+
@app.call(env)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
option :path, [], 'Source directories'
|
|
24
|
+
option :prefix, '/assets', 'Directory where the assets will be served from'
|
|
25
|
+
|
|
26
|
+
def initialize(app, options_hash={}, &block)
|
|
27
|
+
# Call super to build options from the options_hash
|
|
28
|
+
super
|
|
29
|
+
|
|
30
|
+
# Require libraries only when activated
|
|
31
|
+
require 'condenser'
|
|
32
|
+
require 'condenser/server'
|
|
33
|
+
|
|
34
|
+
cache = Condenser::Cache::FileStore.new(File.join(app.root, 'tmp/cache'))
|
|
35
|
+
@condenser = Condenser.new(app.root, cache: cache)
|
|
36
|
+
app.use(Middleware, app)
|
|
37
|
+
|
|
38
|
+
Middleman::Application.send(:attr_reader, :condenser)
|
|
39
|
+
app.instance_variable_set(:@condenser, @condenser)
|
|
40
|
+
|
|
41
|
+
options[:path].each { |p| @condenser.append_path(p) }
|
|
42
|
+
|
|
43
|
+
# Append sources
|
|
44
|
+
asset_dir = File.join(app.source_dir, 'assets')
|
|
45
|
+
if File.exist?(asset_dir) && File.directory?(asset_dir)
|
|
46
|
+
Dir.each_child(asset_dir).each do |child|
|
|
47
|
+
child = File.join(asset_dir, child)
|
|
48
|
+
@condenser.append_path(child) if File.directory?(child)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Append npm sources
|
|
53
|
+
asset_dir = File.join(app.root, 'node_modules')
|
|
54
|
+
if File.exist?(asset_dir) && File.directory?(asset_dir)
|
|
55
|
+
@condenser.append_npm_path(asset_dir)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def before_build(builder)
|
|
60
|
+
builder.instance_variable_set(:@parallel, false)
|
|
61
|
+
@required_assets = []
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def export(file)
|
|
65
|
+
@required_assets << file if @required_assets
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def after_configuration
|
|
69
|
+
# Do something
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def manipulate_resource_list resources
|
|
73
|
+
resources.reject do |resource|
|
|
74
|
+
resource.path.start_with?(options[:prefix])
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def before_clean(builder)
|
|
79
|
+
build_dir = File.join(app.config[:build_dir], options[:prefix])
|
|
80
|
+
|
|
81
|
+
manifest = Condenser::Manifest.new(@condenser, build_dir)
|
|
82
|
+
puts @required_assets.inspect
|
|
83
|
+
manifest.compile(@required_assets).each do |a|
|
|
84
|
+
puts a.inspect
|
|
85
|
+
builder.instance_variable_get(:@to_clean).delete_if! { |x| a.to_s == a }
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
helpers do
|
|
91
|
+
def asset_path(kind, source=nil, options={})
|
|
92
|
+
accept = case kind
|
|
93
|
+
when :css
|
|
94
|
+
'text/css'
|
|
95
|
+
when :js
|
|
96
|
+
'application/javascript'
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
source = kind if source.nil?
|
|
100
|
+
|
|
101
|
+
asset = app.condenser.find_export(source, accept: accept)
|
|
102
|
+
app.extensions[:condenser].export(source)
|
|
103
|
+
"/#{app.extensions[:condenser].options[:prefix].gsub(/^\//, '')}/#{asset.path}"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def image_tag(source, options = {})
|
|
107
|
+
puts 'xx'
|
|
108
|
+
if options[:size] && (options[:height] || options[:width])
|
|
109
|
+
raise ArgumentError, "Cannot pass a :size option with a :height or :width option"
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
src = options[:src] = asset_path(source)
|
|
113
|
+
|
|
114
|
+
options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
|
|
115
|
+
puts options.inspect
|
|
116
|
+
tag("img", options)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def extract_dimensions(size)
|
|
120
|
+
size = size.to_s
|
|
121
|
+
if /\A\d+x\d+\z/.match?(size)
|
|
122
|
+
size.split("x")
|
|
123
|
+
elsif /\A\d+\z/.match?(size)
|
|
124
|
+
[size, size]
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = "middleman-condenser"
|
|
5
|
+
s.version = "0.0.1"
|
|
6
|
+
s.platform = Gem::Platform::RUBY
|
|
7
|
+
s.authors = ["Your Name"]
|
|
8
|
+
s.email = ["email@example.com"]
|
|
9
|
+
s.homepage = "http://example.com"
|
|
10
|
+
s.summary = %q{A short summary of your extension}
|
|
11
|
+
s.description = %q{A longer description of your extension}
|
|
12
|
+
|
|
13
|
+
s.files = `git ls-files`.split("\n")
|
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
16
|
+
s.require_paths = ["lib"]
|
|
17
|
+
|
|
18
|
+
# The version of middleman-core your extension depends on
|
|
19
|
+
s.add_runtime_dependency "condenser", "~> 0.0.4"
|
|
20
|
+
s.add_runtime_dependency "middleman-core", ">= 4.2.1"
|
|
21
|
+
|
|
22
|
+
# Additional dependencies
|
|
23
|
+
# s.add_runtime_dependency("gem-name", "gem-version")
|
|
24
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: middleman-condenser
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Your Name
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-07-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: condenser
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.0.4
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.0.4
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: middleman-core
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 4.2.1
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 4.2.1
|
|
41
|
+
description: A longer description of your extension
|
|
42
|
+
email:
|
|
43
|
+
- email@example.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- ".gitignore"
|
|
49
|
+
- Gemfile
|
|
50
|
+
- LICENSE
|
|
51
|
+
- README.md
|
|
52
|
+
- Rakefile
|
|
53
|
+
- features/support/env.rb
|
|
54
|
+
- lib/middleman-condenser.rb
|
|
55
|
+
- lib/middleman/condenser.rb
|
|
56
|
+
- middleman-condenser.gemspec
|
|
57
|
+
homepage: http://example.com
|
|
58
|
+
licenses: []
|
|
59
|
+
metadata: {}
|
|
60
|
+
post_install_message:
|
|
61
|
+
rdoc_options: []
|
|
62
|
+
require_paths:
|
|
63
|
+
- lib
|
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
requirements: []
|
|
75
|
+
rubyforge_project:
|
|
76
|
+
rubygems_version: 2.7.4
|
|
77
|
+
signing_key:
|
|
78
|
+
specification_version: 4
|
|
79
|
+
summary: A short summary of your extension
|
|
80
|
+
test_files:
|
|
81
|
+
- features/support/env.rb
|