raindeer 0.9.2 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53220880f52ce3a7fbeec96659fbf6388bc614072b1a759175d3f99f0e5fe572
4
- data.tar.gz: 0f4a1ea786f9bc421936ea0fced8f233d60376279160a006799748ff12991c95
3
+ metadata.gz: 41aa9563466af4e0a352cb288bf3af4dc340de96baa2417928f0807d745e7f4e
4
+ data.tar.gz: cf4ba9e858b140c6e3893814df02e04acc85a24320cf9e71580d2df5188aa615
5
5
  SHA512:
6
- metadata.gz: 9bf8b3a92b44923653298d24b2b33a614213c96edd7db24d92bcd6f9c8ac1218f4390b3dfc5312ac431506b21aaf54e65762d7af13962dffc1314ff9b2f3fafc
7
- data.tar.gz: 57d336165d6d774a968ecd744c73516022c439bd2cfab66b044dbaf1af9ffadd8aa58921b775791db56903dcfa4f86bdb301b589ed8a77830b86c02ae13517ea
6
+ metadata.gz: 90762ce5864de9c7bdd5a69f6d30f5246388745d6bf2c44c85e01b661b48431210d6bc475cfe7b2d83f21de2305053292de4fbbfafc0b8922be5294761b36e5c
7
+ data.tar.gz: c63d7c49fedcbf168731510c4e5d07fdeeac7dfd27c81fdd099516f44a4940a8d700513b9cbfcab56eeea0aa46849774eae036aa1f5585cf4940cdae7a3b6395
data/bin/rain CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  # Call "rain" to access the CLI loaded on your $PATH by Bundler.
4
5
  # Uncomment the line below and call "bin/rain" to load local gems from your Gemfile in development.
data/lib/cli/cli.rb CHANGED
@@ -7,13 +7,18 @@ module Rain
7
7
  module CLI
8
8
  extend Trees
9
9
 
10
+ TEMPLATE_URL = 'https://github.com/raindeer-rb/raindeer-template'
11
+
10
12
  line('new :app_name') do |app_name|
11
- summary { "Generates a Raindeer application with the specified name." }
12
- execute { 'TODO' }
13
+ summary { 'Generates a Raindeer application with the specified name.' }
14
+ execute do
15
+ system("git clone #{TEMPLATE_URL} #{app_name}")
16
+ system("cd #{app_name}")
17
+ end
13
18
  end
14
19
 
15
20
  line('server') do
16
- summary { "Starts a Raindeer application. Once run visit http://127.0.0.1:4133" }
21
+ summary { 'Starts a Raindeer application. Once run visit http://127.0.0.1:4133' }
17
22
  execute { system('bin/server') }
18
23
  end
19
24
 
data/lib/cli/static.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'antlers'
4
- require 'lowload'
5
-
6
- require 'async'
7
- require 'async/http/internet'
3
+ require 'ruby-progressbar'
8
4
  require 'fileutils'
9
5
 
6
+ require 'antlers' # Adds antlers support to lowload.
7
+ require 'lowload'
8
+
10
9
  require_relative '../pages/pages'
11
10
 
12
11
  module Rain
@@ -14,70 +13,65 @@ module Rain
14
13
  module Static
15
14
  extend self
16
15
 
17
- RequestResult = Data.define(:path, :html)
16
+ FakeRequest = Data.define(:path)
17
+ RequestResult = Data.define(:path, :status, :html)
18
18
 
19
19
  def build(application_path:)
20
- metadata = LowLoad.dirload(File.expand_path('app', application_path))
21
-
20
+ metadata = load_user_application(app_path: File.expand_path('app', application_path))
22
21
  build_path = File.expand_path('build', application_path)
22
+
23
23
  FileUtils.rm_rf(build_path)
24
24
  FileUtils.mkdir_p(build_path)
25
25
  FileUtils.cp_r(File.expand_path('public', application_path), File.expand_path('public', build_path))
26
26
 
27
- request_paths(metadata:, application_path:).each do |result|
28
- path = File.expand_path(result.path, build_path)
29
- FileUtils.mkdir_p(path)
30
- File.write(File.expand_path('index.html', path), result.html)
27
+ Low::Events::RequestEvent.define do |observers|
28
+ observers << Providers['rain.router']
31
29
  end
32
- end
33
-
34
- private
35
-
36
- def request_paths(metadata:, application_path:)
37
- file_paths = metadata.file_types.values_at('md', 'rd', 'markdown', 'raindown').flat_map { it }.compact
38
- url_paths = file_paths.map { |file_path| Rain::Pages.url_path(file_path:) }.compact
39
- # Skip files that became solely metadata due to underscores hiding the entire file path.
40
- url_paths.reject! { |url_path| url_path == '' }
41
30
 
42
- tasks = url_paths.map do |file_path|
43
- Async do
44
- request_path = request_path(application_path:, file_path:)
45
- request_url = endpoint + request_path
31
+ request_results(metadata:).each do |request_result|
32
+ folder_path = File.join(build_path, request_result.path)
46
33
 
47
- response = client.get(request_url)
48
- response_html = response.read
49
- response.close
34
+ puts "#{folder_path} => #{request_result.status}"
50
35
 
51
- RequestResult.new(path: request_path, html: response_html)
52
- end
36
+ FileUtils.mkdir_p(folder_path)
37
+ File.write(File.expand_path('index.html', folder_path), request_result.html)
53
38
  end
54
-
55
- tasks.map(&:result)
56
39
  end
57
40
 
58
- def request_path(application_path:, file_path:)
59
- file_path.delete_prefix("#{application_path}/app/pages/")
60
- end
41
+ private
61
42
 
62
- def client
63
- Async::HTTP::Internet.new
64
- end
43
+ def load_user_application(app_path:)
44
+ metadata = LowLoad.dirload(app_path)
65
45
 
66
- def endpoint
67
- "http://#{config.host}:#{config.port}/"
46
+ if Dir.exist?(File.expand_path('pages', app_path))
47
+ Providers.define('rain.pages', eager: true) do
48
+ require_relative '../pages/pages'
49
+ Rain::Pages.new(metadata:)
50
+ end
51
+ end
52
+
53
+ metadata
68
54
  end
69
55
 
70
- def config
71
- env = {
72
- host: ENV.fetch('RAIN_HOST', nil),
73
- port: ENV.fetch('RAIN_PORT', nil),
74
- web_root: ENV.fetch('RAIN_WEB_ROOT', nil),
75
- debug_mode: ConfigLoader.parse_boolean(ENV.fetch('RAIN_DEBUG', true)),
76
- matrix_mode: ConfigLoader.parse_boolean(ENV.fetch('RAIN_MATRIX', nil)),
77
- mirror_mode: ConfigLoader.parse_boolean(ENV.fetch('RAIN_MIRROR', nil)),
78
- }
79
- config_path = File.expand_path('config/config.yaml', Dir.pwd)
80
- ConfigLoader.load(config_path, env)
56
+ def request_results(metadata:)
57
+ file_paths = metadata.file_types.values_at('md', 'rd', 'markdown', 'raindown').flat_map { it }.compact
58
+ paths = file_paths.map { |file_path| Rain::Pages.url_path(file_path:) }.compact
59
+ paths << '/'
60
+ # Skip files that became solely metadata due to underscores hiding the entire file path.
61
+ paths.reject! { |url_path| url_path == '' }
62
+
63
+ progress_bar = ProgressBar.create(
64
+ total: paths.size,
65
+ format: "\e[0;34m%a |%B| %p%%\e[0m"
66
+ )
67
+
68
+ paths.map do |path|
69
+ request = FakeRequest.new(path:)
70
+ response = Low::Events::RequestEvent.take(request:).response
71
+ result = RequestResult.new(path:, status: response.status, html: response.read)
72
+ progress_bar.increment
73
+ result
74
+ end
81
75
  end
82
76
  end
83
77
  end
@@ -8,6 +8,7 @@ module Rain
8
8
  color = next_output ? @config.cell_color : @config.lead_color
9
9
 
10
10
  return Paint[output, '#006ab0'] if @config.leet_keys.invert.key?(output)
11
+
11
12
  output ? Paint[output, color] : Paint[' ']
12
13
  end
13
14
  end
@@ -11,14 +11,14 @@ module Rain
11
11
  @leet_letters = @leet_numbers.invert
12
12
  end
13
13
 
14
- def render(output:, next_output:, x:, y:)
15
- output = filter(output:, next_output:, x:, y:)
14
+ def render(output:, x:, y:, **)
15
+ output = filter(output:, x:, y:, **)
16
16
  save(output:, x:, y:)
17
17
  end
18
18
 
19
19
  private
20
20
 
21
- def filter(output:, next_output:, x:, y:)
21
+ def filter(output:, x:, y:, **)
22
22
  return unless output
23
23
 
24
24
  character = output.downcase
@@ -26,7 +26,7 @@ module Rain
26
26
 
27
27
  return @leet_numbers[character] if @leet_letters.key?(last_character) && rand < 0.99
28
28
  return @leet_numbers[character] if @leet_numbers.key?(character) && rand < 0.005
29
-
29
+
30
30
  output
31
31
  end
32
32
  end
data/lib/matrix/stream.rb CHANGED
@@ -75,8 +75,8 @@ module Rain
75
75
  # └─────┴─────┴─────┘
76
76
  def render(duration: nil)
77
77
  @show_cursor.increment(delays:, inputs:, duration:) do |index|
78
- prev_index = index.zero? ? @inputs.count - 1 : index - 1
79
- next_index = index + 1 >= @inputs.count ? 0 : index + 1
78
+ index.zero? ? @inputs.count - 1 : index - 1
79
+ index + 1 >= @inputs.count ? 0 : index + 1
80
80
 
81
81
  if @inputs[index]
82
82
  @outputs[index] = @inputs[index]
data/lib/pages/pages.rb CHANGED
@@ -56,7 +56,7 @@ module Rain
56
56
  metadata, * = parse_file(file_path:, parse_content: false)
57
57
  metadata.each do |type, tag|
58
58
  tag(type:, tag:, file_path:)
59
- end
59
+ end
60
60
  end
61
61
  end
62
62
 
@@ -68,10 +68,10 @@ module Rain
68
68
 
69
69
  def folders(file_path:)
70
70
  File.dirname(file_path)
71
- .split(Regexp.union(['/', '&', '-']))
72
- .filter { it.start_with?('_') }
73
- .map { it.delete_prefix('_') }
74
- .filter { !number?(it) }
71
+ .split(Regexp.union(['/', '&', '-']))
72
+ .filter { it.start_with?('_') }
73
+ .map { it.delete_prefix('_') }
74
+ .filter { !number?(it) }
75
75
  end
76
76
 
77
77
  def order(file_path)
@@ -100,7 +100,7 @@ module Rain
100
100
  data_lines = []
101
101
  text_lines = []
102
102
 
103
- File.foreach(file_path).with_index do |line, index|
103
+ File.foreach(file_path) do |line|
104
104
  if line.strip == '---' && dash_lines.count < 2
105
105
  dash_lines << line
106
106
  next
@@ -5,7 +5,8 @@ require 'interfaces/lexeme' # From antlers gem, too generic.
5
5
  module Rain
6
6
  module TOCLexeme
7
7
  include Antlers::Lexeme
8
- extend self
8
+
9
+ module_function
9
10
 
10
11
  KEYWORDS = [':toc'].freeze
11
12
 
@@ -14,14 +14,14 @@ module Rain
14
14
  def render(current_binding: nil, parent_binding: nil, slot_node: nil)
15
15
  doc = Nokogiri::HTML(@template)
16
16
 
17
- output = <<~HTML
17
+ <<~HTML
18
18
  <div class="floating">
19
19
  <details id="toc" open>
20
20
  <summary>Table of contents</summary>
21
21
  <ul>
22
- #{doc.css('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]').map { |h|
22
+ #{doc.css('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]').map do |h|
23
23
  "<li class='#{h.name}'><a href='\##{h['id']}'>#{h.text.strip}</a></li>"
24
- }.join("\n")}
24
+ end.join("\n")}
25
25
  </ul>
26
26
  </details>
27
27
  </div>
@@ -6,14 +6,14 @@ require_relative 'elements'
6
6
 
7
7
  module Rain
8
8
  module Raindown
9
- extend self
9
+ module_function
10
10
 
11
11
  def render(markdown:)
12
12
  template = markdown.gsub('<{', '<!-- ANTLERS').gsub('}>', 'ANTLERS -->')
13
13
 
14
14
  doc = Commonmarker.parse(template)
15
15
  doc.walk do |node|
16
- if node.type == :code || node.type == :code_block
16
+ if %i[code code_block].include?(node.type)
17
17
  node.string_content = node.string_content.gsub('<!-- ANTLERS', '<{').gsub('ANTLERS -->', '}>')
18
18
  end
19
19
  end
data/lib/raindeer/cli.rb CHANGED
@@ -5,7 +5,12 @@ require 'low_type'
5
5
  require 'observers'
6
6
  require 'providers'
7
7
 
8
- # Allows the CLI to load application code and metadata, but not start a server.
8
+ # The CLI loads user application code and metadata, but doesn't start a server.
9
+ #
10
+ # Flow:
11
+ # 1. bin/rain - Located in raindeer or user application, loads "raindeer/cli" which is available on $PATH.
12
+ # 2. lib/raindeer/cli - Boots up a raindeer/user application that is suitable for use by the CLI. <-- YOU ARE HERE
13
+ # 3. lib/cli/cli - Defines and runs the CLI that responds to the ARGs given to bin/rain.
9
14
 
10
15
  #################################################
11
16
  # FRAMEWORK INTERNAL API
@@ -24,13 +29,7 @@ end
24
29
  # FRAMEWORK EXTERNAL API
25
30
  #################################################
26
31
 
27
- module Raindeer
28
- class << self
29
- def router(&block)
30
- Providers['rain.router'].instance_eval(&block)
31
- end
32
- end
33
- end
32
+ require_relative 'raindeer'
34
33
 
35
34
  #################################################
36
35
  # CLI
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'boot'
4
-
5
3
  module Raindeer
6
4
  class << self
7
5
  def router(&block)
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raindeer
4
- VERSION = '0.9.2'
4
+ VERSION = '0.9.3'
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.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi
@@ -10,7 +10,7 @@ cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
- name: ostruct
13
+ name: commonmarker
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - ">="
@@ -24,7 +24,7 @@ dependencies:
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0'
26
26
  - !ruby/object:Gem::Dependency
27
- name: paint
27
+ name: nokogiri
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
@@ -38,7 +38,21 @@ dependencies:
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  - !ruby/object:Gem::Dependency
41
- name: commonmarker
41
+ name: ostruct
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: paint
42
56
  requirement: !ruby/object:Gem::Requirement
43
57
  requirements:
44
58
  - - ">="
@@ -66,7 +80,7 @@ dependencies:
66
80
  - !ruby/object:Gem::Version
67
81
  version: '0'
68
82
  - !ruby/object:Gem::Dependency
69
- name: nokogiri
83
+ name: ruby-progressbar
70
84
  requirement: !ruby/object:Gem::Requirement
71
85
  requirements:
72
86
  - - ">="