fontello_rails_converter 0.4.5 → 0.4.6
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +33 -2
- data/bin/fontello +4 -0
- data/lib/fontello_rails_converter/cli.rb +21 -4
- data/lib/fontello_rails_converter/railtie.rb +4 -2
- data/lib/fontello_rails_converter/version.rb +1 -1
- data/spec/cli_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 020ee67bca377d279123901d2a0c72642cb04ff9
|
4
|
+
data.tar.gz: a5af04e53fd60d44265346d4a72e951a8405f9c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cbb068f5f071070e9a26733e506cf1d56330bc1767f73bc269881b01df9df8819b9976d58fb04b777de9bc176d83cba729a3c940fc3f9977be7efc24f06f02d
|
7
|
+
data.tar.gz: e66f51934877c30dba2831ddcc89dfe65d90dd534c521d184c18f1b03db8c3e2dca9dc0050e4a08357e4b8f2cf021e43b45c6cca999141c3d841cd4c3eb1ba44
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -41,6 +41,10 @@ Next you click the 'Save session' button on the fontello website. After that you
|
|
41
41
|
|
42
42
|
Alternatively, you can download & save the `.zip` file just like in the initial setp and run `bundle exec fontello convert --no-download` to use the manually downloaded file instead of pulling it down from fontello.
|
43
43
|
|
44
|
+
## Options
|
45
|
+
|
46
|
+
* `--webpack` [command: `convert`]: generate the stylesheets for use with webpack, prefixing the font file names with the tilde (~). Es: `src: url('~fontello.eot?99999999');`. See [Webpack](#webpack).
|
47
|
+
|
44
48
|
## More help
|
45
49
|
|
46
50
|
For more help run `fontello --help`
|
@@ -49,9 +53,36 @@ For more help run `fontello --help`
|
|
49
53
|
|
50
54
|
The conversion process will do a couple of things to make working with the main fontello stylesheet easier in Rails/Sass:
|
51
55
|
|
52
|
-
* It will convert font paths to use `font-url`
|
56
|
+
* It will convert font paths to use `font-url` (unless you use the `--webpack` option)
|
53
57
|
* It will create [Sass placeholder selectors](http://sass-lang.com/documentation/file.SASS_REFERENCE.html#placeholder_selectors_) (e.g. `%icon-foo` for all the icons) so you have the choice to use the CSS classes in your markup or to `@extend` the placeholders in your Sass code
|
54
58
|
|
59
|
+
## Webpack
|
60
|
+
|
61
|
+
You can convert the fontello stylesheets for use with Webpack instead of Sprockets.
|
62
|
+
|
63
|
+
If you have not alreday done it, you must add the vendor paths to the resolve roots of Webpack, as well as all the extensions of the font files.
|
64
|
+
|
65
|
+
```javascript
|
66
|
+
[...]
|
67
|
+
const path = require("path")
|
68
|
+
const railsRoot = path.join(__dirname, ".")
|
69
|
+
[...]
|
70
|
+
module.exports = {
|
71
|
+
[...]
|
72
|
+
resolve: {
|
73
|
+
root: [
|
74
|
+
[...]
|
75
|
+
path.join(railsRoot, './vendor/assets/javascripts'),
|
76
|
+
path.join(railsRoot, './vendor/assets/stylesheets'),
|
77
|
+
path.join(railsRoot, './vendor/assets/fonts'),
|
78
|
+
],
|
79
|
+
|
80
|
+
extensions: [ [...] '.woff', '.woff2', '.eot']
|
81
|
+
[...]
|
82
|
+
},
|
83
|
+
|
84
|
+
```
|
85
|
+
|
55
86
|
## Misc
|
56
87
|
|
57
88
|
#### Additional fontello stylesheets
|
@@ -64,4 +95,4 @@ If you don't want to load this gem in your app's production environment to save
|
|
64
95
|
|
65
96
|
#### Configuration file
|
66
97
|
|
67
|
-
By default the gem will look in `Rails.root.join("config", "fontello_rails_converter.yml")` for configuration options. You can use this to set default options for the tool.
|
98
|
+
By default the gem will look in `Rails.root.join("config", "fontello_rails_converter.yml")` for configuration options. You can use this to set default options for the tool.
|
data/bin/fontello
CHANGED
@@ -73,6 +73,10 @@ OptionParser.new do |opts|
|
|
73
73
|
options[:stylesheet_extension] = opt
|
74
74
|
end
|
75
75
|
|
76
|
+
opts.on("--webpack", "Generate for webpack") do |opt|
|
77
|
+
options[:webpack] = true
|
78
|
+
end
|
79
|
+
|
76
80
|
opts.separator "`download` options:"
|
77
81
|
|
78
82
|
opts.on("-u", "--use-config", "Uses existing config.json instead of persisted or passed in fontello session ID\n\n") do |opt|
|
@@ -59,7 +59,7 @@ module FontelloRailsConverter
|
|
59
59
|
copy
|
60
60
|
|
61
61
|
puts "---- convert -----"
|
62
|
-
convert_stylesheets
|
62
|
+
convert_stylesheets(@options[:webpack])
|
63
63
|
convert_icon_guide
|
64
64
|
|
65
65
|
end
|
@@ -73,7 +73,7 @@ module FontelloRailsConverter
|
|
73
73
|
FileUtils.mkdir_p @options[:icon_guide_dir]
|
74
74
|
end
|
75
75
|
|
76
|
-
def convert_stylesheets
|
76
|
+
def convert_stylesheets(webpack)
|
77
77
|
['', '-embedded'].each do |stylesheet_postfix|
|
78
78
|
source_file = stylesheet_file(postfix: stylesheet_postfix)
|
79
79
|
content = File.read(source_file).encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
|
@@ -81,8 +81,13 @@ module FontelloRailsConverter
|
|
81
81
|
content = sass_enhance(content)
|
82
82
|
puts "enhancing with Sass placeholder selectors"
|
83
83
|
|
84
|
-
|
85
|
-
|
84
|
+
if webpack
|
85
|
+
content = convert_for_webpack(content)
|
86
|
+
puts "converting for webpack"
|
87
|
+
else
|
88
|
+
content = convert_for_asset_pipeline(content)
|
89
|
+
puts "converting for asset pipeline"
|
90
|
+
end
|
86
91
|
|
87
92
|
target_file = stylesheet_file(postfix: stylesheet_postfix, extension: @options[:stylesheet_extension])
|
88
93
|
File.open(target_file, 'w') { |f| f.write(content) }
|
@@ -101,6 +106,18 @@ module FontelloRailsConverter
|
|
101
106
|
end
|
102
107
|
end
|
103
108
|
|
109
|
+
def convert_for_webpack(content)
|
110
|
+
content.gsub! /\.\.\/font\//, ""
|
111
|
+
content.gsub!(/url\(([^\(]+)\)/) do |m|
|
112
|
+
replace = if $1[0] == "'"
|
113
|
+
"'~#{$1[1..-1]}"
|
114
|
+
else
|
115
|
+
"~#{$1}"
|
116
|
+
end
|
117
|
+
$1.include?("application/octet-stream") ? "url(#{$1})" : "url(#{replace})"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
104
121
|
def sass_enhance(content)
|
105
122
|
# turn icon base class into placeholder selector
|
106
123
|
content.gsub! /\[class\^="icon-[^\{]+{/m, "%icon-base {"
|
@@ -2,8 +2,10 @@ module FontelloRailsConverter
|
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
|
4
4
|
initializer "fontello_rails_converter.setup" do |app|
|
5
|
-
app.config.
|
6
|
-
|
5
|
+
if app.config.respond_to? (:assets)
|
6
|
+
app.config.assets.paths << Rails.root.join('vendor', 'assets', 'fonts')
|
7
|
+
app.config.assets.precompile << /\.(?:svg|eot|woff|woff2|ttf)$/
|
8
|
+
end
|
7
9
|
end
|
8
10
|
|
9
11
|
end
|
data/spec/cli_spec.rb
CHANGED
@@ -39,6 +39,18 @@ describe FontelloRailsConverter::Cli do
|
|
39
39
|
expect(cli.send(:convert_for_asset_pipeline, "url(/this/is/a/link)")).to eql 'font-url(/this/is/a/link)'
|
40
40
|
end
|
41
41
|
|
42
|
+
specify do
|
43
|
+
expect(cli.send(:convert_for_webpack, "url(/this/is/a/link)")).to eql 'url(~/this/is/a/link)'
|
44
|
+
end
|
45
|
+
|
46
|
+
specify do
|
47
|
+
expect(cli.send(:convert_for_webpack, "url('/this/is/a/link')")).to eql %q[url('~/this/is/a/link')]
|
48
|
+
end
|
49
|
+
|
50
|
+
specify do
|
51
|
+
expect(cli.send(:convert_for_webpack, "url(data:application/octet-stream;base64,FFF)")).to eql 'url(data:application/octet-stream;base64,FFF)'
|
52
|
+
end
|
53
|
+
|
42
54
|
specify do
|
43
55
|
expect(cli.send(:convert_for_asset_pipeline, "url(data:application/octet-stream;base64,FFF)")).to eql 'url(data:application/octet-stream;base64,FFF)'
|
44
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fontello_rails_converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakob Hilden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|