yarrow 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 648a0f70b24617f5498150579e5c18775c1b4c8c
4
- data.tar.gz: 25f8f7a1f34525764329e798169c0c430362f31a
3
+ metadata.gz: bc35279dd3d2e8d12c883c813391011aeb64656f
4
+ data.tar.gz: eb12a310c3fb88687d69e4602a4dbac50d6010d6
5
5
  SHA512:
6
- metadata.gz: 887acaa6c3d7fe08fe3c8ef0ede960c825a312e47510a10b456f3170c052dfacfe041609fdf5d7d599d98efd6b49ba71d74b7fdb4aa84369911f42e5f4e6449a
7
- data.tar.gz: fc1cfe571626692b46cf1946f54294e74c87dee9c81df8545e9585245756baf2caa84472021563331f21c68a15b1e239a025d3b30e9b2884148f450d97052b37
6
+ metadata.gz: b6d3cc965dcc26c80d564f776f2eeefc8e66e9db8c9bda124c15c2d1dbef2927c523656c6a93092ceaeb5fdc175b9fa3b9796ad7f84eee4444862998bbd8b5b6
7
+ data.tar.gz: 1b6f155d6b036f0ab25cb002fc83f2c0e82c647aa9520ef7f8c0d70c7b4b02e666d1ec0afa548fbc88d725fa7adf265d5644b978feedea6070a211e5ba50a82e
@@ -18,6 +18,9 @@ assets:
18
18
  - js
19
19
  manifest_file: manifest.json
20
20
  server:
21
+ auto_index: true
22
+ default_index: index.html
23
+ default_type: text/plain
21
24
  port: 8888
22
25
  host: localhost
23
26
  handler: thin
@@ -25,4 +28,3 @@ server:
25
28
  - Rack::ShowExceptions
26
29
  - Rack::CommonLogger
27
30
  - Rack::ContentLength
28
-
data/lib/yarrow/server.rb CHANGED
@@ -43,16 +43,26 @@ module Yarrow
43
43
  # @return [Yarrow::Server::StaticFiles]
44
44
  def app
45
45
  root = docroot
46
- index = @index_file || 'index.html'
47
- plugins = middleware || []
46
+ index = default_index
47
+ middleware_stack = middleware_map
48
+ auto_index = auto_index?
49
+ mime_type = default_type
48
50
 
49
51
  Rack::Builder.new do
50
- plugins.each do |plugin|
51
- puts plugin
52
- use plugin
52
+ middleware_stack.each do |middleware|
53
+ use middleware
53
54
  end
55
+
54
56
  use DirectoryIndex, root: root, index: index
55
- run Rack::Directory.new(root)
57
+
58
+ app_args = [root, {}].tap { |args| args.push(mime_type) if mime_type }
59
+ static_app = Rack::File.new(*app_args)
60
+
61
+ if auto_index
62
+ run Rack::Directory.new(root, static_app)
63
+ else
64
+ run static_app
65
+ end
56
66
  end
57
67
  end
58
68
 
@@ -63,8 +73,8 @@ module Yarrow
63
73
  # provided in the config.
64
74
  #
65
75
  def run
66
- server = Rack::Handler.get(rack_options[:server])
67
- server.run(app, rack_options)
76
+ server = Rack::Handler.get(run_options[:server])
77
+ server.run(app, run_options)
68
78
  end
69
79
 
70
80
  private
@@ -75,19 +85,37 @@ module Yarrow
75
85
  config.output_dir || Dir.pwd
76
86
  end
77
87
 
88
+ ##
89
+ # @return [String]
90
+ def default_index
91
+ config.server.default_index || 'index.html'
92
+ end
93
+
94
+ ##
95
+ # @return [TrueClass, FalseClass]
96
+ def auto_index?
97
+ return true if config.server.auto_index.nil?
98
+ config.server.auto_index
99
+ end
100
+
101
+ ##
102
+ # @return [String]
103
+ def default_type
104
+ config.server.default_type
105
+ end
106
+
78
107
  ##
79
108
  # @return [Array<Class>]
80
- def middleware
81
- plugins = config.server.middleware || []
82
- plugins.map { |plugin| Kernel.const_get(plugin) }
109
+ def middleware_map
110
+ middleware = config.server.middleware || []
111
+ middleware.map { |class_name| Kernel.const_get(class_name) }
83
112
  end
84
113
 
85
114
  ##
86
- # Stub to fill in default Rack options that will eventually be
87
- # provided by config.
115
+ # Provides options required by the Rack server on startup.
88
116
  #
89
- # TODO: remove this and use config.merge to build a single access point
90
- def rack_options
117
+ # @return [Hash]
118
+ def run_options
91
119
  {
92
120
  :Port => config.server.port,
93
121
  :Host => config.server.port,
@@ -2,7 +2,7 @@ module Yarrow
2
2
  module Tools
3
3
  # TODO: consider renaming this to OutputDocument.
4
4
  class OutputFile
5
- include ::Configurable
5
+ include Yarrow::Configurable
6
6
 
7
7
  WRITE_MODE = 'w+:UTF-8'.freeze
8
8
 
@@ -13,7 +13,7 @@ module Yarrow
13
13
 
14
14
  # @return [String] Docroot of the output target
15
15
  def docroot
16
- @docroot ||= config.output_dir
16
+ @docroot ||= config.output_dir || 'public'
17
17
  end
18
18
 
19
19
  # Write an output file to the specified path under the docroot.
@@ -27,7 +27,7 @@ module Yarrow
27
27
  path = "#{path}#{index_name}"
28
28
  end
29
29
 
30
- target_path = Pathname.new("docroot#{path}")
30
+ target_path = Pathname.new("#{docroot}#{path}")
31
31
 
32
32
  FileUtils.mkdir_p(target_path.dirname)
33
33
 
@@ -1,4 +1,4 @@
1
1
  module Yarrow
2
2
  APP_NAME = 'Yarrow'.freeze
3
- VERSION = '0.3.3'.freeze
3
+ VERSION = '0.3.4'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yarrow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rickerby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-25 00:00:00.000000000 Z
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -208,4 +208,3 @@ signing_key:
208
208
  specification_version: 4
209
209
  summary: Documentation generator based on a fluent data model.
210
210
  test_files: []
211
- has_rdoc: