icosmith-rails 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 809b309a7de9d2b3c862b8a93edd869d67f3c878
4
- data.tar.gz: e47c92f1661ce66e35ce46cd12d28a02c52f0343
3
+ metadata.gz: b4aa17ef164d9888ca23d79c9913c705e46a06cc
4
+ data.tar.gz: 43c37f47a4b99826086c7a6f1aa10e9543573626
5
5
  SHA512:
6
- metadata.gz: 8e68dd7f3c4ddd4df7ffefcb2b869762cac5a487b521205e2170486a921f5c684492fbaf29ba7bfbcfdecc24ba958f3bbb36aa40d64563e403773d934f852be5
7
- data.tar.gz: 07ea9142fce61f11d1ccf1ead413183131da55ce734488b223556f190b07c725a3ae3225c31590048e6018297262efb8144479c2a0a0d9b56dfbd08ef68aae6c
6
+ metadata.gz: 116686f3490dfa7e30c9a165584a088194e801f4a5a5ec0cc5ea6c2413cce0ac1c71d5e5513819f42b9b95cbf4373eef87bd42e72ce2d754722a842300caa2c4
7
+ data.tar.gz: 36fda53cb0ee075a2425c2a5928d7178f813114c57c2bf75fc14cae645333870b7dcc6a96061c0c4853707b2b57a3409c11cebe2753976cf5768a02b50e456cc
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- icosmith-rails (0.3.0)
4
+ icosmith-rails (0.3.1)
5
5
  rest-client (~> 1.6.7)
6
- rubyzip (< 1.0.0)
6
+ rubyzip
7
7
  thor (~> 0.18.1)
8
8
 
9
9
  GEM
@@ -15,7 +15,7 @@ GEM
15
15
  columnize (0.3.6)
16
16
  debugger-linecache (1.2.0)
17
17
  diff-lcs (1.2.4)
18
- mime-types (1.25)
18
+ mime-types (2.1)
19
19
  rest-client (1.6.7)
20
20
  mime-types (>= 1.16)
21
21
  rspec (2.13.0)
@@ -26,7 +26,7 @@ GEM
26
26
  rspec-expectations (2.13.0)
27
27
  diff-lcs (>= 1.1.3, < 2.0)
28
28
  rspec-mocks (2.13.1)
29
- rubyzip (0.9.9)
29
+ rubyzip (1.1.0)
30
30
  thor (0.18.1)
31
31
 
32
32
  PLATFORMS
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
 
21
21
  gem.add_dependency "rest-client", "~> 1.6.7"
22
- gem.add_dependency "rubyzip", "< 1.0.0"
22
+ gem.add_dependency "rubyzip"
23
23
  gem.add_dependency "thor", "~> 0.18.1"
24
24
 
25
25
  gem.add_development_dependency "rspec"
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require "zip/zip"
3
+ require "zip"
4
4
  require "rest_client"
5
5
  require "json"
6
6
  require "logger"
@@ -17,7 +17,7 @@ module Icosmith
17
17
  FileUtils.rm_f(@svg_zipfile)
18
18
 
19
19
  log("Compressing SVGs")
20
- Zip::ZipFile.open(@svg_zipfile, Zip::ZipFile::CREATE) do |zipfile|
20
+ Zip::File.open(@svg_zipfile, Zip::File::CREATE) do |zipfile|
21
21
  Dir.glob("#{@src_dir}#{File::SEPARATOR}*.svg").each do |filename|
22
22
  zipfile.add(filename.split(File::SEPARATOR).last, filename)
23
23
  end
@@ -50,12 +50,12 @@ module Icosmith
50
50
  log("Replacing files")
51
51
  temp_font_path = @fonts_zipfile.gsub(/\.zip$/, '')
52
52
  FileUtils.rm_f(temp_font_path)
53
- FileUtils.mkdir(temp_font_path)
53
+ FileUtils.mkdir_p(File.join(temp_font_path, "fonts"))
54
54
  FileUtils.mkdir_p(@font_dir)
55
55
  FileUtils.mkdir_p(@css_dir)
56
56
 
57
- unzip @fonts_zipfile, temp_font_path
58
- copy_css temp_font_path
57
+ unzip(@fonts_zipfile, temp_font_path)
58
+ copy_css(temp_font_path)
59
59
 
60
60
  Dir.glob("#{temp_font_path}#{File::SEPARATOR}fonts#{File::SEPARATOR}*.{ttf,woff,svg,eot,afm}").each do |file|
61
61
  FileUtils.mv(file, @font_dir)
@@ -88,7 +88,7 @@ module Icosmith
88
88
  end
89
89
 
90
90
  def unzip path, target
91
- Zip::ZipFile.open(path) do |zip_file|
91
+ Zip::File.open(path) do |zip_file|
92
92
  zip_file.each do |file|
93
93
  zip_file.extract(file, File.join(target, file.name))
94
94
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Icosmith
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
@@ -0,0 +1,63 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+ require 'yaml'
5
+
6
+ describe Icosmith::Config do
7
+ subject do
8
+ Icosmith::Config.new
9
+ end
10
+
11
+ describe "accessors for keys" do
12
+ [:svg_dir, :font_dir, :fonts, :css_dir, :manifest_dir, :generate_fonts_url, :use_sass].each do |key|
13
+ it "creates an acessor for #{key} key" do
14
+ subject.should respond_to(key)
15
+ end
16
+ end
17
+ end
18
+
19
+ describe ".load" do
20
+ let!(:root_path) do
21
+ Dir.mktmpdir
22
+ end
23
+
24
+ before do
25
+ File.write("#{root_path}/config.yml", "css_dir: path/to/css\nuse_sass: true")
26
+ end
27
+
28
+ after do
29
+ FileUtils.rm_rf(root_path)
30
+ end
31
+
32
+ it "sets the configuration values from a file" do
33
+ config = Icosmith::Config.load("#{root_path}/config.yml")
34
+
35
+ config.css_dir.should eql "path/to/css"
36
+ config.use_sass.should be_true
37
+ end
38
+ end
39
+ end
40
+
41
+ describe Icosmith do
42
+ describe ".config" do
43
+ it "returns a new instance of Icosmith::Config" do
44
+ Icosmith.config.should be_an_instance_of Icosmith::Config
45
+ end
46
+ end
47
+
48
+ describe ".logger" do
49
+ it "returns a logger with a configured formatter" do
50
+ logger = Icosmith.logger
51
+ logger_message = logger.formatter.call(:error, Time.now, nil, "error message")
52
+ logger_message.should eql " - error message\n"
53
+ end
54
+ end
55
+
56
+ describe ".configure" do
57
+ it "yields a configuration block to config method" do
58
+ expect do |block|
59
+ Icosmith.configure(&block)
60
+ end.to yield_with_args(Icosmith.config)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,134 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+ require 'tmpdir'
5
+ require 'zip'
6
+
7
+ describe Icosmith::Font do
8
+ let!(:root_path) do
9
+ Dir.mktmpdir
10
+ end
11
+
12
+ before do
13
+ Icosmith.logger.stub(:info)
14
+ end
15
+
16
+ after do
17
+ FileUtils.rm_rf(root_path)
18
+ end
19
+
20
+ describe "#create_svg_zipfile" do
21
+ before do
22
+ FileUtils.mkdir_p("#{root_path}/manifest/my-font")
23
+ FileUtils.touch("#{root_path}/manifest/my-font/manifest.json")
24
+
25
+ FileUtils.mkdir_p("#{root_path}/svgs/my-font")
26
+ FileUtils.touch("#{root_path}/svgs/my-font/icon1.svg")
27
+ FileUtils.touch("#{root_path}/svgs/my-font/icon2.svg")
28
+ end
29
+
30
+ subject do
31
+ Icosmith::Font.new(root_path, config, "my-font")
32
+ end
33
+
34
+ let(:config) do
35
+ double("config", manifest_dir: "manifest", svg_dir: "svgs", css_dir: "stylesheets", font_dir: "fonts")
36
+ end
37
+
38
+ it "creates a zip file with the font .svg files and manifest.json" do
39
+ subject.create_svg_zipfile
40
+
41
+ Zip::File.open("#{root_path}/tmp/icosmith/my-font/svg.zip") do |zip_file|
42
+ zip_file.map(&:name).should eql %w{icon1.svg icon2.svg manifest.json}
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "#generate_font" do
48
+ subject do
49
+ Icosmith::Font.new(root_path, config, "my-font")
50
+ end
51
+
52
+ let(:config) do
53
+ double("config", generate_fonts_url: "/url", manifest_dir: "manifest", svg_dir: "svgs", css_dir: "stylesheets", font_dir: "fonts")
54
+ end
55
+
56
+ let(:fontfile_contents) do
57
+ double("font", headers: {content_disposition: 'filename="file.zip"'})
58
+ end
59
+
60
+ before do
61
+ FileUtils.mkdir_p("#{root_path}/manifest/my-font")
62
+ FileUtils.touch("#{root_path}/manifest/my-font/manifest.json")
63
+
64
+ file = double("svg.zip")
65
+ File.stub(:new).and_return(file)
66
+ RestClient.stub(:post).with("/url", file: file).and_return(fontfile_contents)
67
+
68
+ subject.generate_font
69
+ end
70
+
71
+ it "saves the server response to a local file" do
72
+ fontfile = "#{root_path}/tmp/icosmith/my-font/file.zip"
73
+ File.read(fontfile).should eql fontfile_contents.to_s
74
+ end
75
+
76
+ it "removes the svg zip file" do
77
+ File.exists?("#{root_path}/tmp/icosmith/my-font/svg.zip").should be_false
78
+ end
79
+ end
80
+
81
+ describe "#extract_font" do
82
+ subject do
83
+ Icosmith::Font.new(root_path, config, "my-font")
84
+ end
85
+
86
+ let(:config) do
87
+ double("config", use_sass: false, manifest_dir: "manifest", svg_dir: "svgs", css_dir: "stylesheets", font_dir: "fonts")
88
+ end
89
+
90
+ before do
91
+ FileUtils.mkdir_p("#{root_path}/manifest/my-font")
92
+ FileUtils.touch("#{root_path}/manifest/my-font/manifest.json")
93
+
94
+ fontfile = "#{root_path}/tmp/icosmith/my-font/file.zip"
95
+ subject.instance_variable_set(:@fonts_zipfile, fontfile)
96
+ FileUtils.mkdir_p("#{root_path}/tmp/icosmith/my-font/fonts")
97
+
98
+ fontfiles = []
99
+ %w{ttf woff svg eot afm}.each do |extension|
100
+ fontfiles << "#{root_path}/tmp/icosmith/my-font/fonts/my-font.#{extension}"
101
+ end
102
+ otherfiles = []
103
+ otherfiles << "#{root_path}/tmp/icosmith/my-font/manifest.json"
104
+ otherfiles << "#{root_path}/tmp/icosmith/my-font/my-font.css"
105
+ Zip::File.open("#{root_path}/tmp/icosmith/my-font/file.zip", Zip::File::CREATE) do |zipfile|
106
+ fontfiles.each do |filename|
107
+ FileUtils.touch(filename)
108
+ zipfile.add("fonts/"+filename.split(File::SEPARATOR).last, filename)
109
+ end
110
+
111
+ otherfiles.each do |filename|
112
+ FileUtils.touch(filename)
113
+ zipfile.add(filename.split(File::SEPARATOR).last, filename)
114
+ end
115
+ end
116
+
117
+ subject.extract_font
118
+ end
119
+
120
+ it "moves css file to css_dir" do
121
+ File.exists?("#{root_path}/stylesheets/my-font.css").should be_true
122
+ end
123
+
124
+ it "moves font files to font_dir" do
125
+ %w{ttf woff svg eot afm}.each do |extension|
126
+ File.exists?("#{root_path}/fonts/my-font.#{extension}").should be_true
127
+ end
128
+ end
129
+
130
+ it "moves manifest.json file to manifest_dir" do
131
+ File.exists?("#{root_path}/manifest/my-font/manifest.json").should be_true
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Icosmith::Generator do
6
+ describe "#setup_fonts" do
7
+ before do
8
+ Icosmith::Config.should_receive(:load).
9
+ with("path/config/icosmith/icosmith.yml").and_return(config)
10
+ end
11
+
12
+ subject do
13
+ Icosmith::Generator.new("path")
14
+ end
15
+
16
+ context "without fonts key configured" do
17
+ let(:config) do
18
+ double("config", fonts: nil)
19
+ end
20
+
21
+ before do
22
+ Icosmith::Font.should_receive(:new).with("path", config)
23
+ end
24
+
25
+ it "returns an array with a single Icosmith::Font instance" do
26
+ subject.setup_fonts.size.should eql 1
27
+ end
28
+ end
29
+
30
+ context "with fonts key configured" do
31
+ let(:config) do
32
+ double("config", fonts: %w{font1 font2 font3})
33
+ end
34
+
35
+ before do
36
+ Icosmith::Font.should_receive(:new).with("path", config, "font1")
37
+ Icosmith::Font.should_receive(:new).with("path", config, "font2")
38
+ Icosmith::Font.should_receive(:new).with("path", config, "font3")
39
+ end
40
+
41
+ it "returns an array with an Icosmith::Font instance for each font" do
42
+ subject.setup_fonts.size.should eql 3
43
+ end
44
+ end
45
+ end
46
+ end
@@ -12,4 +12,6 @@ RSpec.configure do |config|
12
12
  config.run_all_when_everything_filtered = true
13
13
  config.filter_run :focus
14
14
  config.order = 'random'
15
+ config.color_enabled = true
16
+ config.formatter = :documentation
15
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icosmith-rails
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
  - tulios
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-10 00:00:00.000000000 Z
12
+ date: 2014-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -29,16 +29,16 @@ dependencies:
29
29
  name: rubyzip
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - <
32
+ - - '>='
33
33
  - !ruby/object:Gem::Version
34
- version: 1.0.0
34
+ version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - <
39
+ - - '>='
40
40
  - !ruby/object:Gem::Version
41
- version: 1.0.0
41
+ version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: thor
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -109,6 +109,9 @@ files:
109
109
  - lib/icosmith-rails/railtie.rb
110
110
  - lib/icosmith-rails/tasks/icosmith.rake
111
111
  - lib/icosmith-rails/version.rb
112
+ - spec/lib/icosmith-rails/config_spec.rb
113
+ - spec/lib/icosmith-rails/font_spec.rb
114
+ - spec/lib/icosmith-rails/generator_spec.rb
112
115
  - spec/spec_helper.rb
113
116
  homepage: https://github.com/tulios/icosmith-rails
114
117
  licenses:
@@ -135,4 +138,7 @@ signing_key:
135
138
  specification_version: 4
136
139
  summary: Rails integration with an icosmith server
137
140
  test_files:
141
+ - spec/lib/icosmith-rails/config_spec.rb
142
+ - spec/lib/icosmith-rails/font_spec.rb
143
+ - spec/lib/icosmith-rails/generator_spec.rb
138
144
  - spec/spec_helper.rb