cheat 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module Cheat
2
+ VERSION = "1.3.0"
3
+ end
File without changes
metadata CHANGED
@@ -1,58 +1,93 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: cheat
5
3
  version: !ruby/object:Gem::Version
6
- version: 1.2.1
7
- date: 2006-11-10 00:00:00 -08:00
8
- summary: Cheat is a simple command line utility reference program.
9
- require_paths:
10
- - lib
11
- email: chris@ozmm.org
12
- homepage: http://cheat.errtheblog.com/
13
- rubyforge_project:
14
- description: Cheat is a simple command line utility reference program. Use it to, well, cheat.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 3
8
+ - 0
9
+ version: 1.3.0
25
10
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
11
  authors:
30
12
  - Chris Wanstrath
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-24 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: " cheat prints cheat sheets from cheat.errtheblog.com, a wiki-like\n repository of programming knowledge.\n"
22
+ email: chris@ozmm.org
23
+ executables:
24
+ - cheat
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
31
29
  files:
32
30
  - README
33
31
  - LICENSE
34
- - bin/cheat
35
- - lib/cheat
32
+ - lib/ambition/init.rb
33
+ - lib/ambition/lib/ambition/count.rb
34
+ - lib/ambition/lib/ambition/enumerable.rb
35
+ - lib/ambition/lib/ambition/limit.rb
36
+ - lib/ambition/lib/ambition/order.rb
37
+ - lib/ambition/lib/ambition/processor.rb
38
+ - lib/ambition/lib/ambition/query.rb
39
+ - lib/ambition/lib/ambition/where.rb
40
+ - lib/ambition/lib/ambition.rb
41
+ - lib/ambition/lib/proc_to_ruby.rb
42
+ - lib/ambition/LICENSE
43
+ - lib/ambition/Rakefile
44
+ - lib/ambition/README
45
+ - lib/ambition/test/chaining_test.rb
46
+ - lib/ambition/test/count_test.rb
47
+ - lib/ambition/test/enumerable_test.rb
48
+ - lib/ambition/test/helper.rb
49
+ - lib/ambition/test/join_test.rb
50
+ - lib/ambition/test/limit_test.rb
51
+ - lib/ambition/test/order_test.rb
52
+ - lib/ambition/test/types_test.rb
53
+ - lib/ambition/test/where_test.rb
54
+ - lib/cheat/diffr.rb
55
+ - lib/cheat/responder.rb
56
+ - lib/cheat/rv_harness.rb
57
+ - lib/cheat/site.rb
58
+ - lib/cheat/version.rb
59
+ - lib/cheat/wrap.rb
36
60
  - lib/cheat.rb
37
- - lib/diffr.rb
38
- - lib/new_cheat.rb
39
- - lib/responder.rb
40
- - lib/site.rb
41
- - lib/wrap.rb
42
- - lib/cheat/commands.rb
43
- - test/fixtures
44
- - test/test_cheat.rb
45
- test_files: []
61
+ - bin/cheat
62
+ has_rdoc: true
63
+ homepage: http://cheat.errtheblog.com
64
+ licenses: []
46
65
 
66
+ post_install_message:
47
67
  rdoc_options: []
48
68
 
49
- extra_rdoc_files: []
50
-
51
- executables:
52
- - cheat
53
- extensions: []
54
-
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
55
85
  requirements: []
56
86
 
57
- dependencies: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.6
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: cheat prints cheat sheets from cheat.errtheblog.com
92
+ test_files: []
58
93
 
@@ -1,41 +0,0 @@
1
- module Cheat
2
- class Commands
3
- def initialize(args)
4
- @sheet = args.shift unless args.first =~ /^--/
5
- parse_args(args)
6
- end
7
-
8
- private
9
- def parse_args(args)
10
- args.each_with_index do |arg, i|
11
- if arg =~ /^--(.+)$/ && respond_to?(meth = $1)
12
- if method(meth).arity.zero? || args[i+1] =~ /^--/
13
- send(meth)
14
- else
15
- send(meth, args[i+1])
16
- end
17
- end
18
- end
19
- end
20
-
21
- public
22
- def help
23
- puts self.class.public_instance_methods(false)
24
- end
25
-
26
- def diff
27
- end
28
-
29
- def add
30
- end
31
-
32
- def new
33
- end
34
-
35
- def clear_cache
36
- end
37
-
38
- def edit
39
- end
40
- end
41
- end
@@ -1,163 +0,0 @@
1
- $:.unshift File.dirname(__FILE__)
2
- %w[rubygems tempfile fileutils net/http yaml open-uri wrap].each { |f| require f }
3
- %w[cheat/commands].each { |f| require f }
4
-
5
- module Cheat
6
- extend self
7
-
8
- HOST = ARGV.include?('debug') ? 'localhost' : 'cheat.errtheblog.com'
9
- PORT = ARGV.include?('debug') ? 3001 : 80
10
- SUFFIX = ''
11
-
12
- def sheets(args)
13
- Commands.new(args)
14
-
15
- return
16
- return unless parse_args(args)
17
-
18
- FileUtils.mkdir(cache_dir) unless File.exists?(cache_dir) if cache_dir
19
-
20
- uri = "http://#{cheat_uri}/y/"
21
-
22
- if %w[sheets all recent].include? @sheet
23
- uri = uri.sub('/y/', sheet == 'recent' ? '/yr/' : '/ya/')
24
- return open(uri) { |body| show(body.read) }
25
- end
26
-
27
- return show(File.read(cache_file)) if File.exists?(cache_file) rescue clear_cache if cache_file
28
-
29
- fetch_sheet(uri, @sheet) if @sheet
30
- end
31
-
32
- def fetch_sheet(uri, try_to_cache = true)
33
- open(uri, headers) do |body|
34
- sheet = body.read
35
- File.open(cache_file, 'w') { |f| f.write(sheet) } if try_to_cache && cache_file && !@edit
36
- @edit ? edit(sheet) : show(sheet)
37
- end
38
- rescue OpenURI::HTTPError => e
39
- puts "Whoa, some kind of Internets error!", "=> #{e} from #{uri}"
40
- end
41
-
42
- def parse_args(args)
43
- puts "Looking for help? Try http://cheat.errtheblog.com or `$ cheat cheat'" and return if args.empty?
44
-
45
- if args.delete('--clear-cache') || args.delete('--new')
46
- clear_cache
47
- return if args.empty?
48
- end
49
-
50
- if i = args.index('--diff')
51
- diff_sheets(args.first, args[i+1])
52
- return
53
- end
54
-
55
- add(args.shift) and return if args.delete('--add')
56
- clear_cache if @edit = args.delete('--edit')
57
-
58
- @sheet = args.shift
59
-
60
- true
61
- end
62
-
63
- # $ cheat greader --diff 1[:3]
64
- def diff_sheets(sheet, version)
65
- if version =~ /^(\d+)(:(\d+))?$/
66
- old_version, new_version = $1, $3
67
- else return
68
- end
69
-
70
- uri = "http://#{cheat_uri}/d/#{sheet}/#{old_version}"
71
- uri += "/#{new_version}" if new_version
72
-
73
- fetch_sheet(uri, false)
74
- end
75
-
76
- def cache_file
77
- "#{cache_dir}/#{@sheet}.yml" if cache_dir
78
- end
79
-
80
- def headers
81
- { 'User-Agent' => 'cheat!', 'Accept' => 'text/yaml' }
82
- end
83
-
84
- def cheat_uri
85
- "#{HOST}:#{PORT}#{SUFFIX}"
86
- end
87
-
88
- def show(sheet_yaml)
89
- sheet = YAML.load(sheet_yaml).to_a.first
90
- sheet[-1] = sheet.last.join("\n") if sheet[-1].is_a?(Array)
91
- puts sheet.first + ':'
92
- puts ' ' + sheet.last.gsub("\r",'').gsub("\n", "\n ").wrap
93
- end
94
-
95
- def edit(sheet_yaml)
96
- sheet = YAML.load(sheet_yaml).to_a.first
97
- sheet[-1] = sheet.last.gsub("\r", '')
98
- body, title = write_to_tempfile(*sheet), sheet.first
99
- return if body.strip == sheet.last.strip
100
- res = post_sheet(title, body)
101
- check_errors(res, title, body)
102
- end
103
-
104
- def add(title)
105
- body = write_to_tempfile(title)
106
- res = post_sheet(title, body, true)
107
- check_errors(res, title, body)
108
- end
109
-
110
- def post_sheet(title, body, new = false)
111
- uri = "http://#{cheat_uri}/w/"
112
- uri += title unless new
113
- Net::HTTP.post_form(URI.parse(uri), "sheet_title" => title, "sheet_body" => body.strip, "from_gem" => true)
114
- end
115
-
116
- def write_to_tempfile(title, body = nil)
117
- # god dammit i hate tempfile, this is so messy but i think it's
118
- # the only way.
119
- tempfile = Tempfile.new(title + '.cheat')
120
- tempfile.write(body) if body
121
- tempfile.close
122
- system "#{editor} #{tempfile.path}"
123
- tempfile.open
124
- body = tempfile.read
125
- tempfile.close
126
- body
127
- end
128
-
129
- def check_errors(result, title, text)
130
- if result.body =~ /<p class="error">(.+?)<\/p>/m
131
- puts $1.gsub(/\n/, '').gsub(/<.+?>/, '').squeeze(' ').wrap(80)
132
- puts
133
- puts "Here's what you wrote, so it isn't lost in the void:"
134
- puts text
135
- else
136
- puts "Success! Try it!", "$ cheat #{title} --new"
137
- end
138
- end
139
-
140
- def editor
141
- ENV['VISUAL'] || ENV['EDITOR'] || "vim"
142
- end
143
-
144
- def cache_dir
145
- PLATFORM =~ /win32/ ? win32_cache_dir : File.join(File.expand_path("~"), ".cheat")
146
- end
147
-
148
- def win32_cache_dir
149
- unless File.exists?(home = ENV['HOMEDRIVE'] + ENV['HOMEPATH'])
150
- puts "No HOMEDRIVE or HOMEPATH environment variable. Set one to save a" +
151
- "local cache of cheat sheets."
152
- return false
153
- else
154
- return File.join(home, 'Cheat')
155
- end
156
- end
157
-
158
- def clear_cache
159
- FileUtils.rm_rf(cache_dir) if cache_dir
160
- end
161
- end
162
-
163
- Cheat.sheets(ARGV) if __FILE__ == $0
@@ -1,50 +0,0 @@
1
- # eh. one day.
2
- $:.unshift File.dirname(__FILE__) + "/..:lib"
3
- require 'test/unit'
4
- require 'fileutils'
5
- require 'tempfile'
6
- require 'cheat'
7
-
8
- Sheets = Hash.new do |h,k|
9
- k = k.to_s
10
- h[k] = YAML.load(File.read("test/fixtures/#{k}.yml")) rescue nil
11
- end
12
-
13
- class CheatTest < Test::Unit::TestCase
14
-
15
- def test_gets_from_host
16
- end
17
-
18
- def test_sets_to_cache
19
- end
20
-
21
- def test_gets_from_arbitrary_host
22
- end
23
-
24
- def test_gracefully_fail_if_host_bunk
25
- end
26
-
27
- def test_creates_cache_dir
28
- end
29
-
30
- def test_doesnt_create_cache_dir_if_exists
31
- end
32
-
33
- def test_loads_from_cache_if_exists
34
- end
35
-
36
- def test_gets_section_if_exists
37
- end
38
-
39
- def test_displays_everything_on_failed_section_search
40
- end
41
-
42
- def test_gets_recent_sheets
43
- end
44
-
45
- def test_gets_all_sheets
46
- end
47
-
48
- def test_uses_env_for_cache_dir
49
- end
50
- end