yarrow 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/yarrow-server +2 -0
- data/lib/yarrow/configuration.rb +23 -9
- data/lib/yarrow/console_runner.rb +1 -1
- data/lib/yarrow/defaults.yml +5 -1
- data/lib/yarrow/server.rb +13 -4
- data/lib/yarrow/tools/output_file.rb +40 -0
- data/lib/yarrow/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 648a0f70b24617f5498150579e5c18775c1b4c8c
|
4
|
+
data.tar.gz: 25f8f7a1f34525764329e798169c0c430362f31a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 887acaa6c3d7fe08fe3c8ef0ede960c825a312e47510a10b456f3170c052dfacfe041609fdf5d7d599d98efd6b49ba71d74b7fdb4aa84369911f42e5f4e6449a
|
7
|
+
data.tar.gz: fc1cfe571626692b46cf1946f54294e74c87dee9c81df8545e9585245756baf2caa84472021563331f21c68a15b1e239a025d3b30e9b2884148f450d97052b37
|
data/bin/yarrow-server
CHANGED
data/lib/yarrow/configuration.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
module Yarrow
|
2
|
-
|
3
2
|
##
|
4
3
|
# Hash-like object containing runtime configuration values. Can be accessed indifferently
|
5
4
|
# via object style lookups or symbol keys.
|
6
5
|
#
|
7
6
|
class Configuration < Hashie::Mash
|
8
|
-
|
9
7
|
class << self
|
10
|
-
|
11
8
|
##
|
12
9
|
# Provides access to the registered global configuration.
|
13
10
|
#
|
@@ -20,12 +17,24 @@ module Yarrow
|
|
20
17
|
end
|
21
18
|
|
22
19
|
##
|
23
|
-
# Loads and registers a global configuration
|
20
|
+
# Loads and registers a global configuration instance.
|
21
|
+
#
|
22
|
+
# This will reset any previously initialized configuration.
|
24
23
|
#
|
25
24
|
# @param [String] path to YAML file
|
26
25
|
#
|
27
26
|
def register(file)
|
28
|
-
@@configuration =
|
27
|
+
@@configuration = load(file)
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Loads and registers a global configuration instance with
|
32
|
+
# library-provided defaults.
|
33
|
+
#
|
34
|
+
# This will reset any previously initialized configuration.
|
35
|
+
#
|
36
|
+
def register_defaults
|
37
|
+
@@configuration = load_defaults
|
29
38
|
end
|
30
39
|
|
31
40
|
##
|
@@ -56,15 +65,22 @@ module Yarrow
|
|
56
65
|
self.new(YAML.load_file(file))
|
57
66
|
end
|
58
67
|
|
68
|
+
##
|
69
|
+
# Yarrow is distributed with a `defaults.yml` which provides minimum
|
70
|
+
# boostrap configuration and default settings for various internal
|
71
|
+
# classes. Use this method to automatically load these defaults.
|
72
|
+
#
|
73
|
+
# @return [Yarrow::Configuration]
|
74
|
+
def load_defaults
|
75
|
+
load(File.join(File.dirname(__FILE__), 'defaults.yml'))
|
76
|
+
end
|
59
77
|
end
|
60
|
-
|
61
78
|
end
|
62
79
|
|
63
80
|
##
|
64
81
|
# Embeds global configuration access in a client object.
|
65
82
|
#
|
66
83
|
module Configurable
|
67
|
-
|
68
84
|
##
|
69
85
|
# Provides access to the registered global configuration. This can
|
70
86
|
# be overriden by subclasses to customize behaviour (eg: in test cases).
|
@@ -74,12 +90,10 @@ module Yarrow
|
|
74
90
|
def config
|
75
91
|
Configuration.instance
|
76
92
|
end
|
77
|
-
|
78
93
|
end
|
79
94
|
|
80
95
|
##
|
81
96
|
# Raised when a required config section or property is missing.
|
82
97
|
class ConfigurationError < StandardError
|
83
98
|
end
|
84
|
-
|
85
99
|
end
|
data/lib/yarrow/defaults.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Default configuration settings for Yarrow.
|
2
2
|
# This is loaded when the configuration is initialized.
|
3
3
|
input_dir: content
|
4
|
-
output_dir:
|
4
|
+
output_dir: .
|
5
5
|
meta:
|
6
6
|
title: Default Project
|
7
7
|
author: Default Name
|
@@ -21,4 +21,8 @@ server:
|
|
21
21
|
port: 8888
|
22
22
|
host: localhost
|
23
23
|
handler: thin
|
24
|
+
middleware:
|
25
|
+
- Rack::ShowExceptions
|
26
|
+
- Rack::CommonLogger
|
27
|
+
- Rack::ContentLength
|
24
28
|
|
data/lib/yarrow/server.rb
CHANGED
@@ -44,11 +44,13 @@ module Yarrow
|
|
44
44
|
def app
|
45
45
|
root = docroot
|
46
46
|
index = @index_file || 'index.html'
|
47
|
+
plugins = middleware || []
|
47
48
|
|
48
49
|
Rack::Builder.new do
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
plugins.each do |plugin|
|
51
|
+
puts plugin
|
52
|
+
use plugin
|
53
|
+
end
|
52
54
|
use DirectoryIndex, root: root, index: index
|
53
55
|
run Rack::Directory.new(root)
|
54
56
|
end
|
@@ -73,13 +75,20 @@ module Yarrow
|
|
73
75
|
config.output_dir || Dir.pwd
|
74
76
|
end
|
75
77
|
|
78
|
+
##
|
79
|
+
# @return [Array<Class>]
|
80
|
+
def middleware
|
81
|
+
plugins = config.server.middleware || []
|
82
|
+
plugins.map { |plugin| Kernel.const_get(plugin) }
|
83
|
+
end
|
84
|
+
|
76
85
|
##
|
77
86
|
# Stub to fill in default Rack options that will eventually be
|
78
87
|
# provided by config.
|
79
88
|
#
|
80
89
|
# TODO: remove this and use config.merge to build a single access point
|
81
90
|
def rack_options
|
82
|
-
|
91
|
+
{
|
83
92
|
:Port => config.server.port,
|
84
93
|
:Host => config.server.port,
|
85
94
|
:server => config.server.handler.to_sym,
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Yarrow
|
2
|
+
module Tools
|
3
|
+
# TODO: consider renaming this to OutputDocument.
|
4
|
+
class OutputFile
|
5
|
+
include ::Configurable
|
6
|
+
|
7
|
+
WRITE_MODE = 'w+:UTF-8'.freeze
|
8
|
+
|
9
|
+
# @return [String] Basename reflecting the server convention (usually: index.html)
|
10
|
+
def index_name
|
11
|
+
@index_name ||= config.index_name || 'index.html'
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [String] Docroot of the output target
|
15
|
+
def docroot
|
16
|
+
@docroot ||= config.output_dir
|
17
|
+
end
|
18
|
+
|
19
|
+
# Write an output file to the specified path under the docroot.
|
20
|
+
#
|
21
|
+
# @param path [String]
|
22
|
+
# @param content [String]
|
23
|
+
def write(path, content)
|
24
|
+
# If the target path is a directory,
|
25
|
+
# generate a default index filename.
|
26
|
+
if path[path.length-1] == '/'
|
27
|
+
path = "#{path}#{index_name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
target_path = Pathname.new("docroot#{path}")
|
31
|
+
|
32
|
+
FileUtils.mkdir_p(target_path.dirname)
|
33
|
+
|
34
|
+
File.open(target_path.to_s, WRITE_MODE) do |file|
|
35
|
+
file.puts(content)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/yarrow/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.3
|
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-
|
11
|
+
date: 2015-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -181,6 +181,7 @@ files:
|
|
181
181
|
- lib/yarrow/output/mapper.rb
|
182
182
|
- lib/yarrow/server.rb
|
183
183
|
- lib/yarrow/tools/front_matter.rb
|
184
|
+
- lib/yarrow/tools/output_file.rb
|
184
185
|
- lib/yarrow/version.rb
|
185
186
|
homepage: http://rubygemspec.org/gems/yarrow
|
186
187
|
licenses:
|