fontello_rails_converter 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzdhMjhjZGZjMjE1NDNjYmYxNzQ3NjIwZDMyYTI1YjA5Y2FjMGRhMw==
4
+ ZDAzOGE4NTFmYzg4NTRkNThlOTZlZjBjNWZiY2MyMTBkYmI3ZjkxOQ==
5
5
  data.tar.gz: !binary |-
6
- Y2NlYTNmNWFjMTAyMjVmN2IzNGVlN2YxYmM1ZjFjZDc5NjcwYThkNw==
6
+ ZWFjN2QzZTcwNWI1ZDgzMmQ3MGRkOTdhODA1NTBmMjEwMWNjYzZhMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- M2VkZGMxNmQ4MDljOTIwZWE4YjdiYjJmOTY1ZTJmNjIwY2FlNTc2ZThhNzcz
10
- OWQzNzYzMmYxOWFlYjllYjI3OGE3ODU5NTQwNjA0MTZkNGEzMmMzMzQ4YTk3
11
- OGI5ZTM3MGZiZTE4Mjc2OTYyYjI3ZGY1NjI2YWI1MTU3OTliYTc=
9
+ ODNlNzU5OTczYjU0NjI5Mzk3NWFiMzJiODM4Y2ViZWU4ZjgxMDdkOWE4ZTEx
10
+ MmYwNTI1MTg4N2E5ZWJhOWUzMTc1NTcxYzFhYWM4NTdmYjI2NDU4MzNlZmIz
11
+ NjYwZTdjYmRmZmYzZmFlMDViNDA3YzRmM2Y2NjM4M2Y4YzVkNTc=
12
12
  data.tar.gz: !binary |-
13
- MGZiZTUzOTVjMWYwNTAyZTc3MTY3NDZhYTBhZDhlZTNkOGUzNTEzMTBjOWIw
14
- YWUzNDk3YmJhMjhkZWQwMjVkZTUyZDQwNGVhN2RlYTYyNzM2YTRiOWU5ODli
15
- ODAwYmJmYzE4YWQ0MmYyZWQ2NWU2NjBjYThkMjk3NjRiNjM0MTc=
13
+ MmI5NDRkNGM2NGQ2ZjgwYjNjMGRlODc4NmE3MTEyYmNhNjQ0YWExYzY0MjMw
14
+ N2QxZDM4NWIwYWM5NTA0ZTg1MDc2OGMzNjBmZDBkNDVmMGZmZTQzMzQyMzAz
15
+ YTJkNDNhNTBlOGQ1MTdlNzdkMzU5OWVlMWUxYmY5MzIxYzVlOGM=
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.3.1
4
+
5
+ * allow configuration (and automatic creation) of icon guide directory (/rails_root/public/fontello-demo.html), fixes #19
6
+ * more verbose/helpful CLI output
7
+ * add `-v`/`--version` switch to CLI for printing out the current version
8
+
3
9
  ### 0.3.0
4
10
 
5
11
  * allow setting global options using a .yml file (e.g. /rails_root/config/fontello_rails_converter.yml)
data/bin/fontello CHANGED
@@ -15,6 +15,7 @@ def set_options_based_on_rails_root(options)
15
15
  options.merge!({
16
16
  stylesheet_dir: "#{options[:asset_dir]}/stylesheets",
17
17
  font_dir: "#{options[:asset_dir]}/fonts",
18
+ icon_guide_dir: "#{options[:rails_root_dir]}/public",
18
19
  zip_file: "#{options[:rails_root_dir]}/tmp/fontello.zip",
19
20
  config_file: "#{options[:asset_dir]}/fonts/config.json",
20
21
  fontello_session_id_file: "#{options[:rails_root_dir]}/tmp/fontello_session_id",
@@ -24,6 +25,7 @@ end
24
25
 
25
26
  def set_options_from_file(options)
26
27
  if File.exist?(options[:options_file])
28
+ puts "Loading options from #{options[:options_file]}"
27
29
  options_from_file = YAML.load_file options[:options_file]
28
30
  options_from_file.each do |key, value|
29
31
  options[key.to_sym] = value if options.keys.include?(key.to_sym)
@@ -68,7 +70,7 @@ OptionParser.new do |opts|
68
70
  end
69
71
 
70
72
  opts.on("--stylesheet-extension", "Pick between e.g. '.css.scss' or '.scss'\n\n") do |opt|
71
- options[:no_download] = true
73
+ options[:stylesheet_extension] = opt
72
74
  end
73
75
 
74
76
  opts.separator "`download` options:"
@@ -104,10 +106,19 @@ OptionParser.new do |opts|
104
106
  options[:font_dir] = opt
105
107
  end
106
108
 
109
+ opts.on("--icon-guide-dir [PATH]", "Target icon guide (fontello-demo.html) directory (default: /rails_root/public)") do |opt|
110
+ options[:icon_guide_dir] = opt
111
+ end
112
+
107
113
  opts.on("-p", "--session-id-file [PATH]", "File to persist fontello session ID (default: /rails_root/tmp/fontello_session_id)") do |opt|
108
114
  options[:font_dir] = opt
109
115
  end
110
116
 
117
+ opts.on_tail("-v", "--version", "Show version") do
118
+ puts FontelloRailsConverter::VERSION
119
+ exit
120
+ end
121
+
111
122
  opts.separator "\nExamples:\n"\
112
123
  " fontello open -r /path/to/railsapp\n"\
113
124
  " fontello convert\n"\
@@ -12,104 +12,141 @@ module FontelloRailsConverter
12
12
  end
13
13
 
14
14
  def open
15
+ puts "---- open ----"
15
16
  if config_file_exists?
16
17
  @fontello_api.new_session_from_config unless @options[:open_existing] == true
17
18
  Launchy.open @fontello_api.session_url
18
- else
19
- puts red("there's no config file yet!")
20
- puts red("follow these instructions: https://github.com/railslove/fontello_rails_converter#initial-usage")
21
- puts red("to setup your project")
22
19
  end
23
20
  end
24
21
 
25
22
  def download
26
- @fontello_api.new_session_from_config if @options[:use_config] == true
23
+ puts "---- download ----"
24
+
25
+ if @options[:use_config] == true && config_file_exists?
26
+ puts "Using '#{options[:config_file]}' to create new fontello session"
27
+ @fontello_api.new_session_from_config
28
+ end
29
+
27
30
  File.open(@options[:zip_file], "w+") do |file|
28
31
  file.write @fontello_api.download_zip_body
29
32
  end
33
+ puts green "Downloaded '#{@options[:zip_file]}' from fontello (#{@fontello_api.session_url})"
30
34
  end
31
35
 
32
36
  def convert
33
- self.download unless @options[:no_download] == true || !config_file_exists?
34
- self.prepare_directories
37
+ if @options[:no_download] == true
38
+ puts "Use existing '#{@options[:zip_file]}' file due to `--no-download` switch"
39
+ else
40
+ self.download
41
+ end
35
42
 
36
- Zip::File.open(@options[:zip_file]) do |zipfile|
37
- zipfile.each do |file|
38
- filename = file.to_s.split("/").last
43
+ puts "---- convert -----"
44
+ prepare_directories
39
45
 
40
- # stylesheets
41
- if filename.end_with? '.css'
42
- # extract stylesheet to target location
43
- target_file = File.join @options[:stylesheet_dir], filename.gsub('.css', @options[:stylesheet_extension])
44
- zipfile.extract(file, target_file) { true }
45
- puts green("copied #{target_file}")
46
-
47
- if !filename.end_with? "animation.css", "-ie7.css", "-codes.css", "-ie7-codes.css", "-embedded.css"
48
- converted_css = self.convert_main_stylesheet File.read(target_file).encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
49
- File.open(target_file, 'w') { |f| f.write(converted_css) }
50
- puts green("converted #{target_file} for Sass & asset pipeline")
51
- end
52
-
53
- # font files
54
- elsif filename.end_with? ".eot", ".woff", ".ttf", ".svg", "config.json"
55
- target_file = File.join @options[:font_dir], filename
56
- zipfile.extract(file, target_file) { true }
57
- puts green("copied #{target_file}")
58
-
59
- # demo.html
60
- elsif filename == 'demo.html'
61
- target_file = File.join @options[:rails_root_dir], "public", "fontello-demo.html"
62
- zipfile.extract(file, target_file) { true }
63
- puts green("copied #{target_file}")
64
-
65
- converted_html = convert_demo_html File.read(target_file)
66
- File.open(target_file, 'w') { |f| f.write(converted_html) }
67
- puts green("converted #{filename}'s HTML for asset pipeline")
68
- end
46
+ if zip_file_exists?
47
+ Zip::File.open(@options[:zip_file]) do |zipfile|
48
+ grouped_files = zipfile.group_by{ |file| file.to_s.split("/")[1] }
69
49
 
50
+ copy_and_convert_stylesheets(zipfile, grouped_files['css'])
51
+ copy_font_files(zipfile, grouped_files['font'])
52
+ copy_and_convert_icon_guide(zipfile, grouped_files['demo.html'].first)
70
53
  end
71
54
  end
72
55
  end
73
56
 
74
- def prepare_directories
75
- FileUtils.mkdir_p @options[:font_dir]
76
- FileUtils.mkdir_p @options[:stylesheet_dir]
77
- FileUtils.mkdir_p @options[:asset_dir]
78
- end
57
+ private
58
+
59
+ def prepare_directories
60
+ FileUtils.mkdir_p @options[:font_dir]
61
+ FileUtils.mkdir_p @options[:stylesheet_dir]
62
+ FileUtils.mkdir_p @options[:asset_dir]
63
+ FileUtils.mkdir_p @options[:icon_guide_dir]
64
+ end
79
65
 
80
- def convert_main_stylesheet(content)
81
- # asset URLs
82
- content.gsub! /\.\.\/font\//, ""
83
- content.gsub!(/url\(([^\(]+)\)/) { |m| "url(font-path(#{$1}))" }
66
+ def convert_main_stylesheet(content)
67
+ # asset URLs
68
+ content.gsub! /\.\.\/font\//, ""
69
+ content.gsub!(/url\(([^\(]+)\)/) { |m| "url(font-path(#{$1}))" }
84
70
 
85
- # turn icon base class into placeholder selector
86
- content.gsub! /\[class\^="icon-[^\{]+{/m, "%icon-base {"
71
+ # turn icon base class into placeholder selector
72
+ content.gsub! /\[class\^="icon-[^\{]+{/m, "%icon-base {"
87
73
 
88
- # get icons
89
- icons = content.scan(/\.(icon-\S+):before/).map(&:first)
74
+ # get icons
75
+ icons = content.scan(/\.(icon-\S+):before/).map(&:first)
90
76
 
91
- # convert icon classes to placeholder selectors
92
- content.gsub!(/^\.(icon-\S+:before) { (.+)$/) { |m| "%#{$1} { @extend %icon-base; #{$2}" }
77
+ # convert icon classes to placeholder selectors
78
+ content.gsub!(/^\.(icon-\S+:before) { (.+)$/) { |m| "%#{$1} { @extend %icon-base; #{$2}" }
93
79
 
94
- # recreate icon classes using the mixins
95
- if icons.any?
96
- content += "\n\n"
97
- icons.each do |icon|
98
- content += ".#{icon} { @extend %#{icon}; }\n"
80
+ # recreate icon classes using the mixins
81
+ if icons.any?
82
+ content += "\n\n"
83
+ icons.each do |icon|
84
+ content += ".#{icon} { @extend %#{icon}; }\n"
85
+ end
99
86
  end
87
+
88
+ return content
100
89
  end
101
90
 
102
- return content
103
- end
91
+ def copy_font_files(zipfile, files)
92
+ puts "font files:"
93
+ files.select{ |file| file.to_s.end_with?(".eot", ".woff", ".ttf", ".svg", "config.json") }.each do |file|
94
+ filename = file.to_s.split("/").last
104
95
 
105
- private
96
+ target_file = File.join @options[:font_dir], filename
97
+ zipfile.extract(file, target_file) { true }
98
+ puts green("Copied #{target_file}")
99
+ end
100
+ end
101
+
102
+ def copy_and_convert_stylesheets(zipfile, files)
103
+ puts "stylesheets:"
104
+ files.select{ |file| file.to_s.end_with?('.css') }.each do |file|
105
+ filename = file.to_s.split("/").last
106
+
107
+ # extract stylesheet to target location
108
+ target_file = File.join @options[:stylesheet_dir], filename.gsub('.css', @options[:stylesheet_extension])
109
+ zipfile.extract(file, target_file) { true }
110
+ puts green("Copied #{target_file}")
111
+
112
+ if !filename.end_with? "animation.css", "-ie7.css", "-codes.css", "-ie7-codes.css", "-embedded.css"
113
+ converted_css = convert_main_stylesheet File.read(target_file).encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
114
+ File.open(target_file, 'w') { |f| f.write(converted_css) }
115
+ puts green("Converted #{target_file} for Sass & asset pipeline")
116
+ end
117
+ end
118
+ end
119
+
120
+ def copy_and_convert_icon_guide(zipfile, demo_file)
121
+ puts "icon guide (demo.html):"
122
+
123
+ target_file = File.join @options[:icon_guide_dir], "fontello-demo.html"
124
+ zipfile.extract(demo_file, target_file) { true }
125
+ puts green("Copied #{target_file}")
126
+
127
+ converted_html = File.read(target_file).gsub! /css\//, "/assets/"
128
+ File.open(target_file, 'w') { |f| f.write(converted_html) }
129
+ puts green("Converted demo.html for asset pipeline")
130
+ end
106
131
 
107
132
  def config_file_exists?
108
- @options[:config_file] && File.exist?(@options[:config_file])
133
+ if File.exist?(@options[:config_file])
134
+ true
135
+ else
136
+ puts red("missing config file: #{@options[:config_file]}")
137
+ puts red("follow these instructions: https://github.com/railslove/fontello_rails_converter#initial-usage")
138
+ puts red("to setup your project")
139
+ false
140
+ end
109
141
  end
110
142
 
111
- def convert_demo_html(content)
112
- content.gsub! /css\//, "/assets/"
143
+ def zip_file_exists?
144
+ if File.exist?(@options[:zip_file])
145
+ true
146
+ else
147
+ puts red("missing zip file: #{@options[:zip_file]}")
148
+ false
149
+ end
113
150
  end
114
151
 
115
152
  end
@@ -1,3 +1,3 @@
1
1
  module FontelloRailsConverter
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Hilden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-18 00:00:00.000000000 Z
11
+ date: 2014-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip