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
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+ require 'json'
5
+
6
+ module Raindown
7
+ class Forecast
8
+ # Where a place's forecast is kept, in ~/.cache/raindown, with when it was kept, and when Open-Meteo last couldn't be
9
+ # reached, so it's fresh for FRESH_FOR seconds after it was kept, or RETRY_AFTER after Open-Meteo couldn't be.
10
+ class Cache
11
+ def initialize(key)
12
+ @key = key
13
+ end
14
+
15
+ # The forecast kept, and whether it's still fresh, which it isn't with fewer days than DAYS, or [nil, false].
16
+ def report
17
+ kept = read
18
+ report = Report.new(**kept[:report], place: Place.new(**kept[:report][:place]), days: kept[:report][:days].map { Day.new(**it) })
19
+ [report, fresh?(kept, report)]
20
+ rescue Errno::ENOENT, JSON::ParserError, ArgumentError, TypeError, NoMethodError
21
+ [nil, false]
22
+ end
23
+
24
+ def keep(report)
25
+ kept = report.to_h.merge(place: report.place.to_h, days: report.days.map(&:to_h))
26
+ write(at: Time.now.to_i, report: kept)
27
+ end
28
+
29
+ # Notes when Open-Meteo couldn't be reached, beside what was kept, keeping when it was kept.
30
+ def unreached
31
+ write(read.merge(unreached_at: Time.now.to_i))
32
+ rescue Errno::ENOENT, JSON::ParserError
33
+ nil
34
+ end
35
+
36
+ private
37
+
38
+ def fresh?(kept, report)
39
+ now = Time.now.to_i
40
+ return true if kept[:unreached_at] && now - kept[:unreached_at] < RETRY_AFTER
41
+
42
+ now - kept[:at] < FRESH_FOR && report.days.size >= DAYS
43
+ end
44
+
45
+ def read = JSON.parse(File.read(file), symbolize_names: true)
46
+
47
+ def write(kept)
48
+ FileUtils.mkdir_p(File.dirname(file))
49
+ File.write(file, JSON.generate(kept))
50
+ end
51
+
52
+ def file
53
+ name = Digest::SHA256.hexdigest(@key)[0, 12]
54
+ File.join(ENV.fetch('XDG_CACHE_HOME', File.join(Dir.home, '.cache')), 'raindown', "forecast-#{name}.json")
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module Raindown
6
+ # A forecast's days as little cards side by side, in text, each with an emoji for its weather in its padding at its
7
+ # top right, its day, its high and low, and its weather in words, on two lines, padded inside:
8
+ # ╭────────────╮╭────────────╮
9
+ # │ ☁️ ││ 🌧️ │
10
+ # │ Today ││ Fri │
11
+ # │ 20° 10° ││ 19° 14° │
12
+ # │ overcast ││ light │
13
+ # │ ││ rain │
14
+ # ╰────────────╯╰────────────╯
15
+ module ForecastCards
16
+ # How wide a card's padding is on each side, its text inside it, and the card inside its borders.
17
+ PADDING = 2
18
+ TEXT = 8
19
+ WIDTH = TEXT + (2 * PADDING)
20
+ BORDERS = '╭╮╰╯─│'
21
+ # An emoji for each of the WMO's weather codes, each two characters wide, as editors show them.
22
+ EMOJI = {
23
+ 0 => '☀️', 1 => '🌤️', 2 => '⛅', 3 => '☁️', 45 => '🌫️', 48 => '🌫️', 51 => '🌦️', 53 => '🌦️', 55 => '🌦️', 56 => '🌨️',
24
+ 57 => '🌨️', 61 => '🌧️', 63 => '🌧️', 65 => '🌧️', 66 => '🌨️', 67 => '🌨️', 71 => '❄️', 73 => '❄️', 75 => '❄️',
25
+ 77 => '❄️', 80 => '🌦️', 81 => '🌦️', 82 => '🌧️', 85 => '🌨️', 86 => '🌨️', 95 => '⛈️', 96 => '⛈️', 99 => '⛈️'
26
+ }.freeze
27
+ UNKNOWN = '❔'
28
+ # Shorter words for the weather where the WMO's don't fit a card's two lines, and how many lines they have.
29
+ SHORTER = { 86 => 'heavy snow', 95 => 'storms', 96 => 'storms, hail', 99 => 'storms, hail' }.freeze
30
+ WORD_LINES = 2
31
+ EMOJI_WIDTH = 2
32
+ EMOJI_GAP = 2
33
+
34
+ module_function
35
+
36
+ # The cards' lines, from the days, the first of them today.
37
+ def lines(days)
38
+ days.each_with_index.map { |day, index| card(day, index) }.transpose.map(&:join)
39
+ end
40
+
41
+ # A card's lines: its top border, its padding with its weather's emoji at its right, its day, temperatures, its
42
+ # weather in words on two lines, and its bottom.
43
+ def card(day, index)
44
+ texts = [label(day, index), temperatures(day), *words(day)]
45
+ pad = ' ' * PADDING
46
+ ["╭#{'─' * WIDTH}╮", "│#{top_padding(day)}│", *texts.map { "│#{pad}#{fit(it)}#{pad}│" }, "╰#{'─' * WIDTH}╯"]
47
+ end
48
+
49
+ # The card's top padding, with its weather's emoji at its right, in the padding's corner, a space from the border,
50
+ # as an app may draw it larger than its text, in line with the text's padding.
51
+ def top_padding(day)
52
+ emoji = EMOJI.fetch(day.code, UNKNOWN)
53
+ "#{' ' * (WIDTH - Unicode::DisplayWidth.of(emoji, emoji: :all) - EMOJI_GAP)}#{emoji}#{' ' * EMOJI_GAP}"
54
+ end
55
+
56
+ # Text padded, by how wide it shows, to the card's text's width.
57
+ def fit(text)
58
+ text + (' ' * [TEXT - Unicode::DisplayWidth.of(text, emoji: :all), 0].max)
59
+ end
60
+
61
+ # The day's weather in words, like partly cloudy, wrapped to the card's text's width, on WORD_LINES lines.
62
+ def words(day)
63
+ wrapped = SHORTER.fetch(day.code, day.words).split.each_with_object([]) do |word, lines|
64
+ next lines << word if lines.empty? || "#{lines.last} #{word}".length > TEXT
65
+
66
+ lines[-1] = "#{lines.last} #{word}"
67
+ end
68
+ (wrapped + ([''] * WORD_LINES)).first(WORD_LINES)
69
+ end
70
+
71
+ def label(day, index)
72
+ return 'Today' if index.zero?
73
+
74
+ Date.parse(day.date).strftime('%a')
75
+ end
76
+
77
+ # Its high and low, without their degrees when they're too long for a card, like -12 -20.
78
+ def temperatures(day)
79
+ text = "#{day.high.round}° #{day.low.round}°"
80
+ return text if text.length <= TEXT
81
+
82
+ text.delete('°')
83
+ end
84
+
85
+ # Where each card's emoji is, on the cards' second line, as [line, from, to], in columns, for an app to draw as large
86
+ # as a line is tall.
87
+ def emoji(days)
88
+ days.each_index.map do |index|
89
+ from = (index * (WIDTH + 2)) + 1 + WIDTH - EMOJI_WIDTH - EMOJI_GAP
90
+ [1, from, from + EMOJI_WIDTH]
91
+ end
92
+ end
93
+
94
+ # Where each card's day is, on the cards' third line, as [line, from, to], for an app to embolden.
95
+ def headings(days)
96
+ days.each_with_index.map do |day, index|
97
+ from = (index * (WIDTH + 2)) + 1 + PADDING
98
+ [2, from, from + label(day, index).length]
99
+ end
100
+ end
101
+
102
+ # The characters of a card's lines that are its borders, as [line, from, to], in columns, as an emoji takes two,
103
+ # for an app to dim.
104
+ def borders(lines)
105
+ lines.each_with_index.flat_map do |line, index|
106
+ column = 0
107
+ line.each_grapheme_cluster.filter_map do |character|
108
+ at = column
109
+ column += Unicode::DisplayWidth.of(character, emoji: :all)
110
+ [index, at, at + 1] if BORDERS.include?(character)
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Raindown
4
+ # The weather now as a sky for an app to paint, as how much of each kind of weather there is, from 0 to 1, so its
5
+ # painters blend them: cloud, how much of the sky's covered, rain and snow, how hard they're falling, fog, storm,
6
+ # whether there's thunder, wind, how hard it's blowing, and the temperature in °C. From Open-Meteo's current
7
+ # conditions, and from its weather code, which says what's falling when its amounts are small, like drizzle.
8
+ module Sky
9
+ # How much rain or snow a weather code means, at least, and fog.
10
+ RAIN = { 51 => 0.25, 53 => 0.35, 55 => 0.45, 56 => 0.35, 57 => 0.45, 61 => 0.4, 63 => 0.65, 65 => 0.9, 66 => 0.4,
11
+ 67 => 0.6, 80 => 0.4, 81 => 0.65, 82 => 0.9, 95 => 0.85, 96 => 0.85, 99 => 0.9 }.freeze
12
+ SNOW = { 71 => 0.35, 73 => 0.6, 75 => 0.9, 77 => 0.3, 85 => 0.5, 86 => 0.85 }.freeze
13
+ FOG = { 45 => 0.8, 48 => 0.85 }.freeze
14
+ # How much each layer of cloud covers the sky, as its high cloud's thin, like cirrus, so a sky Open-Meteo calls
15
+ # clear can have it all over, and how much cloud there is for each weather code, so the sky's what its words say.
16
+ # Rain, snow, fog and storms have at least WET_CLOUD.
17
+ LAYERS = { cloud_cover_low: 1.0, cloud_cover_mid: 0.8, cloud_cover_high: 0.25 }.freeze
18
+ CLOUD = { 0 => 0.0..0.15, 1 => 0.1..0.4, 2 => 0.3..0.7, 3 => 0.8..1.0 }.freeze
19
+ WET_CLOUD = 0.7
20
+ # The rain, in mm an hour, snow, in cm an hour, wind, in km/h, and visibility, in metres, at which they're at their
21
+ # most.
22
+ HEAVIEST_RAIN = 3.0
23
+ HEAVIEST_SNOW = 1.5
24
+ STRONGEST_WIND = 50.0
25
+ CLEAREST = 5000.0
26
+ # The kinds of weather, which RAINDOWN_SKY can set, like "rain=0.8,cloud=1", to see them.
27
+ KINDS = %i[cloud rain snow fog storm wind temperature].freeze
28
+
29
+ module_function
30
+
31
+ # The sky from Open-Meteo's current conditions, as cloud_cover, rain, showers, snowfall, wind_speed_10m,
32
+ # visibility, weather_code and temperature_2m, in °C, with RAINDOWN_SKY's on top.
33
+ def of(conditions, overrides: ENV.fetch('RAINDOWN_SKY', ''))
34
+ code = conditions[:weather_code].to_i
35
+ sky = { cloud: cloud(conditions, code), **falling(conditions, code), fog: fog(conditions, code),
36
+ storm: storm(code), wind: clamp(conditions[:wind_speed_10m].to_f / STRONGEST_WIND),
37
+ temperature: conditions[:temperature_2m].to_f }
38
+ sky.merge(overridden(overrides))
39
+ end
40
+
41
+ # How much of the sky's covered: its layers of cloud, weighted by how thick they are, or else its cloud cover, in
42
+ # the range its weather code says.
43
+ def cloud(conditions, code)
44
+ layers = LAYERS.filter_map { |layer, weight| conditions[layer] && (conditions[layer].to_f / 100 * weight) }
45
+ cover = layers.max || (conditions[:cloud_cover].to_f / 100)
46
+ range = CLOUD.fetch(code) { WET_CLOUD..1.0 }
47
+ clamp(cover.clamp(range.begin, range.end))
48
+ end
49
+
50
+ # How hard rain and snow are falling, by how much falls, or at least as much as the weather code says.
51
+ def falling(conditions, code)
52
+ rain = clamp((conditions[:rain].to_f + conditions[:showers].to_f) / HEAVIEST_RAIN)
53
+ snow = clamp(conditions[:snowfall].to_f / HEAVIEST_SNOW)
54
+ { rain: [rain, RAIN.fetch(code, 0)].max, snow: [snow, SNOW.fetch(code, 0)].max }
55
+ end
56
+
57
+ # Whether there's thunder, as 1, or not, as 0.
58
+ def storm(code)
59
+ return 1 if code >= 95
60
+
61
+ 0
62
+ end
63
+
64
+ # How foggy it is, by how far it can be seen, or at least as foggy as the weather code says.
65
+ def fog(conditions, code) = [visibility_fog(conditions[:visibility]), FOG.fetch(code, 0)].max
66
+
67
+ # How foggy a visibility, in metres, makes it, from none at CLEAREST to most at none.
68
+ def visibility_fog(visibility)
69
+ return 0 if visibility.nil?
70
+
71
+ clamp((CLEAREST - visibility.to_f) / CLEAREST) * 0.8
72
+ end
73
+
74
+ def overridden(overrides)
75
+ overrides.split(',').to_h { it.split('=', 2) }.filter_map do |kind, amount|
76
+ [kind.strip.to_sym, amount.to_f] if KINDS.include?(kind.strip.to_sym)
77
+ end.to_h
78
+ end
79
+
80
+ def clamp(value) = value.clamp(0.0, 1.0).round(2)
81
+ end
82
+ end
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cgi/escape'
4
+ require_relative '../config'
5
+ require_relative '../node'
6
+ require_relative '../scene'
7
+ require_relative 'branch_tree'
8
+ require_relative 'forecast'
9
+
10
+ module Raindown
11
+ # The node behind weather:, the weather where you are, from Open-Meteo, now and for the week, which apps draw a sky
12
+ # behind, like over a valley in the app. Where you are is your time zone's city, or a place you name, like
13
+ # weather: Brisbane:
14
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15
+ # < weather:
16
+ # < ╭────────────╮╭────────────╮ …
17
+ # < │ ☁️ ││ 🌧️ │
18
+ # < │ Today ││ Fri │
19
+ # < │ 20° 10° ││ 19° 14° │
20
+ # < │ overcast ││ light │
21
+ # < │ ││ rain │
22
+ # < ╰────────────╯╰────────────╯
23
+ # In an app that draws pixels, it shows a valley behind its text, by day or by night, which the app paints itself,
24
+ # from the weather now it gives it, and in a code project, a constellation for each of its branches that aren't merged
25
+ # into main, a star a commit.
26
+ class Weather < Node
27
+ # How long its branches and weather are kept, as an app asks for its sky about once a second, and how long it waits
28
+ # to ask for the weather again when there's none, as Open-Meteo couldn't be reached.
29
+ FRESH_FOR = 5
30
+ RETRY_AFTER = 60
31
+
32
+ def initialize(place = nil)
33
+ @place = place
34
+ super()
35
+ end
36
+
37
+ def rewrite
38
+ forecast_lines.join("\n")
39
+ end
40
+
41
+ # Its valley, with its branches' names and commits for their constellations, and the weather now, with its UV index
42
+ # now and today's at its strongest, to a decimal place, and its sky, how much cloud, rain, snow, fog, storm and wind there is,
43
+ # as Sky gives it, at any size, which the app paints. Without the weather, its sky's clear, but for what RAINDOWN_SKY
44
+ # sets. For a place it names, it's that place's time of day too, from how far ahead of UTC its clocks are, in
45
+ # seconds, as utc_offset.
46
+ def rasterize(metadata: NoMetadata, **)
47
+ report = forecast_now
48
+ now = report && { temperature: report.temperature, unit: report.unit, code: report.code, words: report.words,
49
+ uv: report.uv&.round(1), uv_peak: report.uv_peak&.round(1) }
50
+ branches = branches(metadata).map { { name: it.name, commits: it.commits } }
51
+ data = { branches:, now:, sky: report&.sky || Sky.of({}) }
52
+ data[:utc_offset] = report.utc_offset if @place && report
53
+ Scene.new(name: 'valley', data:)
54
+ end
55
+
56
+ # The characters of its lines an app formats, as [line, from, to], its lines counted from the first it writes: its
57
+ # cards' borders dimmed, as quiet, so the weather stands out, their days in bold, and their emoji as large as a line
58
+ # is tall.
59
+ def formatting(**)
60
+ report = forecast_now
61
+ return {} unless report
62
+
63
+ { quiet: report.quiet, bold: report.bold, large: report.large }
64
+ end
65
+
66
+ # Its lines as they're written, keeping their spaces, so its cards stay as they're drawn.
67
+ def render
68
+ %(<pre class="weather">#{CGI.escapeHTML(rewrite)}</pre>)
69
+ end
70
+
71
+ private
72
+
73
+ # The weather now and the week's, as ForecastCards draws it, or none when it can't be found.
74
+ def forecast_lines
75
+ forecast&.lines || []
76
+ end
77
+
78
+ # The weather, kept FRESH_FOR seconds, or RETRY_AFTER when there's none, waiting for it when it's asked for again.
79
+ def forecast
80
+ return @forecast.last if kept?
81
+
82
+ found(fetched_report)
83
+ end
84
+
85
+ # The weather without waiting for it, for an app painting it, which never waits for the network: what it last had,
86
+ # or else what was kept, however old, while it's asked for again in the background.
87
+ def forecast_now
88
+ return @forecast.last if kept?
89
+
90
+ refresh
91
+ @forecast&.last || Forecast.cached(@place)
92
+ end
93
+
94
+ def kept?
95
+ found_at, report = @forecast
96
+ found_at && Time.now - found_at < (report ? FRESH_FOR : RETRY_AFTER)
97
+ end
98
+
99
+ def found(report)
100
+ @forecast = [Time.now, report]
101
+ report
102
+ end
103
+
104
+ def fetched_report
105
+ Forecast.for(@place)
106
+ rescue Forecast::Error
107
+ nil
108
+ end
109
+
110
+ # The weather, asked for again in a thread of its own, one at a time.
111
+ def refresh
112
+ return if @refreshing
113
+
114
+ @refreshing = true
115
+ Thread.new do
116
+ found(fetched_report)
117
+ ensure
118
+ @refreshing = false
119
+ end
120
+ end
121
+
122
+ # Its branches, found again once they're FRESH_FOR seconds old, or none in a notes project.
123
+ def branches(metadata)
124
+ root = root(metadata)
125
+ return [] unless Config.kind(root) == 'code'
126
+
127
+ found_at, branches = @branches
128
+ return branches if found_at && Time.now - found_at < FRESH_FOR
129
+
130
+ BranchTree.new(root).branches.tap { @branches = [Time.now, it] }
131
+ end
132
+
133
+ # The project's folder, from the page being written, or else the current one.
134
+ def root(metadata)
135
+ return metadata.root if metadata.respond_to?(:root)
136
+
137
+ Dir.pwd
138
+ end
139
+ end
140
+ end
data/lib/raindown.rb CHANGED
@@ -3,6 +3,14 @@
3
3
  require 'antlers'
4
4
  require 'antlers/api'
5
5
 
6
+ # Libraries that take a while to load, loaded the first time they're used: FileUtils and URI, and unicode-display_width,
7
+ # which reads its tables of characters' widths as it loads.
8
+ autoload :FileUtils, 'fileutils'
9
+ autoload :URI, 'uri'
10
+ module Unicode
11
+ autoload :DisplayWidth, 'unicode/display_width'
12
+ end
13
+
6
14
  require_relative 'elements'
7
15
  require_relative 'raindown/bare_directives'
8
16
  require_relative 'raindown/code'
@@ -13,6 +21,7 @@ require_relative 'raindown/fragments'
13
21
  require_relative 'raindown/front_matter'
14
22
  require_relative 'raindown/heading_ids'
15
23
  require_relative 'raindown/node_blocks'
24
+ require_relative 'raindown/outdent'
16
25
  require_relative 'raindown/pages/pages'
17
26
  require_relative 'raindown/pre_renderer'
18
27
  require_relative 'raindown/table/table_formatter'
@@ -52,7 +61,7 @@ module Raindown
52
61
  # Without commonmark, it's Markdown, not HTML, with nodes as they'd be written back, for an app to render itself, like
53
62
  # Obsidian's reading view in the plugin, where Commonmarker, which is native, can't run.
54
63
  def render(markdown:, metadata: NoMetadata, bare: false, highlight_code: true, commonmark: true)
55
- context = Context.new(document: markdown, metadata:, bare: bare || BareDirectives.front_matter?(markdown))
64
+ context = Context.new(document: Outdent.unwrapped(markdown), metadata:, bare: bare || BareDirectives.front_matter?(markdown))
56
65
 
57
66
  rendering(highlight_code:, commonmark:) do
58
67
  Fragments.collect do
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raindown
4
- VERSION = '0.19.0'
4
+ VERSION = '0.21.0'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raindown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-11-10 00:00:00.000000000 Z
10
+ date: 2026-11-14 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: antlers
@@ -210,6 +210,7 @@ files:
210
210
  - lib/nodes/write_in_node.rb
211
211
  - lib/raindown.rb
212
212
  - lib/raindown/actions.rb
213
+ - lib/raindown/area.rb
213
214
  - lib/raindown/bare_directives.rb
214
215
  - lib/raindown/blueprints.rb
215
216
  - lib/raindown/chart/bars.rb
@@ -237,23 +238,40 @@ files:
237
238
  - lib/raindown/fragments.rb
238
239
  - lib/raindown/front_matter.rb
239
240
  - lib/raindown/gitignore.rb
241
+ - lib/raindown/grid.rb
242
+ - lib/raindown/grid_directives.rb
243
+ - lib/raindown/grid_wrapping.rb
240
244
  - lib/raindown/heading_ids.rb
241
- - lib/raindown/js/host.mjs
245
+ - lib/raindown/http_json.rb
246
+ - lib/raindown/image.rb
242
247
  - lib/raindown/js/js_nodes.rb
248
+ - lib/raindown/js/quickjs_host.rb
249
+ - lib/raindown/js/quickjs_runtime.js
250
+ - lib/raindown/js/services.js
243
251
  - lib/raindown/list.rb
244
252
  - lib/raindown/markdown_nodes.rb
245
253
  - lib/raindown/node.rb
246
254
  - lib/raindown/node_blocks.rb
247
255
  - lib/raindown/node_injector.rb
248
256
  - lib/raindown/nodes.rb
257
+ - lib/raindown/outdent.rb
249
258
  - lib/raindown/pages/listings.rb
250
259
  - lib/raindown/pages/page.rb
251
260
  - lib/raindown/pages/pages.rb
252
261
  - lib/raindown/pre_renderer.rb
253
262
  - lib/raindown/problem.rb
263
+ - lib/raindown/project/card.rb
264
+ - lib/raindown/project/endpoint.rb
265
+ - lib/raindown/project/project.rb
266
+ - lib/raindown/project_nodes.rb
254
267
  - lib/raindown/projects.rb
268
+ - lib/raindown/rasters.rb
255
269
  - lib/raindown/rewriter.rb
270
+ - lib/raindown/scene.rb
256
271
  - lib/raindown/server.rb
272
+ - lib/raindown/services.rb
273
+ - lib/raindown/services/connections.rb
274
+ - lib/raindown/services/local.rb
257
275
  - lib/raindown/skeleton.rb
258
276
  - lib/raindown/stat.rb
259
277
  - lib/raindown/table/file_cell.rb
@@ -275,10 +293,8 @@ files:
275
293
  - lib/raindown/tui/blueprints/filter.rb
276
294
  - lib/raindown/tui/blueprints/traced_code.rb
277
295
  - lib/raindown/tui/blueprints/tracing.rb
278
- - lib/raindown/tui/card.rb
279
296
  - lib/raindown/tui/cloud.rb
280
297
  - lib/raindown/tui/code_box.rb
281
- - lib/raindown/tui/endpoint.rb
282
298
  - lib/raindown/tui/endpoints.rb
283
299
  - lib/raindown/tui/events.rb
284
300
  - lib/raindown/tui/feelings/batch.rb
@@ -312,7 +328,6 @@ files:
312
328
  - lib/raindown/tui/navigator/project_menu.rb
313
329
  - lib/raindown/tui/navigator/teleport.rb
314
330
  - lib/raindown/tui/navigator/views.rb
315
- - lib/raindown/tui/project.rb
316
331
  - lib/raindown/tui/project_box.rb
317
332
  - lib/raindown/tui/renderers/dashboard_renderer.rb
318
333
  - lib/raindown/tui/renderers/endpoint_renderer.rb
@@ -342,6 +357,12 @@ files:
342
357
  - lib/raindown/watcher/file_watcher.rb
343
358
  - lib/raindown/watcher/project.rb
344
359
  - lib/raindown/watcher/supervisor.rb
360
+ - lib/raindown/weather/branch_tree.rb
361
+ - lib/raindown/weather/forecast.rb
362
+ - lib/raindown/weather/forecast_cache.rb
363
+ - lib/raindown/weather/forecast_cards.rb
364
+ - lib/raindown/weather/sky.rb
365
+ - lib/raindown/weather/weather.rb
345
366
  - lib/raindown/wiki_links.rb
346
367
  - lib/raindown/workers/worker.rb
347
368
  - lib/raindown/workers/workers.rb
@@ -1,51 +0,0 @@
1
- // Runs a project's JavaScript Components for Raindown, which starts it with node -e, since inside Raindown's package
2
- // the script is where NodeJS can't read it. Each line on stdin is a request, answered by one line of JSON on stdout:
3
- // { op: 'load', folder } → { nodes: [{ name, render }] }
4
- // { op: 'new', id, name, args, props } → {}
5
- // { op: 'call', id, method, context } → { value }
6
- // A request that throws is answered with { error }.
7
- import { readdirSync } from 'node:fs'
8
- import { join } from 'node:path'
9
- import { createInterface } from 'node:readline'
10
- import { pathToFileURL } from 'node:url'
11
-
12
- // stdout carries the replies, so what nodes log goes to stderr.
13
- console.log = console.info = console.error
14
-
15
- const classes = {}
16
- const nodes = {}
17
-
18
- const requests = {
19
- // Every exported class with rewrite is a node, named by its export, or by its class for a default export.
20
- async load({ folder }) {
21
- for (const file of readdirSync(folder).filter((file) => /\.m?js$/.test(file))) {
22
- const exports = await import(pathToFileURL(join(folder, file)).href)
23
-
24
- for (const [name, value] of Object.entries(exports)) {
25
- if (typeof value?.prototype?.rewrite === 'function') classes[name === 'default' ? value.name : name] = value
26
- }
27
- }
28
-
29
- const nodes = Object.entries(classes).map(([name, node]) => ({ name, render: typeof node.prototype.render === 'function' }))
30
- return { nodes }
31
- },
32
-
33
- new({ id, name, args, props }) {
34
- nodes[id] = new classes[name](props, ...args)
35
- return {}
36
- },
37
-
38
- async call({ id, method, context }) {
39
- return { value: await nodes[id][method](context) }
40
- },
41
- }
42
-
43
- for await (const line of createInterface({ input: process.stdin })) {
44
- const request = JSON.parse(line)
45
-
46
- try {
47
- process.stdout.write(`${JSON.stringify(await requests[request.op](request))}\n`)
48
- } catch (error) {
49
- process.stdout.write(`${JSON.stringify({ error: String(error?.message ?? error) })}\n`)
50
- }
51
- }
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'unicode/display_width'
4
-
5
- module Raindown
6
- module TUI
7
- # A chart on the dashboard, drawn from its data by its project's Worker: a title of its file, from its project,
8
- # and the heading above it, then its directive, then the chart, each line with its Layout style,
9
- # in a border with rounded corners. It's as wide as the chart, so the title and directive are cut to fit it:
10
- # ╭───────────────────────────────────────╮
11
- # │ markdown.md › Charts │
12
- # │ chart: 'data/downloads.csv' width: 30 │
13
- # │ Jun ██████▊ 640 │
14
- # ╰───────────────────────────────────────╯
15
- class Card < Data.define(:project, :path, :line, :heading, :directive, :chart)
16
- # The border's columns either side of a card's lines, "│ " and " │", and its lines above and below them.
17
- BORDER_WIDTH = 4
18
- BORDER_HEIGHT = 2
19
-
20
- def title = [path.delete_prefix(File.join(project, '')), heading].compact.join(' › ')
21
-
22
- def lines = parts.map(&:first)
23
-
24
- # Each line, with its style.
25
- def parts = [[title, :heading], [directive, :directive], *chart.map { [it, :chart] }]
26
-
27
- # As wide as its chart.
28
- def width = chart.map { Unicode::DisplayWidth.of(it) }.max || 0
29
-
30
- def height = lines.length
31
-
32
- # With its border, within a range of widths, like a pane's.
33
- def box_width(within: nil) = within ? (width + BORDER_WIDTH).clamp(within) : width + BORDER_WIDTH
34
- def box_height = height + BORDER_HEIGHT
35
-
36
- # A line of the card in its border, as [text, style, width] parts, for a card the box width wide.
37
- # The border's top is line 0, and below its bottom, the lines are blank, for a card shorter than its row.
38
- # The title's style is title_style, like when the card's selected.
39
- def format_line(line, box_width:, title_style: :heading)
40
- width = [box_width - BORDER_WIDTH, 0].max
41
- return [border(width, '╭', '╮')] if line.zero?
42
- return [border(width, '╰', '╯')] if line == height + 1
43
- return [['', :blank, width + BORDER_WIDTH]] if line > height + 1
44
-
45
- text, style = parts[line - 1]
46
- [['│ ', :border, 2], [text, style == :heading ? title_style : style, width], [' │', :border, 2]]
47
- end
48
-
49
- private
50
-
51
- def border(width, left, right)
52
- ["#{left}#{'─' * (width + 2)}#{right}", :border, width + BORDER_WIDTH]
53
- end
54
- end
55
- end
56
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Raindown
4
- module TUI
5
- # An endpoint in a project's files, listed in the nav pane by its request, like "GET httpbin.org/uuid",
6
- # with its method in its style, like GET in :method_get.
7
- Endpoint = Data.define(:project, :path, :line, :method, :url) do
8
- def text = "#{method} #{address}"
9
-
10
- # The URL without its scheme.
11
- def address = url.sub(%r{\Ahttps?://}i, '')
12
-
13
- def style = :"method_#{method.downcase}"
14
- end
15
- end
16
- end