hldr 0.1.1 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +38 -41
- data/bin/hldr +1 -1
- data/lib/hldr.rb +62 -1
- data/lib/hldr/hldr_globals.rb +3 -1
- data/lib/hldr/hldr_processor.rb +75 -16
- data/lib/hldr/inliners/inliner.rb +11 -3
- metadata +2 -3
- data/lib/hldr/hldr_entry.rb +0 -53
data/Readme.md
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
# Hldr
|
2
|
-
A Ruby gem to generate portable interactive documents by compiling all linked assets from an HTML document into a single file (rendered to `stdout`). The value of the Word document is diminishing by the minute!
|
3
|
-
|
4
2
|
Suppose you have a somewhat complicated, well broken out HTML document or front-end prototype that you want to quickly show a non-technical colleague, Bernard. Your document may look like this:
|
5
3
|
|
6
4
|
.
|
@@ -22,57 +20,56 @@ Wouldn't it be great if we could quickly compile all of this into a **single** f
|
|
22
20
|
|
23
21
|
$ hldr cakeRecipe.html > flatfile.html
|
24
22
|
|
25
|
-
![There can be only be one](http://
|
23
|
+
![There can be only be one](http://i.imgflip.com/4cgiz.jpg)
|
26
24
|
|
27
25
|
Yeah, obviously the output is a lot bigger than the original structure or a zip archive (especially if embedding images), but this is easier and cleaner for all parties involved. The vision for Hldr is twofold:
|
28
26
|
|
29
|
-
1.
|
30
|
-
1. Make HTML front-end prototype sharing quick and easy.
|
27
|
+
1. Allow (even non-technical) content creators to more easily leverage modern interactive frameworks within their document.
|
28
|
+
1. Make server-less (and connection-less) HTML content and front-end prototype sharing quick and easy.
|
31
29
|
|
32
|
-
##
|
30
|
+
## Setup
|
33
31
|
|
34
32
|
Installation is simple, just suck down the gem via `gem install hldr`
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
$ hldr new cakeRecipe
|
39
|
-
$ cd cakeRecipe
|
40
|
-
|
41
|
-
$ hldr add bootstrap-3.0.0-rc2
|
42
|
-
$ hldr add jquery-mobile js
|
43
|
-
$ hldr add d3 js
|
44
|
-
$ hldr add flatui css
|
45
|
-
$ hldr add anotherCssJsFw
|
46
|
-
|
47
|
-
As a bonus, swapping out assets is a breeze:
|
34
|
+
You can then immediately use the binary on any HTML file (`hldr document.html`), or you can have Hldr help you setup a new document with popular frameworks (see next section).
|
48
35
|
|
49
|
-
|
50
|
-
$ hldr add bootstrap-2.3.0
|
51
|
-
$ hldr cakeRecipe.md > flatCakeRecipeFile.html
|
36
|
+
## Environment File
|
52
37
|
|
53
|
-
|
38
|
+
This file (`.hldrenv`) resides in the project root and can help you jump start a project by adding libraries and frameworks quickly. If you already have a resource linked into your HTML file, you would not want to have it in this file as well. An environment file can be created with `hldr init` or `hldr new NAME`
|
54
39
|
|
55
40
|
scaffolding:
|
56
41
|
- http://somecdn.com/css/bootstrap.min.css
|
57
42
|
- http://somecdn.com/js/BBD-G23-4SIOU23-452 : js
|
58
43
|
|
44
|
+
Using it is simple. Just specify the remote resources you want included and Hldr will always inline the content. If the resource type cannot be determined by extension, it will be ignored. However, you can force a content type by using a colon and then the type (which can be either `js` or `css`).
|
45
|
+
|
46
|
+
## Limitations
|
47
|
+
|
48
|
+
1. The file is going to be big. If you choose to embed images, it will be significantly larger than referencing them externally. However, this isn't too big a deal for a small amount of images. Also, if you decide against this feature, it's easily disabled with the `--no-images` flag.
|
49
|
+
1. Internet Explorer 8 will not show any embedded image data over 32k. Awesome, right?
|
50
|
+
|
59
51
|
## The Future
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
##
|
78
|
-
|
52
|
+
* compress images, html, js and css
|
53
|
+
* templates
|
54
|
+
* keep everything in .hldr cache
|
55
|
+
* set max cache size in config
|
56
|
+
* support inline of css `@import`
|
57
|
+
* support inline of css `@import` media queries
|
58
|
+
* support inline of css fonts
|
59
|
+
* option to compress images below 32k for IE8 support
|
60
|
+
* support css image inline
|
61
|
+
* create gem that installs to path
|
62
|
+
* handle css, scss, less, sass
|
63
|
+
* handle requireJs
|
64
|
+
* support input files outside of pwd
|
65
|
+
* support remote input
|
66
|
+
* support markdown input
|
67
|
+
* support haml input
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Gitty up! If you love it and you know it, send a pull request!
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
Hldr is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/bin/hldr
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'hldr
|
2
|
+
require 'hldr'
|
data/lib/hldr.rb
CHANGED
@@ -1,2 +1,63 @@
|
|
1
|
-
require '
|
1
|
+
require 'trollop'
|
2
|
+
require 'hldr/hldr_processor'
|
3
|
+
require 'hldr/hldr_globals'
|
4
|
+
|
5
|
+
hldr_opts = Trollop::options do
|
6
|
+
version "Hldr #{HLDR_VERSION} (c) 2013 Nate Fisher. \n\nThere can be only one!"
|
7
|
+
banner <<-EOS
|
8
|
+
Hldr - Generate a flat HTML file from linked assets.
|
9
|
+
|
10
|
+
Usage:
|
11
|
+
hldr [options] <file>
|
12
|
+
hldr <command> [args]
|
13
|
+
|
14
|
+
Examples:
|
15
|
+
hldr index.html > flat.html
|
16
|
+
|
17
|
+
Commands:
|
18
|
+
init Creates a env file
|
19
|
+
new NAME Creates a new document folder, empty contents and a env file
|
20
|
+
|
21
|
+
Options:
|
22
|
+
|
23
|
+
EOS
|
24
|
+
|
25
|
+
opt :images, "Embeds images as base64 in the data URI (allows you to embed images into the HTML file)", :default => true
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
hldr_cmd = ARGV.shift
|
30
|
+
case hldr_cmd
|
31
|
+
|
32
|
+
when "init"
|
33
|
+
# create env and cache
|
34
|
+
HldrProcessor::generate_env
|
35
|
+
HldrProcessor::generate_cache
|
36
|
+
|
37
|
+
when "new"
|
38
|
+
if ARGV.first.nil?
|
39
|
+
Trollop::die "Name of project required for NEW command"
|
40
|
+
else
|
41
|
+
# create project folder
|
42
|
+
if !Dir::exist? ARGV.first
|
43
|
+
if Dir::mkdir ARGV.first
|
44
|
+
# create content file
|
45
|
+
File::open File::join(ARGV.first, "#{ARGV.first}.html"), "w"
|
46
|
+
# create env file and cache
|
47
|
+
HldrProcessor::generate_env(ARGV.first)
|
48
|
+
HldrProcessor::generate_cache(ARGV.first)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
else
|
54
|
+
if hldr_cmd.nil?
|
55
|
+
# no command entered
|
56
|
+
Trollop::die "No input given"
|
57
|
+
else
|
58
|
+
# Processing file
|
59
|
+
puts HldrProcessor.new(hldr_cmd, hldr_opts).to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
2
63
|
|
data/lib/hldr/hldr_globals.rb
CHANGED
data/lib/hldr/hldr_processor.rb
CHANGED
@@ -3,6 +3,7 @@ require 'yaml'
|
|
3
3
|
require 'hldr/inliners/script_inliner'
|
4
4
|
require 'hldr/inliners/image_inliner'
|
5
5
|
require 'hldr/inliners/style_inliner'
|
6
|
+
require 'hldr/hldr_globals'
|
6
7
|
|
7
8
|
class HldrProcessor
|
8
9
|
|
@@ -28,20 +29,62 @@ class HldrProcessor
|
|
28
29
|
|
29
30
|
end
|
30
31
|
|
32
|
+
# inline resources specified in the ENV file
|
31
33
|
def add_scaffolding
|
32
34
|
|
33
|
-
|
35
|
+
# load yaml env file
|
36
|
+
env_path = File::join(Dir::pwd, HLDR_ENV)
|
37
|
+
|
38
|
+
return if !File::exists? env_path
|
39
|
+
return if File.zero?(env_path)
|
40
|
+
hldr_config = YAML.load_file(env_path)
|
41
|
+
|
42
|
+
# ensure scaffolding section is defined
|
43
|
+
return if !hldr_config ||
|
44
|
+
hldr_config["scaffolding"].nil? ||
|
45
|
+
hldr_config["scaffolding"].empty?
|
46
|
+
|
34
47
|
hldr_config["scaffolding"].each do |resource|
|
35
48
|
|
36
49
|
# if ends in .css or is a hash with value of css, add style
|
37
|
-
if resource[-4..-1] == ".css"
|
50
|
+
if (resource[-4..-1] == ".css") ||
|
51
|
+
(resource.is_a?(Hash) && resource[resource.keys.first] == "css")
|
52
|
+
|
53
|
+
begin
|
54
|
+
css_res = Nokogiri::XML::Node.new "style", @doc
|
55
|
+
res_handler = open(resource)
|
56
|
+
next if !res_handler
|
57
|
+
|
58
|
+
css_res.content = res_handler.read
|
59
|
+
css_res[:type] = "text/css"
|
60
|
+
head = @doc.at_css("html")
|
61
|
+
head << css_res if !head.nil?
|
62
|
+
|
63
|
+
res_handler.close
|
64
|
+
rescue
|
65
|
+
next
|
66
|
+
end
|
38
67
|
|
39
|
-
|
40
|
-
css_res.content = open(resource).read
|
41
|
-
css_res[:type] = "text/css"
|
68
|
+
end
|
42
69
|
|
43
|
-
|
44
|
-
|
70
|
+
# if ends in .js or is a hash with value of js, add script
|
71
|
+
if (resource[-4..-1] == ".js") ||
|
72
|
+
(resource.is_a?(Hash) && resource[resource.keys.first] == "js")
|
73
|
+
|
74
|
+
begin
|
75
|
+
css_res = Nokogiri::XML::Node.new "script", @doc
|
76
|
+
res_handler = open(resource)
|
77
|
+
next if !res_handler
|
78
|
+
|
79
|
+
css_res.content = res_handler.read
|
80
|
+
css_res[:type] = "text/javascript"
|
81
|
+
head = @doc.at_css("html")
|
82
|
+
head << css_res if !head.nil?
|
83
|
+
|
84
|
+
res_handler.close
|
85
|
+
rescue
|
86
|
+
next
|
87
|
+
end
|
45
88
|
|
46
89
|
end
|
47
90
|
|
@@ -49,6 +92,7 @@ class HldrProcessor
|
|
49
92
|
|
50
93
|
end
|
51
94
|
|
95
|
+
# copy all asset content directly into the original document
|
52
96
|
def inline_assets
|
53
97
|
|
54
98
|
inliners = {
|
@@ -57,7 +101,7 @@ class HldrProcessor
|
|
57
101
|
}
|
58
102
|
|
59
103
|
# inhibit embedding images if flag set
|
60
|
-
if @options[:
|
104
|
+
if @options[:images]
|
61
105
|
inliners[:img] = ImageInliner
|
62
106
|
end
|
63
107
|
|
@@ -69,18 +113,33 @@ class HldrProcessor
|
|
69
113
|
|
70
114
|
end
|
71
115
|
|
72
|
-
|
73
|
-
|
74
116
|
end
|
75
117
|
|
76
|
-
# creates a cache location
|
77
|
-
def HldrProcessor.generate_cache
|
78
|
-
|
118
|
+
# creates a cache location (optionally in another path)
|
119
|
+
def HldrProcessor.generate_cache(path=nil)
|
120
|
+
# guard against bogus path
|
121
|
+
return nil if (!path.nil? && !Dir::exist?(path))
|
122
|
+
|
123
|
+
dir_path = File::join(Dir::pwd, HLDR_CACHE)
|
124
|
+
dir_path = File::join(path, HLDR_CACHE) if path
|
125
|
+
|
126
|
+
Dir::mkdir(dir_path) if !Dir::exist? dir_path
|
79
127
|
end
|
80
128
|
|
81
|
-
# creates a new config file
|
82
|
-
def HldrProcessor.
|
83
|
-
|
129
|
+
# creates a new config file (optionally in another path)
|
130
|
+
def HldrProcessor.generate_env(path=nil)
|
131
|
+
# guard against bogus path
|
132
|
+
return nil if (!path.nil? && !Dir::exist?(path))
|
133
|
+
|
134
|
+
env_path = File::join(Dir::pwd, HLDR_ENV)
|
135
|
+
env_path = File::join(path, HLDR_ENV) if path
|
136
|
+
|
137
|
+
if !File::exist? env_path
|
138
|
+
env_file = File::open(env_path, "w")
|
139
|
+
env_file.write("scaffolding:\n")
|
140
|
+
env_file.close
|
141
|
+
end
|
142
|
+
|
84
143
|
end
|
85
144
|
|
86
145
|
end
|
@@ -33,11 +33,19 @@ class Inliner
|
|
33
33
|
|
34
34
|
begin
|
35
35
|
if location[0..3] == "http"
|
36
|
-
|
37
|
-
|
36
|
+
handler = open(location)
|
37
|
+
return if !handler
|
38
|
+
|
39
|
+
content[:data] = handler.read
|
40
|
+
content[:type] = handler.meta["content-type"]
|
41
|
+
handler.close
|
38
42
|
else
|
39
|
-
|
43
|
+
handler = File::open(location, "rb")
|
44
|
+
return if !handler
|
45
|
+
|
46
|
+
content[:data] = handler.read
|
40
47
|
content[:type] = self.get_image_extension(location)
|
48
|
+
handler.close
|
41
49
|
end
|
42
50
|
rescue
|
43
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hldr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -43,12 +43,11 @@ files:
|
|
43
43
|
- lib/hldr/inliners/style_inliner.rb
|
44
44
|
- lib/hldr/inliners/script_inliner.rb
|
45
45
|
- lib/hldr/hldr_processor.rb
|
46
|
-
- lib/hldr/hldr_entry.rb
|
47
46
|
- lib/hldr/hldr_globals.rb
|
48
47
|
- test/test_inliner.rb
|
49
48
|
- Readme.md
|
50
49
|
- Rakefile
|
51
|
-
homepage: http://github.
|
50
|
+
homepage: http://thenatefisher.github.io/hldr
|
52
51
|
licenses:
|
53
52
|
- MIT
|
54
53
|
post_install_message:
|
data/lib/hldr/hldr_entry.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'trollop'
|
2
|
-
require 'hldr/hldr_processor'
|
3
|
-
require 'hldr/hldr_globals'
|
4
|
-
|
5
|
-
hldr_opts = Trollop::options do
|
6
|
-
version "Hldr #{HLDR_VERSION} (c) 2013 Nate Fisher. \n\nThere can be only one!"
|
7
|
-
banner <<-EOS
|
8
|
-
Hldr - Generate a flat HTML file from linked assets.
|
9
|
-
|
10
|
-
Usage:
|
11
|
-
hldr [options] <file>
|
12
|
-
hldr <command> [args]
|
13
|
-
|
14
|
-
Examples:
|
15
|
-
hldr index.html > flat.html
|
16
|
-
hldr index.md > flat.html
|
17
|
-
|
18
|
-
Commands:
|
19
|
-
update Updates external content in the config file and stores to cache
|
20
|
-
init Creates a config file
|
21
|
-
new NAME Creates a new document folder, empty contents and a config file
|
22
|
-
|
23
|
-
Options:
|
24
|
-
|
25
|
-
EOS
|
26
|
-
|
27
|
-
opt :no_embed, "Inhibits base64 data URI image embedding", :default => true
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
hldr_cmd = ARGV.shift
|
32
|
-
case hldr_cmd
|
33
|
-
when "update"
|
34
|
-
# update cache from config file
|
35
|
-
when "init"
|
36
|
-
# create config file
|
37
|
-
HldrProcessor::generate_config
|
38
|
-
HldrProcessor::generate_cache
|
39
|
-
when "new"
|
40
|
-
if ARGV.first.nil?
|
41
|
-
puts "Name of document required for NEW command."
|
42
|
-
else
|
43
|
-
# create project folder
|
44
|
-
end
|
45
|
-
else
|
46
|
-
# no subcommand entered
|
47
|
-
if hldr_cmd.nil?
|
48
|
-
Trollop::die "No input given."
|
49
|
-
else
|
50
|
-
# Processing file
|
51
|
-
puts HldrProcessor.new(hldr_cmd, hldr_opts).to_s
|
52
|
-
end
|
53
|
-
end
|