activeadmin_mitosis_editor 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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +17 -0
- data/CLAUDE.md +118 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +126 -0
- data/RELEASE.md +80 -0
- data/Rakefile +2 -0
- data/activeadmin_mitosis_editor.gemspec +17 -0
- data/app/views/inputs/mitosis_editor_input/_dependencies.html.erb +9 -0
- data/app/views/inputs/mitosis_editor_input/_form.html.erb +52 -0
- data/bin/console +5 -0
- data/bin/setup +14 -0
- data/demo/.dockerignore +51 -0
- data/demo/.gitattributes +9 -0
- data/demo/.gitignore +37 -0
- data/demo/.kamal/hooks/docker-setup.sample +3 -0
- data/demo/.kamal/hooks/post-app-boot.sample +3 -0
- data/demo/.kamal/hooks/post-deploy.sample +14 -0
- data/demo/.kamal/hooks/post-proxy-reboot.sample +3 -0
- data/demo/.kamal/hooks/pre-app-boot.sample +3 -0
- data/demo/.kamal/hooks/pre-build.sample +51 -0
- data/demo/.kamal/hooks/pre-connect.sample +47 -0
- data/demo/.kamal/hooks/pre-deploy.sample +122 -0
- data/demo/.kamal/hooks/pre-proxy-reboot.sample +3 -0
- data/demo/.kamal/secrets +20 -0
- data/demo/.rubocop.yml +8 -0
- data/demo/.ruby-version +1 -0
- data/demo/Dockerfile +76 -0
- data/demo/Gemfile +78 -0
- data/demo/Procfile.dev +2 -0
- data/demo/README.md +24 -0
- data/demo/Rakefile +6 -0
- data/demo/app/admin/articles.rb +12 -0
- data/demo/app/admin/dashboard.rb +17 -0
- data/demo/app/admin/pages.rb +12 -0
- data/demo/app/admin/posts.rb +12 -0
- data/demo/app/assets/builds/.keep +0 -0
- data/demo/app/assets/builds/active_admin.css +3852 -0
- data/demo/app/assets/images/.keep +0 -0
- data/demo/app/assets/stylesheets/active_admin.css +3 -0
- data/demo/app/assets/stylesheets/application.css +1 -0
- data/demo/app/assets/stylesheets/mitosis-editor.css +1 -0
- data/demo/app/assets/stylesheets/theme-dark.css +1 -0
- data/demo/app/assets/stylesheets/theme-light.css +1 -0
- data/demo/app/controllers/application_controller.rb +7 -0
- data/demo/app/controllers/articles_controller.rb +7 -0
- data/demo/app/controllers/concerns/.keep +0 -0
- data/demo/app/helpers/application_helper.rb +2 -0
- data/demo/app/helpers/articles_helper.rb +2 -0
- data/demo/app/javascript/application.js +3 -0
- data/demo/app/javascript/controllers/application.js +9 -0
- data/demo/app/javascript/controllers/hello_controller.js +7 -0
- data/demo/app/javascript/controllers/index.js +4 -0
- data/demo/app/jobs/application_job.rb +7 -0
- data/demo/app/mailers/application_mailer.rb +4 -0
- data/demo/app/models/application_record.rb +3 -0
- data/demo/app/models/article.rb +5 -0
- data/demo/app/models/concerns/.keep +0 -0
- data/demo/app/models/page.rb +5 -0
- data/demo/app/models/post.rb +5 -0
- data/demo/app/views/articles/_article.html.erb +12 -0
- data/demo/app/views/articles/_article.json.jbuilder +2 -0
- data/demo/app/views/articles/_form.html.erb +27 -0
- data/demo/app/views/articles/edit.html.erb +12 -0
- data/demo/app/views/articles/index.html.erb +16 -0
- data/demo/app/views/articles/index.json.jbuilder +1 -0
- data/demo/app/views/articles/new.html.erb +11 -0
- data/demo/app/views/articles/show.html.erb +10 -0
- data/demo/app/views/articles/show.json.jbuilder +1 -0
- data/demo/app/views/inputs/mitosis_editor_input/_dependencies.html.erb +17 -0
- data/demo/app/views/layouts/application.html.erb +29 -0
- data/demo/app/views/layouts/mailer.html.erb +13 -0
- data/demo/app/views/layouts/mailer.text.erb +1 -0
- data/demo/app/views/pwa/manifest.json.erb +22 -0
- data/demo/app/views/pwa/service-worker.js +26 -0
- data/demo/bin/brakeman +7 -0
- data/demo/bin/bundler-audit +6 -0
- data/demo/bin/ci +6 -0
- data/demo/bin/dev +8 -0
- data/demo/bin/docker-entrypoint +8 -0
- data/demo/bin/importmap +4 -0
- data/demo/bin/jobs +6 -0
- data/demo/bin/kamal +27 -0
- data/demo/bin/rails +4 -0
- data/demo/bin/rake +4 -0
- data/demo/bin/rubocop +8 -0
- data/demo/bin/setup +35 -0
- data/demo/bin/thrust +5 -0
- data/demo/config/application.rb +27 -0
- data/demo/config/boot.rb +4 -0
- data/demo/config/bundler-audit.yml +5 -0
- data/demo/config/cable.yml +17 -0
- data/demo/config/cache.yml +16 -0
- data/demo/config/ci.rb +23 -0
- data/demo/config/credentials.yml.enc +1 -0
- data/demo/config/database.yml +41 -0
- data/demo/config/deploy.yml +120 -0
- data/demo/config/environment.rb +21 -0
- data/demo/config/environments/development.rb +78 -0
- data/demo/config/environments/production.rb +90 -0
- data/demo/config/environments/test.rb +53 -0
- data/demo/config/importmap.rb +7 -0
- data/demo/config/initializers/active_admin.rb +275 -0
- data/demo/config/initializers/activeadmin_mitosis_editor.rb +19 -0
- data/demo/config/initializers/assets.rb +7 -0
- data/demo/config/initializers/content_security_policy.rb +29 -0
- data/demo/config/initializers/filter_parameter_logging.rb +8 -0
- data/demo/config/initializers/inflections.rb +16 -0
- data/demo/config/locales/en.yml +31 -0
- data/demo/config/puma.rb +42 -0
- data/demo/config/queue.yml +18 -0
- data/demo/config/recurring.yml +15 -0
- data/demo/config/routes.rb +16 -0
- data/demo/config/storage.yml +27 -0
- data/demo/config.ru +6 -0
- data/demo/db/cable_schema.rb +11 -0
- data/demo/db/cache_schema.rb +12 -0
- data/demo/db/migrate/20260215110410_create_active_admin_comments.rb +16 -0
- data/demo/db/migrate/20260215110416_create_articles.rb +10 -0
- data/demo/db/migrate/20260216124916_create_posts.rb +10 -0
- data/demo/db/migrate/20260216124919_create_pages.rb +10 -0
- data/demo/db/queue_schema.rb +129 -0
- data/demo/db/schema.rb +48 -0
- data/demo/db/seeds.rb +9 -0
- data/demo/lib/tasks/.keep +0 -0
- data/demo/log/.keep +0 -0
- data/demo/package-lock.json +1260 -0
- data/demo/package.json +13 -0
- data/demo/public/400.html +135 -0
- data/demo/public/404.html +135 -0
- data/demo/public/406-unsupported-browser.html +135 -0
- data/demo/public/422.html +135 -0
- data/demo/public/500.html +135 -0
- data/demo/public/icon.png +0 -0
- data/demo/public/icon.svg +3 -0
- data/demo/public/robots.txt +1 -0
- data/demo/script/.keep +0 -0
- data/demo/spec/rails_helper.rb +72 -0
- data/demo/spec/spec_helper.rb +94 -0
- data/demo/spec/system/admin_articles_spec.rb +22 -0
- data/demo/spec/system/mitosis_editor_prism_spec.rb +34 -0
- data/demo/spec/system/mitosis_editor_theme_spec.rb +63 -0
- data/demo/storage/.keep +0 -0
- data/demo/tailwind-active_admin.config.js +17 -0
- data/demo/tmp/.keep +0 -0
- data/demo/tmp/storage/.keep +0 -0
- data/demo/vendor/.keep +0 -0
- data/demo/vendor/javascript/.keep +0 -0
- data/docs/plans/2026-02-15-mitosis-editor-gem-design.md +70 -0
- data/docs/plans/2026-02-15-mitosis-editor-gem-implementation.md +407 -0
- data/lib/activeadmin_mitosis_editor/inputs/mitosis_editor_input.rb +29 -0
- data/lib/activeadmin_mitosis_editor/railtie.rb +7 -0
- data/lib/activeadmin_mitosis_editor/version.rb +3 -0
- data/lib/activeadmin_mitosis_editor.rb +13 -0
- data/lib/generators/mitosis_editor/styles_generator.rb +23 -0
- data/lib/generators/mitosis_editor/templates/_dependencies.html.erb +17 -0
- data/lib/generators/mitosis_editor/views_generator.rb +14 -0
- data/preview.png +0 -0
- data/script/bump-version +78 -0
- data/vendor/assets/javascripts/mitosis-editor.js +61 -0
- data/vendor/assets/stylesheets/mitosis-editor.css +1 -0
- data/vendor/assets/stylesheets/theme-dark.min.css +1 -0
- data/vendor/assets/stylesheets/theme-light.min.css +1 -0
- metadata +248 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2ad40eae80694ed08d0c1d66cebcaf83a9b143511f59fd60c40267efc080242e
|
|
4
|
+
data.tar.gz: d7193e1d92c8c41fefad21f94324c82cacd0679918cac018cb27fc1aaf1d43c5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3fd8c21be7f91bb7f0a53f1457d1661badfb563d8e497cf9d6616ce75d7155380ff8e81a6cc5c2cda8149d185e4e63a9a2b656cf6ca7fa4e0e022f11b2d59d78
|
|
7
|
+
data.tar.gz: 4b3051769cebe415c0b54ef9ed21267d03cf430e7819d221e79fa298cd308bde7ec074f5866ed033949cc46c1ffd87ddf0acc70af7f010fb6a98fc72c7ee6f7a
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2025-02-15
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Initial release
|
|
14
|
+
- MitosisEditorInput Formtastic input for ActiveAdmin
|
|
15
|
+
- Split-view markdown editor using mitosis-js
|
|
16
|
+
- Light and dark theme support
|
|
17
|
+
- Prism syntax highlighting support
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
This is a Ruby gem called `activeadmin_mitosis_editor` that provides a split-view markdown editor input for ActiveAdmin forms. It wraps the mitosis-js library (a split-view markdown editor) as a Formtastic custom input type. The gem consists of:
|
|
8
|
+
|
|
9
|
+
1. **Main Gem** (`/lib`): The Ruby gem with Formtastic input class and Railtie for asset pipeline integration.
|
|
10
|
+
2. **Demo App** (`/demo`): A Rails 8.1 application demonstrating the gem's usage and system tests.
|
|
11
|
+
3. **Assets** (`/vendor/assets`): Pre-compiled mitosis-js and Prism syntax highlighter bundles. Downloaded from https://www.npmjs.com/package/@codxse/mitosis-js v1.6.1
|
|
12
|
+
|
|
13
|
+
- The gem bundles pre-compiled CSS/JS assets in `/vendor/assets`
|
|
14
|
+
- No database migrations required - stores markdown as plain strings
|
|
15
|
+
- Demo apps must copy assets to their own `/app/assets/` directory to ensure proper asset pipeline precedence
|
|
16
|
+
- Demo app uses modern Rails 8.1 with import maps and Tailwind CSS
|
|
17
|
+
- The editor is fully functional in both light and dark themes with automatic detection
|
|
18
|
+
|
|
19
|
+
## Architecture
|
|
20
|
+
|
|
21
|
+
### Gem Structure
|
|
22
|
+
- **`lib/activeadmin_mitosis_editor.rb`**: Main entry point defining the module and asset root
|
|
23
|
+
- **`lib/activeadmin_mitosis_editor/railtie.rb`**: Rails integration for the gem
|
|
24
|
+
- **`lib/activeadmin_mitosis_editor/inputs/mitosis_editor_input.rb`**: Formtastic input class that extends `StringInput`
|
|
25
|
+
- **`app/views/inputs/mitosis_editor_input/_form.html.erb`**: Form partial rendering the editor container and initialization JavaScript
|
|
26
|
+
- **`app/views/inputs/mitosis_editor_input/_dependencies.html.erb`**: Partial for conditional stylesheet loading based on theme
|
|
27
|
+
- **`vendor/assets/`**: Pre-compiled mitosis-js and Prism.js bundles (must be copied to app for use)
|
|
28
|
+
- **`lib/generators/`**: Rails generators for users to customize CSS and dependencies
|
|
29
|
+
|
|
30
|
+
## File Organization
|
|
31
|
+
|
|
32
|
+
Key directories:
|
|
33
|
+
- `/lib`: Main gem code
|
|
34
|
+
- `/app/views`: View templates for the gem
|
|
35
|
+
- `/lib/generators`: Rails generators for customization
|
|
36
|
+
- `/vendor/assets`: Pre-built mitosis-js and Prism.js bundles
|
|
37
|
+
- `/demo`: Full Rails app demonstrating the gem
|
|
38
|
+
- `/demo/app/admin`: ActiveAdmin resource definitions for demo
|
|
39
|
+
- `/demo/spec`: RSpec test suite for the demo app
|
|
40
|
+
|
|
41
|
+
### Key Implementation Details
|
|
42
|
+
- The input stores markdown content in a hidden field
|
|
43
|
+
- JavaScript initialization happens inline in the form partial, using IIFE to avoid global scope pollution
|
|
44
|
+
- Theme support: 'light', 'dark', or 'auto' (auto detects via mutation observer on `<html>` class)
|
|
45
|
+
- Form submission captures editor content via `getMarkdown()` and writes to hidden field
|
|
46
|
+
- Optional Prism syntax highlighter auto-detection via `window.Prism`
|
|
47
|
+
- Assets loaded via Rails asset pipeline, with conditional theme stylesheets
|
|
48
|
+
|
|
49
|
+
### Data Flow
|
|
50
|
+
1. User registers editor via `f.input :field, as: :mitosis_editor` in ActiveAdmin form. Look at @demo/app/admin/articles.rb for example usage.
|
|
51
|
+
2. `MitosisEditorInput` renders the form partial with editor options
|
|
52
|
+
3. Form partial loads CSS/JS via `_dependencies` and initializes editor in a container div
|
|
53
|
+
4. Editor updates hidden field on form submit via `editor.getMarkdown()`
|
|
54
|
+
5. Rails saves the markdown string to the database as usual
|
|
55
|
+
|
|
56
|
+
## Common Development Tasks
|
|
57
|
+
|
|
58
|
+
### Setup Development Environment
|
|
59
|
+
```bash
|
|
60
|
+
# Install gem dependencies
|
|
61
|
+
bin/setup
|
|
62
|
+
|
|
63
|
+
# Set up and start demo app
|
|
64
|
+
cd demo
|
|
65
|
+
bundle install
|
|
66
|
+
npm install
|
|
67
|
+
bin/rails db:create db:migrate
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Running the Demo App
|
|
71
|
+
```bash
|
|
72
|
+
# From root directory
|
|
73
|
+
cd demo
|
|
74
|
+
|
|
75
|
+
# Start development server with CSS building
|
|
76
|
+
foreman start -f Procfile.dev
|
|
77
|
+
|
|
78
|
+
# Or run manually:
|
|
79
|
+
bin/rails server # Port 3000
|
|
80
|
+
npm run build:css # In another terminal
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Building and Testing the Gem
|
|
84
|
+
```bash
|
|
85
|
+
# From gem root directory
|
|
86
|
+
|
|
87
|
+
# Build the gem package
|
|
88
|
+
rake build
|
|
89
|
+
|
|
90
|
+
# Install the built gem locally
|
|
91
|
+
rake install
|
|
92
|
+
|
|
93
|
+
# Run demo app tests (must run from demo/ directory)
|
|
94
|
+
cd demo
|
|
95
|
+
bundle exec rspec
|
|
96
|
+
|
|
97
|
+
# Run specific spec file
|
|
98
|
+
bundle exec rspec spec/system/mitosis_editor_prism_spec.rb
|
|
99
|
+
|
|
100
|
+
# Run a single test
|
|
101
|
+
bundle exec rspec spec/system/mitosis_editor_prism_spec.rb:8
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Note: RSpec is only available in the demo app, not in the gem root. The gem itself has no development dependencies; tests are integration tests in the demo Rails application.
|
|
105
|
+
|
|
106
|
+
## Dependencies
|
|
107
|
+
|
|
108
|
+
### Runtime
|
|
109
|
+
- Rails >= 6.0
|
|
110
|
+
- Formtastic >= 4.0
|
|
111
|
+
- Mitosis-js (bundled in vendor/assets)
|
|
112
|
+
|
|
113
|
+
### Development (Demo App)
|
|
114
|
+
- Rails 8.1
|
|
115
|
+
- ActiveAdmin 4.0.0.beta21
|
|
116
|
+
- RSpec + RSpec-Rails
|
|
117
|
+
- Tailwind CSS with cssbundling-rails
|
|
118
|
+
- Propshaft for asset pipeline
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 - 2026 Nadiar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# ActiveadminMitosisEditor
|
|
2
|
+
|
|
3
|
+
A Ruby gem that provides a split-view markdown editor input for ActiveAdmin, powered by mitosis-js.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your Rails application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem "activeadmin_mitosis_editor"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then run `bundle install`.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
In your ActiveAdmin resource:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
ActiveAdmin.register Article do
|
|
23
|
+
form do |f|
|
|
24
|
+
f.inputs do
|
|
25
|
+
f.input :title
|
|
26
|
+
f.input :body, as: :mitosis_editor
|
|
27
|
+
end
|
|
28
|
+
f.actions
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Editor Options
|
|
34
|
+
|
|
35
|
+
Pass serializable options to `createEditor()` via `editor_options`:
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
f.input :body, as: :mitosis_editor,
|
|
39
|
+
editor_options: { height: "400px", placeholder: "Write markdown...", theme: "dark" }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
| Option | Type | Default | Description |
|
|
43
|
+
|--------|------|---------|-------------|
|
|
44
|
+
| height | string | '500px' | Editor height |
|
|
45
|
+
| placeholder | string | '' | Placeholder text |
|
|
46
|
+
| theme | string | 'light' | Theme: 'light', 'dark', or 'auto' |
|
|
47
|
+
| readonly | boolean | false | Make editor read-only |
|
|
48
|
+
| cssVars | hash | {} | Custom CSS variables |
|
|
49
|
+
|
|
50
|
+
Any key in `editor_options` is passed through to the JS `createEditor()` call.
|
|
51
|
+
|
|
52
|
+
#### Theme Examples
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
# Light theme (default)
|
|
56
|
+
f.input :body, as: :mitosis_editor,
|
|
57
|
+
editor_options: { theme: "light" }
|
|
58
|
+
|
|
59
|
+
# Dark theme
|
|
60
|
+
f.input :body, as: :mitosis_editor,
|
|
61
|
+
editor_options: { theme: "dark" }
|
|
62
|
+
|
|
63
|
+
# Auto-detect based on system preference
|
|
64
|
+
f.input :body, as: :mitosis_editor,
|
|
65
|
+
editor_options: { theme: "auto" }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Customizing CSS
|
|
69
|
+
|
|
70
|
+
To customize CSS variables, copy the CSS files to your app:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
rails generate mitosis_editor:styles
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
This creates:
|
|
77
|
+
- `app/assets/stylesheets/mitosis_editor/mitosis-editor.css`
|
|
78
|
+
- `app/assets/stylesheets/mitosis_editor/theme-light.css`
|
|
79
|
+
- `app/assets/stylesheets/mitosis_editor/theme-dark.css`
|
|
80
|
+
|
|
81
|
+
Edit the CSS variables in these files, then update your dependencies to use your custom CSS:
|
|
82
|
+
|
|
83
|
+
```erb
|
|
84
|
+
<%= stylesheet_link_tag "mitosis_editor/mitosis-editor" %>
|
|
85
|
+
<%= stylesheet_link_tag "mitosis_editor/theme-light" %>
|
|
86
|
+
<%= javascript_include_tag "mitosis-editor" %>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Customizing Dependencies
|
|
90
|
+
|
|
91
|
+
By default, the gem loads its own CSS and JS. To control which scripts and stylesheets are loaded (e.g. to add Prism for syntax highlighting), copy the dependencies partial into your app:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
rails generate mitosis_editor:views
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
This creates `app/views/inputs/mitosis_editor_input/_dependencies.html.erb` with commented-out examples for Prism CDN. Uncomment or add whatever you need:
|
|
98
|
+
|
|
99
|
+
```erb
|
|
100
|
+
<%= stylesheet_link_tag "mitosis-editor" %>
|
|
101
|
+
<%= javascript_include_tag "mitosis-editor" %>
|
|
102
|
+
|
|
103
|
+
<%= stylesheet_link_tag "https://cdn.jsdelivr.net/npm/prismjs@1.29.0/themes/prism-tomorrow.min.css" %>
|
|
104
|
+
<%= javascript_include_tag "https://cdn.jsdelivr.net/npm/prismjs@1.29.0/prism.min.js" %>
|
|
105
|
+
<%= javascript_include_tag "https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-javascript.min.js" %>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The editor JS auto-detects `window.Prism` and passes it to `createEditor()` when present.
|
|
109
|
+
|
|
110
|
+
## Requirements
|
|
111
|
+
|
|
112
|
+
- Rails >= 6.0
|
|
113
|
+
- ActiveAdmin
|
|
114
|
+
- Formtastic
|
|
115
|
+
|
|
116
|
+
## Development
|
|
117
|
+
|
|
118
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
|
119
|
+
|
|
120
|
+
## Contributing
|
|
121
|
+
|
|
122
|
+
Bug reports and pull requests are welcome on GitHub.
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
The gem is available as open source under the terms of the MIT License.
|
data/RELEASE.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Release Guide
|
|
2
|
+
|
|
3
|
+
This document describes how to release new versions of the gem.
|
|
4
|
+
|
|
5
|
+
## Version Bumping
|
|
6
|
+
|
|
7
|
+
Use the `bump-version` script to bump the version:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
ruby script/bump-version [major|minor|patch]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The script auto-detects the bump type from commit messages:
|
|
14
|
+
- `feat!:` or `BREAKING` → major
|
|
15
|
+
- `feat:` → minor
|
|
16
|
+
- `fix:` → patch (default)
|
|
17
|
+
|
|
18
|
+
## Manual Release
|
|
19
|
+
|
|
20
|
+
1. Bump the version:
|
|
21
|
+
```bash
|
|
22
|
+
ruby script/bump-version patch
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
2. Build the gem:
|
|
26
|
+
```bash
|
|
27
|
+
gem build *.gemspec
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
3. Publish to RubyGems:
|
|
31
|
+
```bash
|
|
32
|
+
gem push activeadmin_mitosis_editor-X.X.X.gem
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
4. Create a git tag:
|
|
36
|
+
```bash
|
|
37
|
+
git tag vX.X.X
|
|
38
|
+
git push origin main --tags
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## GitHub Actions Release
|
|
42
|
+
|
|
43
|
+
The repository has an automated workflow that runs on push to `main`.
|
|
44
|
+
|
|
45
|
+
### Automatic (on push)
|
|
46
|
+
|
|
47
|
+
On every push to `main`, the workflow:
|
|
48
|
+
1. Detects version bump type from commits
|
|
49
|
+
2. Updates version in `lib/activeadmin_mitosis_editor/version.rb`
|
|
50
|
+
3. Updates CHANGELOG.md
|
|
51
|
+
4. Builds the gem
|
|
52
|
+
5. Publishes to RubyGems
|
|
53
|
+
6. Creates a git tag
|
|
54
|
+
|
|
55
|
+
### Manual (workflow dispatch)
|
|
56
|
+
|
|
57
|
+
You can manually trigger a release from the GitHub Actions UI:
|
|
58
|
+
|
|
59
|
+
1. Go to Actions → Release
|
|
60
|
+
2. Click "Run workflow"
|
|
61
|
+
3. Select version type: `patch`, `minor`, or `major`
|
|
62
|
+
4. Click "Run workflow"
|
|
63
|
+
|
|
64
|
+
## Requirements
|
|
65
|
+
|
|
66
|
+
- Ruby 3.3+
|
|
67
|
+
- RubyGems account with API key
|
|
68
|
+
- `RUBYGEMS_API_KEY` secret in GitHub repository settings
|
|
69
|
+
|
|
70
|
+
## CHANGELOG
|
|
71
|
+
|
|
72
|
+
The CHANGELOG.md follows [Keep a Changelog](https://keepachangelog.com/) format.
|
|
73
|
+
|
|
74
|
+
When bumping version, add entries under `## [Unreleased]` with appropriate change type:
|
|
75
|
+
- `### Added` - new features
|
|
76
|
+
- `### Changed` - changes to existing functionality
|
|
77
|
+
- `### Deprecated` - soon-to-be removed features
|
|
78
|
+
- `### Removed` - removed features
|
|
79
|
+
- `### Fixed` - bug fixes
|
|
80
|
+
- `### Security` - security fixes
|
data/Rakefile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require_relative "lib/activeadmin_mitosis_editor/version"
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "activeadmin_mitosis_editor"
|
|
5
|
+
spec.version = ActiveAdminMitosisEditor::VERSION
|
|
6
|
+
spec.authors = ["Nadiar"]
|
|
7
|
+
spec.email = ["codex@nadiar.id"]
|
|
8
|
+
spec.summary = "A split-view markdown editor input for ActiveAdmin"
|
|
9
|
+
spec.description = "Wraps mitosis-js as a custom input for ActiveAdmin forms"
|
|
10
|
+
spec.license = "MIT"
|
|
11
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|\.git)}) }
|
|
12
|
+
spec.require_paths = ["lib"]
|
|
13
|
+
|
|
14
|
+
spec.add_runtime_dependency "railties", ">= 6.0"
|
|
15
|
+
spec.add_runtime_dependency "formtastic", ">= 4.0"
|
|
16
|
+
spec.add_runtime_dependency "activesupport", ">= 6.0"
|
|
17
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<%
|
|
2
|
+
theme = local_assigns[:theme] || 'auto'
|
|
3
|
+
theme_light = %w[light auto].include?(theme)
|
|
4
|
+
theme_dark = %w[dark auto].include?(theme)
|
|
5
|
+
%>
|
|
6
|
+
<%= stylesheet_link_tag "mitosis-editor" %>
|
|
7
|
+
<%= stylesheet_link_tag "theme-light" if theme_light %>
|
|
8
|
+
<%= stylesheet_link_tag "theme-dark" if theme_dark %>
|
|
9
|
+
<%= javascript_include_tag "mitosis-editor" %>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<%
|
|
2
|
+
theme = editor_options.fetch(:theme, 'auto')
|
|
3
|
+
%>
|
|
4
|
+
<%= render "inputs/mitosis_editor_input/dependencies", theme: theme %>
|
|
5
|
+
|
|
6
|
+
<div class="mitosis-editor-wrapper" data-editor-options="<%= editor_options.to_json %>">
|
|
7
|
+
<div id="mitosis-editor-<%= input_html_options[:id] %>" class="mitosis-editor-container"></div>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<script>
|
|
11
|
+
(function() {
|
|
12
|
+
var container = document.getElementById('mitosis-editor-<%= input_html_options[:id] %>');
|
|
13
|
+
var wrapper = container.closest('.mitosis-editor-wrapper');
|
|
14
|
+
var options = JSON.parse(wrapper.dataset.editorOptions || '{}');
|
|
15
|
+
var hiddenInput = document.getElementById('<%= input_html_options[:id] %>');
|
|
16
|
+
|
|
17
|
+
options.container = container;
|
|
18
|
+
options.content = hiddenInput ? hiddenInput.value : '';
|
|
19
|
+
|
|
20
|
+
if (window.Prism) {
|
|
21
|
+
options.prism = window.Prism;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (window.MitosisEditor && window.MitosisEditor.createEditor) {
|
|
25
|
+
var editor = window.MitosisEditor.createEditor(options);
|
|
26
|
+
|
|
27
|
+
if (options.theme === 'auto') {
|
|
28
|
+
var htmlEl = document.documentElement;
|
|
29
|
+
var mutationObserver = new MutationObserver(function(mutations) {
|
|
30
|
+
mutations.forEach(function(mutation) {
|
|
31
|
+
if (mutation.attributeName === 'class') {
|
|
32
|
+
var isDark = htmlEl.classList.contains('dark');
|
|
33
|
+
editor.setTheme(isDark ? 'dark' : 'light');
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
mutationObserver.observe(htmlEl, { attributes: true });
|
|
38
|
+
} else {
|
|
39
|
+
editor.setTheme(options.theme);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var form = container.closest('form');
|
|
43
|
+
if (form) {
|
|
44
|
+
form.addEventListener('submit', function() {
|
|
45
|
+
if (hiddenInput && editor && editor.getMarkdown) {
|
|
46
|
+
hiddenInput.value = editor.getMarkdown();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
52
|
+
</script>
|
data/bin/console
ADDED
data/bin/setup
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require "fileutils"
|
|
3
|
+
|
|
4
|
+
APP_ROOT = File.expand_path("..", __dir__)
|
|
5
|
+
|
|
6
|
+
def system!(*args)
|
|
7
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
FileUtils.chdir APP_ROOT do
|
|
11
|
+
puts "== Installing dependencies =="
|
|
12
|
+
system! "gem install bundler --conservative"
|
|
13
|
+
system("bundle check") || system!("bundle install")
|
|
14
|
+
end
|
data/demo/.dockerignore
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# Ignore git directory.
|
|
4
|
+
/.git/
|
|
5
|
+
/.gitignore
|
|
6
|
+
|
|
7
|
+
# Ignore bundler config.
|
|
8
|
+
/.bundle
|
|
9
|
+
|
|
10
|
+
# Ignore all environment files.
|
|
11
|
+
/.env*
|
|
12
|
+
|
|
13
|
+
# Ignore all default key files.
|
|
14
|
+
/config/master.key
|
|
15
|
+
/config/credentials/*.key
|
|
16
|
+
|
|
17
|
+
# Ignore all logfiles and tempfiles.
|
|
18
|
+
/log/*
|
|
19
|
+
/tmp/*
|
|
20
|
+
!/log/.keep
|
|
21
|
+
!/tmp/.keep
|
|
22
|
+
|
|
23
|
+
# Ignore pidfiles, but keep the directory.
|
|
24
|
+
/tmp/pids/*
|
|
25
|
+
!/tmp/pids/.keep
|
|
26
|
+
|
|
27
|
+
# Ignore storage (uploaded files in development and any SQLite databases).
|
|
28
|
+
/storage/*
|
|
29
|
+
!/storage/.keep
|
|
30
|
+
/tmp/storage/*
|
|
31
|
+
!/tmp/storage/.keep
|
|
32
|
+
|
|
33
|
+
# Ignore assets.
|
|
34
|
+
/node_modules/
|
|
35
|
+
/app/assets/builds/*
|
|
36
|
+
!/app/assets/builds/.keep
|
|
37
|
+
/public/assets
|
|
38
|
+
|
|
39
|
+
# Ignore CI service files.
|
|
40
|
+
/.github
|
|
41
|
+
|
|
42
|
+
# Ignore Kamal files.
|
|
43
|
+
/config/deploy*.yml
|
|
44
|
+
/.kamal
|
|
45
|
+
|
|
46
|
+
# Ignore development files
|
|
47
|
+
/.devcontainer
|
|
48
|
+
|
|
49
|
+
# Ignore Docker-related files
|
|
50
|
+
/.dockerignore
|
|
51
|
+
/Dockerfile*
|
data/demo/.gitattributes
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# See https://git-scm.com/docs/gitattributes for more about git attribute files.
|
|
2
|
+
|
|
3
|
+
# Mark the database schema as having been generated.
|
|
4
|
+
db/schema.rb linguist-generated
|
|
5
|
+
|
|
6
|
+
# Mark any vendored files as having been vendored.
|
|
7
|
+
vendor/* linguist-vendored
|
|
8
|
+
config/credentials/*.yml.enc diff=rails_credentials
|
|
9
|
+
config/credentials.yml.enc diff=rails_credentials
|
data/demo/.gitignore
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
|
2
|
+
#
|
|
3
|
+
# Temporary files generated by your text editor or operating system
|
|
4
|
+
# belong in git's global ignore instead:
|
|
5
|
+
# `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore`
|
|
6
|
+
|
|
7
|
+
# Ignore bundler config.
|
|
8
|
+
/.bundle
|
|
9
|
+
|
|
10
|
+
# Ignore all environment files.
|
|
11
|
+
/.env*
|
|
12
|
+
|
|
13
|
+
# Ignore all logfiles and tempfiles.
|
|
14
|
+
/log/*
|
|
15
|
+
/tmp/*
|
|
16
|
+
!/log/.keep
|
|
17
|
+
!/tmp/.keep
|
|
18
|
+
|
|
19
|
+
# Ignore pidfiles, but keep the directory.
|
|
20
|
+
/tmp/pids/*
|
|
21
|
+
!/tmp/pids/
|
|
22
|
+
!/tmp/pids/.keep
|
|
23
|
+
|
|
24
|
+
# Ignore storage (uploaded files in development and any SQLite databases).
|
|
25
|
+
/storage/*
|
|
26
|
+
!/storage/.keep
|
|
27
|
+
/tmp/storage/*
|
|
28
|
+
!/tmp/storage/
|
|
29
|
+
!/tmp/storage/.keep
|
|
30
|
+
|
|
31
|
+
/public/assets
|
|
32
|
+
|
|
33
|
+
# Ignore key files for decrypting credentials and more.
|
|
34
|
+
/config/*.key
|
|
35
|
+
|
|
36
|
+
# Ignore node_modules
|
|
37
|
+
node_modules/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
# A sample post-deploy hook
|
|
4
|
+
#
|
|
5
|
+
# These environment variables are available:
|
|
6
|
+
# KAMAL_RECORDED_AT
|
|
7
|
+
# KAMAL_PERFORMER
|
|
8
|
+
# KAMAL_VERSION
|
|
9
|
+
# KAMAL_HOSTS
|
|
10
|
+
# KAMAL_ROLES (if set)
|
|
11
|
+
# KAMAL_DESTINATION (if set)
|
|
12
|
+
# KAMAL_RUNTIME
|
|
13
|
+
|
|
14
|
+
echo "$KAMAL_PERFORMER deployed $KAMAL_VERSION to $KAMAL_DESTINATION in $KAMAL_RUNTIME seconds"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
# A sample pre-build hook
|
|
4
|
+
#
|
|
5
|
+
# Checks:
|
|
6
|
+
# 1. We have a clean checkout
|
|
7
|
+
# 2. A remote is configured
|
|
8
|
+
# 3. The branch has been pushed to the remote
|
|
9
|
+
# 4. The version we are deploying matches the remote
|
|
10
|
+
#
|
|
11
|
+
# These environment variables are available:
|
|
12
|
+
# KAMAL_RECORDED_AT
|
|
13
|
+
# KAMAL_PERFORMER
|
|
14
|
+
# KAMAL_VERSION
|
|
15
|
+
# KAMAL_HOSTS
|
|
16
|
+
# KAMAL_ROLES (if set)
|
|
17
|
+
# KAMAL_DESTINATION (if set)
|
|
18
|
+
|
|
19
|
+
if [ -n "$(git status --porcelain)" ]; then
|
|
20
|
+
echo "Git checkout is not clean, aborting..." >&2
|
|
21
|
+
git status --porcelain >&2
|
|
22
|
+
exit 1
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
first_remote=$(git remote)
|
|
26
|
+
|
|
27
|
+
if [ -z "$first_remote" ]; then
|
|
28
|
+
echo "No git remote set, aborting..." >&2
|
|
29
|
+
exit 1
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
current_branch=$(git branch --show-current)
|
|
33
|
+
|
|
34
|
+
if [ -z "$current_branch" ]; then
|
|
35
|
+
echo "Not on a git branch, aborting..." >&2
|
|
36
|
+
exit 1
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
remote_head=$(git ls-remote $first_remote --tags $current_branch | cut -f1)
|
|
40
|
+
|
|
41
|
+
if [ -z "$remote_head" ]; then
|
|
42
|
+
echo "Branch not pushed to remote, aborting..." >&2
|
|
43
|
+
exit 1
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
if [ "$KAMAL_VERSION" != "$remote_head" ]; then
|
|
47
|
+
echo "Version ($KAMAL_VERSION) does not match remote HEAD ($remote_head), aborting..." >&2
|
|
48
|
+
exit 1
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
exit 0
|