vita 0.1.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30ec3104878bed6bb49429fa0c92603a7620ec376351c446c293715f35ea0e5b
4
- data.tar.gz: e81e41f8df895e5f62364df1a42bfc7d44faf40a41815676dd71cad0e38f8e72
3
+ metadata.gz: 1718643c6633bbe89990a662fd29739153a7233dd21352d8784b7af27a74383a
4
+ data.tar.gz: 89cf60afa27e2b06d8d43251c9ebe64f81a2f7b19ac8c3ecc154acd95af77943
5
5
  SHA512:
6
- metadata.gz: 69a47a2d3dd45ac46ab4fe9d807f5b441e667499822c0ee2f61689a7dcafba664879659455bbaf46c0212fafb54cf0697ff5edbc44f2959964d984985c47b466
7
- data.tar.gz: 1be52214d2daee544a50fecf7f68295efaf3fae9435a61c37524f66012d26092e6e4adcd0905e4c7610e15534d6d91bcd9ea0fa5bd5015f10408052d472b1b1c
6
+ metadata.gz: 18f962183bc9bf35ca240b8820ca882770b6edc3b82d0a183f3adf6553044c207ec3705dc2f6098e2113618ac9258c0d6e39c8356fd4d383989cf8cb0aed3303
7
+ data.tar.gz: e129b89cc3194e9eca15fdb1e14a786150df89a53c278fef0f250e0449d520e09f2dad7a2913158bc532736fad5d8f4b24d0bfd24dcd85d6986a7e9e46280cdd
data/README.md CHANGED
@@ -33,6 +33,8 @@ __ _(_) |_ __ _
33
33
  Starting Vita at http://localhost:9000
34
34
  ```
35
35
 
36
+ Your web browser refreshes as you make changes to your files.
37
+
36
38
  To publish:
37
39
 
38
40
  ```
@@ -43,17 +45,31 @@ Vita creates a `publish` folder containing HTML files for publishing to a web se
43
45
 
44
46
  ## Links between notes
45
47
 
46
- Vita looks for connections between notes.
48
+ Vita looks for connections between notes. When a note's title (or a [synonym](#synonyms)) appears in the content of another note, Vita creates a link between the two.
49
+
50
+ When viewing a note, links in the note's content are hyperlinked:
51
+
52
+ <img src="doc/outlinks.png" alt="Screenshot of a note in Vita, showing hyperlinks from a note's content to other notes" style="width: 75%">
53
+
54
+ A list of links from other notes to the current note follows the note's content:
55
+
56
+ <img src="doc/backlinks.png" alt="Screenshot of the &quot;links to this note&quot; panel in Vita, showing notes that reference the current note" style="width: 75%">
47
57
 
48
- When a note's content includes the title of another note, Vita creates a link between the two notes.
58
+ Each link includes an excerpt from the other note. Clicking one of these links navigates to the other note.
49
59
 
50
- Links are clickable. Wherever a note's title appears in another note's content, clicking on it navigates to that note:
60
+ ## Synonyms
51
61
 
52
- <img src="doc/outlinks.png" alt="Screenshot of a note in Vita, showing hyperlinks from a note's content to other notes">
62
+ Synonyms allow referring to notes using multiple names. Adding synonyms can be helpful when a note's title appears in other notes in different forms or tenses.
53
63
 
54
- Each note lists the other notes that link to it, along with an excerpt from the source note. Clicking on any of these navigates to the source note:
64
+ For example, notes may refer to a note titled "Cohesion" using terms like "cohesive", "coherent", or "coherence". Adding these words as synonyms to the "Cohesion" note allows Vita to connect the notes with links.
55
65
 
56
- <img src="doc/backlinks.png" alt="Screenshot of the &quot;links to this note&quot; panel in Vita, showing notes that reference the currently-displayed note">
66
+ To specify a note's synonyms, add a `Synonyms:` line at the start of the file containing a comma-separated list of alternative names. For example, in a file called `Cohesion.txt`:
67
+
68
+ ```
69
+ Synonyms: cohesive, coherent, coherence
70
+
71
+ A module is cohesive if the elements in the module are related and the module is coherent as a whole.
72
+ ```
57
73
 
58
74
  ## Home note
59
75
 
data/doc/backlinks.png CHANGED
Binary file
data/doc/notes.png CHANGED
Binary file
data/doc/outlinks.png CHANGED
Binary file
data/lib/vita/garden.rb CHANGED
@@ -15,7 +15,11 @@ module Vita
15
15
  raise Vita::Error.new("Directory not found at #{root}")
16
16
  end
17
17
 
18
- Dir[File.join(root, "*.*")].map { |filename| Note.new(filename) }
18
+ Dir[note_filename_pattern(root)].map { |filename| Note.new(filename) }
19
+ end
20
+
21
+ def self.note_filename_pattern(root)
22
+ File.join(root, "*.*")
19
23
  end
20
24
 
21
25
  def initialize(root, notes)
@@ -56,11 +60,17 @@ module Vita
56
60
  links.filter { |link| link.to_note == note }
57
61
  end
58
62
 
63
+ def note_filename_pattern
64
+ self.class.note_filename_pattern(root)
65
+ end
66
+
59
67
  private
60
68
 
61
69
  def notes=(notes)
62
70
  @notes = notes.map { |note| GardenNote.new(self, note) }.sort_by(&:title)
63
- @notes_hash = @notes.map { |note| [note.title.downcase, note] }.to_h
71
+ @notes_hash = @notes.flat_map { |note|
72
+ note.all_names.map { |name| [name.downcase, note] }
73
+ }.to_h
64
74
 
65
75
  if home_note
66
76
  @notes.delete(home_note)
@@ -12,12 +12,30 @@ module Vita
12
12
  @note = note
13
13
  end
14
14
 
15
+ # Get this note's primary title.
15
16
  def title
16
17
  @note.title
17
18
  end
18
19
 
19
- def title_regexp
20
- /\b#{Regexp.quote(title)}\b/i
20
+ # Get alternative names for this note.
21
+ def synonyms
22
+ if @note.content.start_with? "Synonyms:"
23
+ @note.content[9..@note.content.index("\n")].split(",").map(&:strip)
24
+ else
25
+ []
26
+ end
27
+ end
28
+
29
+ # Get all names for this note, including its title and synonyms.
30
+ def all_names
31
+ [title, *synonyms]
32
+ end
33
+
34
+ # Get a regular expression that matches any of this note's names surrounded
35
+ # by word boundaries.
36
+ def names_regexp
37
+ elements = all_names.map { |name| /#{Regexp.quote(name)}/i }
38
+ /\b#{Regexp.union(elements)}\b/
21
39
  end
22
40
 
23
41
  def path
@@ -29,7 +47,11 @@ module Vita
29
47
  end
30
48
 
31
49
  def content
32
- @note.content
50
+ if @note.content.start_with? "Synonyms:"
51
+ @note.content[@note.content.index("\n") + 1..]
52
+ else
53
+ @note.content
54
+ end
33
55
  end
34
56
 
35
57
  def html
@@ -62,7 +84,7 @@ module Vita
62
84
 
63
85
  def create_outlinks
64
86
  notes = garden.linkable_notes - [self]
65
- regexp = Regexp.union(notes.map(&:title_regexp))
87
+ regexp = Regexp.union(notes.map(&:names_regexp))
66
88
  matches = NoteScanner.new(content).scan(regexp)
67
89
 
68
90
  matches.map do |match|
data/lib/vita/server.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require "sinatra"
2
+ require "sinatra/streaming"
2
3
 
3
4
  module Vita
4
5
  class Server < Sinatra::Base
6
+ helpers Sinatra::Streaming
7
+
5
8
  def self.await_startup
6
9
  sleep 0.1 until settings.running?
7
10
  end
@@ -25,6 +28,14 @@ module Vita
25
28
  end
26
29
  end
27
30
 
31
+ get "/events", provides: "text/event-stream" do
32
+ stream do |out|
33
+ Watcher.new(garden).watch do
34
+ out << "event: change\ndata: {}\n\n"
35
+ end
36
+ end
37
+ end
38
+
28
39
  get "/:path.html" do |path|
29
40
  note = garden.note_at_path("#{path}.html")
30
41
 
data/lib/vita/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vita
2
- VERSION = "0.1.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,13 @@
1
+ require "filewatcher"
2
+
3
+ module Vita
4
+ class Watcher
5
+ def initialize(garden)
6
+ @garden = garden
7
+ end
8
+
9
+ def watch(&)
10
+ Filewatcher.new(@garden.note_filename_pattern).watch(&)
11
+ end
12
+ end
13
+ end
data/lib/vita.rb CHANGED
@@ -9,6 +9,7 @@ require "vita/note"
9
9
  require "vita/renderer"
10
10
  require "vita/rendering_context"
11
11
  require "vita/version"
12
+ require "vita/watcher"
12
13
 
13
14
  module Vita
14
15
  BASE_DIRECTORY = File.expand_path("..", __dir__)
@@ -16,6 +16,7 @@
16
16
  <script defer src="https://unpkg.com/htmx.org@1.9.10"></script>
17
17
  </head>
18
18
  <body>
19
+ <div hx-trigger="sse:change" hx-get="/<%= h note.path %>" hx-target="body">
19
20
  <nav class="navbar bg-body-tertiary mb-3">
20
21
  <div class="container">
21
22
  <a class="navbar-brand" href="/">
@@ -70,10 +71,14 @@
70
71
  </div>
71
72
  </div>
72
73
  </div>
74
+ </div>
73
75
  <script defer>
74
76
  if (location.protocol !== "file:") {
75
77
  document.body.setAttribute('hx-boost', true);
76
78
  }
79
+ if (location.port === "9000") {
80
+ document.body.setAttribute('hx-sse', 'connect:/events');
81
+ }
77
82
  </script>
78
83
  </body>
79
84
  </html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vita
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alec Cursley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-20 00:00:00.000000000 Z
11
+ date: 2024-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra-contrib
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rackup
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: '6.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: filewatcher
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.1'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.1'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: rake
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +198,14 @@ dependencies:
170
198
  requirements:
171
199
  - - "~>"
172
200
  - !ruby/object:Gem::Version
173
- version: 1.34.0
201
+ version: 1.35.1
174
202
  type: :development
175
203
  prerelease: false
176
204
  version_requirements: !ruby/object:Gem::Requirement
177
205
  requirements:
178
206
  - - "~>"
179
207
  - !ruby/object:Gem::Version
180
- version: 1.34.0
208
+ version: 1.35.1
181
209
  description:
182
210
  email:
183
211
  - alec@cursley.net
@@ -210,6 +238,7 @@ files:
210
238
  - lib/vita/rendering_context.rb
211
239
  - lib/vita/server.rb
212
240
  - lib/vita/version.rb
241
+ - lib/vita/watcher.rb
213
242
  - templates/note.html.erb
214
243
  homepage: https://github.com/cursley/vita
215
244
  licenses: