gopher2000 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #
5
+ # Simple gopher example
6
+ #
7
+
8
+ require 'gopher2000'
9
+
10
+ set :host, '0.0.0.0'
11
+ set :port, 7070
12
+
13
+ route '/figlet' do
14
+ render :figlet
15
+ end
16
+
17
+ #
18
+ # special text output rendering
19
+ #
20
+ text :figlet do
21
+ @text = "Hello!"
22
+
23
+ # nicely wrapped text
24
+ figlet @text
25
+
26
+ # spacing
27
+ br(2)
28
+ end
data/gopher2000.gemspec CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  s.add_development_dependency "watchr"
31
31
  s.add_development_dependency "eventmachine"
32
32
 
33
+ s.add_runtime_dependency "artii", ">= 2.0.1"
33
34
  s.add_runtime_dependency "eventmachine"
34
35
  s.add_runtime_dependency "logging"
35
36
  end
@@ -91,9 +91,9 @@ module Gopher
91
91
  #
92
92
  # mount a directory for browsing via gopher
93
93
  #
94
- # @param [Hash] A hash specifying the path your route will answer to, and the filesystem path to use '/route' => '/home/path/etc'
95
- #
96
- # @param [Hash] a hash of options for the mount. Primarily this is a filter, which will restrict the list files outputted. example: :filter => '*.jpg'
94
+ # @param [Hash] path A hash specifying the path your route will answer to, and the filesystem path to use '/route' => '/home/path/etc'
95
+ # @param [Hash] opts a hash of options for the mount. Primarily this is a filter, which will restrict the list files outputted. example: :filter => '*.jpg'
96
+ # @param [Class] klass The class that should be used to handle this mount. You could write and use a custom handler if desired
97
97
  #
98
98
  # @example mount the directory '/home/user/foo' at the gopher path '/files', and only show JPG files:
99
99
  # mount '/files' => '/home/user/foo', :filter => '*.jpg'
@@ -118,8 +118,7 @@ module Gopher
118
118
 
119
119
  #
120
120
  # define a route.
121
- # @param [String] the path your route will answer to. This is
122
- # basically a URI path
121
+ # @param [String] path the path your route will answer to. This is basically a URI path
123
122
  # @yield a block that handles your route
124
123
  #
125
124
  # @example respond with a simple string
@@ -145,6 +144,7 @@ module Gopher
145
144
 
146
145
  #
147
146
  # specify a default route to handle requests if no other route exists
147
+ # @yield a block to handle the default route
148
148
  #
149
149
  # @example render a template
150
150
  # default_route do
@@ -158,7 +158,7 @@ module Gopher
158
158
  #
159
159
  # lookup an incoming path
160
160
  #
161
- # @param [String] the selector path of the incoming request
161
+ # @param [String] selector the selector path of the incoming request
162
162
  #
163
163
  def lookup(selector)
164
164
  unless routes.nil?
@@ -190,7 +190,7 @@ module Gopher
190
190
 
191
191
  #
192
192
  # find and run the first route which matches the incoming request
193
- # @param [Request] Gopher::Request object
193
+ # @param [Request] req Gopher::Request object
194
194
  #
195
195
  def dispatch(req)
196
196
  debug_log(req)
@@ -233,11 +233,11 @@ module Gopher
233
233
  # define a template which will be used to render a gopher-style
234
234
  # menu.
235
235
  #
236
- # @param [String/Symbol] -- the name of the template. This is what
237
- # identifies the template when making a call to render
236
+ # @param [String/Symbol] name the name of the template. This is what
237
+ # identifies the template when making a call to render
238
238
  # @yield a block which will output the menu. This block is
239
- # executed within an instance of Gopher::Rendering::Menu and will
240
- # have access to all of its methods.
239
+ # executed within an instance of Gopher::Rendering::Menu and will
240
+ # have access to all of its methods.
241
241
  #
242
242
  # @example a simple menu:
243
243
  # menu :index do
@@ -273,7 +273,7 @@ module Gopher
273
273
  # access to the methods defined in Gopher::Rendering::Text for
274
274
  # wrapping strings, adding simple headers, etc.
275
275
  #
276
- # @param [String/Symbol] -- the name of the template. This is what identifies the template when making a call to render
276
+ # @param [String/Symbol] name the name of the template. This is what identifies the template when making a call to render
277
277
  #
278
278
  # @yield a block which will output the menu. This block is executed within an instance of Gopher::Rendering::Text and will have access to all of its methods.
279
279
  # @example simple example
@@ -295,7 +295,7 @@ module Gopher
295
295
 
296
296
  #
297
297
  # find a template
298
- # @param [String/Symbol] name of the template
298
+ # @param [String/Symbol] t name of the template
299
299
  # @return template block and the class context it should use
300
300
  #
301
301
  def find_template(t)
@@ -311,8 +311,8 @@ module Gopher
311
311
 
312
312
  #
313
313
  # Find the desired template and call it within the proper context
314
- # @param [String/Symbol] name of the template to render
315
- # @param [Array] optional arguments to be passed to template
314
+ # @param [String/Symbol] template name of the template to render
315
+ # @param [Array] arguments optional arguments to be passed to template
316
316
  # @return result of rendering
317
317
  #
318
318
  def render(template, *arguments)
@@ -411,7 +411,7 @@ module Gopher
411
411
  # turn a path string with optional keys (/foo/:bar/:boo) into a
412
412
  # regexp which will be used when searching for a route
413
413
  #
414
- # @param [String] the path to compile
414
+ # @param [String] path the path to compile
415
415
  #
416
416
  def compile(path)
417
417
  keys = []
@@ -448,7 +448,7 @@ module Gopher
448
448
  # generate a method which we will use to run routes. this is
449
449
  # based on #generate_method as used by sinatra.
450
450
  # @see https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb
451
- # @param [String] name to use for the method
451
+ # @param [String] method_name name to use for the method
452
452
  # @yield block to use for the method
453
453
  def generate_method(method_name, &block)
454
454
  define_method(method_name, &block)
@@ -22,7 +22,7 @@ module Gopher
22
22
  #
23
23
  # called by EventMachine when there's an incoming request
24
24
  #
25
- # @param [String] incoming selector
25
+ # @param [String] selector incoming selector
26
26
  # @return Response object
27
27
  #
28
28
  def receive_data(selector)
@@ -31,7 +31,7 @@ module Gopher
31
31
 
32
32
  #
33
33
  # generate a request object from an incoming selector, and dispatch it to the app
34
- # @param [String] incoming selector
34
+ # @param [Request] request Request object to handle
35
35
  # @return Response object
36
36
  #
37
37
  def call!(request)
@@ -81,7 +81,7 @@ module Gopher
81
81
  end
82
82
 
83
83
  # watch the specified script for changes
84
- # @param [String] script to watch
84
+ # @param [String] f script to watch
85
85
  def watch(f)
86
86
  application.scripts << f
87
87
  end
@@ -27,7 +27,7 @@ module Gopher
27
27
 
28
28
  #
29
29
  # strip slashes, extra dots, etc, from an incoming selector and turn it into a 'normalized' path
30
- # @param [String] path
30
+ # @param [String] p path to check
31
31
  # @return clean path string
32
32
  #
33
33
  def sanitize(p)
@@ -65,12 +65,10 @@ module Gopher
65
65
  #
66
66
  # handle a request
67
67
  #
68
- # @param [Hash] the params as parsed during the dispatching process - the main thing here should be :splat, which will basically be the path requested.
69
- # @param [Request] - the Request object for this session -- not currently used?
68
+ # @param [Hash] params the params as parsed during the dispatching process - the main thing here should be :splat, which will basically be the path requested.
69
+ # @param [Request] request the Request object for this session -- not currently used?
70
70
  #
71
71
  def call(params = {}, request = nil)
72
- # debug_log "DirectoryHandler: call #{params.inspect}, #{request.inspect}"
73
-
74
72
  lookup = request_path(params)
75
73
 
76
74
  raise Gopher::InvalidRequest if ! contained?(lookup)
@@ -86,7 +84,7 @@ module Gopher
86
84
 
87
85
  #
88
86
  # generate a directory listing
89
- # @param [String] path to directory
87
+ # @param [String] dir path to directory
90
88
  # @return rendered directory output for a response
91
89
  #
92
90
  def directory(dir)
@@ -5,6 +5,8 @@ module Gopher
5
5
  #
6
6
  module Rendering
7
7
 
8
+ require 'artii'
9
+
8
10
  # "A CR LF denotes the end of the item." RFC 1436
9
11
  # @see http://www.faqs.org/rfcs/rfc1436.html
10
12
  LINE_ENDING = "\r\n"
@@ -94,6 +96,32 @@ module Gopher
94
96
  self.to_s
95
97
  end
96
98
 
99
+ #
100
+ # output a figlet, which is a big ASCII art header like this:
101
+ # _ _ _ _ _
102
+ # | | | | | | | | |
103
+ # | |__| | ___| | | ___ | |
104
+ # | __ |/ _ \ | |/ _ \| |
105
+ # | | | | __/ | | (_) |_|
106
+ # |_| |_|\___|_|_|\___/(_)
107
+ #
108
+ # This method doesn't do any width checks, so you should be
109
+ # careful with it.
110
+ # You can get a list of fonts from the artii source code or
111
+ # http://www.figlet.org/examples.html
112
+ # https://github.com/miketierney/artii/tree/master/lib/figlet/fonts
113
+
114
+ # @param [String] str the text you want to use for your figlet
115
+ # @param [String] font name of the font. Defaults to 'big'.
116
+ #
117
+ def figlet(str, font = 'big')
118
+ a = Artii::Base.new(:font => font)
119
+ a.asciify(str).split("\n").each do |l|
120
+ text l
121
+ end
122
+ self.to_s
123
+ end
124
+
97
125
  #
98
126
  # output a centered string with a nice underline below it,
99
127
  # centered on the current output width
@@ -119,6 +147,11 @@ module Gopher
119
147
  underline(@width, under)
120
148
  end
121
149
 
150
+ #
151
+ # output a 'small' header, just the text with an underline
152
+ # @param [String] str - the string to output
153
+ # @param [String] under - the desired underline character
154
+ #
122
155
  def small_header(str, under = '=')
123
156
  str = " " + str + " "
124
157
  text(str)
@@ -15,7 +15,7 @@ module Gopher
15
15
  NO_PORT = 0
16
16
 
17
17
  # Sanitizes text for use in gopher menus
18
- # @param [String] text text to cleanup
18
+ # @param [String] raw text to cleanup
19
19
  # @return string that can be used in a gopher menu
20
20
  def sanitize_text(raw)
21
21
  raw.
@@ -111,7 +111,7 @@ module Gopher
111
111
  # Determines the gopher type for +selector+ based on the
112
112
  # extension. This is a pretty simple check based on the entities
113
113
  # list in http://www.ietf.org/rfc/rfc1436.txt
114
- # @param [String] selector, presumably a link to a file name with an extension
114
+ # @param [String] selector presumably a link to a file name with an extension
115
115
  # @return gopher selector type
116
116
  #
117
117
  def determine_type(selector)
@@ -8,7 +8,7 @@ module Gopher
8
8
 
9
9
  #
10
10
  # constructor
11
- # @param [Application] instance of Gopher::Application we want to run
11
+ # @param [Application] a instance of Gopher::Application we want to run
12
12
  #
13
13
  def initialize(a)
14
14
  @app = a
@@ -1,4 +1,4 @@
1
1
  module Gopher
2
2
  # current version of the app
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
@@ -31,6 +31,13 @@ describe Gopher::Rendering::Base do
31
31
  end
32
32
  end
33
33
 
34
+ describe "figlet" do
35
+ it "outputs a figlet" do
36
+ @ctx.figlet('pie').should == " _ \r\n (_) \r\n _ __ _ ___ \r\n | '_ \\| |/ _ \\\r\n | |_) | | __/\r\n | .__/|_|\\___|\r\n | | \r\n |_| \r\n"
37
+ end
38
+ end
39
+
40
+
34
41
  describe "big_header" do
35
42
  it "outputs a box with text" do
36
43
  @ctx.width(5)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gopher2000
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-02 00:00:00.000000000Z
12
+ date: 2012-05-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &18116460 !ruby/object:Gem::Requirement
16
+ requirement: &13099820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *18116460
24
+ version_requirements: *13099820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redcarpet
27
- requirement: &18115520 !ruby/object:Gem::Requirement
27
+ requirement: &13098680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *18115520
35
+ version_requirements: *13098680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yard
38
- requirement: &18114820 !ruby/object:Gem::Requirement
38
+ requirement: &13096940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *18114820
46
+ version_requirements: *13096940
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: shoulda
49
- requirement: &18113580 !ruby/object:Gem::Requirement
49
+ requirement: &13066600 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *18113580
57
+ version_requirements: *13066600
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rdoc
60
- requirement: &18093380 !ruby/object:Gem::Requirement
60
+ requirement: &13062740 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *18093380
68
+ version_requirements: *13062740
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &18092340 !ruby/object:Gem::Requirement
71
+ requirement: &13003680 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *18092340
79
+ version_requirements: *13003680
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: watchr
82
- requirement: &18086720 !ruby/object:Gem::Requirement
82
+ requirement: &13002280 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *18086720
90
+ version_requirements: *13002280
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: eventmachine
93
- requirement: &18032500 !ruby/object:Gem::Requirement
93
+ requirement: &13001380 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,21 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *18032500
101
+ version_requirements: *13001380
102
+ - !ruby/object:Gem::Dependency
103
+ name: artii
104
+ requirement: &13000160 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 2.0.1
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: *13000160
102
113
  - !ruby/object:Gem::Dependency
103
114
  name: eventmachine
104
- requirement: &18031440 !ruby/object:Gem::Requirement
115
+ requirement: &12998560 !ruby/object:Gem::Requirement
105
116
  none: false
106
117
  requirements:
107
118
  - - ! '>='
@@ -109,10 +120,10 @@ dependencies:
109
120
  version: '0'
110
121
  type: :runtime
111
122
  prerelease: false
112
- version_requirements: *18031440
123
+ version_requirements: *12998560
113
124
  - !ruby/object:Gem::Dependency
114
125
  name: logging
115
- requirement: &18029980 !ruby/object:Gem::Requirement
126
+ requirement: &12997620 !ruby/object:Gem::Requirement
116
127
  none: false
117
128
  requirements:
118
129
  - - ! '>='
@@ -120,7 +131,7 @@ dependencies:
120
131
  version: '0'
121
132
  type: :runtime
122
133
  prerelease: false
123
- version_requirements: *18029980
134
+ version_requirements: *12997620
124
135
  description: Gopher2000 is a ruby-based Gopher server. It is built for speedy, enjoyable
125
136
  development of all sorts of gopher sites.
126
137
  email:
@@ -138,6 +149,7 @@ files:
138
149
  - Rakefile
139
150
  - bin/gopher2000
140
151
  - examples/default_route.rb
152
+ - examples/figlet.rb
141
153
  - examples/nyan.rb
142
154
  - examples/simple.rb
143
155
  - examples/twitter.rb
@@ -191,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
203
  version: '0'
192
204
  segments:
193
205
  - 0
194
- hash: -579980991170337830
206
+ hash: -984672476065544858
195
207
  required_rubygems_version: !ruby/object:Gem::Requirement
196
208
  none: false
197
209
  requirements:
@@ -200,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
212
  version: '0'
201
213
  segments:
202
214
  - 0
203
- hash: -579980991170337830
215
+ hash: -984672476065544858
204
216
  requirements: []
205
217
  rubyforge_project: gopher2000
206
218
  rubygems_version: 1.8.17