trix-genius 0.0.1a

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: 833ff434d3a6fc0c9dd9358b6b5d712b82cf2a90010952c48605a1192c8d9cca
4
+ data.tar.gz: 2c85b80fab2601ebb131674a297691644b747605034d997b91b580be5d0a70f0
5
+ SHA512:
6
+ metadata.gz: 148429f5e3f0d3ed5a80bebdb7714d5aada09d6def2a0ef8230659babf93135e7c04e99317f58ee76f5949772df72778e8d40095e9eaf3b7119f480534b26b00
7
+ data.tar.gz: 3aa785da64a4eed332748d88159a4b3c46b85f3607efa672e0f6db75663c70e89e41181042f5ff23cd5fee16e49c81491cc7368d4937230c3fd407e78971ea92
@@ -0,0 +1,35 @@
1
+ require "rails/generators"
2
+
3
+ module TrixGenius
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ def create_initializer
9
+ initializer "trix_genius" <<~RUBY
10
+ TrixGenius.configure do |config|
11
+ config.deepseek_api_key=ENV['DEEPSEEK_API_KEY']
12
+ end
13
+ RUBY
14
+ end
15
+
16
+ def update_applications_js
17
+ # app/javascript/application.js
18
+
19
+ # import "controllers"
20
+ # import "trix"
21
+ # import "@rails/actiontext"
22
+
23
+
24
+ # app/javascript/controllers/application.js
25
+ # import TrixController from "controllers/trix-controller"
26
+ # application.register("trix", TrixController)
27
+ end
28
+
29
+ def create_stimulus_controller
30
+ copy_file "trix_genius_controller.js", "app/javascript/controllers/trix_genius_controller.js"
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,54 @@
1
+ import { Controller } from "@hotwired/stimulus";
2
+ export default class extends Controller {
3
+ connect() {
4
+ // Use an arrow function to preserve `this` context
5
+ addEventListener("trix-initialize", (event) => {
6
+ const trixEditor = event.target;
7
+
8
+ // Create the AI button
9
+ const aiButton = document.createElement("button");
10
+ aiButton.setAttribute("type", "button");
11
+ aiButton.setAttribute("tabindex", -1);
12
+ aiButton.setAttribute("title", "Correct Orthography");
13
+ aiButton.classList.add("trix-button"); // Use Trix's default button styling
14
+ aiButton.innerHTML = `
15
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" fill="currentColor">
16
+ <path d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z"/>
17
+ </svg>
18
+ `;
19
+
20
+ // Append the button to the toolbar
21
+ document.querySelector(".trix-button-group--text-tools").appendChild(aiButton);
22
+
23
+ // Attach the click event to the button
24
+ aiButton.addEventListener("click", () => {
25
+ this.correctOrthography(trixEditor);
26
+ });
27
+ });
28
+ }
29
+
30
+ async correctOrthography(trixEditor) {
31
+ try {
32
+ const editor = trixEditor.editor;
33
+ const content = editor.getDocument().toString(); // Get the current content
34
+
35
+ // Send the content to the backend for correction
36
+ const response = await fetch("/orthography/correct", {
37
+ method: "POST",
38
+ headers: { "Content-Type": "application/json" },
39
+ body: JSON.stringify({ text: content }),
40
+ });
41
+
42
+ if (!response.ok) {
43
+ throw new Error("Network response was not ok");
44
+ }
45
+
46
+ const result = await response.json();
47
+
48
+ editor.loadHTML(result.corrected_text);
49
+ } catch (error) {
50
+ console.error("Error correcting orthography:", error);
51
+ alert("An error occurred while correcting orthography.");
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,5 @@
1
+ module TrixGenius
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace TrixGenius
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module TrixGenius
2
+ class << self
3
+ attr_accessor :deepseek_api_key
4
+
5
+ def configure
6
+ yield self
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trix-genius
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1a
5
+ platform: ruby
6
+ authors:
7
+ - Giménez Silva Germán Alberto https://rubystacknews.com/
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-04-01 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '6.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '6.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: stimulus
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: trix
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ description: Trix-Genius adds AI-powered buttons and other custom controls to Trix
55
+ editor using Stimulus.
56
+ email: ggerman@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/generators/trix-genius/install_generator.rb
62
+ - lib/generators/trix-genius/templates/trix_genius_controller.js
63
+ - lib/trix-genius.rb
64
+ - lib/trix-genius/engine.rb
65
+ homepage: https://rubystacknews.com/
66
+ licenses:
67
+ - GNU
68
+ metadata: {}
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.6.2
84
+ specification_version: 4
85
+ summary: Integrates AI-powered buttons with Trix using Stimulus
86
+ test_files: []