raindown 0.19.0 → 0.21.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/raindown/area.rb +88 -0
  3. data/lib/raindown/chart/drawing.rb +0 -2
  4. data/lib/raindown/chart/line.rb +1 -1
  5. data/lib/raindown/cli.rb +2 -2
  6. data/lib/raindown/config.rb +11 -0
  7. data/lib/raindown/document.rb +7 -3
  8. data/lib/raindown/editing.rb +4 -2
  9. data/lib/raindown/endpoint/curl.rb +0 -1
  10. data/lib/raindown/grid.rb +154 -0
  11. data/lib/raindown/grid_directives.rb +43 -0
  12. data/lib/raindown/grid_wrapping.rb +46 -0
  13. data/lib/raindown/http_json.rb +45 -0
  14. data/lib/raindown/image.rb +44 -0
  15. data/lib/raindown/js/js_nodes.rb +83 -36
  16. data/lib/raindown/js/quickjs_host.rb +63 -0
  17. data/lib/raindown/js/quickjs_runtime.js +61 -0
  18. data/lib/raindown/js/services.js +31 -0
  19. data/lib/raindown/markdown_nodes.rb +2 -0
  20. data/lib/raindown/node_blocks.rb +22 -9
  21. data/lib/raindown/node_injector.rb +56 -17
  22. data/lib/raindown/nodes.rb +50 -15
  23. data/lib/raindown/outdent.rb +100 -0
  24. data/lib/raindown/problem.rb +12 -3
  25. data/lib/raindown/project/card.rb +54 -0
  26. data/lib/raindown/project/endpoint.rb +14 -0
  27. data/lib/raindown/project/project.rb +168 -0
  28. data/lib/raindown/project_nodes.rb +47 -0
  29. data/lib/raindown/rasters.rb +98 -0
  30. data/lib/raindown/scene.rb +10 -0
  31. data/lib/raindown/services/connections.rb +65 -0
  32. data/lib/raindown/services/local.rb +139 -0
  33. data/lib/raindown/services.rb +72 -0
  34. data/lib/raindown/table/table.rb +2 -2
  35. data/lib/raindown/table/table_column.rb +0 -2
  36. data/lib/raindown/table/table_file.rb +0 -1
  37. data/lib/raindown/table/written_table.rb +0 -2
  38. data/lib/raindown/tui/endpoints.rb +1 -1
  39. data/lib/raindown/tui/navigator/navigator.rb +1 -1
  40. data/lib/raindown/watcher/project.rb +2 -2
  41. data/lib/raindown/weather/branch_tree.rb +129 -0
  42. data/lib/raindown/weather/forecast.rb +193 -0
  43. data/lib/raindown/weather/forecast_cache.rb +58 -0
  44. data/lib/raindown/weather/forecast_cards.rb +115 -0
  45. data/lib/raindown/weather/sky.rb +82 -0
  46. data/lib/raindown/weather/weather.rb +140 -0
  47. data/lib/raindown.rb +10 -1
  48. data/lib/version.rb +1 -1
  49. metadata +27 -6
  50. data/lib/raindown/js/host.mjs +0 -51
  51. data/lib/raindown/tui/card.rb +0 -56
  52. data/lib/raindown/tui/endpoint.rb +0 -16
  53. data/lib/raindown/tui/project.rb +0 -147
@@ -1,147 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../actions'
4
- require_relative '../bare_directives'
5
- require_relative '../chart/chart'
6
- require_relative '../document'
7
- require_relative '../front_matter'
8
- require_relative '../node_blocks'
9
- require_relative '../nodes'
10
- require_relative '../pages/pages'
11
- require_relative '../projects'
12
- require_relative '../workers/workers'
13
- require_relative '../stat'
14
- require_relative 'card'
15
- require_relative 'endpoint'
16
- require_relative '../code_blocks'
17
- require_relative '../endpoint/curl'
18
- require_relative '../endpoint/endpoint_variables'
19
-
20
- module Raindown
21
- module TUI
22
- # What the terminal UI asks of a project, answered in the project's Worker with its own nodes loaded,
23
- # so two projects' nodes of the same name stay apart. Answers are plain data, which a Worker sends back through a pipe.
24
- class Project
25
- Outline = Data.define(:lines, :headings, :directives)
26
-
27
- attr_reader :root
28
-
29
- # Workers for the projects in the folder, each answering as a Project, which allows bare directives in any file,
30
- # and runs endpoints with no response as it writes back, when asked, like with --bare and -x.
31
- def self.workers(root:, bare: false, execute: false, **)
32
- Workers.new(root:, **) { new(root: it, bare:, execute:) }
33
- end
34
-
35
- # The projects inside this one have workers of their own, so their files are left out.
36
- def initialize(root:, bare: false, execute: false)
37
- @root = root
38
- @bare = bare
39
- @execute = execute
40
- @load_errors = []
41
- @file_errors = []
42
- Nodes.load(File.join(root, Nodes::FOLDER))
43
- rescue StandardError, ScriptError => e
44
- @load_errors << "#{File.basename(root)}/#{Nodes::FOLDER}: #{e.message}"
45
- end
46
-
47
- # A file's lines, headings and directives.
48
- def outline(path)
49
- document = document(path)
50
- Outline.new(lines: File.readlines(path, chomp: true), headings: document.headings, directives: document.directives)
51
- end
52
-
53
- # Every chart and stat in the project's files, or any node that draws a card, drawn from its data, and the files
54
- # that couldn't be read.
55
- # The charts are found again when asked, and otherwise drawn again, so they follow changes to their data.
56
- def charts(find: false)
57
- if find || @charts.nil?
58
- @file_errors = []
59
- @charts = Projects.files(root).flat_map { |path| charts_in(path) }
60
- end
61
-
62
- { cards: drawn, errors: @load_errors + @file_errors }
63
- end
64
-
65
- # Every endpoint in the project's files that writes its response back, so it can run, by its request, leaving out
66
- # the ones whose snippet can't be read.
67
- def endpoints
68
- Projects.files(root).flat_map do |path|
69
- document = document(path)
70
- # Most files have no endpoint, so they aren't parsed for one.
71
- next [] unless document.markdown.include?('endpoint')
72
-
73
- runnable = document.directives.select { it.endpoint? && it.writes }
74
- runnable.filter_map { |directive| endpoint(path, document.markdown.lines, directive) }
75
- rescue StandardError
76
- []
77
- end
78
- end
79
-
80
- def write_back(path)
81
- Actions.write_back(path, bare: @bare, execute: @execute)
82
- end
83
-
84
- # Runs the endpoint on the line, replacing its response.
85
- def execute(path, line)
86
- directive = Document.read(path, bare: @bare).directives.find { it.line == line && it.endpoint? }
87
- raise Actions::NotAnEndpoint, "There's no endpoint on line #{line}" unless directive
88
-
89
- Actions.execute(path, directive)
90
- end
91
-
92
- private
93
-
94
- def endpoint(path, lines, directive)
95
- snippet = CodeBlocks.endpoint(lines, directive.line).first&.dig(:body)
96
- variables = EndpointVariables.new(path:, content: lines.join)
97
- request = Curl.request(snippet.to_s, variables)
98
- Endpoint.new(project: root, path:, line: directive.line, method: request.method, url: variables.redact(request.url)) if request
99
- end
100
-
101
- def charts_in(path)
102
- document = document(path)
103
- lines = document.markdown.lines
104
- # Its headings are only parsed when it has a chart, as most files don't.
105
- NodeBlocks.find(lines, front_matter: FrontMatter.parse(document.markdown).first, bare: document.bare)
106
- .select { it[:node].respond_to?(:card_lines) }
107
- .map { |block| chart(block, path:, lines:, headings: document.headings) }
108
- rescue StandardError => e
109
- @file_errors << "#{path.delete_prefix(File.join(root, ''))}: #{e.message}"
110
- []
111
- end
112
-
113
- # The file's Document, read and parsed again only once the file's changed, so its endpoints, charts and outline
114
- # share it, and finding them again only parses the files that changed.
115
- def document(path)
116
- stat = File.stat(path)
117
- changed = [stat.mtime, stat.size]
118
- cached_at, document = (@documents ||= {})[path]
119
- return document if cached_at == changed
120
-
121
- Document.read(path, bare: @bare).tap { @documents[path] = [changed, it] }
122
- end
123
-
124
- def drawn
125
- pages = {}
126
- @charts.map do |chart|
127
- lines = lines(chart, pages[File.dirname(chart[:path])] ||= Pages.for(chart[:path]))
128
- Card.new(project: root, chart: lines, **chart.except(:node))
129
- end
130
- end
131
-
132
- def chart(block, path:, lines:, headings:)
133
- line = block[:open] + 1
134
- directive = Directives.text(lines[block[:open]])
135
-
136
- { path:, line:, heading: headings.select { it.line < line }.last&.text, directive:, node: block[:node] }
137
- end
138
-
139
- # Draws the chart or stat as its Markdown would be written back, with the files its project lists.
140
- def lines(chart, metadata)
141
- chart[:node].card_lines(metadata:)
142
- rescue StandardError => e
143
- ["Can't chart: #{e.message}"]
144
- end
145
- end
146
- end
147
- end