trix-genius 0.0.11 → 0.0.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: baaf509c27813f29f422005956926f5867d8c871d718cfdfff70758a2bbe1da4
4
- data.tar.gz: 1285ce3f39c78cbe26baf9666e0b4c15770b010d27bafcdef827802b44018777
3
+ metadata.gz: 49ca5aace487c4ebfdd60c9a786abfea8be60aeb14b08c8f2e64768d1cd6ea0d
4
+ data.tar.gz: 60ff48a5897cbdf104d711bef41e81afe5aa805e2e834e57de32b4cec7a09d4f
5
5
  SHA512:
6
- metadata.gz: '0939fff0b6691f87db1c615503b9de5744e95a8b892bdfa6d666bb3025d296eca8c3baf27a709ad41430928d8c71a4949f863ebbd4f0edadf83224a0f6d27880'
7
- data.tar.gz: 68bdea101e83fe38d68afa5d694d059d72e93bccabb508df3da351e8fcc73a33eea2b2d3e99bb8afe6a9c977bfeda9061c1a540f5eb241ac36b529f1f8efb2f8
6
+ metadata.gz: af2e581b55224bde3a1831179ad3734e33b4d05b0775ce83907f52260d615b59d4b7266d122eb31bb79db8703a55d3ee2991508f03fdc079d734ead38b141e81
7
+ data.tar.gz: 8b7ab05be42f0c5195708a66ce5444429e37da6d10a7a3309c20da9154f6b76f566e57d65e4982dec71f942c70017600e33c37ffd2b1e8fa7cce407e44c75f4a
@@ -0,0 +1,69 @@
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
+ template "trix_genius.rb", File.join(destination_root, "config/initializers/trix_genius.rb")
10
+ end
11
+
12
+ def add_import_to_application_js
13
+ create_file "verbose.log", "DEST: #{destination_root}"
14
+
15
+ js_application_path = "app/javascript/application.js"
16
+ js_application_path = File.join(destination_root, js_application_path)
17
+ application_lines = []
18
+ application_lines << "// Trix Genius block\n"
19
+ application_lines << "import \"controllers\""
20
+ application_lines << "import \"trix\""
21
+ application_lines << "import \"@rails/actiontext\"\n\n"
22
+
23
+ if File.exist?(js_application_path)
24
+ application_file = File.read(js_application_path)
25
+ update_js_file(application_lines, application_file, js_application_path)
26
+ else
27
+ say_status("error", "Could not find #{js_application_path}", :red)
28
+ end
29
+
30
+
31
+ js_application_controller_path = "app/javascript/controllers/application.js"
32
+ js_application_controller_path = File.join(destination_root, js_application_controller_path)
33
+ application_controller_lines = []
34
+ application_controller_lines << "// Trix Genius block"
35
+ application_controller_lines << "import TrixController from \"controllers/trix-controller\""
36
+ application_controller_lines << "application.register(\"trix\", TrixController)\n\n"
37
+
38
+ if File.exist?(js_application_controller_path)
39
+ application_controller_file = File.read(js_application_controller_path)
40
+ update_js_file(application_controller_lines, application_controller_file, js_application_controller_path, false)
41
+ else
42
+ say_status("error", "Could not find #{js_application_controller_path}", :red)
43
+ end
44
+ end
45
+
46
+ def create_stimulus_controller
47
+ template "trix_genius_controller.js", File.join(destination_root, "app/javascript/controllers/trix_genius_controller.js")
48
+ end
49
+
50
+ protected
51
+
52
+ def update_js_file(lines, content, path, append=true)
53
+ row = content.lines
54
+ lines.each do |line|
55
+ unless content.include?(line)
56
+ if append
57
+ append_to_file path, "\n#{line}"
58
+ else
59
+ row.insert(-2, "\n#{line}")
60
+ create_file path, row.join, force: true
61
+ end
62
+ else
63
+ say_status("skipped", "Import already present in application.js", :yellow)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,4 @@
1
+ TrixGenius.configure do |config|
2
+ config.deepseek_api_key=ENV['DEEPSEEK_API_KEY']
3
+ end
4
+
@@ -0,0 +1,60 @@
1
+ require "spec_helper"
2
+ require "generator_spec"
3
+ require "generators/trix_genius/install/install_generator"
4
+ require "pry"
5
+
6
+
7
+ RSpec.describe TrixGenius::Generators::InstallGenerator, type: :generator do
8
+ include GeneratorSpec::TestCase
9
+ destination File.expand_path("../../../../tmp/dummy_app", __FILE__)
10
+
11
+ before(:all) do
12
+ prepare_destination
13
+
14
+ # Create application.js to simulate existing file
15
+ initializer_rb = File.join(destination_root, "config/initialize/trix_genius.rb")
16
+ js_path = File.join(destination_root, "app/javascript/application.js")
17
+ js_controller_path = File.join(destination_root, "app/javascript/controllers/application.js")
18
+
19
+ FileUtils.mkdir_p(File.dirname(js_path))
20
+ File.write(js_path, <<~JS)
21
+ import "controllers"
22
+ JS
23
+
24
+ FileUtils.mkdir_p(File.dirname(js_controller_path))
25
+ File.write(js_controller_path, <<~JS)
26
+ import { Application } from "@hotwired/stimulus"
27
+ const application = Application.start()
28
+ // Configure Stimulus development experience
29
+ application.debug = false
30
+ window.Stimulus = application
31
+ export { application }
32
+ JS
33
+ end
34
+
35
+ it "creates the initializer" do
36
+ run_generator
37
+ assert_file "config/initializers/trix_genius.rb"
38
+ end
39
+
40
+ it "updates application.js with import line" do
41
+ run_generator
42
+ assert_file "app/javascript/application.js" do |content|
43
+ expect(content).to include('import "trix"')
44
+ expect(content).to include('import "@rails/actiontext"')
45
+ end
46
+ end
47
+
48
+ it "updates controller application.js with import line" do
49
+ run_generator
50
+ assert_file "app/javascript/controllers/application.js" do |content|
51
+ expect(content).to include('import TrixController from "controllers/trix-controller"')
52
+ expect(content).to include('application.register("trix", TrixController)')
53
+ end
54
+ end
55
+
56
+ it "creates the trix_genius_controller.js file" do
57
+ run_generator
58
+ assert_file "app/javascript/controllers/trix_genius_controller.js"
59
+ end
60
+ end
@@ -0,0 +1,101 @@
1
+ require 'rails/generators'
2
+ require 'generators/trix_genius/install/install_generator'
3
+
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
44
+ # have no way to turn it off -- the option exists only for backwards
45
+ # compatibility in RSpec 3). It causes shared context metadata to be
46
+ # inherited by the metadata hash of host groups and examples, rather than
47
+ # triggering implicit auto-inclusion in groups with matching metadata.
48
+ config.shared_context_metadata_behavior = :apply_to_host_groups
49
+
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # This allows you to limit a spec run to individual examples or groups
54
+ # you care about by tagging them with `:focus` metadata. When nothing
55
+ # is tagged with `:focus`, all examples get run. RSpec also provides
56
+ # aliases for `it`, `describe`, and `context` that include `:focus`
57
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
58
+ config.filter_run_when_matching :focus
59
+
60
+ # Allows RSpec to persist some state between runs in order to support
61
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
62
+ # you configure your source control system to ignore this file.
63
+ config.example_status_persistence_file_path = "spec/examples.txt"
64
+
65
+ # Limits the available syntax to the non-monkey patched syntax that is
66
+ # recommended. For more details, see:
67
+ # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
68
+ config.disable_monkey_patching!
69
+
70
+ # This setting enables warnings. It's recommended, but in some cases may
71
+ # be too noisy due to issues in dependencies.
72
+ config.warnings = true
73
+
74
+ # Many RSpec users commonly either run the entire suite or an individual
75
+ # file, and it's useful to allow more verbose output when running an
76
+ # individual spec file.
77
+ if config.files_to_run.one?
78
+ # Use the documentation formatter for detailed output,
79
+ # unless a formatter has already been configured
80
+ # (e.g. via a command-line flag).
81
+ config.default_formatter = "doc"
82
+ end
83
+
84
+ # Print the 10 slowest examples and example groups at the
85
+ # end of the spec run, to help surface which specs are running
86
+ # particularly slow.
87
+ config.profile_examples = 10
88
+
89
+ # Run specs in random order to surface order dependencies. If you find an
90
+ # order dependency and want to debug it, you can fix the order by providing
91
+ # the seed, which is printed after each run.
92
+ # --seed 1234
93
+ config.order = :random
94
+
95
+ # Seed global randomization in this process using the `--seed` CLI option.
96
+ # Setting this allows you to use `--seed` to deterministically reproduce
97
+ # test failures related to randomization by passing the same `--seed` value
98
+ # as the one that triggered the failure.
99
+ Kernel.srand config.seed
100
+ =end
101
+ end
@@ -0,0 +1,7 @@
1
+ import "controllers"
2
+
3
+ // Trix Genius block
4
+
5
+ import "trix"
6
+ import "@rails/actiontext"
7
+
@@ -0,0 +1,11 @@
1
+ import { Application } from "@hotwired/stimulus"
2
+ const application = Application.start()
3
+ // Configure Stimulus development experience
4
+ application.debug = false
5
+ window.Stimulus = application
6
+
7
+ // Trix Genius block
8
+ import TrixController from "controllers/trix-controller"
9
+ application.register("trix", TrixController)
10
+
11
+ export { application }
@@ -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,4 @@
1
+ TrixGenius.configure do |config|
2
+ config.deepseek_api_key=ENV['DEEPSEEK_API_KEY']
3
+ end
4
+
@@ -0,0 +1 @@
1
+ DEST: /app/generator/trix-genius/spec/tmp/dummy_app
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trix-genius
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giménez Silva Germán Alberto https://rubystacknews.com/
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-07 00:00:00.000000000 Z
10
+ date: 2025-04-09 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -57,6 +57,20 @@ dependencies:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
59
  version: '8.0'
60
+ - !ruby/object:Gem::Dependency
61
+ name: generator_spec
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
60
74
  description: Trix-Genius adds AI-powered buttons and other custom controls to Trix
61
75
  editor using Stimulus.
62
76
  email: ggerman@gmail.com
@@ -64,10 +78,18 @@ executables: []
64
78
  extensions: []
65
79
  extra_rdoc_files: []
66
80
  files:
67
- - lib/generators/trix_genius/install_generator.rb
68
- - lib/generators/trix_genius/templates/trix_genius_controller.js
81
+ - lib/generators/trix_genius/install/install_generator.rb
82
+ - lib/generators/trix_genius/install/templates/trix_genius.rb
83
+ - lib/generators/trix_genius/install/templates/trix_genius_controller.js
69
84
  - lib/trix-genius.rb
70
85
  - lib/trix_genius/engine.rb
86
+ - spec/generators/trix_genius/install/install_generator_spec.rb
87
+ - spec/spec_helper.rb
88
+ - spec/tmp/dummy_app/app/javascript/application.js
89
+ - spec/tmp/dummy_app/app/javascript/controllers/application.js
90
+ - spec/tmp/dummy_app/app/javascript/controllers/trix_genius_controller.js
91
+ - spec/tmp/dummy_app/config/initializers/trix_genius.rb
92
+ - spec/tmp/dummy_app/verbose.log
71
93
  homepage: https://rubystacknews.com/
72
94
  licenses:
73
95
  - GNU
@@ -1,60 +0,0 @@
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.rb", <<~RUBY
10
- TrixGenius.configure do |config|
11
- config.deepseek_api_key=ENV['DEEPSEEK_API_KEY']
12
- end
13
- RUBY
14
- end
15
-
16
- def add_import_to_application_js
17
- js_application_path = "app/javascript/application.js"
18
- application_lines = []
19
- application_lines << "import \"controllers\""
20
- application_lines << "import \"trix\""
21
- application_lines << "import \"@rails/actiontext\""
22
-
23
- if File.exist?(js_application_path)
24
- application_file = File.read(js_application_path)
25
- update_file application_lines, application_file, js_application_path
26
- else
27
- say_status("error", "Could not find #{js_application_path}", :red)
28
- end
29
-
30
- js_application_controller_path ="app/javascript/controllers/application.js"
31
-
32
- application_controller_lines = []
33
- application_controller_lines << "import TrixController from \"controllers/trix-controller\""
34
- application_controller_lines << "application.register(\"trix\", TrixController)"
35
-
36
- if File.exist?(js_application_controller_path)
37
- application_controller_file = File.read(js_application_controller_path)
38
- update_file application_controller_lines, application_controller_file, js_application_controller_path
39
- else
40
- say_status("error", "Could not find #{js_application_path}", :red)
41
- end
42
- end
43
-
44
- def create_stimulus_controller
45
- copy_file "trix_genius_controller.js", "app/javascript/controllers/trix_genius_controller.js"
46
- end
47
-
48
- def update_file lines, file_content, path
49
- lines.each do |line|
50
- unless application_file.include?(line)
51
- append_to_file path, "\n#{line}\n"
52
- else
53
- say_status("skipped", "Import already present in application.js", :yellow)
54
- end
55
- end
56
- end
57
-
58
- end
59
- end
60
- end