htty 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{spec/system/scenarios/exit/actual_stderr → .gemtest} +0 -0
- data/.gitignore +8 -0
- data/.yardopts +1 -0
- data/Gemfile +8 -0
- data/History.markdown +28 -20
- data/MIT-LICENSE.markdown +1 -1
- data/README.markdown +37 -37
- data/Rakefile +85 -0
- data/autotest/discover.rb +3 -0
- data/htty.gemspec +36 -0
- data/lib/htty.rb +1 -6
- data/lib/htty/cli/body_open_command.rb +93 -0
- data/lib/htty/cli/command.rb +5 -7
- data/lib/htty/cli/commands/address.rb +1 -1
- data/lib/htty/cli/commands/body_request.rb +3 -1
- data/lib/htty/cli/commands/body_request_open.rb +46 -0
- data/lib/htty/cli/commands/body_response.rb +5 -3
- data/lib/htty/cli/commands/body_response_open.rb +57 -0
- data/lib/htty/cli/commands/body_set.rb +1 -1
- data/lib/htty/cli/commands/body_unset.rb +1 -1
- data/lib/htty/cli/commands/cookies_add.rb +1 -1
- data/lib/htty/cli/commands/cookies_remove.rb +1 -1
- data/lib/htty/cli/commands/cookies_remove_all.rb +1 -1
- data/lib/htty/cli/commands/cookies_use.rb +1 -1
- data/lib/htty/cli/commands/follow.rb +1 -1
- data/lib/htty/cli/commands/fragment_set.rb +1 -1
- data/lib/htty/cli/commands/fragment_unset.rb +1 -1
- data/lib/htty/cli/commands/headers_set.rb +1 -1
- data/lib/htty/cli/commands/headers_unset.rb +1 -1
- data/lib/htty/cli/commands/headers_unset_all.rb +1 -1
- data/lib/htty/cli/commands/host_set.rb +1 -1
- data/lib/htty/cli/commands/path_set.rb +1 -1
- data/lib/htty/cli/commands/port_set.rb +1 -1
- data/lib/htty/cli/commands/query_add.rb +1 -1
- data/lib/htty/cli/commands/query_remove.rb +1 -1
- data/lib/htty/cli/commands/query_set.rb +1 -1
- data/lib/htty/cli/commands/query_unset.rb +1 -1
- data/lib/htty/cli/commands/query_unset_all.rb +1 -1
- data/lib/htty/cli/commands/reuse.rb +1 -1
- data/lib/htty/cli/commands/scheme_set.rb +1 -1
- data/lib/htty/cli/commands/userinfo_set.rb +1 -1
- data/lib/htty/cli/commands/userinfo_unset.rb +1 -1
- data/lib/htty/cli/http_method_command.rb +1 -1
- data/lib/htty/platform.rb +10 -0
- data/lib/htty/request.rb +5 -1
- data/lib/htty/tempfile_preserving_extname.rb +16 -0
- data/lib/htty/version.rb +6 -0
- data/spec/unit/htty/cli/commands/body_request_spec.rb +4 -9
- data/spec/unit/htty/cli/commands/body_response_spec.rb +3 -1
- data/spec/unit/htty/request_spec.rb +10 -1
- data/spec/unit/{htty_spec.rb → htty/version_spec.rb} +1 -1
- metadata +145 -35
- data/VERSION +0 -1
- data/spec/system/scenarios/exit/actual_stdout +0 -2
- data/spec/system/scenarios/quit/actual_stderr +0 -0
- data/spec/system/scenarios/quit/actual_stdout +0 -2
File without changes
|
data/.gitignore
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--file MIT-LICENSE.markdown --file History.markdown --no-private --protected --title "htty, the HTTP TTY"
|
data/Gemfile
ADDED
data/History.markdown
CHANGED
@@ -1,34 +1,42 @@
|
|
1
1
|
Version history for the _htty_ project
|
2
2
|
======================================
|
3
3
|
|
4
|
-
v1.
|
5
|
-
|
4
|
+
<a name="v1.3.0"></a>v1.3.0, Fri 2/25/2011
|
5
|
+
-------------------------------------------
|
6
|
+
|
7
|
+
* Added the `body-request-open` and `body-response-open` commands for viewing body content in an external program \[with help from [rbxbx](http://github.com/rbxbx "rbxbx at GitHub")\]
|
8
|
+
* Added validation of the URL scheme
|
9
|
+
* Added support for the [rubygems-test](http://rubygems.org/gems/rubygems-test) gem for compatibility testing in the field
|
10
|
+
* Refined dependencies
|
11
|
+
|
12
|
+
<a name="v1.2.1"></a>v1.2.1, Wed 12/01/2010
|
13
|
+
-------------------------------------------
|
6
14
|
|
7
15
|
* Made Ruby v1.8.7 or later a requirement for gem installation
|
8
16
|
* Upgraded dependencies
|
9
17
|
|
10
|
-
v1.2.0, Wed 12/01/2010
|
11
|
-
|
18
|
+
<a name="v1.2.0"></a>v1.2.0, Wed 12/01/2010
|
19
|
+
-------------------------------------------
|
12
20
|
|
13
21
|
* Added support for Tab-key completion of user input [[carsonmcdonald](http://github.com/carsonmcdonald "carsonmcdonald at GitHub")]
|
14
22
|
* Enhanced the `query-unset` command to accept an optional _value_ argument [[mattsa](http://github.com/mattsa "mattsa at GitHub")]
|
15
23
|
|
16
|
-
v1.1.6, Mon 11/22/2010
|
17
|
-
|
24
|
+
<a name="v1.1.6"></a>v1.1.6, Mon 11/22/2010
|
25
|
+
-------------------------------------------
|
18
26
|
|
19
27
|
* Added the `query-add` and `query-remove` commands [[mattsa](http://github.com/mattsa "mattsa at GitHub")]:
|
20
28
|
* Added context-sensitive help in connection with server certificate verification
|
21
29
|
* Upgraded various dependencies
|
22
30
|
|
23
|
-
v1.1.5, Wed 10/20/2010
|
24
|
-
|
31
|
+
<a name="v1.1.5"></a>v1.1.5, Wed 10/20/2010
|
32
|
+
-------------------------------------------
|
25
33
|
|
26
34
|
* Added the `ssl-verification*` commands for controlling the verification of server certificates [[dtjm](http://github.com/dtjm "dtjm at GitHub")]
|
27
35
|
* Fixed a bug in the `query-set` command [[mattsa](http://github.com/mattsa "mattsa at GitHub")]
|
28
36
|
* Fixed a Ruby < v1.9 compatibility problem
|
29
37
|
|
30
|
-
v1.1.4, Sat 10/16/2010
|
31
|
-
|
38
|
+
<a name="v1.1.4"></a>v1.1.4, Sat 10/16/2010
|
39
|
+
-------------------------------------------
|
32
40
|
|
33
41
|
* Enhanced the `query-set` command [[mattsa](http://github.com/mattsa "mattsa at GitHub")] to:
|
34
42
|
- Accept an arbitrary number of arguments
|
@@ -36,25 +44,25 @@ v1.1.4, Sat 10/16/2010
|
|
36
44
|
- Support duplicate keys
|
37
45
|
- Support keys with brackets in their names, à la Rails
|
38
46
|
|
39
|
-
v1.1.3, Tue 10/12/2010
|
40
|
-
|
47
|
+
<a name="v1.1.3"></a>v1.1.3, Tue 10/12/2010
|
48
|
+
-------------------------------------------
|
41
49
|
|
42
50
|
* Fixed a bug in the arrow keys and Emacs key bindings support within the `body-set` command [ephox-rob/[rojotek](http://github.com/rojotek "rojotek at GitHub")]
|
43
51
|
* Fixed a bug involving empty response bodies such as are received with _304 Not Modified_
|
44
52
|
|
45
|
-
v1.1.2, Wed 9/29/2010
|
46
|
-
|
53
|
+
<a name="v1.1.2"></a>v1.1.2, Wed 9/29/2010
|
54
|
+
------------------------------------------
|
47
55
|
|
48
56
|
* Stopped recording blank and repeated entries in the command history [[jgorset](http://github.com/jgorset "jgorset at GitHub")]
|
49
57
|
* Fixed a bug in the help index
|
50
58
|
|
51
|
-
v1.1.1, Tue 9/28/2010
|
52
|
-
|
59
|
+
<a name="v1.1.1"></a>v1.1.1, Tue 9/28/2010
|
60
|
+
------------------------------------------
|
53
61
|
|
54
62
|
* Classified RubyGems for building documentation as development-only dependencies
|
55
63
|
|
56
|
-
v1.1.0, Tue 9/28/2010
|
57
|
-
|
64
|
+
<a name="v1.1.0"></a>v1.1.0, Tue 9/28/2010
|
65
|
+
------------------------------------------
|
58
66
|
|
59
67
|
* Added HTTP Secure support
|
60
68
|
* Added HTTP Basic Authentication support
|
@@ -67,7 +75,7 @@ v1.1.0, Tue 9/28/2010
|
|
67
75
|
* Fixed various bugs
|
68
76
|
* Corrected and expanded built-in help content
|
69
77
|
|
70
|
-
v1.0.0, Mon 9/06/2010
|
71
|
-
|
78
|
+
<a name="v1.0.0"></a>v1.0.0, Mon 9/06/2010
|
79
|
+
------------------------------------------
|
72
80
|
|
73
81
|
(First release)
|
data/MIT-LICENSE.markdown
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
The MIT License
|
2
2
|
===============
|
3
3
|
|
4
|
-
Source code for _htty_ is Copyright © 2010 [Nils Jonsson](mailto:htty@nilsjonsson.com).
|
4
|
+
Source code for _htty_ is Copyright © 2010–2011 [Nils Jonsson](mailto:htty@nilsjonsson.com) and [contributors](http://github.com/htty/htty/contributors "htty contributors at GitHub").
|
5
5
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
7
|
|
data/README.markdown
CHANGED
@@ -27,12 +27,12 @@
|
|
27
27
|
|____| |____| / ______|
|
28
28
|
\/
|
29
29
|
|
30
|
-
[htty](http://htty.github.com) is a console application for interacting with
|
30
|
+
[htty](http://htty.github.com) is a console application for interacting with web servers. It’s a fun way to explore web APIs and to learn the ins and outs of HTTP.
|
31
31
|
|
32
32
|
See what’s changed lately by reading the [project history](http://htty.github.com/file.History.html). [![Flattr this](http://api.flattr.com/button/button-compact-static-100x17.png)](http://flattr.com/thing/68277/htty-the-HTTP-TTY "Flattr this")
|
33
33
|
|
34
|
-
Installation
|
35
|
-
|
34
|
+
<a name="installation"></a>Installation
|
35
|
+
=======================================
|
36
36
|
|
37
37
|
It couldn’t be much easier.
|
38
38
|
|
@@ -40,8 +40,8 @@ It couldn’t be much easier.
|
|
40
40
|
|
41
41
|
You’ll need Ruby and RubyGems. It’s known to work well under OS X against Ruby v1.8.7 and v1.9.2.
|
42
42
|
|
43
|
-
Features
|
44
|
-
|
43
|
+
<a name="features"></a>Features
|
44
|
+
===============================
|
45
45
|
|
46
46
|
* Intuitive, Tab-completed commands and command aliases
|
47
47
|
* Support for familiar HTTP methods _GET_, _POST_, _PUT_, and _DELETE_, as well as _HEAD_, _OPTIONS_ and _TRACE_
|
@@ -60,13 +60,13 @@ The things you can do with _htty_ are:
|
|
60
60
|
* **Review history** — a normal and a verbose transcript of your session are available at all times (destroyed when you quit _htty_)
|
61
61
|
* **Reuse previous requests** — you can refer to prior requests and copy them
|
62
62
|
|
63
|
-
Examples
|
64
|
-
|
63
|
+
<a name="examples"></a>Examples
|
64
|
+
===============================
|
65
65
|
|
66
66
|
Here are a few annotated _htty_ session transcripts to get you started.
|
67
67
|
|
68
|
-
Querying a web service
|
69
|
-
|
68
|
+
<a name="basic-example"></a>Querying a web service
|
69
|
+
--------------------------------------------------
|
70
70
|
|
71
71
|
This simple example shows how to explore a read-only web service with _htty_.
|
72
72
|
|
@@ -98,8 +98,8 @@ We do a Julia Child maneuver and use the `address` command to change the entire
|
|
98
98
|
|
99
99
|
Exit your session at any time by typing `quit`.
|
100
100
|
|
101
|
-
Working with cookies
|
102
|
-
|
101
|
+
<a name="cookies-example"></a>Working with cookies
|
102
|
+
--------------------------------------------------
|
103
103
|
|
104
104
|
The next example demonstrates _htty_’s HTTP Secure support and cookies features, as well as how to review and revisit past requests.
|
105
105
|
|
@@ -121,8 +121,8 @@ Note that history contains only numbered HTTP request and response pairs, not a
|
|
121
121
|
|
122
122
|
The `reuse` command makes a copy of the headers and body of an earlier request for you to build on.
|
123
123
|
|
124
|
-
Understanding complex HTTP conversations at a glance using history
|
125
|
-
|
124
|
+
<a name="history-example"></a>Understanding complex HTTP conversations at a glance using history
|
125
|
+
------------------------------------------------------------------------------------------------
|
126
126
|
|
127
127
|
Now we’ll look at _htty_’s HTTP Basic Authentication support and learn how to display unabbreviated transcripts of _htty_ sessions.
|
128
128
|
|
@@ -167,8 +167,8 @@ Different response codes are rendered with colors that suggest their meaning:
|
|
167
167
|
|
168
168
|
As with the abbreviated history demonstrated earlier, verbose history shows a numbered list of requests and the responses they elicited. All information exchanged between client and server is shown.
|
169
169
|
|
170
|
-
Getting help
|
171
|
-
|
170
|
+
<a name="help"></a>Getting help
|
171
|
+
-------------------------------
|
172
172
|
|
173
173
|
You can learn how to use _htty_ commands from within _htty_.
|
174
174
|
|
@@ -176,13 +176,13 @@ You can learn how to use _htty_ commands from within _htty_.
|
|
176
176
|
|
177
177
|
The `help` command takes an optional argument of the abbreviated or full name of a command.
|
178
178
|
|
179
|
-
Coming soon
|
180
|
-
|
179
|
+
<a name="coming-soon"></a>Coming soon
|
180
|
+
=====================================
|
181
181
|
|
182
182
|
Here are some features that are coming down the pike.
|
183
183
|
|
184
|
-
Commands for streamlining web form submission
|
185
|
-
|
184
|
+
<a name="forms-coming-soon"></a>Commands for streamlining web form submission
|
185
|
+
-----------------------------------------------------------------------------
|
186
186
|
|
187
187
|
These features will make _htty_ better at screen-scraping.
|
188
188
|
|
@@ -196,43 +196,43 @@ Using any of the forthcoming `form` commands will clear any non-form content in
|
|
196
196
|
|
197
197
|
You will also be able to pop open a browser window containing request and response bodies.
|
198
198
|
|
199
|
-
Custom command aliases and shell emulation of _http-console_
|
200
|
-
|
199
|
+
<a name="custom-aliases-coming-soon"></a>Custom command aliases and shell emulation of _http-console_
|
200
|
+
-----------------------------------------------------------------------------------------------------
|
201
201
|
|
202
202
|
You should be able to make your own command aliases.
|
203
203
|
|
204
204
|
_http-console_ has a nice command-line. We should have an _http-console_ skin for _htty_.
|
205
205
|
|
206
|
-
Contributing
|
207
|
-
|
206
|
+
<a name="contributing"></a>Contributing
|
207
|
+
=======================================
|
208
208
|
|
209
209
|
Report defects and feature requests on [GitHub Issues](http://github.com/htty/htty/issues).
|
210
210
|
|
211
211
|
Your patches are welcome, and you will receive attribution here for good stuff. Fork [the official _htty_ repository](http://github.com/htty/htty "htty’s ‘htty’ repository at GitHub") and send a pull request.
|
212
212
|
|
213
|
-
News and information
|
214
|
-
|
213
|
+
<a name="contact"></a>News and information
|
214
|
+
==========================================
|
215
215
|
|
216
216
|
Stay in touch with the _htty_ project by following [@get_htty](http://twitter.com/get_htty "get_htty at Twitter") on Twitter.
|
217
217
|
|
218
218
|
You can also get help in the [#htty channel on Freenode](http://webchat.freenode.net/?channels=htty).
|
219
219
|
|
220
|
-
Credits [![Flattr this](http://api.flattr.com/button/button-compact-static-100x17.png)](http://flattr.com/thing/68277/htty-the-HTTP-TTY "Flattr this")
|
221
|
-
|
220
|
+
<a name="credits"></a>Credits [![Flattr this](http://api.flattr.com/button/button-compact-static-100x17.png)](http://flattr.com/thing/68277/htty-the-HTTP-TTY "Flattr this")
|
221
|
+
=============================
|
222
222
|
|
223
223
|
The author, [Nils Jonsson](mailto:htty@nilsjonsson.com), owes a debt of inspiration to the [_http-console_](http://github.com/cloudhead/http-console) project.
|
224
224
|
|
225
|
-
Thanks to [contributors](
|
225
|
+
Thanks to [contributors](http://github.com/htty/htty/contributors "htty contributors at GitHub") (in alphabetical order):
|
226
226
|
|
227
|
-
* Rob Dawson (ephox-rob/[rojotek](
|
228
|
-
* Bo Frederiksen ([bofrede](
|
229
|
-
* Johannes Gorset ([jgorset](
|
230
|
-
* Carson McDonald ([carsonmcdonald](
|
231
|
-
* Sam Nguyen ([dtjm](
|
232
|
-
* Robert Pitts ([rbxbx](
|
233
|
-
* Matt Sanders ([mattsa](
|
227
|
+
* Rob Dawson (ephox-rob/[rojotek](http://github.com/rojotek "rojotek at GitHub"))
|
228
|
+
* Bo Frederiksen ([bofrede](http://github.com/bofrede "bofrede at GitHub"))
|
229
|
+
* Johannes Gorset ([jgorset](http://github.com/jgorset "jgorset at GitHub"))
|
230
|
+
* Carson McDonald ([carsonmcdonald](http://github.com/carsonmcdonald "carsonmcdonald at GitHub"))
|
231
|
+
* Sam Nguyen ([dtjm](http://github.com/dtjm "dtjm at GitHub"))
|
232
|
+
* Robert Pitts ([rbxbx](http://github.com/rbxbx "rbxbx at GitHub"))
|
233
|
+
* Matt Sanders ([mattsa](http://github.com/mattsa "mattsa at GitHub"))
|
234
234
|
|
235
|
-
License
|
236
|
-
|
235
|
+
<a name="license"></a>License
|
236
|
+
=============================
|
237
237
|
|
238
238
|
Released under the [MIT License](http://htty.github.com/file.MIT-LICENSE.html).
|
data/Rakefile
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
yard, rspec = false, false
|
5
|
+
|
6
|
+
namespace :build do
|
7
|
+
begin
|
8
|
+
require 'yard'
|
9
|
+
rescue LoadError
|
10
|
+
desc '(Not available -- install YARD)'
|
11
|
+
task :doc do
|
12
|
+
STDERR.puts '*** Install YARD in order to build documentation'
|
13
|
+
end
|
14
|
+
else
|
15
|
+
yard = true
|
16
|
+
YARD::Rake::YardocTask.new :doc
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
namespace :lib do
|
21
|
+
desc "Check the source for missing 'require' statements. Set the 'VERBOSE' " +
|
22
|
+
'environment variable to "t[rue]" to display the name of each file as ' +
|
23
|
+
'it is loaded.'
|
24
|
+
task :find_missing_requires do
|
25
|
+
def verbose?
|
26
|
+
ENV['VERBOSE'].to_s =~ /^T/i
|
27
|
+
end
|
28
|
+
|
29
|
+
Dir.glob 'lib/**/*.rb' do |f|
|
30
|
+
if verbose?
|
31
|
+
puts "* #{f}"
|
32
|
+
else
|
33
|
+
print "\x1b[1;32m.\x1b[0m"
|
34
|
+
end
|
35
|
+
command = "/usr/bin/env ruby -e 'require File.expand_path(#{f.inspect})'"
|
36
|
+
break unless system(command)
|
37
|
+
end
|
38
|
+
puts unless verbose?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
begin
|
43
|
+
require 'rspec/core/rake_task'
|
44
|
+
rescue LoadError
|
45
|
+
desc '(Not available -- install RSpec)'
|
46
|
+
task :spec do
|
47
|
+
STDERR.puts '*** Install RSpec in order to run specs'
|
48
|
+
end
|
49
|
+
else
|
50
|
+
rspec = true
|
51
|
+
|
52
|
+
def define_spec_task(name, as_subdirectory=true)
|
53
|
+
RSpec::Core::RakeTask.new name do |t|
|
54
|
+
t.rspec_opts = ['--color']
|
55
|
+
# TODO: Change '-d' to '--debug' when that `rspec` bug is fixed
|
56
|
+
t.rspec_opts << '-d'
|
57
|
+
|
58
|
+
directory = as_subdirectory ? "spec/#{name}" : 'spec'
|
59
|
+
t.pattern = "#{directory}/**/*_spec.rb"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
namespace :spec do |n|
|
64
|
+
%w(unit integration system).each do |type_of_spec|
|
65
|
+
desc "Run #{type_of_spec} specs"
|
66
|
+
define_spec_task type_of_spec
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
desc 'Run all specs'
|
71
|
+
define_spec_task :spec, false
|
72
|
+
end
|
73
|
+
|
74
|
+
if yard && !rspec
|
75
|
+
desc 'Generate YARD documentation'
|
76
|
+
task '' => :doc
|
77
|
+
task :default => :doc
|
78
|
+
else
|
79
|
+
desc 'Run all specs'
|
80
|
+
task '' => :spec
|
81
|
+
task :default => :spec
|
82
|
+
end
|
83
|
+
|
84
|
+
# Support the 'gem test' command.
|
85
|
+
task :test => :spec
|
data/htty.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'htty/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'htty'
|
7
|
+
s.version = HTTY::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Nils Jonsson']
|
10
|
+
s.email = ['htty@nilsjonsson.com']
|
11
|
+
s.homepage = 'http://htty.github.com'
|
12
|
+
s.summary = 'The HTTP TTY'
|
13
|
+
s.description = 'htty is a console application for interacting with web ' +
|
14
|
+
"servers. It's a fun way to explore web APIs and to learn " +
|
15
|
+
'the ins and outs of HTTP.'
|
16
|
+
s.license = 'MIT'
|
17
|
+
|
18
|
+
s.required_ruby_version = '>= 1.8.7'
|
19
|
+
|
20
|
+
s.add_dependency 'mime-types', '~> 1.0'
|
21
|
+
|
22
|
+
s.add_development_dependency 'bluecloth', '~> 2.0'
|
23
|
+
s.add_development_dependency 'rake', '~> 0.8'
|
24
|
+
s.add_development_dependency 'rspec', '~> 2.0'
|
25
|
+
s.add_development_dependency 'yard', '~> 0.2'
|
26
|
+
|
27
|
+
s.rubyforge_project = 'htty'
|
28
|
+
s.has_rdoc = true
|
29
|
+
|
30
|
+
s.files = `git ls-files`.split("\n")
|
31
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
32
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
|
33
|
+
File.basename f
|
34
|
+
end
|
35
|
+
s.require_paths = %w(lib)
|
36
|
+
end
|
data/lib/htty.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
# Contains the implementation of _htty_.
|
2
|
-
module HTTY
|
3
|
-
|
4
|
-
# The version of this release of _htty_.
|
5
|
-
VERSION = File.read("#{File.dirname __FILE__}/../VERSION").chomp
|
6
|
-
|
7
|
-
end
|
2
|
+
module HTTY; end
|
8
3
|
|
9
4
|
Dir.glob "#{File.dirname __FILE__}/htty/*.rb" do |f|
|
10
5
|
require File.expand_path("#{File.dirname __FILE__}/htty/" +
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'mime/types'
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../platform")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/../tempfile_preserving_extname")
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/display")
|
5
|
+
|
6
|
+
module HTTY; end
|
7
|
+
|
8
|
+
class HTTY::CLI; end
|
9
|
+
|
10
|
+
# Encapsulates behavior common to all HTTY::CLI::Command subclasses that open
|
11
|
+
# body content in an external viewer program.
|
12
|
+
module HTTY::CLI::BodyOpenCommand
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
|
16
|
+
# Returns the arguments for the command-line usage of the command.
|
17
|
+
def command_line_arguments
|
18
|
+
'[OPTIONS]'
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns the extended help text for the command.
|
22
|
+
def help_extended
|
23
|
+
"#{help_extended_preamble}\n" +
|
24
|
+
"\n" +
|
25
|
+
'The shell command used to launch the program is platform-specific. On ' +
|
26
|
+
"Windows, the 'start' command is used. On other platforms, the 'open' " +
|
27
|
+
"command is used. (The 'open' command may not be available on your " +
|
28
|
+
"system.)\n" +
|
29
|
+
"\n" +
|
30
|
+
'You may specify options to be passed to the program. For example, on ' +
|
31
|
+
'Mac OS X, your default program for HTML files may be Google Chrome, ' +
|
32
|
+
'but you can launch Firefox instead by typing ' +
|
33
|
+
"#{strong command_line + ' -a firefox'}. Likewise, on Windows your " +
|
34
|
+
'default program for HTML files may be Internet Explorer, but you can ' +
|
35
|
+
"launch Opera instead by typing #{strong command_line + ' opera'}."
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.included(other_module)
|
41
|
+
other_module.extend ClassMethods
|
42
|
+
other_module.module_eval do
|
43
|
+
include HTTY::CLI::Display
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def open(payload)
|
50
|
+
if (body = payload.body).to_s.empty?
|
51
|
+
puts notice("#{payload.class.name.split('::').last} does not have a body")
|
52
|
+
return self
|
53
|
+
end
|
54
|
+
content_type_header = payload.headers.detect do |name, value|
|
55
|
+
name == 'Content-Type'
|
56
|
+
end
|
57
|
+
content_type = content_type_header ? content_type_header.last : nil
|
58
|
+
tempfile = render_to_file(body, content_type)
|
59
|
+
path = platform_path(tempfile.path)
|
60
|
+
arguments_to_open = arguments.empty? ? '' : " #{arguments.join ' '}"
|
61
|
+
`#{open_command}#{arguments_to_open} #{path}`
|
62
|
+
end
|
63
|
+
|
64
|
+
def open_command
|
65
|
+
HTTY::Platform.windows? ? 'start' : 'open'
|
66
|
+
end
|
67
|
+
|
68
|
+
def platform_path(path)
|
69
|
+
HTTY::Platform.windows? ? path.gsub('/', '\\') : path
|
70
|
+
end
|
71
|
+
|
72
|
+
def render_to_file(body, content_type)
|
73
|
+
filename = "htty.#{tempfile_extension content_type}"
|
74
|
+
HTTY::TempfilePreservingExtname.new(filename).tap do |f|
|
75
|
+
f.write body
|
76
|
+
f.close
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def tempfile_extension(content_type)
|
81
|
+
unless (types = MIME::Types[content_type].first)
|
82
|
+
if content_type.to_s.empty?
|
83
|
+
puts notice("No 'Content-Type' header value -- assuming 'text/html'")
|
84
|
+
else
|
85
|
+
puts notice("Unrecognized 'Content-Type' header value " +
|
86
|
+
"'#{content_type}' -- using 'text/html' instead")
|
87
|
+
end
|
88
|
+
return 'html'
|
89
|
+
end
|
90
|
+
type.extensions.first
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|