scene7ize 0.2.0 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/scene7ize/version.rb +1 -1
- data/lib/scene7ize.rb +18 -11
- data/scene7ize.gemspec +1 -1
- data/spec/scene7ize_spec.rb +28 -6
- metadata +3 -3
data/README.md
CHANGED
@@ -16,11 +16,11 @@ Third argument (optional) is an output file.
|
|
16
16
|
|
17
17
|
To run in "safe mode", specify an output file:
|
18
18
|
|
19
|
-
$ scene7ize http://s7.example.com index.html output.html
|
19
|
+
$ scene7ize parse -u http://s7.example.com -i index.html -o output.html
|
20
20
|
|
21
21
|
Or, omit the output file to replace contents of an input file.
|
22
22
|
|
23
|
-
$ scene7ize http://s7.example.com index.html
|
23
|
+
$ scene7ize parse -u http://s7.example.com -i index.html
|
24
24
|
|
25
25
|
## TODO
|
26
26
|
|
data/lib/scene7ize/version.rb
CHANGED
data/lib/scene7ize.rb
CHANGED
@@ -3,10 +3,11 @@ require 'mini_magick'
|
|
3
3
|
require 'uri'
|
4
4
|
|
5
5
|
module Scene7ize
|
6
|
-
DEFAULT_REGEX = /(?<=['"])(?<dir_and_basename>((?!['"]).)*)\.(?<ext>gif|jpg|jpeg|png)(?=['"])/
|
6
|
+
DEFAULT_REGEX = /(?<=['"\())])(?<dir_and_basename>((?!['"\)]).)*)\.(?<ext>gif|jpg|jpeg|png)(?=['"\)])/i
|
7
7
|
|
8
|
+
class << self; attr_accessor :scene7prefix; end
|
8
9
|
|
9
|
-
def self.scene7url_from(
|
10
|
+
def self.scene7url_from(image_filename)
|
10
11
|
# TODO: error handling
|
11
12
|
image = MiniMagick::Image.open(image_filename)
|
12
13
|
|
@@ -24,25 +25,31 @@ module Scene7ize
|
|
24
25
|
basename = File.basename(image_filename, File.extname(image_filename))
|
25
26
|
|
26
27
|
# TODO: error handle URI::InvalidURIError
|
27
|
-
URI.join(scene7prefix, "#{basename}?wid=#{image[:width]}&hei=#{image[:height]}#{suffix}").to_s
|
28
|
+
URI.join(self.scene7prefix, "#{basename}?wid=#{image[:width]}&hei=#{image[:height]}#{suffix}").to_s
|
28
29
|
end
|
29
30
|
|
30
31
|
|
31
|
-
def self.
|
32
|
-
|
33
|
-
input_file_path = File.dirname(input_file)
|
34
|
-
|
35
|
-
replacement = file_content.gsub!(DEFAULT_REGEX) do |match|
|
32
|
+
def self.replace(content)
|
33
|
+
replacement = content.gsub(DEFAULT_REGEX) do |match|
|
36
34
|
image_filename = "#{$~[:dir_and_basename]}.#{$~[:ext]}"
|
37
35
|
|
38
36
|
# reconstruct image path relative to input file and open
|
39
|
-
image_filename = File.join(input_file_path, image_filename)
|
40
|
-
self.scene7url_from(
|
37
|
+
image_filename = File.join(@input_file_path, image_filename)
|
38
|
+
self.scene7url_from(image_filename)
|
41
39
|
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def self.parse_file(scene7prefix, input_file, output_file = nil)
|
44
|
+
@scene7prefix = scene7prefix
|
45
|
+
|
46
|
+
file_content = File.read(input_file)
|
47
|
+
@input_file_path = File.dirname(input_file)
|
48
|
+
|
49
|
+
replacement = replace(file_content)
|
42
50
|
|
43
51
|
output_file = input_file if output_file.nil?
|
44
52
|
File.open(output_file, "w") { |file| file.puts replacement }
|
45
53
|
|
46
54
|
end
|
47
|
-
|
48
55
|
end
|
data/scene7ize.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["brad@pixelwavedesign.com"]
|
11
11
|
gem.description = %q{...}
|
12
12
|
gem.summary = %q{Converts local image paths in an HTML or CSS file to Scene7 paths containing dimensions and format data}
|
13
|
-
gem.homepage = ""
|
13
|
+
gem.homepage = "https://github.com/codercarson/scene7ize"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/spec/scene7ize_spec.rb
CHANGED
@@ -41,7 +41,25 @@ describe Scene7ize do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should display an error given an invalid input file" do
|
44
|
-
expect { Scene7ize.parse_file(
|
44
|
+
expect { Scene7ize.parse_file('file-that-doesnt-exist.ext') }.to raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
context "#replace" do
|
51
|
+
|
52
|
+
it "should parse a CSS url string with no quotes" do
|
53
|
+
@scene7url = "http://s7.example.com/dancing-happy-face.gif?wid=10&hei=10&fmt=gif-alpha"
|
54
|
+
@input_data = <<-CONTENTS
|
55
|
+
background: url(../../../../images/dancing-happy-face.gif) top left no-repeat;
|
56
|
+
CONTENTS
|
57
|
+
@expected_output = <<-CONTENTS
|
58
|
+
background: url(#{@scene7url}) top left no-repeat;
|
59
|
+
CONTENTS
|
60
|
+
|
61
|
+
Scene7ize.stub(:scene7url_from).and_return(@scene7url)
|
62
|
+
Scene7ize.replace(@input_data).should == @expected_output
|
45
63
|
end
|
46
64
|
|
47
65
|
end
|
@@ -56,13 +74,14 @@ describe Scene7ize do
|
|
56
74
|
@image = { :width => 10, :height => 15, :format => 'jpg' }
|
57
75
|
|
58
76
|
MiniMagick::Image.should_receive(:open).and_return(@image)
|
59
|
-
|
77
|
+
Scene7ize.should_receive(:scene7prefix).and_return("http://s7.example.com/")
|
78
|
+
@scene7url = Scene7ize.scene7url_from(@image_filename)
|
60
79
|
end
|
61
80
|
|
62
81
|
it "should contain a specified prefix"
|
63
82
|
|
64
83
|
it "should create a valid scene7 url" do
|
65
|
-
@scene7url.should == "http://example.com/
|
84
|
+
@scene7url.should == "http://s7.example.com/test?wid=10&hei=15&qlt=100"
|
66
85
|
end
|
67
86
|
|
68
87
|
it "should contain a valid width parameter" do
|
@@ -87,7 +106,8 @@ describe Scene7ize do
|
|
87
106
|
@image = { :width => 10, :height => 15, :format => 'png' }
|
88
107
|
|
89
108
|
MiniMagick::Image.should_receive(:open).and_return(@image)
|
90
|
-
|
109
|
+
Scene7ize.should_receive(:scene7prefix).and_return("http://s7.example.com/")
|
110
|
+
@scene7url = Scene7ize.scene7url_from(@image_filename)
|
91
111
|
|
92
112
|
@scene7url.should match /fmt=png-alpha/
|
93
113
|
@scene7url.should_not match /fmt=gif-alpha/
|
@@ -99,7 +119,8 @@ describe Scene7ize do
|
|
99
119
|
@image = { :width => 10, :height => 15, :format => 'gif' }
|
100
120
|
|
101
121
|
MiniMagick::Image.should_receive(:open).and_return(@image)
|
102
|
-
|
122
|
+
Scene7ize.should_receive(:scene7prefix).and_return("http://s7.example.com/")
|
123
|
+
@scene7url = Scene7ize.scene7url_from(@image_filename)
|
103
124
|
|
104
125
|
@scene7url.should match /fmt=gif-alpha/
|
105
126
|
@scene7url.should_not match /fmt=png-alpha/
|
@@ -108,8 +129,9 @@ describe Scene7ize do
|
|
108
129
|
|
109
130
|
it "should throw an error if not a valid image file" do
|
110
131
|
@image_filename = 'test.png'
|
132
|
+
Scene7ize.stub(:scene7prefix).and_return("http://s7.example.com/")
|
111
133
|
|
112
|
-
expect { Scene7ize.scene7url_from(
|
134
|
+
expect { Scene7ize.scene7url_from(@image_filename) }.to raise_error
|
113
135
|
end
|
114
136
|
|
115
137
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scene7ize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -95,7 +95,7 @@ files:
|
|
95
95
|
- scene7ize.gemspec
|
96
96
|
- spec/scene7ize_spec.rb
|
97
97
|
- spec/spec_helper.rb
|
98
|
-
homepage:
|
98
|
+
homepage: https://github.com/codercarson/scene7ize
|
99
99
|
licenses: []
|
100
100
|
post_install_message:
|
101
101
|
rdoc_options: []
|