httphere 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  httphere is a very small and simple ruby command-line HTTP file server.
4
4
 
5
+ == Features
6
+
7
+ * Serves any file found at the current path, simply the content-type determined by shared-mime-types, and the content of the file.
8
+ * Defaults to index.* for a root request.
9
+ * Renders *.markdown as Markdown (html).
10
+
5
11
  = To work on
6
12
 
7
13
  * Improve content-negotiation behind the scenes. For example, a file found to be "application/x-ruby" could just as well be transferred as "text/plain".
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/bin/httphere CHANGED
@@ -534,19 +534,42 @@ end
534
534
 
535
535
  require 'iconv'
536
536
  require 'rubygems'
537
+ module Renderers
538
+ autoload :Markdown, 'httphere/markdown'
539
+ autoload :Textile, 'httphere/textile'
540
+ end
537
541
  require 'UniversalDetector'
538
542
  require 'shared-mime-info'
539
543
  class FileServer < EventParsers::Http11Parser::Request
540
544
  # This is where the routing is processed.
541
545
  def process
542
546
  # Get the filename desired
543
- filename = resource_uri.sub(/^\//,'')
547
+ filename, query = resource_uri.split('?',2)
548
+ filename = filename.sub(/^\//,'')
549
+ # Default to any file named index.*
550
+ filename = Dir["index.*"].first if filename.to_s == '' && Dir["index.*"].length > 0
551
+ file_extension = (filename.match(/\.([^\.]+)$/) || [])[1]
552
+
544
553
  if File.exists?(filename) && !File.directory?(filename)
545
554
  content_type = MIME.check(filename).type
546
555
  file_body = File.read(filename)
556
+
557
+ # If .markdown, render as Markdown
558
+ if file_extension == 'markdown'
559
+ file_body = Renderers::Markdown.render_content(file_body)
560
+ content_type = 'text/html'
561
+ end
562
+
563
+ # If .textile, render as Textile
564
+ if file_extension == 'textile'
565
+ file_body = Renderers::Textile.render_content(file_body)
566
+ content_type = 'text/html'
567
+ end
568
+
569
+ # Send Response
547
570
  respond!('200 Ok', content_type, file_body)
548
571
  else
549
- respond!('400 Not Found', 'text/plain', "Could not find file: '#{resource_uri}'")
572
+ respond!('404 Not Found', 'text/plain', "Could not find file: '#{resource_uri}'")
550
573
  end
551
574
  end
552
575
 
@@ -571,7 +594,7 @@ class FileServer < EventParsers::Http11Parser::Request
571
594
  puts (status =~ /200/ ?
572
595
  "Served #{resource_uri} (#{content_type})" :
573
596
  "404 #{resource_uri}"
574
- ) + " at #{1 / span} requests/second"
597
+ ) + " at #{1 / span} requests/second" unless status =~ /404/ && resource_uri == '/favicon.ico'
575
598
  end
576
599
  end
577
600
 
data/httphere.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{httphere}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Parker"]
12
- s.date = %q{2010-01-06}
12
+ s.date = %q{2010-02-10}
13
13
  s.default_executable = %q{httphere}
14
14
  s.description = %q{httphere is a very small and simple ruby command-line HTTP file server.}
15
15
  s.email = %q{gems@behindlogic.com}
@@ -26,7 +26,9 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "bin/httphere",
29
- "httphere.gemspec"
29
+ "httphere.gemspec",
30
+ "lib/httphere/markdown.rb",
31
+ "lib/httphere/textile.rb"
30
32
  ]
31
33
  s.homepage = %q{http://dcparker.github.com/httphere}
32
34
  s.post_install_message = %q{
@@ -0,0 +1,9 @@
1
+ module Renderers
2
+ class Markdown
3
+ def self.render_content(content)
4
+ require 'rubygems'
5
+ require 'bluecloth'
6
+ BlueCloth.new(content).to_html
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Renderers
2
+ class Textile
3
+ def self.render_content(content)
4
+ require 'rubygems'
5
+ require 'redcloth'
6
+ RedCloth.new(content).to_html
7
+ end
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Parker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-06 00:00:00 -05:00
12
+ date: 2010-02-10 00:00:00 -05:00
13
13
  default_executable: httphere
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,8 @@ files:
50
50
  - VERSION
51
51
  - bin/httphere
52
52
  - httphere.gemspec
53
+ - lib/httphere/markdown.rb
54
+ - lib/httphere/textile.rb
53
55
  has_rdoc: true
54
56
  homepage: http://dcparker.github.com/httphere
55
57
  licenses: []