yarrow 0.3.4 → 0.3.5
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/defaults.yml +3 -2
- data/lib/yarrow/html/asset_tags.rb +21 -16
- data/lib/yarrow/server/livereload.rb +74 -0
- data/lib/yarrow/server.rb +46 -25
- data/lib/yarrow/tools/front_matter.rb +23 -5
- data/lib/yarrow/version.rb +1 -1
- data/lib/yarrow.rb +1 -2
- metadata +46 -5
- data/lib/yarrow/model/base.rb +0 -13
- data/lib/yarrow/model/index.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e033523f4e9cd963daf57a6550813742b5639c99
|
4
|
+
data.tar.gz: fce06e453eb7ade5d7cceb0d1aef81412c5d12d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91c941f27267787bdf6e0959262e966d2be36c2dde5261b89cc80dec853dd24409b8a48c4e17372509cbfd3938ea89b029e182d6ddf95965bc0f0cb81e51c724
|
7
|
+
data.tar.gz: 675e0ffd43413591ccc5eeaee2a88977254a62e57eb58c53a0157ce3ad66716ff3be5a24c1801840230464415b64e332e70653b40a63eabe88236c6aa71cc227
|
data/bin/yarrow-server
CHANGED
data/lib/yarrow/defaults.yml
CHANGED
@@ -18,12 +18,13 @@ assets:
|
|
18
18
|
- js
|
19
19
|
manifest_file: manifest.json
|
20
20
|
server:
|
21
|
+
live_reload: true
|
21
22
|
auto_index: true
|
22
23
|
default_index: index.html
|
23
24
|
default_type: text/plain
|
24
|
-
port:
|
25
|
+
port: 4000
|
25
26
|
host: localhost
|
26
|
-
handler:
|
27
|
+
handler: webrick
|
27
28
|
middleware:
|
28
29
|
- Rack::ShowExceptions
|
29
30
|
- Rack::CommonLogger
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Yarrow
|
2
2
|
module HTML
|
3
|
-
module AssetTags
|
3
|
+
module AssetTags
|
4
4
|
include Yarrow::Configurable
|
5
5
|
|
6
6
|
# TODO: make sprockets manifest optional/pluggable
|
@@ -11,44 +11,49 @@ module Yarrow
|
|
11
11
|
##
|
12
12
|
# Computes the base URL path to assets in the public web directory.
|
13
13
|
def base_url_path
|
14
|
-
|
15
|
-
|
14
|
+
if config.assets.nil? || config.output_dir.nil?
|
15
|
+
raise Yarrow::ConfigurationError
|
16
|
+
end
|
16
17
|
|
17
18
|
# TODO: prepend configurable CDN URL for host path
|
18
19
|
# TODO: dev/production mode switch
|
19
20
|
|
20
|
-
|
21
|
-
assets_path.gsub(config.output_dir, '')
|
21
|
+
config.assets.output_dir.gsub(config.output_dir, '')
|
22
22
|
end
|
23
23
|
|
24
24
|
def script_tags
|
25
|
-
manifest.js_logical_paths.map { |
|
25
|
+
manifest.js_logical_paths.map { |path| script_tag(asset: path) }.join("\n")
|
26
26
|
end
|
27
27
|
|
28
|
-
# TODO: support asset path option?
|
29
28
|
def script_tag(options)
|
30
|
-
|
31
|
-
|
32
|
-
src_path = "#{base_url_path}/#{script_path}"
|
29
|
+
src_path = if asset_in_manifest?(options)
|
30
|
+
digest_path(options[:asset])
|
33
31
|
else
|
34
|
-
|
32
|
+
options[:src]
|
35
33
|
end
|
36
34
|
|
37
35
|
"<script src=\"#{src_path}\"></script>"
|
38
36
|
end
|
39
37
|
|
40
|
-
# TODO: support asset path option?
|
41
38
|
def link_tag(options)
|
42
|
-
|
43
|
-
|
44
|
-
href_path = "#{base_url_path}/#{stylesheet_path}"
|
39
|
+
href_path = if asset_in_manifest?(options)
|
40
|
+
digest_path(options[:asset])
|
45
41
|
else
|
46
|
-
|
42
|
+
options[:href]
|
47
43
|
end
|
48
44
|
|
49
45
|
"<link href=\"#{href_path}\" rel=\"stylesheet\" type=\"text/css\">"
|
50
46
|
end
|
51
47
|
|
48
|
+
private
|
49
|
+
|
50
|
+
def asset_in_manifest?(options)
|
51
|
+
options.has_key?(:asset) and manifest.exists?(options[:asset])
|
52
|
+
end
|
53
|
+
|
54
|
+
def digest_path(path)
|
55
|
+
"#{base_url_path}/#{manifest.digest_path(path)}"
|
56
|
+
end
|
52
57
|
end
|
53
58
|
end
|
54
59
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
require 'em-websocket'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Yarrow
|
6
|
+
class Server
|
7
|
+
module Livereload
|
8
|
+
class Reactor
|
9
|
+
include Yarrow::Loggable
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@sockets = []
|
13
|
+
@running = false
|
14
|
+
end
|
15
|
+
|
16
|
+
def running?
|
17
|
+
@running
|
18
|
+
end
|
19
|
+
|
20
|
+
def start
|
21
|
+
@thread = Thread.new do
|
22
|
+
run_loop
|
23
|
+
end
|
24
|
+
@running = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def stop
|
28
|
+
logger.info 'Shutting down Livereload'
|
29
|
+
@thread.kill
|
30
|
+
@running = false
|
31
|
+
end
|
32
|
+
|
33
|
+
def refresh_payload(path)
|
34
|
+
data = JSON.dump(['refresh', {
|
35
|
+
:path => path,
|
36
|
+
:apply_js_live => false,
|
37
|
+
:apply_css_live => false
|
38
|
+
}])
|
39
|
+
end
|
40
|
+
|
41
|
+
def send_refresh
|
42
|
+
@updated_paths.each do |path|
|
43
|
+
@sockets.each do |ws|
|
44
|
+
ws.send(refresh_payload(path))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def run_loop
|
50
|
+
EventMachine.run do
|
51
|
+
logger.info 'Starting Livereload reactor on port: 35729'
|
52
|
+
|
53
|
+
EventMachine::WebSocket.start(:host => 'localhost', :port => 35729) do |socket|
|
54
|
+
socket.onopen do
|
55
|
+
socket.send "!!ver:1.6"
|
56
|
+
@sockets << socket
|
57
|
+
logger.info 'Livereload connected'
|
58
|
+
end
|
59
|
+
|
60
|
+
socket.onmessage do |message|
|
61
|
+
logger.info "Receiving message: #{message}"
|
62
|
+
end
|
63
|
+
|
64
|
+
socket.onclose do
|
65
|
+
@sockets.delete(socket)
|
66
|
+
logger.info 'Livereload disconnected'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/yarrow/server.rb
CHANGED
@@ -26,7 +26,7 @@ module Yarrow
|
|
26
26
|
|
27
27
|
def call(env)
|
28
28
|
index_path = File.join(@root, Rack::Request.new(env).path.split('/'), @index_file)
|
29
|
-
if File.
|
29
|
+
if File.exist?(index_path)
|
30
30
|
return [200, {"Content-Type" => "text/html"}, [File.read(index_path)]]
|
31
31
|
else
|
32
32
|
@app.call(env)
|
@@ -40,41 +40,56 @@ module Yarrow
|
|
40
40
|
# If no output directory is specified, defaults to the current working
|
41
41
|
# directory.
|
42
42
|
#
|
43
|
+
# `auto_index` and `live_reload` middleware needs to run in the specific order
|
44
|
+
# which is hardcoded here.
|
45
|
+
#
|
43
46
|
# @return [Yarrow::Server::StaticFiles]
|
44
47
|
def app
|
45
|
-
|
46
|
-
index = default_index
|
47
|
-
middleware_stack = middleware_map
|
48
|
-
auto_index = auto_index?
|
49
|
-
mime_type = default_type
|
50
|
-
|
51
|
-
Rack::Builder.new do
|
52
|
-
middleware_stack.each do |middleware|
|
53
|
-
use middleware
|
54
|
-
end
|
48
|
+
app = Rack::Builder.new
|
55
49
|
|
56
|
-
|
50
|
+
middleware_stack.each do |middleware|
|
51
|
+
app.use(middleware)
|
52
|
+
end
|
57
53
|
|
58
|
-
|
59
|
-
static_app = Rack::File.new(*app_args)
|
54
|
+
app.use(DirectoryIndex, root: docroot, index: default_index)
|
60
55
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
app_args = [docroot, {}].tap { |args| args.push(default_type) if default_type }
|
57
|
+
static_app = Rack::File.new(*app_args)
|
58
|
+
|
59
|
+
if live_reload?
|
60
|
+
require 'rack-livereload'
|
61
|
+
app.use(Rack::LiveReload, no_swf: true)
|
62
|
+
end
|
63
|
+
|
64
|
+
if auto_index?
|
65
|
+
app.run(Rack::Directory.new(docroot, static_app))
|
66
|
+
else
|
67
|
+
app.run(static_app)
|
66
68
|
end
|
69
|
+
|
70
|
+
app
|
67
71
|
end
|
68
72
|
|
69
73
|
##
|
70
74
|
# Starts the server.
|
71
75
|
#
|
72
|
-
# Listens on `localhost:
|
76
|
+
# Listens on `localhost:4000` unless `server.host` and `server.port` are
|
73
77
|
# provided in the config.
|
74
78
|
#
|
75
79
|
def run
|
76
|
-
|
77
|
-
|
80
|
+
if live_reload?
|
81
|
+
reactor = Livereload::Reactor.new
|
82
|
+
reactor.start
|
83
|
+
end
|
84
|
+
|
85
|
+
handler = Rack::Handler.get(run_options[:server])
|
86
|
+
|
87
|
+
trap(:INT) do
|
88
|
+
handler.shutdown if handler.respond_to?(:shutdown)
|
89
|
+
reactor.stop
|
90
|
+
end
|
91
|
+
|
92
|
+
handler.run(app, run_options)
|
78
93
|
end
|
79
94
|
|
80
95
|
private
|
@@ -98,6 +113,12 @@ module Yarrow
|
|
98
113
|
config.server.auto_index
|
99
114
|
end
|
100
115
|
|
116
|
+
##
|
117
|
+
# @return [TrueClass, FalseClass]
|
118
|
+
def live_reload?
|
119
|
+
if config.server.live_reload then true else false; end
|
120
|
+
end
|
121
|
+
|
101
122
|
##
|
102
123
|
# @return [String]
|
103
124
|
def default_type
|
@@ -106,7 +127,7 @@ module Yarrow
|
|
106
127
|
|
107
128
|
##
|
108
129
|
# @return [Array<Class>]
|
109
|
-
def
|
130
|
+
def middleware_stack
|
110
131
|
middleware = config.server.middleware || []
|
111
132
|
middleware.map { |class_name| Kernel.const_get(class_name) }
|
112
133
|
end
|
@@ -118,12 +139,12 @@ module Yarrow
|
|
118
139
|
def run_options
|
119
140
|
{
|
120
141
|
:Port => config.server.port,
|
121
|
-
:Host => config.server.
|
142
|
+
:Host => config.server.host,
|
122
143
|
:server => config.server.handler.to_sym,
|
123
144
|
:daemonize => false,
|
124
145
|
:quiet => false,
|
125
146
|
:warn => true,
|
126
|
-
:debug =>
|
147
|
+
:debug => false,
|
127
148
|
}
|
128
149
|
end
|
129
150
|
end
|
@@ -2,17 +2,21 @@ module Yarrow
|
|
2
2
|
module Tools
|
3
3
|
module FrontMatter
|
4
4
|
|
5
|
-
def read_split_content(path)
|
6
|
-
extract_split_content(File.read(path, :encoding => 'utf-8'))
|
5
|
+
def read_split_content(path, options={})
|
6
|
+
extract_split_content(File.read(path, :encoding => 'utf-8'), options)
|
7
7
|
end
|
8
8
|
|
9
|
-
def extract_split_content(text)
|
9
|
+
def extract_split_content(text, options={})
|
10
10
|
pattern = /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
11
11
|
if text =~ pattern
|
12
12
|
content = text.sub(pattern, "")
|
13
13
|
|
14
14
|
begin
|
15
|
-
|
15
|
+
if options.key?(:symbolize_keys)
|
16
|
+
meta = symbolize_keys(YAML.load($1))
|
17
|
+
else
|
18
|
+
meta = YAML.load($1)
|
19
|
+
end
|
16
20
|
return [content, meta]
|
17
21
|
rescue Psych::SyntaxError => error
|
18
22
|
if defined? ::Logger
|
@@ -22,12 +26,26 @@ module Yarrow
|
|
22
26
|
end
|
23
27
|
return [content, nil]
|
24
28
|
end
|
25
|
-
|
26
29
|
end
|
27
30
|
|
28
31
|
[text, nil]
|
29
32
|
end
|
30
33
|
|
34
|
+
def symbolize_keys(hash)
|
35
|
+
hash.inject({}) do |result, (key, value)|
|
36
|
+
new_key = case key
|
37
|
+
when String then key.to_sym
|
38
|
+
else key
|
39
|
+
end
|
40
|
+
new_value = case value
|
41
|
+
when Hash then symbolize_keys(value)
|
42
|
+
when Array then value.map { |entry| symbolize_keys(entry) }
|
43
|
+
else value
|
44
|
+
end
|
45
|
+
result[new_key] = new_value
|
46
|
+
result
|
47
|
+
end
|
48
|
+
end
|
31
49
|
end
|
32
50
|
end
|
33
51
|
end
|
data/lib/yarrow/version.rb
CHANGED
data/lib/yarrow.rb
CHANGED
@@ -6,8 +6,6 @@ require 'yarrow/logging'
|
|
6
6
|
require 'yarrow/configuration'
|
7
7
|
require 'yarrow/console_runner'
|
8
8
|
require 'yarrow/generator'
|
9
|
-
require 'yarrow/model/index'
|
10
|
-
require 'yarrow/model/base'
|
11
9
|
require 'yarrow/html/asset_tags'
|
12
10
|
require 'yarrow/output/mapper'
|
13
11
|
require 'yarrow/output/generator'
|
@@ -17,6 +15,7 @@ require 'yarrow/assets'
|
|
17
15
|
require 'yarrow/html'
|
18
16
|
require 'yarrow/tools/front_matter'
|
19
17
|
require 'yarrow/server'
|
18
|
+
require 'yarrow/server/livereload'
|
20
19
|
|
21
20
|
# Dir[File.dirname(__FILE__) + '/yarrow/generators/*.rb'].each do |generator|
|
22
21
|
# require generator
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rickerby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -80,6 +80,48 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rack-livereload
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: eventmachine
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: em-websocket
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: bundler
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,12 +216,11 @@ files:
|
|
174
216
|
- lib/yarrow/html/asset_tags.rb
|
175
217
|
- lib/yarrow/html/content_tags.rb
|
176
218
|
- lib/yarrow/logging.rb
|
177
|
-
- lib/yarrow/model/base.rb
|
178
|
-
- lib/yarrow/model/index.rb
|
179
219
|
- lib/yarrow/output/context.rb
|
180
220
|
- lib/yarrow/output/generator.rb
|
181
221
|
- lib/yarrow/output/mapper.rb
|
182
222
|
- lib/yarrow/server.rb
|
223
|
+
- lib/yarrow/server/livereload.rb
|
183
224
|
- lib/yarrow/tools/front_matter.rb
|
184
225
|
- lib/yarrow/tools/output_file.rb
|
185
226
|
- lib/yarrow/version.rb
|
@@ -203,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
244
|
version: '0'
|
204
245
|
requirements: []
|
205
246
|
rubyforge_project:
|
206
|
-
rubygems_version: 2.
|
247
|
+
rubygems_version: 2.5.1
|
207
248
|
signing_key:
|
208
249
|
specification_version: 4
|
209
250
|
summary: Documentation generator based on a fluent data model.
|
data/lib/yarrow/model/base.rb
DELETED
data/lib/yarrow/model/index.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require "active_support/inflector"
|
2
|
-
|
3
|
-
module Yarrow
|
4
|
-
module Model
|
5
|
-
class Index
|
6
|
-
def self.register(klass)
|
7
|
-
method_name = ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(klass.to_s)).to_sym
|
8
|
-
define_singleton_method method_name, lambda { klass.all }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|