raindeer 0.7.0 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1911af310e0e12743cd151c8d0434b247d959385ea04329a40287538199b0407
4
- data.tar.gz: 84320dbf6de9d25dd6c9c3315f51abfddeb2e21d62ddd6e99e8ff754ba252ba4
3
+ metadata.gz: 1e658170ed7da3124e736b68df8a271a9c6bfce0eae60d2b25e36196bec2e3c2
4
+ data.tar.gz: 22c8a59224ba2cdf3956c18b57261460334798015570e134c5da1bc7e5e85501
5
5
  SHA512:
6
- metadata.gz: 7341996eb059d5dc1f7fb6075c2ffeb866efc6a68fc4a69142c321be325bdc5e15dad955a67d24b39b185dbbe2d6670466fddaf802ae8b43cb448cd0258fe33e
7
- data.tar.gz: db80a6183bde1082b49cb230252f43ca9a5ff97eea0c5effda469ae0c09f17a4f2be9f16d8a9b9041388fb53eeebeda1b691dac8ed37a47459e70ef21f30c890
6
+ metadata.gz: 861bb11691f40b9436b73d24754c2a2c0391d6910318a59dde2ec5f809308cf6cdce7da132b31dd794db3c99c1708bdb84d299e5c0e4e91b4fb2a2217db3abda
7
+ data.tar.gz: 36b8b720352d4152e18e142ae66479b278848fc74f3cc1959441285d8f8612893ae9932bf2129336f23192582e68b26b46451962a527b5e4eddaf7375bd1a47a
@@ -3,14 +3,75 @@
3
3
  require 'antlers'
4
4
  require 'lowload'
5
5
 
6
+ require 'async'
7
+ require 'async/http/internet'
8
+ require 'fileutils'
9
+
6
10
  module Rain
7
11
  module CLI
8
12
  module Static
9
13
  extend self
10
14
 
15
+ Result = Data.define(:path, :html)
16
+
11
17
  def build(application_path:)
12
18
  metadata = LowLoad.dirload(File.expand_path('app', application_path))
13
- # TODO: Use metadata.url_paths to HTTP Request and export the response to a build folder of HTML.
19
+
20
+ build_path = File.expand_path('build', application_path)
21
+ FileUtils.rm_rf(build_path)
22
+ FileUtils.mkdir_p(build_path)
23
+ FileUtils.cp_r(File.expand_path('public', application_path), File.expand_path('public', build_path))
24
+
25
+ request_paths(metadata:, application_path:).each do |result|
26
+ path = File.expand_path(result.path, build_path)
27
+ FileUtils.mkdir_p(path)
28
+ File.write(File.expand_path('index.html', path), result.html)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def request_paths(metadata:, application_path:)
35
+ tasks = metadata.url_paths.keys.compact.map do |file_path|
36
+ Async do
37
+ request_path = request_path(application_path:, file_path:)
38
+ request_url = endpoint + request_path
39
+
40
+ response = client.get(request_url)
41
+ response_html = response.read
42
+ response.close
43
+
44
+ Result.new(path: request_path, html: response_html)
45
+ end
46
+ end
47
+
48
+ tasks.map(&:result)
49
+ end
50
+
51
+ def request_path(application_path:, file_path:)
52
+ file_path.delete_prefix("#{application_path}/app/pages/")
53
+ end
54
+
55
+ def client
56
+ Async::HTTP::Internet.new
57
+ end
58
+
59
+ def endpoint
60
+ "http://#{config.host}:#{config.port}/"
61
+ end
62
+
63
+ def config
64
+ env = {
65
+ host: ENV.fetch('RAIN_HOST', nil),
66
+ port: ENV.fetch('RAIN_PORT', nil),
67
+ web_root: ENV.fetch('RAIN_WEB_ROOT', nil),
68
+ debug_mode: ConfigLoader.parse_boolean(ENV.fetch('RAIN_DEBUG', true)),
69
+ matrix_mode: ConfigLoader.parse_boolean(ENV.fetch('RAIN_MATRIX', nil)),
70
+ mirror_mode: ConfigLoader.parse_boolean(ENV.fetch('RAIN_MIRROR', nil)),
71
+ }
72
+ config_path = File.expand_path('config/config.yaml', Dir.pwd)
73
+
74
+ ConfigLoader.load(config_path, env)
14
75
  end
15
76
  end
16
77
  end
data/lib/raindeer/cli.rb CHANGED
@@ -12,6 +12,8 @@ require 'providers'
12
12
  #################################################
13
13
 
14
14
  module Rain
15
+ require_relative '../support/config_loader'
16
+
15
17
  Providers.define('rain.router') do
16
18
  require_relative '../router/router'
17
19
  Router.new
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raindeer
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raindeer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi