raindeer 0.10.3 → 0.11.1
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/lib/assets/assets.rb +91 -0
- data/lib/cli/static.rb +31 -3
- data/lib/matrix/effects/color_effect.rb +1 -1
- data/lib/matrix/matrix.rb +1 -1
- data/lib/raindeer/boot.rb +22 -7
- data/lib/support/config_loader.rb +9 -0
- data/lib/version.rb +1 -1
- metadata +32 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 00e1c8ea25c77f078076f7997931cc4d68ffbc073dbc6e38820f42744be37df3
|
|
4
|
+
data.tar.gz: fc8a23be880837861fac8f81af34b440e819ae35863048a624655a557b9b83fa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aef29d377676a4e661d889ac0a87dd6aceb0310d8b2fffe5537ff120c90259f70e910b29765d2bebb04623c3178710a8c2795c64d0064dd64973b77fa34cecc6
|
|
7
|
+
data.tar.gz: 1221b6cc68e0d6b07abc6f1fb844ac3c84fda5c5f9a58db89400c6c66d6dbc9bdee56ef76f1756aa91998618e8492e3258203fc8c1e30bb1dd91ee6b32300c8e
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rain
|
|
4
|
+
# Bundles files in the web root into the bundles listed under "assets" in config/config.yaml:
|
|
5
|
+
#
|
|
6
|
+
# assets:
|
|
7
|
+
# app.css:
|
|
8
|
+
# - style.css
|
|
9
|
+
# - components/*
|
|
10
|
+
# app.js:
|
|
11
|
+
# - components/*/*
|
|
12
|
+
#
|
|
13
|
+
# Paths are relative to the web root. A wildcard like "components/*" adds files in alphabetical order
|
|
14
|
+
# and filters by the bundle's extension. app.css and app.js are exported to the same public folder.
|
|
15
|
+
class Assets
|
|
16
|
+
GLOB_CHARACTERS = /[*?\[{]/
|
|
17
|
+
|
|
18
|
+
def initialize(web_root:, bundles:)
|
|
19
|
+
@web_root = File.realpath(web_root)
|
|
20
|
+
@bundles = bundles.to_h { |output, sources| [output.to_s, sources] }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def build
|
|
24
|
+
@bundles.each_key { |output| write(output) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Rebuilds a bundle whenever one of its files is saved, added or deleted. Runs in the background until the process exits.
|
|
28
|
+
def watch
|
|
29
|
+
require 'listen'
|
|
30
|
+
|
|
31
|
+
Listen.to(@web_root) { |modified, added, removed| rebuild(modified + added + removed) }.start
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Rebuilds only the bundles that include a changed file, so writing a bundle doesn't trigger another rebuild.
|
|
35
|
+
def rebuild(changed_paths)
|
|
36
|
+
changed = changed_paths.map { |path| File.expand_path(path) }
|
|
37
|
+
|
|
38
|
+
@bundles.each_key do |output|
|
|
39
|
+
write(output) if changed.any? { |file| source?(output, file) }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def write(output)
|
|
46
|
+
bundle = sources(output).map { |source| wrap(source, File.read(path(source)), extension: File.extname(output)) }
|
|
47
|
+
File.write(path(output), "#{bundle.join("\n\n")}\n")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Each listed path, with wildcards expanded. A file is only included once, and bundles never include themselves.
|
|
51
|
+
def sources(output)
|
|
52
|
+
extension = File.extname(output)
|
|
53
|
+
paths = @bundles[output].flat_map { |source| glob?(source) ? matches(source, extension:) : [source] }
|
|
54
|
+
|
|
55
|
+
paths.uniq - @bundles.keys
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def matches(pattern, extension:)
|
|
59
|
+
Dir.glob(pattern, base: @web_root).select { |match| File.extname(match) == extension && File.file?(path(match)) }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def source?(output, file)
|
|
63
|
+
return false if @bundles.key?(file.delete_prefix("#{@web_root}/"))
|
|
64
|
+
|
|
65
|
+
@bundles[output].any? do |source|
|
|
66
|
+
if glob?(source)
|
|
67
|
+
File.extname(file) == File.extname(output) && File.fnmatch?(path(source), file, File::FNM_PATHNAME | File::FNM_EXTGLOB)
|
|
68
|
+
else
|
|
69
|
+
file == path(source)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def glob?(source)
|
|
75
|
+
source.match?(GLOB_CHARACTERS)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def wrap(source, content, extension:)
|
|
79
|
+
case extension
|
|
80
|
+
when '.css' then "/* #{source} */\n#{content}"
|
|
81
|
+
# Each script gets its own scope so top-level names can't collide.
|
|
82
|
+
when '.js' then "// #{source}\n(() => {\n#{content}\n})();"
|
|
83
|
+
else content
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def path(relative_path)
|
|
88
|
+
File.join(@web_root, relative_path)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
data/lib/cli/static.rb
CHANGED
|
@@ -6,6 +6,7 @@ require 'ruby-progressbar'
|
|
|
6
6
|
|
|
7
7
|
require 'antlers' # Adds antlers support to dirload.
|
|
8
8
|
require 'dirload'
|
|
9
|
+
require 'lowdata' # Data classes can be loaded without a database.
|
|
9
10
|
|
|
10
11
|
require_relative '../pages/pages'
|
|
11
12
|
|
|
@@ -20,9 +21,12 @@ module Rain
|
|
|
20
21
|
metadata = load_user_application(app_path: File.expand_path('app', application_path))
|
|
21
22
|
build_path = File.expand_path('build', application_path)
|
|
22
23
|
|
|
24
|
+
public_path = File.expand_path('public', application_path)
|
|
25
|
+
build_assets(application_path:, public_path:)
|
|
26
|
+
|
|
23
27
|
FileUtils.rm_rf(build_path)
|
|
24
28
|
FileUtils.mkdir_p(build_path)
|
|
25
|
-
FileUtils.cp_r("#{
|
|
29
|
+
FileUtils.cp_r("#{public_path}/.", build_path)
|
|
26
30
|
|
|
27
31
|
Low::Events::RequestEvent.define do |observers|
|
|
28
32
|
observers << Providers['rain.router']
|
|
@@ -32,6 +36,7 @@ module Rain
|
|
|
32
36
|
folder_path = File.join(build_path, request_result.path)
|
|
33
37
|
|
|
34
38
|
puts "#{folder_path} => #{request_result.status}"
|
|
39
|
+
next unless request_result.html
|
|
35
40
|
|
|
36
41
|
FileUtils.mkdir_p(folder_path)
|
|
37
42
|
File.write(File.expand_path('index.html', folder_path), request_result.html)
|
|
@@ -40,6 +45,19 @@ module Rain
|
|
|
40
45
|
|
|
41
46
|
private
|
|
42
47
|
|
|
48
|
+
# Bundles are written into "public" and .gitignore'd, then copied into the build with everything else.
|
|
49
|
+
def build_assets(application_path:, public_path:)
|
|
50
|
+
config_path = File.expand_path('config/config.yaml', application_path)
|
|
51
|
+
return unless File.exist?(config_path)
|
|
52
|
+
|
|
53
|
+
require_relative '../support/config_loader'
|
|
54
|
+
bundles = Rain::ConfigLoader.load(config_path).assets
|
|
55
|
+
return unless bundles
|
|
56
|
+
|
|
57
|
+
require_relative '../assets/assets'
|
|
58
|
+
Rain::Assets.new(web_root: public_path, bundles:).build
|
|
59
|
+
end
|
|
60
|
+
|
|
43
61
|
def load_user_application(app_path:)
|
|
44
62
|
metadata = dirload(app_path)
|
|
45
63
|
|
|
@@ -64,12 +82,22 @@ module Rain
|
|
|
64
82
|
paths.map do |path|
|
|
65
83
|
request = Protocol::HTTP::Request.new('http', nil, 'GET', path)
|
|
66
84
|
response = Low::Events::RequestEvent.take(request:).response
|
|
67
|
-
|
|
85
|
+
RequestResult.new(path:, status: response.status, html: response.read)
|
|
86
|
+
rescue Observers::ObserverError => e
|
|
87
|
+
raise unless database_error?(e)
|
|
88
|
+
|
|
89
|
+
# Static sites don't have a database so paths that need one are skipped.
|
|
90
|
+
RequestResult.new(path:, status: 'Skipped', html: nil)
|
|
91
|
+
ensure
|
|
68
92
|
progress_bar.increment
|
|
69
|
-
result
|
|
70
93
|
end
|
|
71
94
|
end
|
|
72
95
|
|
|
96
|
+
def database_error?(error)
|
|
97
|
+
error = error.cause until error.nil? || error.is_a?(LowData::ConfigError)
|
|
98
|
+
error&.message == LowData::ConfigError::MISSING_DATABASE
|
|
99
|
+
end
|
|
100
|
+
|
|
73
101
|
def request_paths(metadata:)
|
|
74
102
|
file_paths = metadata.file_types.values_at('md', 'rd', 'markdown', 'raindown').flat_map { it }.compact
|
|
75
103
|
paths = file_paths.map { |file_path| Rain::Pages.url_path(file_path:) }.compact
|
|
@@ -7,7 +7,7 @@ module Rain
|
|
|
7
7
|
def render(output:, next_output:, **)
|
|
8
8
|
color = next_output ? @config.cell_color : @config.lead_color
|
|
9
9
|
|
|
10
|
-
return Paint[output, '#006ab0'] if @config.leet_keys.invert.key?(output)
|
|
10
|
+
return Paint[output, '#006ab0'] if @config.leet && @config.leet_keys.invert.key?(output)
|
|
11
11
|
|
|
12
12
|
output ? Paint[output, color] : Paint[' ']
|
|
13
13
|
end
|
data/lib/matrix/matrix.rb
CHANGED
|
@@ -18,7 +18,7 @@ module Rain
|
|
|
18
18
|
def initialize(event_pool:, config: ConfigLoader.load('matrix.yaml'))
|
|
19
19
|
@event_pool = event_pool
|
|
20
20
|
@config = config
|
|
21
|
-
@effects = [LeetEffect.new(config:), ColorEffect.new(config:)]
|
|
21
|
+
@effects = [(LeetEffect.new(config:) if config.leet), ColorEffect.new(config:)].compact
|
|
22
22
|
|
|
23
23
|
@screen_size = nil
|
|
24
24
|
|
data/lib/raindeer/boot.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'lowdata'
|
|
3
4
|
require 'lowevent'
|
|
4
5
|
require 'lownode'
|
|
5
6
|
require 'lowtype'
|
|
@@ -17,7 +18,7 @@ module Rain
|
|
|
17
18
|
require_relative '../support/config_loader'
|
|
18
19
|
env = {
|
|
19
20
|
host: ENV.fetch('RAIN_HOST', nil),
|
|
20
|
-
port: ENV.fetch('RAIN_PORT', nil),
|
|
21
|
+
port: ConfigLoader.parse_integer(ENV.fetch('RAIN_PORT', nil)),
|
|
21
22
|
web_root: ENV.fetch('RAIN_WEB_ROOT', nil),
|
|
22
23
|
debug_mode: ConfigLoader.parse_boolean(ENV.fetch('RAIN_DEBUG', true)),
|
|
23
24
|
matrix_mode: ConfigLoader.parse_boolean(ENV.fetch('RAIN_MATRIX', nil)),
|
|
@@ -37,6 +38,13 @@ module Rain
|
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
Providers.define('low.loop') do
|
|
41
|
+
if config.assets
|
|
42
|
+
require_relative '../assets/assets'
|
|
43
|
+
assets = Assets.new(web_root: config.web_root, bundles: config.assets)
|
|
44
|
+
assets.build
|
|
45
|
+
assets.watch if config.debug_mode
|
|
46
|
+
end
|
|
47
|
+
|
|
40
48
|
require 'lowloop'
|
|
41
49
|
LowLoop.new(config:, router: Providers['rain.router'], renderer: Providers['rain.matrix'])
|
|
42
50
|
end
|
|
@@ -58,13 +66,20 @@ require 'dirload'
|
|
|
58
66
|
dirload(File.expand_path('../system', __dir__))
|
|
59
67
|
|
|
60
68
|
application_path = File.expand_path('app', Dir.pwd)
|
|
61
|
-
return unless Dir.exist?(application_path)
|
|
62
69
|
|
|
63
|
-
|
|
70
|
+
if Dir.exist?(application_path)
|
|
71
|
+
metadata = dirload(application_path)
|
|
64
72
|
|
|
65
|
-
if Dir.exist?(File.expand_path('pages', application_path))
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
if Dir.exist?(File.expand_path('pages', application_path))
|
|
74
|
+
Providers.define('rain.pages', eager: true) do
|
|
75
|
+
require_relative '../pages/pages'
|
|
76
|
+
Rain::Pages.new(metadata:)
|
|
77
|
+
end
|
|
69
78
|
end
|
|
70
79
|
end
|
|
80
|
+
|
|
81
|
+
#################################################
|
|
82
|
+
# FRAMEWORK INTERNAL CLEANUP
|
|
83
|
+
#################################################
|
|
84
|
+
|
|
85
|
+
Lowkey.clear
|
|
@@ -18,6 +18,15 @@ module Rain
|
|
|
18
18
|
OpenStruct.new(config_data)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
# Environment variables are strings, so "4133" becomes 4133.
|
|
22
|
+
def parse_integer(value)
|
|
23
|
+
return nil if value.nil?
|
|
24
|
+
|
|
25
|
+
Integer(value, 10)
|
|
26
|
+
rescue ArgumentError
|
|
27
|
+
raise ArgumentError, "Expected an integer, got #{value.inspect}"
|
|
28
|
+
end
|
|
29
|
+
|
|
21
30
|
def parse_boolean(value)
|
|
22
31
|
return true if value == '1'
|
|
23
32
|
return false if value == '0'
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: raindeer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: listen
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
12
26
|
- !ruby/object:Gem::Dependency
|
|
13
27
|
name: ostruct
|
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -65,6 +79,20 @@ dependencies:
|
|
|
65
79
|
- - "~>"
|
|
66
80
|
- !ruby/object:Gem::Version
|
|
67
81
|
version: 0.7.0
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: lowdata
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0.1'
|
|
89
|
+
type: :runtime
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0.1'
|
|
68
96
|
- !ruby/object:Gem::Dependency
|
|
69
97
|
name: lowevent
|
|
70
98
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -231,6 +259,7 @@ extensions: []
|
|
|
231
259
|
extra_rdoc_files: []
|
|
232
260
|
files:
|
|
233
261
|
- bin/rain
|
|
262
|
+
- lib/assets/assets.rb
|
|
234
263
|
- lib/cli/cli.rb
|
|
235
264
|
- lib/cli/static.rb
|
|
236
265
|
- lib/matrix/cursor.rb
|
|
@@ -283,7 +312,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
283
312
|
- !ruby/object:Gem::Version
|
|
284
313
|
version: '0'
|
|
285
314
|
requirements: []
|
|
286
|
-
rubygems_version:
|
|
315
|
+
rubygems_version: 4.0.6
|
|
287
316
|
specification_version: 4
|
|
288
317
|
summary: An event-driven and compositional web framework that's easy to use. Deer
|
|
289
318
|
to be different.
|