highlite 0.1.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 (45) hide show
  1. checksums.yaml +7 -0
  2. data/.claude/commands/publish.md +45 -0
  3. data/README.md +176 -0
  4. data/Rakefile +12 -0
  5. data/app/assets/stylesheets/highlite/viewer.css +607 -0
  6. data/app/helpers/highlite/application_helper.rb +20 -0
  7. data/app/javascript/highlite/controllers/.keep +0 -0
  8. data/app/javascript/highlite/controllers/highlight_controller.js +829 -0
  9. data/app/javascript/highlite/controllers/highlights_panel_controller.js +313 -0
  10. data/app/javascript/highlite/controllers/sidebar_controller.js +465 -0
  11. data/app/javascript/highlite/controllers/viewer_controller.js +373 -0
  12. data/app/javascript/highlite/index.js +30 -0
  13. data/app/javascript/highlite/lib/.keep +0 -0
  14. data/app/javascript/highlite/lib/highlight_store.js +235 -0
  15. data/app/javascript/highlite/lib/pdf_renderer.js +212 -0
  16. data/app/views/highlite/_floating_toolbar.html.erb +79 -0
  17. data/app/views/highlite/_left_sidebar.html.erb +43 -0
  18. data/app/views/highlite/_right_sidebar.html.erb +56 -0
  19. data/app/views/highlite/_toolbar.html.erb +63 -0
  20. data/app/views/highlite/_viewer.html.erb +63 -0
  21. data/config/importmap.rb +17 -0
  22. data/lib/generators/highlite/install/install_generator.rb +44 -0
  23. data/lib/generators/highlite/install/templates/_right_sidebar.html.erb.tt +16 -0
  24. data/lib/generators/highlite/install/templates/initializer.rb.tt +20 -0
  25. data/lib/highlite/configuration.rb +27 -0
  26. data/lib/highlite/engine.rb +26 -0
  27. data/lib/highlite/version.rb +5 -0
  28. data/lib/highlite.rb +17 -0
  29. data/sig/highlite.rbs +4 -0
  30. data/tasks/todo.md +129 -0
  31. data/test/dummy/Rakefile +3 -0
  32. data/test/dummy/app/controllers/application_controller.rb +2 -0
  33. data/test/dummy/app/controllers/documents_controller.rb +6 -0
  34. data/test/dummy/app/javascript/application.js +1 -0
  35. data/test/dummy/app/views/documents/show.html.erb +1 -0
  36. data/test/dummy/app/views/layouts/application.html.erb +13 -0
  37. data/test/dummy/bin/rails +4 -0
  38. data/test/dummy/config/application.rb +15 -0
  39. data/test/dummy/config/boot.rb +2 -0
  40. data/test/dummy/config/environment.rb +2 -0
  41. data/test/dummy/config/importmap.rb +3 -0
  42. data/test/dummy/config/routes.rb +3 -0
  43. data/test/dummy/config.ru +2 -0
  44. data/test/dummy/public/convention-over-configuration.pdf +0 -0
  45. metadata +117 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e7f70faaaafdc548e86def3816f0d2874a40034bc3d1594a20d456a1f821e683
4
+ data.tar.gz: 5af38211bef0c8671022827fd712dad822dda43d9eb910ac59bdbd011fea95b4
5
+ SHA512:
6
+ metadata.gz: d8a334efaedcfcbcadb1a0f54f7ddb3c69601ffeb71a0481020f0b4a179650c71171736fd6d6a9d8637ceb577bfb6ead53e942317e75c9b8ef9334248fc5b4f9
7
+ data.tar.gz: ffac4a3dce224fd17ac2a6173e81f44ddc946b476c0507bbdd8762ac2e582a3d3b6a74c20297115ae282cea861826017c8e3527ea47cb844bf82c79be144d6c4
@@ -0,0 +1,45 @@
1
+ # Publish Ruby Gem
2
+
3
+ Publish a new version of this Ruby gem. Follow these steps exactly:
4
+
5
+ ## 1. Pre-flight checks
6
+ - Run `bundle exec rspec` to ensure all tests pass. Stop if any fail.
7
+ - Run `git status` to see the current state of the working tree.
8
+ - Read `lib/snitch/version.rb` to determine the current version.
9
+
10
+ ## 2. Bump version
11
+ - Determine the appropriate version bump (patch, minor, or major) based on the changes. Ask the user if unclear.
12
+ - Update the version in `lib/snitch/version.rb`.
13
+
14
+ ## 3. Commit changes
15
+ - Stage all relevant changed files (including the version bump and any uncommitted work).
16
+ - Commit with a descriptive message summarizing the changes.
17
+
18
+ ## 4. Build the gem
19
+ ```
20
+ gem build snitch.gemspec
21
+ ```
22
+ This creates a `.gem` file in the project root.
23
+
24
+ ## 5. Push to RubyGems
25
+ ```
26
+ gem push snitch-rails-<VERSION>.gem
27
+ ```
28
+ Replace `<VERSION>` with the version from step 1.
29
+
30
+ ## 6. Tag, push, and create GitHub release
31
+ ```
32
+ git tag v<VERSION>
33
+ git push origin main
34
+ git push origin v<VERSION>
35
+ gh release create v<VERSION> --title "v<VERSION>" --latest
36
+ ```
37
+
38
+ ## 7. Clean up
39
+ Remove the `.gem` file from the project root (it's in .gitignore but clean up anyway):
40
+ ```
41
+ rm snitch-rails-<VERSION>.gem
42
+ ```
43
+
44
+ ## 8. Confirm
45
+ Report the published version and RubyGems URL: `https://rubygems.org/gems/snitch-rails`
data/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # Highlite
2
+
3
+ A Rails engine that wraps PDF.js to provide a drop-in PDF viewer with text and area highlighting. Powered by Stimulus controllers and importmap-rails.
4
+
5
+ ## Features
6
+
7
+ - Full PDF rendering via PDF.js (CDN-served, zero npm dependencies)
8
+ - Text highlighting -- select text to highlight it
9
+ - Area highlighting -- draw rectangles over any region
10
+ - Four default highlight colors (yellow, green, blue, pink)
11
+ - Three-panel layout: outline/thumbnails sidebar, PDF viewer, highlights panel
12
+ - Highlight persistence via localStorage
13
+ - Keyboard shortcuts for zoom (Ctrl +/-, Ctrl 0)
14
+ - Outline (table of contents) extracted from PDF metadata
15
+ - Page thumbnails with lazy loading
16
+ - Overridable right sidebar for custom integrations
17
+ - Fully configurable via Ruby initializer
18
+
19
+ ## Requirements
20
+
21
+ - Ruby >= 3.1
22
+ - Rails >= 7.1
23
+ - importmap-rails
24
+
25
+ ## Installation
26
+
27
+ Add to your Gemfile:
28
+
29
+ ```ruby
30
+ gem "highlite"
31
+ ```
32
+
33
+ Run the install generator:
34
+
35
+ ```bash
36
+ bin/rails generate highlite:install
37
+ ```
38
+
39
+ This creates `config/initializers/highlite.rb` with default configuration.
40
+
41
+ To also copy the right sidebar partial for customization:
42
+
43
+ ```bash
44
+ bin/rails generate highlite:install --sidebar
45
+ ```
46
+
47
+ ## Quick Start
48
+
49
+ In any view:
50
+
51
+ ```erb
52
+ <%= highlite_viewer(url: url_for(@document.file), document_id: @document.id) %>
53
+ ```
54
+
55
+ That's it -- a full PDF viewer with highlighting is rendered.
56
+
57
+ ## Configuration
58
+
59
+ Configure in `config/initializers/highlite.rb`:
60
+
61
+ ```ruby
62
+ Highlite.configure do |config|
63
+ config.pdf_js_version = "5.4.624"
64
+
65
+ config.default_colors = [
66
+ "rgba(255, 226, 143, 0.5)", # yellow
67
+ "rgba(166, 227, 161, 0.5)", # green
68
+ "rgba(137, 180, 250, 0.5)", # blue
69
+ "rgba(245, 194, 231, 0.5)" # pink
70
+ ]
71
+
72
+ config.toolbar_tools = [:text, :area]
73
+
74
+ config.right_sidebar_partial = "my_app/custom_sidebar"
75
+ end
76
+ ```
77
+
78
+ | Option | Default | Description |
79
+ |---|---|---|
80
+ | `pdf_js_version` | `"5.4.624"` | PDF.js version loaded from jsDelivr CDN |
81
+ | `default_colors` | Yellow, green, blue, pink (rgba) | Array of highlight color strings |
82
+ | `toolbar_tools` | `[:text, :area]` | Enabled tool types in the floating toolbar |
83
+ | `right_sidebar_partial` | `nil` | Custom partial path for the right sidebar |
84
+
85
+ ## Helper Options
86
+
87
+ The `highlite_viewer` helper accepts:
88
+
89
+ | Option | Type | Default | Description |
90
+ |---|---|---|---|
91
+ | `url` | String | *required* | URL of the PDF to display |
92
+ | `document_id` | String | *required* | Unique ID for highlight storage |
93
+ | `scale` | Number | `1.5` | Initial zoom scale |
94
+ | `show_toolbar` | Boolean | `true` | Show the top toolbar with zoom controls |
95
+ | `show_left_sidebar` | Boolean | `true` | Show the outline/thumbnails sidebar |
96
+ | `show_right_sidebar` | Boolean | `true` | Show the highlights panel |
97
+ | `right_sidebar_partial` | String | `nil` | Override the right sidebar partial for this instance |
98
+
99
+ ## Stimulus Controllers
100
+
101
+ Highlite registers four Stimulus controllers with the `highlite--` prefix:
102
+
103
+ | Controller | Identifier | Purpose |
104
+ |---|---|---|
105
+ | ViewerController | `highlite--viewer` | PDF rendering, zoom, page navigation |
106
+ | HighlightController | `highlite--highlight` | Drawing and managing highlights |
107
+ | SidebarController | `highlite--sidebar` | Left sidebar (outline + thumbnails) |
108
+ | HighlightsPanelController | `highlite--highlights-panel` | Right sidebar highlights list |
109
+
110
+ ## Custom Events
111
+
112
+ All events are dispatched with the `highlite:` prefix and bubble up the DOM:
113
+
114
+ | Event | Detail | Description |
115
+ |---|---|---|
116
+ | `highlite:document-loaded` | `{ pageCount, title, outline }` | PDF document loaded |
117
+ | `highlite:page-changed` | `{ page, totalPages }` | Visible page changed |
118
+ | `highlite:highlight-created` | `{ id, page, type, color, text, rects }` | New highlight added |
119
+ | `highlite:highlight-removed` | `{ id }` | Highlight deleted |
120
+ | `highlite:highlight-selected` | `{ id, page }` | Highlight clicked |
121
+ | `highlite:highlights-cleared` | `{ page }` | Highlights cleared (`page` is null for all) |
122
+
123
+ ## Manual Controller Registration
124
+
125
+ If you need to register controllers manually (e.g., you have your own Stimulus application):
126
+
127
+ ```javascript
128
+ import { registerControllers } from "highlite"
129
+ import { Application } from "@hotwired/stimulus"
130
+
131
+ const application = Application.start()
132
+ registerControllers(application)
133
+ ```
134
+
135
+ ## Customizing the Right Sidebar
136
+
137
+ Run the generator with `--sidebar` to copy the default partial:
138
+
139
+ ```bash
140
+ bin/rails generate highlite:install --sidebar
141
+ ```
142
+
143
+ This creates `app/views/highlite/_right_sidebar.html.erb` in your app, which takes precedence over the gem's default. Or set `config.right_sidebar_partial` to point to any partial in your app.
144
+
145
+ ## Development
146
+
147
+ Clone the repo and install dependencies:
148
+
149
+ ```bash
150
+ bin/setup
151
+ ```
152
+
153
+ Run the test suite:
154
+
155
+ ```bash
156
+ bundle exec rake spec
157
+ ```
158
+
159
+ Run the linter:
160
+
161
+ ```bash
162
+ bundle exec rubocop
163
+ ```
164
+
165
+ Launch the dummy app for manual testing:
166
+
167
+ ```bash
168
+ cd test/dummy
169
+ bin/rails server
170
+ ```
171
+
172
+ Then open http://localhost:3000.
173
+
174
+ ## License
175
+
176
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]