editor_rails 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 11ad8dc3c203be3d9ecf220a8dca95fdb601f380430500b6e3715d7c6a86896e
4
+ data.tar.gz: e8f0fac1a186d2aa0254f08be707aba0fc7b4a3313ece399d423a55bedb96b73
5
+ SHA512:
6
+ metadata.gz: dcc0b48d1748fc00d32ef66ae587b2afac439386d2eb5bc1a126c2c22e1b874ced92d7113f9005118b044e7fca342c7045b319c07cc30e72e1dc1f8ff375a794
7
+ data.tar.gz: 159d75f79720dcf0d7dcbab42f4a1a35207a4911566f6cd4e9ac7129ea85d41dfd950a8880e4831dea833978fb7ee33c0a899a93ab9701e65fcbee50f29b8bbd
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ plugins:
2
+ - rubocop-rails
3
+ - rubocop-performance
4
+ - rubocop-rake
5
+ - rubocop-rspec
6
+ AllCops:
7
+ TargetRubyVersion: 3.4
8
+ NewCops: enable
9
+ Style/StringLiterals:
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/StringLiteralsInInterpolation:
13
+ EnforcedStyle: double_quotes
14
+
15
+ Rails/OutputSafety:
16
+ Enabled: false
17
+ Metrics/MethodLength:
18
+ Enabled: true
19
+ CountComments: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
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
+ ---
9
+
10
+ ## [Unreleased]
11
+
12
+ ### Added
13
+ - Initial support for rendering Editor.js blocks (`paragraph`) in HTML and plain text.
14
+ - JSON schema validation for documents and blocks.
15
+ - Configurable list of allowed block types.
16
+ - Default error handling and logging of skipped blocks.
17
+ - Documentation for each component and setup.
18
+
19
+ ---
20
+
21
+ ## [0.1.0] - 2025-04-22
22
+
23
+ ### Added
24
+ - First public release of the `editor_rails` gem.
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Georgy Shcherbakov
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # EditorRails
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.txt)
4
+
5
+ EditorRails is a Ruby gem that brings [Editor.js](https://editorjs.io/) support to Rails applications.
6
+ It allows rendering JSON data generated by Editor.js into safe HTML and plain text.
7
+
8
+ ---
9
+
10
+ ## Features
11
+
12
+ - Support for structured content (Editor.js blocks)
13
+ - Built-in validation using JSON Schema
14
+ - Secure HTML output via escaping
15
+ - Configurable block rendering system
16
+ - No JavaScript dependencies required on the server side
17
+
18
+ ---
19
+
20
+ ## Installation
21
+
22
+ Add this line to your Gemfile:
23
+
24
+ ```ruby
25
+ gem "editor_rails"
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ ```bash
31
+ bundle install
32
+ ```
33
+
34
+ ---
35
+
36
+ ## Usage
37
+
38
+ ```
39
+ data = {
40
+ "time" => "123456789",
41
+ "blocks" => [
42
+ { "type" => "paragraph", "data" => { "text" => "Hello <b>world</b>" } }
43
+ ]
44
+ }
45
+ ```
46
+
47
+ ```bash
48
+ document = EditorRails::Document.new(data)
49
+ document.render(format: :html)
50
+ # => "<p>Hello &lt;b&gt;world&lt;/b&gt;</p>"
51
+
52
+ document.render(format: :plain)
53
+ # => "Hello <b>world</b>"
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Configuration
59
+
60
+ The gem includes a default schema for the `paragraph` block, located at:
61
+
62
+ ```
63
+ lib/editor_rails/schemas/
64
+ ```
65
+
66
+ You can configure enabled block types and schema path:
67
+
68
+ ```ruby
69
+ EditorRails.configure do |config|
70
+ config.enabled_blocks = %w[paragraph]
71
+ config.schemas_path = Rails.root.join("config/editor_schemas").to_s
72
+ end
73
+ ```
74
+
75
+ Schemas should follow the JSON Schema format and be stored in YAML files.
76
+ Each block must have a schema named like paragraph.yml, header.yml, etc.
77
+
78
+ ---
79
+
80
+ ## Development
81
+
82
+ To run tests and linters:
83
+
84
+ ```bash
85
+ bundle exec rake
86
+ ```
87
+
88
+ #### Rendering Custom Blocks
89
+
90
+ To support a new block:
91
+
92
+ 1. Create a class in EditorRails::Blocks namespace (e.g., Header)
93
+ 2. Inherit from EditorRails::Blocks::Base
94
+ 3. Implement render and plain
95
+ 4. Add a corresponding schema
96
+
97
+ ```ruby
98
+ module EditorRails
99
+ module Blocks
100
+ class Header < Base
101
+ def render
102
+ "<h1>#{ERB::Util.html_escape(data["text"])}</h1>"
103
+ end
104
+
105
+ def plain
106
+ data["text"].to_s
107
+ end
108
+ end
109
+ end
110
+ end
111
+ ```
112
+
113
+ ---
114
+
115
+ ## Contributing
116
+
117
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lordsynergy/editor_rails.
118
+
119
+ ---
120
+
121
+ ## License
122
+
123
+ This gem is licensed under the [MIT License](https://opensource.org/license/MIT).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rakefile
4
+
5
+ require "bundler/gem_tasks"
6
+ require "rspec/core/rake_task"
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ require "rubocop/rake_task"
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ task default: %i[spec rubocop]
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/editor_rails/blocks/base.rb
4
+ module EditorRails
5
+ module Blocks
6
+ # Abstract base class for all EditorRails blocks.
7
+ # Implements schema validation using JSON Schemer and requires subclasses
8
+ # to implement `render` (HTML) and `plain` (text) output methods.
9
+ #
10
+ # @abstract
11
+ class Base
12
+ attr_reader :data
13
+
14
+ def initialize(data)
15
+ @data = data
16
+ validate!
17
+ end
18
+
19
+ def render
20
+ raise NotImplementedError
21
+ end
22
+
23
+ def plain
24
+ raise NotImplementedError
25
+ end
26
+
27
+ def validate!
28
+ raise Errors::InvalidBlock, "Anonymous block class has no name" unless self.class.name
29
+
30
+ schema = schema_for(self.class.name)
31
+ EditorRails::SchemaValidator.validate!(
32
+ data: data,
33
+ schema: schema,
34
+ error_class: Errors::InvalidBlock,
35
+ context: self.class.name
36
+ )
37
+ end
38
+
39
+ private
40
+
41
+ def schema_for(class_name)
42
+ schema_file = "#{class_name.demodulize.underscore}.yml"
43
+ schema_path = File.join(EditorRails.config.schemas_path, schema_file)
44
+ raise Errors::InvalidBlock, "Missing schema file for #{class_name}" unless File.exist?(schema_path)
45
+
46
+ YAML.load_file(schema_path)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/editor_rails/blocks/paragraph.rb
4
+ module EditorRails
5
+ module Blocks
6
+ # Paragraph block rendering logic.
7
+ # Converts "paragraph" block data into a `<p>` HTML element and plain text string.
8
+ #
9
+ # Expects schema to define at least a "text" property in the data.
10
+ #
11
+ # @see EditorRails::Blocks::Base
12
+ class Paragraph < Base
13
+ def render
14
+ "<p>#{ERB::Util.html_escape(data["text"])}</p>"
15
+ end
16
+
17
+ def plain
18
+ data["text"].to_s
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/editor_rails/config.rb
4
+ module EditorRails
5
+ # Configuration object for EditorRails.
6
+ # Used to set block schemas path and list of enabled block types.
7
+ #
8
+ # @see EditorRails.configure
9
+ class Config
10
+ attr_accessor :schemas_path, :enabled_blocks
11
+
12
+ def initialize
13
+ @schemas_path = File.join(EditorRails.root, "lib", "editor_rails", "schemas")
14
+ @enabled_blocks = %w[paragraph]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/editor_rails/document.rb
4
+ module EditorRails
5
+ # Represents an EditorJS document parsed from a Hash or JSON structure.
6
+ # Validates the document structure and renders its blocks using configured renderers.
7
+ #
8
+ # @example Rendering HTML
9
+ # document = EditorRails::Document.new(editorjs_data)
10
+ # document.render(format: :html)
11
+ class Document
12
+ attr_reader :blocks
13
+
14
+ def initialize(editorjs_data)
15
+ @editorjs_data = editorjs_data
16
+ validate!
17
+ @blocks = parse_blocks(editorjs_data["blocks"])
18
+ end
19
+
20
+ def render(format: :html)
21
+ renderer = renderer_for(format)
22
+ renderer.render(@blocks)
23
+ end
24
+
25
+ private
26
+
27
+ def parse_blocks(blocks_data)
28
+ blocks_data.filter_map { |block_data| build_block(block_data) }
29
+ end
30
+
31
+ def build_block(block_data)
32
+ klass = block_class(block_data["type"])
33
+ klass.new(block_data["data"])
34
+ rescue StandardError => e
35
+ EditorRails.logger.warn("Invalid block skipped: #{e.message}")
36
+ nil
37
+ end
38
+
39
+ def block_class(type)
40
+ unless EditorRails.config.enabled_blocks.include?(type)
41
+ raise Errors::UnsupportedBlockType, "Unsupported block type: #{type}"
42
+ end
43
+
44
+ EditorRails::Blocks.const_get(type.camelize)
45
+ end
46
+
47
+ def renderer_for(format)
48
+ case format
49
+ when :html then EditorRails::Renderers::HtmlRenderer
50
+ when :plain then EditorRails::Renderers::PlainRenderer
51
+ else raise Errors::UnsupportedFormat, "Unsupported format: #{format}"
52
+ end
53
+ end
54
+
55
+ def validate!
56
+ schema = YAML.load_file(File.join(EditorRails.config.schemas_path, "document.yml"))
57
+ EditorRails::SchemaValidator.validate!(
58
+ data: @editorjs_data,
59
+ schema: schema,
60
+ error_class: Errors::InvalidDocument,
61
+ context: "(document)"
62
+ )
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/editor_rails/errors.rb
4
+ # Contains custom error classes used throughout EditorRails.
5
+ module EditorRails
6
+ # Custom error namespace for all EditorRails-specific exceptions.
7
+ module Errors
8
+ # Raised when the EditorJS document structure is invalid.
9
+ class InvalidDocument < StandardError; end
10
+
11
+ # Raised when the requested output format (e.g., :html, :plain) is not supported.
12
+ class UnsupportedFormat < StandardError; end
13
+
14
+ # Raised when a block type is not listed in the enabled blocks.
15
+ class UnsupportedBlockType < StandardError; end
16
+
17
+ # Raised when a block fails schema validation or its schema file is missing.
18
+ class InvalidBlock < StandardError; end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/editor_rails/renderers/html_renderer.rb
4
+ module EditorRails
5
+ module Renderers
6
+ # Renders an array of block objects to HTML output.
7
+ # Used internally by `EditorRails::Document`.
8
+ module HtmlRenderer
9
+ def self.render(blocks)
10
+ blocks.map(&:render).join("\n").html_safe
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/editor_rails/renderers/plain_renderer.rb
4
+ module EditorRails
5
+ module Renderers
6
+ # Renders an array of block objects to plain text output.
7
+ # Used for indexing, previews, or fallback content.
8
+ module PlainRenderer
9
+ def self.render(blocks)
10
+ blocks.map(&:plain).join("\n")
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/editor_rails/schema_validator.rb
4
+ module EditorRails
5
+ # Provides schema validation using JSON Schema via the `json_schemer` gem.
6
+ # This module is used by EditorRails::Document and block classes to validate
7
+ # structure and content of incoming EditorJS data against YAML-defined schemas.
8
+ #
9
+ # @api internal
10
+ module SchemaValidator
11
+ # Validates the given data against the provided JSON schema.
12
+ #
13
+ # @param params [Hash] a hash of named arguments:
14
+ # - :data [Hash] the data to validate
15
+ # - :schema [Hash] the JSON schema
16
+ # - :error_class [Class<StandardError>] class to raise if validation fails
17
+ # - :context [String] optional name or description to use in error messages
18
+ #
19
+ # @raise [StandardError] instance of provided error_class with detailed message
20
+ #
21
+ # @example
22
+ # EditorRails::SchemaValidator.validate!(
23
+ # data: { "time" => 123456, "blocks" => [] },
24
+ # schema: YAML.load_file("schema.yml"),
25
+ # error_class: EditorRails::Errors::InvalidDocument,
26
+ # context: "EditorJS Document"
27
+ # )
28
+ def self.validate!(params)
29
+ data, schema, error_class, context = extract_params(params)
30
+
31
+ errors = JSONSchemer.schema(schema).validate(data).to_a
32
+ return if errors.empty?
33
+
34
+ message = formatted_message(errors, context)
35
+ raise error_class, message
36
+ end
37
+
38
+ # Extracts and validates required parameters from the input hash.
39
+ #
40
+ # @param params [Hash] input hash with required keys
41
+ # @return [Array] extracted arguments in order: data, schema, error_class, context
42
+ #
43
+ # @raise [KeyError] if any required keys are missing
44
+ def self.extract_params(params)
45
+ data = params.fetch(:data)
46
+ schema = params.fetch(:schema)
47
+ error_class = params.fetch(:error_class)
48
+ context = params.fetch(:context, "(document)")
49
+
50
+ [data, schema, error_class, context]
51
+ end
52
+
53
+ # Builds a human-readable error message from validation errors.
54
+ #
55
+ # @param errors [Array<Hash>] list of validation error hashes
56
+ # @param context [String] the name of the context (block class or document)
57
+ # @return [String] formatted error message
58
+ def self.formatted_message(errors, context)
59
+ error_messages = errors.map do |err|
60
+ location = err["data_pointer"].presence || context
61
+ detail = err["message"].presence || "is invalid"
62
+ "#{location}: #{detail}"
63
+ end
64
+
65
+ "#{context} validation failed: #{error_messages.join(", ")}"
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,9 @@
1
+ # schemas/document.yml
2
+
3
+ type: object
4
+ required:
5
+ - time
6
+ - blocks
7
+ properties:
8
+ blocks:
9
+ type: array
@@ -0,0 +1,8 @@
1
+ # lib/editor_rails/schemas/paragraph.yml
2
+
3
+ type: object
4
+ required:
5
+ - text
6
+ properties:
7
+ text:
8
+ type: string
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EditorRails
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/editor_rails.rb
4
+ require "yaml"
5
+ require "active_support/all"
6
+ require "logger"
7
+ require "json_schemer"
8
+
9
+ # EditorRails provides rendering and configuration logic for EditorJS-compatible
10
+ # data in Ruby applications. It allows transforming structured block-based data
11
+ # into HTML and plain text formats.
12
+ #
13
+ # You can configure enabled blocks and schema paths using `.configure`.
14
+ #
15
+ # @example Basic usage
16
+ # EditorRails.configure do |config|
17
+ # config.enabled_blocks = %w[paragraph]
18
+ # end
19
+ module EditorRails
20
+ # Base error class for all EditorRails-specific exceptions.
21
+ # All library-level exceptions should inherit from this class.
22
+ class Error < StandardError; end
23
+
24
+ class << self
25
+ attr_writer :css_name_prefix, :logger
26
+
27
+ def root
28
+ File.expand_path("..", __dir__)
29
+ end
30
+
31
+ def config
32
+ @config ||= Config.new
33
+ end
34
+
35
+ def configure
36
+ yield config
37
+ end
38
+
39
+ def logger
40
+ @logger ||= Logger.new($stdout, progname: "EditorRails", level: Logger::INFO)
41
+ end
42
+
43
+ def css_name_prefix
44
+ @css_name_prefix ||= "editor_js--"
45
+ end
46
+ end
47
+ end
48
+
49
+ require_relative "editor_rails/errors"
50
+ require_relative "editor_rails/config"
51
+ require_relative "editor_rails/document"
52
+ require_relative "editor_rails/renderers/html_renderer"
53
+ require_relative "editor_rails/renderers/plain_renderer"
54
+ require_relative "editor_rails/blocks/base"
55
+ require_relative "editor_rails/blocks/paragraph"
56
+ require_relative "editor_rails/version"
57
+ require_relative "editor_rails/schema_validator"
@@ -0,0 +1,4 @@
1
+ module EditorRails
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: editor_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Georgy Shcherbakov
8
+ - Sergey Arkhipov
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '8.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '8.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '8.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '8.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json_schemer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.4.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.4.0
55
+ description: Library for rendering and validating Editor.js documents in Rails applications
56
+ email:
57
+ - lordsynergymail@gmail.com
58
+ - sergey-arkhipov@ya.ru
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - CHANGELOG.md
66
+ - CODE_OF_CONDUCT.md
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - lib/editor_rails.rb
71
+ - lib/editor_rails/blocks/base.rb
72
+ - lib/editor_rails/blocks/paragraph.rb
73
+ - lib/editor_rails/config.rb
74
+ - lib/editor_rails/document.rb
75
+ - lib/editor_rails/errors.rb
76
+ - lib/editor_rails/renderers/html_renderer.rb
77
+ - lib/editor_rails/renderers/plain_renderer.rb
78
+ - lib/editor_rails/schema_validator.rb
79
+ - lib/editor_rails/schemas/document.yml
80
+ - lib/editor_rails/schemas/paragraph.yml
81
+ - lib/editor_rails/version.rb
82
+ - sig/editor_rails.rbs
83
+ homepage: https://github.com/lordsynergy/editor_rails
84
+ licenses:
85
+ - MIT
86
+ metadata:
87
+ homepage_uri: https://github.com/lordsynergy/editor_rails
88
+ documentation_uri: https://github.com/lordsynergy/editor_rails#readme
89
+ changelog_uri: https://github.com/lordsynergy/editor_rails/blob/master/CHANGELOG.md
90
+ source_code_uri: https://github.com/lordsynergy/editor_rails
91
+ bug_tracker_uri: https://github.com/lordsynergy/editor_rails/issues
92
+ rubygems_mfa_required: 'true'
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '3.4'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.6.2
108
+ specification_version: 4
109
+ summary: Editor.js renderer for Ruby on Rails
110
+ test_files: []