bunt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # Bunt
2
+
3
+ Bunt is a small tool that isolates and collates webpages. It fetches & inlines all external assets, smushing them into one HTML file.
4
+
5
+ gem install bunt
6
+ bunt my_file.html > packed.html
7
+
8
+ The packed page now contains anything it linked to (for instance Javascript, CSS, images or fonts). You can email it to a friend and not have to worry about zipping it up or where the images it references are. Think Safari's WebArchives but as one HTML file. It's also pretty handy for iPhone web development.
9
+
10
+ Things like images and fonts are inserted using the [data URI scheme](http://en.wikipedia.org/wiki/Data_URI_scheme), even if you reference them from your CSS! Keep in mind though that encoding things as data uris makes their size about 30% larger.
11
+
12
+ # License
13
+
14
+ Raleway font is Copyright (c) 2010, Matt McInerney (http://pixelspread.com|matt@pixelspread.com), with Reserved Font Name Raleway. See [The League of Moveable Type](http://www.theleagueofmoveabletype.com/fonts/14-raleway)
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = 'bunt'
5
+ gem.summary = 'Isolate and collate webpages.'
6
+ gem.description = 'Isolate and collate webpages.'
7
+ gem.email = 'christopher.lloyd@gmail.com'
8
+ gem.homepage = 'http://chrislloyd.github.com/bunt'
9
+ gem.author = 'Chris Lloyd'
10
+ gem.executable = 'bunt'
11
+
12
+ gem.add_dependency 'nokogiri', '>= 1.4.1'
13
+ gem.add_dependency 'mime-types', '>= 1.16'
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
18
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/bunt ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'open-uri'
4
+ require 'pathname'
5
+ require 'base64'
6
+ require 'nokogiri'
7
+ require 'mime/types'
8
+
9
+ abort("usage: bunt FILE") if ARGV.empty?
10
+
11
+ file = Pathname(ARGV.shift)
12
+
13
+ class URI::Generic
14
+ alias_method :join, :merge
15
+ end
16
+
17
+ # begin
18
+ # raw = open(file)
19
+ # rescue Errno::ENOENT
20
+ # file = 'http://' + file and retry if URI(file).absolute?
21
+ # rescue SocketError, Errno::ECONNREFUSED, OpenURI::HTTPError
22
+ # abort("#{file} could not be found")
23
+ # end
24
+
25
+ abort("#{file} could not be found") unless file.exist?
26
+
27
+ doc = Nokogiri::HTML(file.read)
28
+
29
+ Base = begin
30
+ URI(doc.css('base').map{|b| b['href']}.last)
31
+ rescue URI::InvalidURIError
32
+ file.dirname
33
+ end
34
+
35
+ def absolut(wodka)
36
+ URI.parse(wodka).absolute? ? wodka : Base.join(wodka)
37
+ end
38
+
39
+ def fetch(path)
40
+ open(absolut(path)).read
41
+ end
42
+
43
+ def data_uri(path, mime=nil)
44
+ mime ||= (MIME::Types.of(path.to_s).first || 'text/plain').to_s
45
+ data = Base64.encode64(fetch(path)).delete("\s\n")
46
+ "data:#{mime};base64,#{data}"
47
+ rescue OpenURI::HTTPError, Errno::ENOENT
48
+ path.to_s
49
+ end
50
+
51
+ # Inline CSS
52
+ doc.css('link').each do |link|
53
+ link.node_name = 'style'
54
+ link.content = fetch link['href']
55
+ link.delete 'rel'
56
+ end
57
+
58
+ # Inline images in CSS
59
+ doc.css('style').each do |style|
60
+ style.content = style.content.gsub(/url\(['"]?([^\)'"]+)['"]?\)/) do |match|
61
+ # There is a bug here, assets should be found relative to the CSS file
62
+ match.sub($~[1], data_uri($~[1]))
63
+ end
64
+ end
65
+
66
+ # Inline Javascript
67
+ doc.css('script[src]').each do |script|
68
+ script.content = fetch script['src']
69
+ script.delete 'src'
70
+ end
71
+
72
+ # Inline elements with src attribute
73
+ doc.css('*[src]').each do |node|
74
+ node['src'] = data_uri node['src'], node['type']
75
+ end
76
+
77
+ puts doc.to_html(:encoding => 'UTF-8')
data/doc/bg.png ADDED
Binary file
data/doc/bunt.css ADDED
@@ -0,0 +1,64 @@
1
+ @font-face {
2
+ font-family: Raleway;
3
+ src: url('Raleway.otf');
4
+ }
5
+
6
+ body {
7
+ font-family: Helvetica, Arial, sans-serif;
8
+ font-size: 62.5%;
9
+ line-height: 2em;
10
+ }
11
+
12
+ header {
13
+ background: #636 url('bg.png') no-repeat center top;
14
+ height: 200px;
15
+ display: block;
16
+ width: 100%;
17
+ text-align: center;
18
+ margin: 50px 0;
19
+ }
20
+
21
+ header h1 {
22
+ font-family: Raleway;
23
+ color: white;
24
+ font-weight: 400;
25
+ font-size: 72px;
26
+ text-shadow: #636 0 1px 50px;
27
+ line-height: 200px;
28
+ }
29
+
30
+ article {
31
+ margin: 0 auto;
32
+ width: 300px;
33
+ font-size: 14px;
34
+ display: block;
35
+ color: #999;
36
+ }
37
+
38
+ p {
39
+ margin-bottom: 10px;
40
+ }
41
+
42
+ pre {
43
+ margin-bottom: 10px;
44
+ }
45
+
46
+ code {
47
+ color: #333;
48
+ font-size: 13px;
49
+ }
50
+
51
+ a {
52
+ color: #06C;
53
+ text-decoration: none;
54
+ }
55
+
56
+ a:hover {
57
+ text-decoration: underline;
58
+ }
59
+
60
+ footer {
61
+ width: 300px;
62
+ margin: 20px auto;
63
+ color: #CCC;
64
+ }
data/doc/bunt.html ADDED
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <head>
3
+ <title>Bunt</title>
4
+ <link rel=stylesheet href=reset.css type=text/css charset=utf-8>
5
+ <link rel=stylesheet href=bunt.css type=text/css charset=utf-8>
6
+ </head>
7
+ <body>
8
+ <header><h1>Bunt</h1></header>
9
+ <article>
10
+ <p>Bunt is a small tool that isolates and collates webpages. It fetches &amp; inlines all external assets, smushing them into one HTML file.</p>
11
+
12
+ <pre><code>gem install bunt
13
+ bunt my_file.html > packed.html</code></pre>
14
+
15
+ <p>The packed page now contains anything it linked to (for instance Javascript, CSS, images or fonts). You can email it to a friend and not have to worry about zipping it up or where the images it references are. Think Safari's WebArchives but as one HTML file. It's also pretty handy for iPhone web development.</p>
16
+
17
+ <p>Things like images and fonts are inserted using the <a href=http://en.wikipedia.org/wiki/Data_URI_scheme>data URI scheme</a>, even if you reference them from your CSS! Keep in mind though that encoding things as data uris makes their size about 30% larger.</p>
18
+ </article>
19
+
20
+ <footer>
21
+ <a href=http://github.com/chrislloyd/bunt>Code</a> |
22
+ <a href=http://thelincolnshirepoacher.com>The Poacher</a>
23
+ </footer>
24
+ </body>
data/doc/raleway.otf ADDED
Binary file
data/doc/reset.css ADDED
@@ -0,0 +1,15 @@
1
+ html,body,div,span,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,abbr,address,cite,code,del,dfn,em,img,ins,kbd,q,samp,small,strong,sub,sup,var,b,i,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,dialog,figure,footer,header,hgroup,menu,nav,section,time,mark,audio,video{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent;}
2
+ body{line-height:1;}
3
+ article,aside,dialog,figure,footer,header,hgroup,nav,section{display:block;}
4
+ nav ul{list-style:none;}
5
+ blockquote,q{quotes:none;}
6
+ blockquote:before,blockquote:after,
7
+ q:before,q:after{content:'';content:none;}
8
+ a{margin:0;padding:0;border:0;font-size:100%;vertical-align:baseline;background:transparent;}
9
+ ins{background-color:#ff9;color:#000;text-decoration:none;}
10
+ mark{background-color:#ff9;color:#000;font-style:italic;font-weight:bold;}
11
+ del{text-decoration:line-through;}
12
+ abbr[title],dfn[title]{border-bottom:1px dotted #000;cursor:help;}
13
+ table{border-collapse:collapse;border-spacing:0;}
14
+ hr{display:block;height:1px;border:0;border-top:1px solid #cccccc;margin:1em 0;padding:0;}
15
+ input,select{vertical-align:middle;}
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bunt
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Chris Lloyd
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-02-25 00:00:00 +11:00
18
+ default_executable: bunt
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: nokogiri
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 4
30
+ - 1
31
+ version: 1.4.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: mime-types
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 16
44
+ version: "1.16"
45
+ type: :runtime
46
+ version_requirements: *id002
47
+ description: Isolate and collate webpages.
48
+ email: christopher.lloyd@gmail.com
49
+ executables:
50
+ - bunt
51
+ extensions: []
52
+
53
+ extra_rdoc_files:
54
+ - README.md
55
+ files:
56
+ - README.md
57
+ - Rakefile
58
+ - VERSION
59
+ - bin/bunt
60
+ - doc/bg.png
61
+ - doc/bunt.css
62
+ - doc/bunt.html
63
+ - doc/raleway.otf
64
+ - doc/reset.css
65
+ has_rdoc: true
66
+ homepage: http://chrislloyd.github.com/bunt
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.6
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Isolate and collate webpages.
95
+ test_files: []
96
+