inline_image 0.0.1 → 1.0.0

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.
data/README.md CHANGED
@@ -13,9 +13,21 @@ Installation
13
13
 
14
14
  Usage and documentation
15
15
  -----------------------
16
- inline_image inline /path/to/your.css # search for url(img/name.png)
17
- inline_image inline /path/to/your.html # search for src="img/name.png"
18
- inline_image help inline # Brief usage description
16
+ Brief usage description
17
+ inline_image help inline
18
+
19
+ Replace all image in a css file appearing in `url(img/name.png)` (max size 1024B)
20
+
21
+ inline_image inline /path/to/your.css
22
+
23
+ Replace all image in an html file appearing in `url(img/name.png)` (max size 1024B)
24
+
25
+ inline_image inline /path/to/your.html
26
+
27
+ Replace all image in a file with max size 2048B
28
+
29
+ inline_image inline /path/to/your_file --size=2048
30
+ inline_image inline /path/to/your_file -s 2048
19
31
 
20
32
  Todo
21
33
  ----
data/bin/inline_image CHANGED
@@ -5,6 +5,7 @@ require "inline_image"
5
5
 
6
6
  class InlineImg < Thor
7
7
  desc "inline FILENAME", "Inline images contained in FILENAME. FILENAME must be a css or html file. Extension is used to determine if it is either a css or a html file"
8
+ method_option :size, :type => :numeric, :aliases => '-s', :default => 1024, :desc => "max size (in bytes) for an image file to be processed"
8
9
  def inline(filename)
9
10
  return false unless File.exist? filename
10
11
 
@@ -15,9 +16,9 @@ class InlineImg < Thor
15
16
 
16
17
  File.open(filename, File::RDWR) do |file|
17
18
  content = if extension == "css" then
18
- InlineImage.replace_in_css file.read, dir
19
+ InlineImage.replace_in_css file.read, dir, options[:size]
19
20
  else
20
- InlineImage.replace_in_html file.read, dir
21
+ InlineImage.replace_in_html file.read, dir, options[:size]
21
22
  end
22
23
  file.rewind
23
24
  file.truncate(0)
data/inline_image.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = InlineImage::VERSION
8
8
  s.authors = ["Yann Mainier"]
9
9
  s.email = ["yann.mainier@gmail.com"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/ymainier/inline_image"
11
11
  s.summary = %q{Inline images within css and html files using data URI}
12
12
  s.description = %q{Inline image parses css and html files to replace small file by a data URI reprentation in base64.}
13
13
 
@@ -1,3 +1,3 @@
1
1
  module InlineImage
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/inline_image.rb CHANGED
@@ -27,13 +27,13 @@ module InlineImage
27
27
 
28
28
  def self.replace_in_css(css_text, base_dir = '.', max_file_size = MAX_FILE_SIZE)
29
29
  css_text.gsub(/url\(['"]?([^'"\)]+)['"]?\)/m) do |match|
30
- "url(#{process base_dir, $1, max_file_size})"
30
+ "url(#{process(base_dir, $1, max_file_size)})"
31
31
  end
32
32
  end
33
33
 
34
34
  def self.replace_in_html(html_text, base_dir = '.', max_file_size = MAX_FILE_SIZE)
35
35
  html_text.gsub(/src=['"]([^'"\)]+)['"]/m) do |match|
36
- "src=\"#{process base_dir, $1, max_file_size}\""
36
+ "src=\"#{process(base_dir, $1, max_file_size)}\""
37
37
  end
38
38
  end
39
39
 
@@ -1,5 +1,5 @@
1
1
  .with-small {
2
- background: white url(images/small.png) no-repeat center;
2
+ background: white url(images/small.png)
3
3
  }
4
4
  .with-large {
5
5
  background: white url(images/large.png)
@@ -37,6 +37,10 @@ describe InlineImage do
37
37
  InlineImage.process("spec/fixtures", "images/small.png").should eq(SMALL_PNG_DATA_URI)
38
38
  end
39
39
 
40
+ it "change default max size and encodes small images" do
41
+ InlineImage.process("spec/fixtures", "images/small.png", 1025).should eq(SMALL_PNG_DATA_URI)
42
+ end
43
+
40
44
  it "does not modify large image" do
41
45
  InlineImage.process("spec/fixtures", "images/large.png").should eq("images/large.png")
42
46
  end
@@ -46,9 +50,17 @@ describe InlineImage do
46
50
  InlineImage.replace_in_css(SMALL_PNG_IN_CSS_BEFORE, "spec/fixtures").should eq(SMALL_PNG_IN_CSS_AFTER)
47
51
  end
48
52
 
53
+ it "modify max size and replace small images in css" do
54
+ InlineImage.replace_in_css(SMALL_PNG_IN_CSS_BEFORE, "spec/fixtures", 1025).should eq(SMALL_PNG_IN_CSS_AFTER)
55
+ end
56
+
49
57
  it "does not modify large image in css" do
50
58
  InlineImage.replace_in_css(LARGE_PNG_IN_CSS, "spec/fixtures").should eq(LARGE_PNG_IN_CSS)
51
59
  end
60
+
61
+ it "modify max size and does not modify large image in css" do
62
+ InlineImage.replace_in_css(LARGE_PNG_IN_CSS, "spec/fixtures", 1025).should eq(LARGE_PNG_IN_CSS)
63
+ end
52
64
  end
53
65
 
54
66
  context "when processing html" do
@@ -59,5 +71,13 @@ describe InlineImage do
59
71
  it "does not modify large image in html" do
60
72
  InlineImage.replace_in_html(LARGE_PNG_IN_HTML, "spec/fixtures").should eq(LARGE_PNG_IN_HTML)
61
73
  end
74
+
75
+ it "modify max size and replace small images in html" do
76
+ InlineImage.replace_in_html(SMALL_PNG_IN_HTML_BEFORE, "spec/fixtures", 1025).should eq(SMALL_PNG_IN_HTML_AFTER)
77
+ end
78
+
79
+ it "modify max size and does not modify large image in html" do
80
+ InlineImage.replace_in_html(LARGE_PNG_IN_HTML, "spec/fixtures", 1025).should eq(LARGE_PNG_IN_HTML)
81
+ end
62
82
  end
63
83
  end
metadata CHANGED
@@ -3,10 +3,10 @@ name: inline_image
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
8
  - 0
8
- - 1
9
- version: 0.0.1
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Yann Mainier
@@ -65,7 +65,7 @@ files:
65
65
  - spec/fixtures/test.html
66
66
  - spec/inline_image_spec.rb
67
67
  has_rdoc: true
68
- homepage: ""
68
+ homepage: https://github.com/ymainier/inline_image
69
69
  licenses: []
70
70
 
71
71
  post_install_message: