serveable 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 72c6629c8e364e6deab42b42b386c032f056645c
4
+ data.tar.gz: 89707e239b053f6707dbb446c0176472afab1d20
5
+ SHA512:
6
+ metadata.gz: 46a28d12b8db9a58e16f8c232af102d08d47fdff96eed75545707a5d5ec38df26e90f64b1fc31b086cff24427924f656d0f123124dfd8487b7d48050a72f902f
7
+ data.tar.gz: 50311a4f39704a60f6710b274557b4e566a12755d140f376df8297a1bf924082f638b34d751f786736cc3dd3236de7e42e45b302708f5a95909ccbb92bd58f30
data/LICENSE ADDED
File without changes
@@ -0,0 +1,22 @@
1
+ # Serveable
2
+
3
+ Serveable simplifies creating a [Rack][rack] mountable site. It contains a
4
+ `Site` module and an `Item` module. These can be mixed into classes that expose
5
+ the correct interface to turn them into easy Rack-fodder.
6
+
7
+ See [`example/simple.rb`](examples/simple.rb) for a basic implementation.
8
+
9
+
10
+ ## That interface you speak of...
11
+
12
+ A `Site` must implement the following:
13
+
14
+ - `#each(&block)`, which enumerates `Item` type objects.
15
+
16
+ An `Item` must implement the following:
17
+
18
+ - `#contents`, that returns the contents;
19
+ - `#url`, that returns the full url to serve at.
20
+
21
+
22
+ [rack]: http://rack.github.com
@@ -0,0 +1,9 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new(:test) do |t|
4
+ t.libs << 'lib' << 'spec'
5
+ t.pattern = 'spec/**/*_spec.rb'
6
+ t.verbose = true
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,51 @@
1
+ module Serveable
2
+
3
+ # Include {Serveable::Site} into an object that responds to #each, which
4
+ # returns items that expose the same interface (or include) {Item}, to allow
5
+ # it to be run with Rack.
6
+ module Site
7
+
8
+ # @return [Array] Returns the payload for the given environment passed.
9
+ def call(env)
10
+ paths_equal = lambda do |a,b|
11
+ short = a.sub(/index\.html\Z/, '')
12
+ return a == b || short == b || short[0..-2] == b
13
+ end
14
+
15
+ found = Missing
16
+ each do |item|
17
+ if paths_equal.call(item.url, env['REQUEST_PATH'])
18
+ found = item
19
+ end
20
+ end
21
+
22
+ found.serve
23
+ end
24
+ end
25
+
26
+ # The Item module expects the object extending/class including it to respond
27
+ # to the #url and #content methods, it then defines the #serve method which is
28
+ # used by {Site}.
29
+ module Item
30
+
31
+ # @return [String] The contents of the Item to be served.
32
+ def contents; end
33
+
34
+ # @return [String] Full url (including /index.html) to the item.
35
+ def url; end
36
+
37
+ # @return [Array] Payload for rack. Contains, in order, the status, the
38
+ # headers and the body.
39
+ def serve
40
+ mime = Rack::Mime.mime_type ::File.extname(url)
41
+ [200, {"Content-Type" => mime}, [contents]]
42
+ end
43
+ end
44
+
45
+ # The sole missing file is served when no matching item is found.
46
+ Missing = Object.new
47
+ def Missing.serve
48
+ [404, {}, ["404 not found"]]
49
+ end
50
+
51
+ end
@@ -0,0 +1,3 @@
1
+ module Serveable
2
+ VERSION = '0.0.2'
3
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: serveable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Hawxwell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-31 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |2
14
+ Provides a module that allow you to easily incorporate a simple
15
+ 'server -> site -> page' model on top of rack.
16
+ email: m@hawx.me
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - Rakefile
23
+ - LICENSE
24
+ - lib/serveable.rb
25
+ - lib/serveable/version.rb
26
+ homepage: http://github.com/hawx/serveable
27
+ licenses: []
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.0.14
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Minimal fuss rack server hooks.
49
+ test_files: []
50
+ has_rdoc: