https://github.com/lordsynergy/editor_rails
Editor.js rendering and validation engine for Ruby and Rails
https://github.com/lordsynergy/editor_rails
content editorjs json rails renderer ruby wysiwyg
Last synced: about 1 year ago
JSON representation
Editor.js rendering and validation engine for Ruby and Rails
- Host: GitHub
- URL: https://github.com/lordsynergy/editor_rails
- Owner: lordsynergy
- License: mit
- Created: 2025-04-22T14:34:41.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-22T15:44:00.000Z (about 1 year ago)
- Last Synced: 2025-04-22T15:45:09.745Z (about 1 year ago)
- Topics: content, editorjs, json, rails, renderer, ruby, wysiwyg
- Language: Ruby
- Homepage: https://rubygems.org/gems/editor_rails
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# EditorRails
[](LICENSE.txt)
EditorRails is a Ruby gem that brings [Editor.js](https://editorjs.io/) support to Rails applications.
It allows rendering JSON data generated by Editor.js into safe HTML and plain text.
---
## Features
- Support for structured content (Editor.js blocks)
- Built-in validation using JSON Schema
- Secure HTML output via escaping
- Configurable block rendering system
- No JavaScript dependencies required on the server side
---
## Installation
Add this line to your Gemfile:
```ruby
gem "editor_rails"
```
And then execute:
```bash
bundle install
```
---
## Usage
```
data = {
"time" => "123456789",
"blocks" => [
{ "type" => "paragraph", "data" => { "text" => "Hello world" } }
]
}
```
```bash
document = EditorRails::Document.new(data)
document.render(format: :html)
# => "
Hello <b>world</b>
"
document.render(format: :plain)
# => "Hello world"
```
---
## Configuration
The gem includes a default schema for the `paragraph` block, located at:
```
lib/editor_rails/schemas/
```
You can configure enabled block types and schema path:
```ruby
EditorRails.configure do |config|
config.enabled_blocks = %w[paragraph]
config.schemas_path = Rails.root.join("config/editor_schemas").to_s
end
```
Schemas should follow the JSON Schema format and be stored in YAML files.
Each block must have a schema named like paragraph.yml, header.yml, etc.
---
## Development
To run tests and linters:
```bash
bundle exec rake
```
#### Rendering Custom Blocks
To support a new block:
1. Create a class in EditorRails::Blocks namespace (e.g., Header)
2. Inherit from EditorRails::Blocks::Base
3. Implement render and plain
4. Add a corresponding schema
```ruby
module EditorRails
module Blocks
class Header < Base
def render
"
#{ERB::Util.html_escape(data["text"])}
"
end
def plain
data["text"].to_s
end
end
end
end
```
---
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/lordsynergy/editor_rails.
---
## License
This gem is licensed under the [MIT License](https://opensource.org/license/MIT).