extract_files 0.0.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.
- data/.gitignore +4 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/README.md +114 -0
- data/Rakefile +18 -0
- data/bin/extract_files +121 -0
- data/extract_files.gemspec +22 -0
- data/lib/extract_files.rb +59 -0
- data/lib/extract_files/cli.rb +61 -0
- data/lib/extract_files/optparse.rb +4 -0
- data/test/extract_files_test.rb +47 -0
- data/test/fixtures/files.json +2 -0
- data/test/fixtures/index.html +21 -0
- data/test/fixtures/style.css +6 -0
- metadata +105 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# extract_files
|
2
|
+
|
3
|
+
Extract files from files or stdin for a given extension.
|
4
|
+
|
5
|
+
## Yes, but i can do that with sed.
|
6
|
+
|
7
|
+
I know. Before this I use this snippet:
|
8
|
+
|
9
|
+
for css_file in `find css -name "*.css" ` ; do sed -n 's/^.*url *( *"*\'"'"'*\([^"]*\)\'"'"'*"* *).*$/'`dirname $css_file`'\/\1/p' $css_file ; done | ruby -n -e "puts File.expand_path(\$_)[File.expand_path('.').size+1..-1]"
|
10
|
+
|
11
|
+
Probably could be improve.
|
12
|
+
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
Given a css file with absolute and relative images
|
17
|
+
|
18
|
+
$ cat style.css
|
19
|
+
body {
|
20
|
+
background: url(../images/bg.jpg), url ( ../images/bg2.jpg );
|
21
|
+
background: url("../images/bg3.jpg");
|
22
|
+
background: url('/images/bg4.jpg);
|
23
|
+
background: url('images/bg5.jpg');
|
24
|
+
}
|
25
|
+
|
26
|
+
Extract the images only ``-e jpg -e png -e gif``
|
27
|
+
|
28
|
+
$ cat style.css | extract_files -e jpg
|
29
|
+
../images/bg.jpg
|
30
|
+
../images/bg2.jpg
|
31
|
+
../images/bg3.jpg
|
32
|
+
/images/bg4.jpg
|
33
|
+
images/bg5.jpg
|
34
|
+
|
35
|
+
Now, relative to the css directory ``-b css``
|
36
|
+
|
37
|
+
$ cat style.css | extract_files -e jpg -b css
|
38
|
+
css/../images/bg.jpg
|
39
|
+
css/../images/bg2.jpg
|
40
|
+
css/../images/bg3.jpg
|
41
|
+
css/images/bg4.jpg
|
42
|
+
css/images/bg5.jpg
|
43
|
+
|
44
|
+
And do the path expansion ``-p``.
|
45
|
+
|
46
|
+
$ cat style.css | extract_files -e jpg -b css -p
|
47
|
+
images/bg.jpg
|
48
|
+
images/bg2.jpg
|
49
|
+
images/bg3.jpg
|
50
|
+
css/images/bg4.jpg
|
51
|
+
css/images/bg5.jpg
|
52
|
+
|
53
|
+
Or show the full path ``-f``.
|
54
|
+
|
55
|
+
$ cat style.css | extract_files -e jpg -b css -p -f
|
56
|
+
/Users/guillermo/Documents/extract_files/images/bg.jpg
|
57
|
+
/Users/guillermo/Documents/extract_files/images/bg2.jpg
|
58
|
+
/Users/guillermo/Documents/extract_files/images/bg3.jpg
|
59
|
+
/Users/guillermo/Documents/extract_files/css/images/bg4.jpg
|
60
|
+
/Users/guillermo/Documents/extract_files/css/images/bg5.jpg
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
You can pass the file/files directly:
|
65
|
+
|
66
|
+
$ extract_files * -e png
|
67
|
+
image1.png
|
68
|
+
/images/img1.png
|
69
|
+
|
70
|
+
|
71
|
+
## Install
|
72
|
+
|
73
|
+
There are two ways of installing this small libbrary:
|
74
|
+
|
75
|
+
### Rubygems
|
76
|
+
|
77
|
+
$ gem install extract_files
|
78
|
+
|
79
|
+
You will have the code as a library and the binary
|
80
|
+
|
81
|
+
### Script only
|
82
|
+
|
83
|
+
curl -O https://raw.github.com/guillermo/extract_files/master/bin/extract_files
|
84
|
+
chmod +x extract_files
|
85
|
+
|
86
|
+
## Development
|
87
|
+
|
88
|
+
The script is generated automatically with rake, so if you fork, ensure that you edit the correct files.
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
<pre>
|
93
|
+
____ __ __
|
94
|
+
| __ ) ___ ___ _ _\ \ / /_ _ _ __ ___
|
95
|
+
| _ \ / _ \/ _ \ '__\ \ /\ / / _` | '__/ _ \
|
96
|
+
| |_) | __/ __/ | \ V V / (_| | | | __/
|
97
|
+
|____/ \___|\___|_| \_/\_/ \__,_|_| \___|
|
98
|
+
|
99
|
+
_ _
|
100
|
+
| | (_) ___ ___ _ __ ___ ___
|
101
|
+
| | | |/ __/ _ \ '_ \/ __|/ _ \
|
102
|
+
| |___| | (_| __/ | | \__ \ __/
|
103
|
+
|_____|_|\___\___|_| |_|___/\___|
|
104
|
+
|
105
|
+
----------------------------------------------------------------------------
|
106
|
+
"THE BEER-WARE LICENSE" (Revision 42):
|
107
|
+
guillermo@cientifico.net wrote this file. As long as you retain this
|
108
|
+
notice you can do whatever you want with this stuff. If we meet some day,
|
109
|
+
and you think this stuff is worth it, you can buy me a beer in return
|
110
|
+
Guillermo Alvarez Fernandez
|
111
|
+
----------------------------------------------------------------------------
|
112
|
+
|
113
|
+
</pre>
|
114
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/clean'
|
3
|
+
|
4
|
+
|
5
|
+
task :test do
|
6
|
+
sh "ruby -I lib -rubygems test/extract_files_test.rb"
|
7
|
+
end
|
8
|
+
|
9
|
+
file 'bin/extract_files' => ['lib/extract_files.rb', 'lib/extract_files/optparse.rb'] do
|
10
|
+
sh "echo '#!/usr/bin/env ruby' > bin/extract_files"
|
11
|
+
sh "cat lib/extract_files.rb >> bin/extract_files"
|
12
|
+
sh "cat lib/extract_files/cli.rb >> bin/extract_files"
|
13
|
+
sh "chmod +x bin/extract_files"
|
14
|
+
end
|
15
|
+
|
16
|
+
CLEAN.add 'bin/extract_files'
|
17
|
+
|
18
|
+
|
data/bin/extract_files
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module ExtractFiles
|
4
|
+
VERSION = "0.0.1"
|
5
|
+
|
6
|
+
extend self
|
7
|
+
|
8
|
+
DEFAULT_EXTENSIONS = %w(png jpeg jpg gif css js)
|
9
|
+
|
10
|
+
# Process the input io, or anything that respond to __read__ and return a string.
|
11
|
+
# options are:
|
12
|
+
#
|
13
|
+
# * **extensions**: Array of extensions to look for. Default is DEFAULT_EXTENSIONS
|
14
|
+
#
|
15
|
+
# * **base**: Base directory. Image a relative path for a image **bg.png** in a css file inside the **styles** folder. The default output
|
16
|
+
# will say "../images/bg.png". If you say that the base directory is "styles" the output will be "styles/../images/bg.png". Is unset by default.
|
17
|
+
#
|
18
|
+
# * **expand**: If the output is somehing like "sytles/../images/bg.png" expand will convert that in "images/bg.png". Is enabled by false.
|
19
|
+
#
|
20
|
+
# * **full_path**: Show the full_path
|
21
|
+
#
|
22
|
+
# If no **block** is passed, it will output to the stdout throught puts. If a block is given, it will yield each founded entry.
|
23
|
+
#
|
24
|
+
def extract!(io, options = {})
|
25
|
+
raise "Incorrect format for IO" unless io.respond_to?(:read)
|
26
|
+
|
27
|
+
options = {:extensions => DEFAULT_EXTENSIONS}.merge(options)
|
28
|
+
|
29
|
+
ext = "(" + options[:extensions].join("|") + ")"
|
30
|
+
re = /([a-z0-9\-_\/\.]*[a-z0-9]*\.#{ext})/i
|
31
|
+
|
32
|
+
io.read.scan(re).each do |match|
|
33
|
+
path = match[0]
|
34
|
+
path = File.join(options[:base], path) if options[:base]
|
35
|
+
path = simplify_path(path) if options[:expand]
|
36
|
+
path = File.expand_path(path) if options[:full_path]
|
37
|
+
if block_given?
|
38
|
+
yield path
|
39
|
+
else
|
40
|
+
puts path
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
# get! is a wrapper for extract! that returns and array of the matches.
|
47
|
+
def get!(io,options)
|
48
|
+
matches = []
|
49
|
+
extract!(io,options){|match| matches<<match}
|
50
|
+
matches
|
51
|
+
end
|
52
|
+
|
53
|
+
protected
|
54
|
+
|
55
|
+
def simplify_path(string)
|
56
|
+
string.gsub(/[^\/]*\/\.\.\//,'').gsub(/^\.\//,'').gsub(/\.\//,'')
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
require 'optparse'
|
63
|
+
|
64
|
+
|
65
|
+
options = {:extensions => []}
|
66
|
+
OptionParser.new do |opts|
|
67
|
+
opts.banner = "Usage: #{File.basename $0} [options] file"
|
68
|
+
|
69
|
+
|
70
|
+
opts.on("-e", "--ext EXT", "Extract files with extension EXT. Can be used several times.") do |v|
|
71
|
+
options[:extensions] << v
|
72
|
+
end
|
73
|
+
|
74
|
+
opts.separator ""
|
75
|
+
|
76
|
+
opts.on("-b", "--base-directory DIR", "Use DIR as a base directory") do |base_dir|
|
77
|
+
options[:base] = base_dir
|
78
|
+
end
|
79
|
+
|
80
|
+
opts.on("-p", "--expand-path", "Remove .. from output directories") do |e|
|
81
|
+
options[:expand] = true
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.on("-f", "--full-path", "Show full path") do
|
85
|
+
options[:full_path] = true
|
86
|
+
end
|
87
|
+
|
88
|
+
opts.separator ""
|
89
|
+
|
90
|
+
opts.on("-v", "--version", "Show the version") do
|
91
|
+
puts ExtractFiles::VERSION
|
92
|
+
exit 0
|
93
|
+
end
|
94
|
+
|
95
|
+
opts.on_tail("-h", "--help", "Show this help") do
|
96
|
+
puts opts
|
97
|
+
exit 0
|
98
|
+
end
|
99
|
+
|
100
|
+
end.parse!
|
101
|
+
|
102
|
+
if ARGV.empty? || !$stdin.tty?
|
103
|
+
ExtractFiles.extract!($stdin, options)
|
104
|
+
exit 0
|
105
|
+
end
|
106
|
+
|
107
|
+
ARGV.each do |file|
|
108
|
+
(raise "File #{file} not found" ; exit -1) unless File.exists?(file)
|
109
|
+
|
110
|
+
if options[:extensions].any?
|
111
|
+
|
112
|
+
begin
|
113
|
+
file = File.open(file)
|
114
|
+
ExtractFiles.extract!(file, options)
|
115
|
+
ensure
|
116
|
+
file.close
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "extract_files"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "extract_files"
|
7
|
+
s.version = ExtractFiles::VERSION
|
8
|
+
s.authors = ["Guillermo Álvarez"]
|
9
|
+
s.email = ["guillermo@cientifico.net"]
|
10
|
+
s.homepage = "https://github.com/guillermo/extract_files"
|
11
|
+
s.summary = %q{Extract files from stdin or files given an extension/extensions}
|
12
|
+
s.description = File.read('README.md')
|
13
|
+
|
14
|
+
s.rubyforge_project = "extract_files"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "minitest"
|
22
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
|
2
|
+
module ExtractFiles
|
3
|
+
VERSION = "0.0.1"
|
4
|
+
|
5
|
+
extend self
|
6
|
+
|
7
|
+
DEFAULT_EXTENSIONS = %w(png jpeg jpg gif css js)
|
8
|
+
|
9
|
+
# Process the input io, or anything that respond to __read__ and return a string.
|
10
|
+
# options are:
|
11
|
+
#
|
12
|
+
# * **extensions**: Array of extensions to look for. Default is DEFAULT_EXTENSIONS
|
13
|
+
#
|
14
|
+
# * **base**: Base directory. Image a relative path for a image **bg.png** in a css file inside the **styles** folder. The default output
|
15
|
+
# will say "../images/bg.png". If you say that the base directory is "styles" the output will be "styles/../images/bg.png". Is unset by default.
|
16
|
+
#
|
17
|
+
# * **expand**: If the output is somehing like "sytles/../images/bg.png" expand will convert that in "images/bg.png". Is enabled by false.
|
18
|
+
#
|
19
|
+
# * **full_path**: Show the full_path
|
20
|
+
#
|
21
|
+
# If no **block** is passed, it will output to the stdout throught puts. If a block is given, it will yield each founded entry.
|
22
|
+
#
|
23
|
+
def extract!(io, options = {})
|
24
|
+
raise "Incorrect format for IO" unless io.respond_to?(:read)
|
25
|
+
|
26
|
+
options = {:extensions => DEFAULT_EXTENSIONS}.merge(options)
|
27
|
+
|
28
|
+
ext = "(" + options[:extensions].join("|") + ")"
|
29
|
+
re = /([a-z0-9\-_\/\.]*[a-z0-9]*\.#{ext})/i
|
30
|
+
|
31
|
+
io.read.scan(re).each do |match|
|
32
|
+
path = match[0]
|
33
|
+
path = File.join(options[:base], path) if options[:base]
|
34
|
+
path = simplify_path(path) if options[:expand]
|
35
|
+
path = File.expand_path(path) if options[:full_path]
|
36
|
+
if block_given?
|
37
|
+
yield path
|
38
|
+
else
|
39
|
+
puts path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
# get! is a wrapper for extract! that returns and array of the matches.
|
46
|
+
def get!(io,options)
|
47
|
+
matches = []
|
48
|
+
extract!(io,options){|match| matches<<match}
|
49
|
+
matches
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def simplify_path(string)
|
55
|
+
string.gsub(/[^\/]*\/\.\.\//,'').gsub(/^\.\//,'').gsub(/\.\//,'')
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
|
5
|
+
options = {:extensions => []}
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: #{File.basename $0} [options] file"
|
8
|
+
|
9
|
+
|
10
|
+
opts.on("-e", "--ext EXT", "Extract files with extension EXT. Can be used several times.") do |v|
|
11
|
+
options[:extensions] << v
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.separator ""
|
15
|
+
|
16
|
+
opts.on("-b", "--base-directory DIR", "Use DIR as a base directory") do |base_dir|
|
17
|
+
options[:base] = base_dir
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-p", "--expand-path", "Remove .. from output directories") do |e|
|
21
|
+
options[:expand] = true
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on("-f", "--full-path", "Show full path") do
|
25
|
+
options[:full_path] = true
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.separator ""
|
29
|
+
|
30
|
+
opts.on("-v", "--version", "Show the version") do
|
31
|
+
puts ExtractFiles::VERSION
|
32
|
+
exit 0
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on_tail("-h", "--help", "Show this help") do
|
36
|
+
puts opts
|
37
|
+
exit 0
|
38
|
+
end
|
39
|
+
|
40
|
+
end.parse!
|
41
|
+
|
42
|
+
if ARGV.empty? || !$stdin.tty?
|
43
|
+
ExtractFiles.extract!($stdin, options)
|
44
|
+
exit 0
|
45
|
+
end
|
46
|
+
|
47
|
+
ARGV.each do |file|
|
48
|
+
(raise "File #{file} not found" ; exit -1) unless File.exists?(file)
|
49
|
+
|
50
|
+
if options[:extensions].any?
|
51
|
+
|
52
|
+
begin
|
53
|
+
file = File.open(file)
|
54
|
+
ExtractFiles.extract!(file, options)
|
55
|
+
ensure
|
56
|
+
file.close
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'extract_files'
|
4
|
+
|
5
|
+
|
6
|
+
class ExtractFilesTest < MiniTest::Unit::TestCase
|
7
|
+
|
8
|
+
HTML = ["css/font.css", "css/font2.css", "../css/font3.css", "./css/font3.css", "js/script.js", "js/script2.JS", "/js/script3.JS", "./js/script4.JS", "/images/img1.png", "./images/img2.GIF", "../images/img3.GIF"]
|
9
|
+
JSON = ["image1.png", "image_3.jpeg", "images/img2.gif"]
|
10
|
+
CSS = ["../images/bg.jpg", "../images/bg2.jpg", "../images/bg3.jpg", "/images/bg4.jpg", "images/bg5.jpg"]
|
11
|
+
|
12
|
+
|
13
|
+
def test_extract
|
14
|
+
assert_equal JSON, extract!('files.json'), 'should extract files from files.json'
|
15
|
+
assert_equal HTML, extract!('index.html'), 'should extract files from index.html'
|
16
|
+
assert_equal CSS, extract!('style.css'), 'should extract files from style.css'
|
17
|
+
end
|
18
|
+
|
19
|
+
CSS2 = ["fixtures/../images/bg.jpg", "fixtures/../images/bg2.jpg", "fixtures/../images/bg3.jpg", "fixtures/images/bg4.jpg", "fixtures/images/bg5.jpg"]
|
20
|
+
|
21
|
+
def test_base
|
22
|
+
assert_equal CSS2, extract!('style.css', :base => "fixtures"), 'should append fixtures path'
|
23
|
+
end
|
24
|
+
|
25
|
+
CSS3 = ["images/bg.jpg", "images/bg2.jpg", "images/bg3.jpg", "fixtures/images/bg4.jpg", "fixtures/images/bg5.jpg"]
|
26
|
+
|
27
|
+
def test_base_expand
|
28
|
+
assert_equal CSS3, extract!('style.css', :base => 'fixtures', :expand => true), "Should expand the path"
|
29
|
+
end
|
30
|
+
|
31
|
+
CSS4 = ["/images/bg.jpg", "/images/bg2.jpg", "/images/bg3.jpg", "/fixtures/images/bg4.jpg", "/fixtures/images/bg5.jpg"]
|
32
|
+
def test_base_expand_full
|
33
|
+
files = extract!('style.css', :base => 'fixtures', :expand => true, :full_path => true).map{|f| f[File.expand_path('.').size..-1]}
|
34
|
+
assert_equal CSS4, files, "Should show the full path"
|
35
|
+
end
|
36
|
+
|
37
|
+
def extract!(filename, options = {})
|
38
|
+
file = File.join(File.dirname($0), 'fixtures', filename)
|
39
|
+
raise "File #{file} not found" unless File.file?(file)
|
40
|
+
|
41
|
+
f = File.open(file,"r")
|
42
|
+
ExtractFiles.get!(f,options)
|
43
|
+
ensure
|
44
|
+
f.close
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<link rel='stylesheet' href='css/font.css'/>
|
4
|
+
<link rel='stylesheet' href="css/font2.css"/>
|
5
|
+
<link rel="stylesheet" HREF="../css/font3.css"/>
|
6
|
+
<link rel="stylesheet" HREF="./css/font3.css"/>
|
7
|
+
|
8
|
+
<script src="js/script.js"></script>
|
9
|
+
<script src="js/script2.JS"></script>
|
10
|
+
<script src="/js/script3.JS"></script>
|
11
|
+
<script src="./js/script4.JS"></script>
|
12
|
+
</head>
|
13
|
+
<body>
|
14
|
+
<img src="/images/img1.png">
|
15
|
+
<img src="./images/img2.GIF">
|
16
|
+
<img src="../images/img3.GIF">
|
17
|
+
</body>
|
18
|
+
</html>
|
19
|
+
|
20
|
+
|
21
|
+
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: extract_files
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Guillermo Álvarez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: &70282753354860 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70282753354860
|
25
|
+
description: ! "# extract_files\n\nExtract files from files or stdin for a given extension.\n\n##
|
26
|
+
Yes, but i can do that with sed.\n\nI know. Before this I use this snippet:\n\n
|
27
|
+
\ for css_file in `find css -name \"*.css\" ` ; do sed -n 's/^.*url *( *\"*\\'\"'\"'*\\([^\"]*\\)\\'\"'\"'*\"*
|
28
|
+
*).*$/'`dirname $css_file`'\\/\\1/p' $css_file ; done | ruby -n -e \"puts File.expand_path(\\$_)[File.expand_path('.').size+1..-1]\"\n\nProbably
|
29
|
+
could be improve.\n\n\n## Usage\n\nGiven a css file with absolute and relative images\n\n\t\t$
|
30
|
+
cat style.css\n\t\tbody {\n\t\t\tbackground: url(../images/bg.jpg), url ( ../images/bg2.jpg
|
31
|
+
);\n\t\t\tbackground: url(\"../images/bg3.jpg\");\n\t\t\tbackground: url('/images/bg4.jpg);\n\t\t\tbackground:
|
32
|
+
url('images/bg5.jpg');\n\t\t}\n\nExtract the images only ``-e jpg -e png -e gif``\n\n\t\t$
|
33
|
+
cat style.css | extract_files -e jpg\n\t\t../images/bg.jpg\n\t\t../images/bg2.jpg\n\t\t../images/bg3.jpg\n\t\t/images/bg4.jpg\n\t\timages/bg5.jpg\n\nNow,
|
34
|
+
relative to the css directory ``-b css``\n\n\t\t$ cat style.css | extract_files
|
35
|
+
\ -e jpg -b css\n\t\tcss/../images/bg.jpg\n\t\tcss/../images/bg2.jpg\n\t\tcss/../images/bg3.jpg\n\t\tcss/images/bg4.jpg\n\t\tcss/images/bg5.jpg\n\nAnd
|
36
|
+
do the path expansion ``-p``.\n\n\t\t$ cat style.css | extract_files -e jpg -b
|
37
|
+
css -p\n\t\timages/bg.jpg\n\t\timages/bg2.jpg\n\t\timages/bg3.jpg\n\t\tcss/images/bg4.jpg\n\t\tcss/images/bg5.jpg\n\nOr
|
38
|
+
show the full path ``-f``.\n\n\t\t$ cat style.css | extract_files -e jpg -b css
|
39
|
+
-p -f\n\t\t/Users/guillermo/Documents/extract_files/images/bg.jpg\n\t\t/Users/guillermo/Documents/extract_files/images/bg2.jpg\n\t\t/Users/guillermo/Documents/extract_files/images/bg3.jpg\n\t\t/Users/guillermo/Documents/extract_files/css/images/bg4.jpg\n\t\t/Users/guillermo/Documents/extract_files/css/images/bg5.jpg\n\n\n\nYou
|
40
|
+
can pass the file/files directly: \n\n\t\t$ extract_files * -e png\n\t\timage1.png\n\t\t/images/img1.png\n\n\n##
|
41
|
+
Install\n\nThere are two ways of installing this small libbrary:\n\n### Rubygems\n\n
|
42
|
+
\ $ gem install extract_files\n\nYou will have the code as a library and the binary\n\n###
|
43
|
+
Script only\n\n\t\tcurl -O https://raw.github.com/guillermo/extract_files/master/bin/extract_files\n\t\tchmod
|
44
|
+
+x extract_files\n\n## Development\n\nThe script is generated automatically with
|
45
|
+
rake, so if you fork, ensure that you edit the correct files.\n\n## License\n\n<pre>\n
|
46
|
+
____ __ __ \n| __ ) ___ ___ _ _\\ \\ / /_
|
47
|
+
_ _ __ ___ \n| _ \\ / _ \\/ _ \\ '__\\ \\ /\\ / / _` | '__/ _ \\\n| |_) | __/
|
48
|
+
\ __/ | \\ V V / (_| | | | __/\n|____/ \\___|\\___|_| \\_/\\_/ \\__,_|_|
|
49
|
+
\ \\___|\n \n _ _ \n|
|
50
|
+
| (_) ___ ___ _ __ ___ ___ \n| | | |/ __/ _ \\ '_ \\/ __|/ _ \\\n| |___| |
|
51
|
+
(_| __/ | | \\__ \\ __/\n|_____|_|\\___\\___|_| |_|___/\\___|\n \n----------------------------------------------------------------------------\n\"THE
|
52
|
+
BEER-WARE LICENSE\" (Revision 42):\nguillermo@cientifico.net wrote this file. As
|
53
|
+
long as you retain this \nnotice you can do whatever you want with this stuff. If
|
54
|
+
we meet some day,\nand you think this stuff is worth it, you can buy me a beer in
|
55
|
+
return \nGuillermo Alvarez Fernandez\n----------------------------------------------------------------------------\n\n</pre>\n\n"
|
56
|
+
email:
|
57
|
+
- guillermo@cientifico.net
|
58
|
+
executables:
|
59
|
+
- extract_files
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/extract_files
|
69
|
+
- extract_files.gemspec
|
70
|
+
- lib/extract_files.rb
|
71
|
+
- lib/extract_files/cli.rb
|
72
|
+
- lib/extract_files/optparse.rb
|
73
|
+
- test/extract_files_test.rb
|
74
|
+
- test/fixtures/files.json
|
75
|
+
- test/fixtures/index.html
|
76
|
+
- test/fixtures/style.css
|
77
|
+
homepage: https://github.com/guillermo/extract_files
|
78
|
+
licenses: []
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project: extract_files
|
97
|
+
rubygems_version: 1.8.10
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Extract files from stdin or files given an extension/extensions
|
101
|
+
test_files:
|
102
|
+
- test/extract_files_test.rb
|
103
|
+
- test/fixtures/files.json
|
104
|
+
- test/fixtures/index.html
|
105
|
+
- test/fixtures/style.css
|