middleman-fonts 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/LICENSE.txt +20 -0
- data/README.md +0 -0
- data/VERSION +1 -0
- data/lib/middleman-fonts/font_awesome.rb +15 -0
- data/lib/middleman-fonts/fonts4web.rb +156 -0
- data/lib/middleman-fonts/fonts_css.rb +62 -0
- data/lib/middleman-fonts.rb +16 -0
- data/lib/middleman_extension.rb +1 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e9c5936f862b0eec627eab8b1283edd4687f4181076263543c9339a0cc1fdf1f
|
4
|
+
data.tar.gz: 477b07f5a73ad0a932e917745167f73ece4df0cce512436ed8de3b6c01ab6cc7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8768fd73a4e67181f34d65e893302735b4dbc86323ba07ab94129abd3eed95a7aa475f31686d0260e97e44321cd930d0ee27a0e42d4519a6f22eeccf2cca9e15
|
7
|
+
data.tar.gz: 6c2cca6437910586bed0c02c611335ad5e864de03f66ffb89bc03ab368d684061dcb36b51a56911469c1aed51faeb0a768af1ce3ffa7d324006d7853b264b0ba
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Denis Knauf
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
File without changes
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'font-awesome-sass'
|
4
|
+
|
5
|
+
class ::Middleman::Extensions::FontAwesome < ::Middleman::Extension
|
6
|
+
def manipulate_resource_list resources
|
7
|
+
path = Pathname.new FontAwesome::Sass::fonts_path
|
8
|
+
path.find do |f|
|
9
|
+
next unless f.file?
|
10
|
+
dest = Pathname.new( 'assets')/'fonts'/f.relative_path_from( path)
|
11
|
+
resources << ::Middleman::Sitemap::Resource.new( @app.sitemap, dest.to_s, f.to_s)
|
12
|
+
end
|
13
|
+
resources
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'active_support/all'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'shellwords'
|
5
|
+
require 'digest/md5'
|
6
|
+
|
7
|
+
class ::Middleman::Sitemap::Fonts4Web < ::Middleman::Sitemap::Resource
|
8
|
+
def initialize store, path, source
|
9
|
+
source_dir = Pathname.new( store.app.config[:source]).expand_path
|
10
|
+
STDERR.printf "fonts4web %p\n", path: path, source: source, source_dir: source_dir
|
11
|
+
super store, path, nil
|
12
|
+
@source = source
|
13
|
+
end
|
14
|
+
|
15
|
+
def binary?() true end
|
16
|
+
|
17
|
+
def render *_
|
18
|
+
convert( Pathname.new( @source)).read
|
19
|
+
end
|
20
|
+
|
21
|
+
def convert src
|
22
|
+
STDERR.puts "convert #{src}"
|
23
|
+
# files:
|
24
|
+
f = src.basename
|
25
|
+
md5sum = Digest::MD5.hexdigest src.read
|
26
|
+
|
27
|
+
# files in cache:
|
28
|
+
symlink = @cachepath/"#{f.basename f.extname}-#{md5sum}#{f.extname}"
|
29
|
+
cache_dest = @cachepath/"#{symlink.basename f.extname}.woff"
|
30
|
+
relsrc = src.expand_path.relative_path_from @cachepath.expand_path
|
31
|
+
dest = dest ? Pathname.new( dest) : cache_dest.expand_path
|
32
|
+
|
33
|
+
@cachepath.mkpath
|
34
|
+
|
35
|
+
identical = true
|
36
|
+
# cache_dest is older than source
|
37
|
+
unless cache_dest.exist?
|
38
|
+
identical = false
|
39
|
+
# prepare cache-files:
|
40
|
+
symlink.unlink if begin symlink.lstat; rescue Errno::ENOENT; false; end
|
41
|
+
symlink.make_symlink relsrc
|
42
|
+
|
43
|
+
# convert:
|
44
|
+
status = spawn @converter, symlink.basename, chdir: symlink.dirname
|
45
|
+
raise "Convertion #{src} failed!" unless 0 == status.exitstatus
|
46
|
+
raise "Convertion #{src} failed!" unless cache_dest.exist?
|
47
|
+
end
|
48
|
+
|
49
|
+
#FileUtils.copy cache_dest, dest, verbose: false
|
50
|
+
|
51
|
+
#builder.trigger identical ? :identical : :created, "#{dest}"
|
52
|
+
dest
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class ::Middleman::Extensions::Fonts4Web < ::Middleman::Extension
|
57
|
+
def initialize app, **options_hash, &block
|
58
|
+
super
|
59
|
+
@converter = 'sfnt2woff-zopfli'
|
60
|
+
@cachepath = Pathname.new '.fonts_cache'
|
61
|
+
end
|
62
|
+
def included() true end
|
63
|
+
alias registered included
|
64
|
+
class <<self
|
65
|
+
def included() true end
|
66
|
+
alias registered included
|
67
|
+
end
|
68
|
+
|
69
|
+
def spawn *a, **options
|
70
|
+
a = a.map &:to_s
|
71
|
+
if options[:verbose]
|
72
|
+
pre = ''
|
73
|
+
pre = "cd #{Shellwords.escape options[:chdir]}; " if options.has_key? :chdir
|
74
|
+
STDERR.puts "$ #{pre}#{a.shelljoin}"
|
75
|
+
end
|
76
|
+
options.delete :verbose
|
77
|
+
options[:chdir] &&= options[:chdir].to_s
|
78
|
+
pid = Process.spawn *a, **options
|
79
|
+
_, status = Process.wait2 pid
|
80
|
+
status
|
81
|
+
end
|
82
|
+
|
83
|
+
def convert builder, src, dest = nil
|
84
|
+
# files:
|
85
|
+
f = src.basename
|
86
|
+
md5sum = Digest::MD5.hexdigest src.read
|
87
|
+
|
88
|
+
# files in cache:
|
89
|
+
symlink = @cachepath/"#{f.basename f.extname}-#{md5sum}#{f.extname}"
|
90
|
+
cache_dest = @cachepath/"#{symlink.basename f.extname}.woff"
|
91
|
+
relsrc = src.expand_path.relative_path_from @cachepath.expand_path
|
92
|
+
dest = dest ? Pathname.new( dest) : cache_dest.expand_path
|
93
|
+
|
94
|
+
@cachepath.mkpath
|
95
|
+
|
96
|
+
identical = true
|
97
|
+
# cache_dest is older than source
|
98
|
+
unless cache_dest.exist?
|
99
|
+
identical = false
|
100
|
+
# prepare cache-files:
|
101
|
+
symlink.unlink if begin symlink.lstat; rescue Errno::ENOENT; false; end
|
102
|
+
symlink.make_symlink relsrc
|
103
|
+
|
104
|
+
# convert:
|
105
|
+
status = spawn @converter, symlink.basename, chdir: symlink.dirname
|
106
|
+
raise "Convertion #{src} failed!" unless 0 == status.exitstatus
|
107
|
+
raise "Convertion #{src} failed!" unless cache_dest.exist?
|
108
|
+
end
|
109
|
+
|
110
|
+
FileUtils.copy cache_dest, dest, verbose: false
|
111
|
+
|
112
|
+
builder.trigger identical ? :identical : :created, "#{dest}"
|
113
|
+
dest
|
114
|
+
end
|
115
|
+
|
116
|
+
#def manipulate_resource_list resources
|
117
|
+
# source_dir = Pathname.new @app.config[:source]
|
118
|
+
# paths = {}
|
119
|
+
# resources.each {|res| paths[res.path] = res }
|
120
|
+
# resources.each do |res|
|
121
|
+
# path = Pathname.new res.path
|
122
|
+
# if 'assets' == path.descend.first.to_s
|
123
|
+
# case path.extname
|
124
|
+
# when '.otf', '.ttf'
|
125
|
+
# new = path.dirname/"#{path.basename path.extname}.woff"
|
126
|
+
# unless paths.has_key? new
|
127
|
+
# STDERR.puts "convert #{new} <= #{path}"
|
128
|
+
# resource = ::Middleman::Sitemap::Fonts4Web.new( @app.sitemap, new.to_s, res)
|
129
|
+
# if false
|
130
|
+
# woff = convert source_dir.expand_path/path #, path.dirname/"#{path.basename path.extname}.woff"
|
131
|
+
# resources << ::Middleman::Sitemap::Fonts4Web.new( @app.sitemap, new.to_s, woff.to_s)
|
132
|
+
# end
|
133
|
+
# resources << resource
|
134
|
+
# paths[new.to_s] = resource
|
135
|
+
# end
|
136
|
+
# end
|
137
|
+
# end
|
138
|
+
# end
|
139
|
+
# resources
|
140
|
+
#end
|
141
|
+
|
142
|
+
def after_build builder
|
143
|
+
paths = ::Middleman::Util.all_files_under app.config[:build_dir]
|
144
|
+
paths.each do |path|
|
145
|
+
if 'assets' == path.relative_path_from( Pathname.new(@app.config[:build_dir])).descend.first.to_s
|
146
|
+
case path.extname
|
147
|
+
when '.otf', '.ttf'
|
148
|
+
new = path.dirname/"#{path.basename path.extname}.woff"
|
149
|
+
unless paths.include?( new)
|
150
|
+
convert builder, path, path.dirname/"#{path.basename path.extname}.woff"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'active_support/all'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
class ::Middleman::Extensions::Metadata2FontsCss < ::Middleman::Extension
|
6
|
+
def initialize app, **options_hash, &block
|
7
|
+
super
|
8
|
+
@additional_extentions = %w[woff]
|
9
|
+
end
|
10
|
+
def included() true end
|
11
|
+
alias registered included
|
12
|
+
class <<self
|
13
|
+
def included() true end
|
14
|
+
alias registered included
|
15
|
+
end
|
16
|
+
|
17
|
+
def manipulate_resource_list resources
|
18
|
+
fonts_css = StringIO.new
|
19
|
+
resources.lazy.
|
20
|
+
select {|res| Pathname.new( res.path).basename.to_s == 'METADATA.json' }.
|
21
|
+
map do |res|
|
22
|
+
JSON.parse( File.read( f))['fonts'].each do |font|
|
23
|
+
font = font.symbolize_keys
|
24
|
+
font[:ttf] = "/assets/fonts/#{font[:filename]}"
|
25
|
+
font[:woff] = "/assets/fonts/#{font[:filename].gsub /\.[ot]tf\Z/, '.woff'}"
|
26
|
+
fonts_css.printf <<EOF.gsub( /^\s*(.*?)\s*$/, '\1').gsub( /\n/m, ''), font
|
27
|
+
@font-face {
|
28
|
+
font-family: "%<name>s";
|
29
|
+
font-weight: %<weight>i;
|
30
|
+
font-style: %<style>s;
|
31
|
+
src:
|
32
|
+
local("%<fullName>s"),
|
33
|
+
local("%<postScriptName>s"),
|
34
|
+
url("%<woff>s") format("woff"),
|
35
|
+
url("%<ttf>s") format("truetype");
|
36
|
+
}
|
37
|
+
EOF
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
resources.delete_if do |res|
|
42
|
+
path = Pathname.new res.path
|
43
|
+
if 'assets' == path.descend.first.to_s
|
44
|
+
case path.basename.to_s
|
45
|
+
when 'METADATA.pb' then true
|
46
|
+
when 'METADATA.json' then true
|
47
|
+
when 'DESCRIPTION.en_us.html' then true
|
48
|
+
when 'OFL.txt' then true
|
49
|
+
else false
|
50
|
+
end
|
51
|
+
else false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
resources << ::Middleman::Sitemap::StringResource.new(
|
56
|
+
self.app.sitemap,
|
57
|
+
'assets/styles/fonts.css',
|
58
|
+
fonts_css.string)
|
59
|
+
|
60
|
+
resources
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "middleman-core"
|
2
|
+
|
3
|
+
::Middleman::Extensions.register :fonts_css do
|
4
|
+
require 'middleman-fonts/fonts_css'
|
5
|
+
::Middleman::Extensions::Metadata2FontsCss
|
6
|
+
end
|
7
|
+
|
8
|
+
::Middleman::Extensions.register :fonts4web do
|
9
|
+
require 'middleman-fonts/fonts4web'
|
10
|
+
::Middleman::Extensions::Fonts4Web
|
11
|
+
end
|
12
|
+
|
13
|
+
::Middleman::Extensions.register :font_awesome do
|
14
|
+
require 'middleman-fonts/font_awesome'
|
15
|
+
::Middleman::Extensions::FontAwesome
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'middleman-fonts'
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-fonts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Denis Knauf
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jeweler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2'
|
69
|
+
description: Generates WOFFs from TTFs and fonts.css
|
70
|
+
email: '#{"de"}nis@denkn.at'
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.md
|
76
|
+
files:
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.md
|
79
|
+
- VERSION
|
80
|
+
- lib/middleman-fonts.rb
|
81
|
+
- lib/middleman-fonts/font_awesome.rb
|
82
|
+
- lib/middleman-fonts/fonts4web.rb
|
83
|
+
- lib/middleman-fonts/fonts_css.rb
|
84
|
+
- lib/middleman_extension.rb
|
85
|
+
homepage: http://github.com/DenisKnauf/middleman-fonts
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubygems_version: 3.3.20
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Fonts formats convertions
|
108
|
+
test_files: []
|