fontello_rails_converter 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1ffcba90c308427abde64ffabd37fc72b39c555
4
- data.tar.gz: 7b2292e0122adfbc695039f20558e1f2cd5ec05d
3
+ metadata.gz: 020ee67bca377d279123901d2a0c72642cb04ff9
4
+ data.tar.gz: a5af04e53fd60d44265346d4a72e951a8405f9c7
5
5
  SHA512:
6
- metadata.gz: 42ab2f6280d8460addcb86bf702dcf257b304056b1b1e475f2679ae92a6309bde3ae68557ec082f64c43abcc45f487357fb097e0c6a2407be481e7476a56506f
7
- data.tar.gz: 28bb7cbdf35d770864090aa6a53400834cf0128c9dcfa3c586d5deeaafb22a3d7f7d16517345e670a099205d071c2bf9823c5db2d8fdd43a069d68dd54d53464
6
+ metadata.gz: 6cbb068f5f071070e9a26733e506cf1d56330bc1767f73bc269881b01df9df8819b9976d58fb04b777de9bc176d83cba729a3c940fc3f9977be7efc24f06f02d
7
+ data.tar.gz: e66f51934877c30dba2831ddcc89dfe65d90dd534c521d184c18f1b03db8c3e2dca9dc0050e4a08357e4b8f2cf021e43b45c6cca999141c3d841cd4c3eb1ba44
@@ -1,3 +1,8 @@
1
+ # 0.4.6
2
+
3
+ * [feature] added new `--webpack` option to convert stylesheets for use with webpack. #45
4
+ * [bugfix] fixed compatibility with Rails 5 #44
5
+
1
6
  # 0.4.5
2
7
 
3
8
  * [bugfix] embedded base64 fonts (using `url()`) were not decoded correctly #43
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.
@@ -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
- content = convert_for_asset_pipeline(content)
85
- puts "converting for asset pipeline"
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.assets.paths << Rails.root.join('vendor', 'assets', 'fonts')
6
- app.config.assets.precompile << /\.(?:svg|eot|woff|woff2|ttf)$/
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
@@ -1,3 +1,3 @@
1
1
  module FontelloRailsConverter
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.6"
3
3
  end
@@ -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.5
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: 2016-09-07 00:00:00.000000000 Z
11
+ date: 2017-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip