trix-genius 0.0.12 → 0.0.14

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: 12c330540b0ad83c3419f7f3504189f7990b6bc69d28d721e35265bb1f252d30
4
- data.tar.gz: e7014dd5db388632445e0c362cf4430ce89106cfe8b1e309edd8150ff186889b
3
+ metadata.gz: 5b012de7dd80c90da7c071b6913ceaa42a2d210f401537137f8bbbce80e1ce71
4
+ data.tar.gz: 0fe0d891d3b5ebf10a5a356fa2a4df556037ab0f7c1adffd0defe7d96eaac52e
5
5
  SHA512:
6
- metadata.gz: b284e6d6b25567262adc270289b393a2d64752592e80ca8bca0a96b2ec7d6b7ca464a6dd5dc98a30cf6381f0e1e7de2853478a13d76b834b6bb5723c51bd4f27
7
- data.tar.gz: 0705a76cc11e399ec8951c39616de7344d6f1acd415ef2accc81a482611fa3e2e4b160478a4087f07fcfe7eb45d76c6e3e2abe995b552426ea1ad8130537d6ea
6
+ metadata.gz: 520222e15e0aa79bce7dc37af4b30f61c3556dd1db306260e74b15fd9fcedb5c52092252e39e7f936168b28e6f08989e2cc9341ac1baa337f299dc4b4fadd14e
7
+ data.tar.gz: 527584fdd2c718e0c3f591ec8219a395f70ca9f4d13cca7ae8d7d491832435dd221d345bfcbe2595fb73324e05ec3dee759ef8cbf4914b516dc4253dd82f09ec
@@ -0,0 +1,104 @@
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
+ js_application_path = "app/javascript/application.js"
14
+ js_application_path = File.join(destination_root, js_application_path)
15
+
16
+ if File.exist?(js_application_path)
17
+ application_file = File.read(js_application_path)
18
+
19
+ inject_into_file js_application_path, "\n" + 'import "trix"' + "\n", after: 'import "controllers"'
20
+ inject_into_file js_application_path, "\n" + 'import "@rails/actiontext"' + ("\n" * 2), after: 'import "trix"'
21
+ else
22
+ puts javascript_application_msg
23
+ say_status("error", "Could not find #{js_application_path}", :red)
24
+ end
25
+
26
+ js_application_controller_path = "app/javascript/controllers/application.js"
27
+ js_application_controller_path = File.join(destination_root, js_application_controller_path)
28
+
29
+ if File.exist?(js_application_controller_path)
30
+ application_controller_file = File.read(js_application_controller_path)
31
+ inject_into_file js_application_controller_path, "\n" + 'import TrixController from "controllers/trix-controller"' + "\n", after: 'import { Application } from "@hotwired/stimulus"'
32
+ inject_into_file js_application_controller_path, "\n" + 'application.register("trix", TrixController)' + ("\n" * 2), before: 'export { application }'
33
+ else
34
+ puts javascript_application_controller_msg
35
+ say_status("error", "Could not find #{js_application_controller_path}", :red)
36
+ end
37
+ end
38
+
39
+ def create_stimulus_controller
40
+ template "trix_genius_controller.js", File.join(destination_root, "app/javascript/controllers/trix_genius_controller.js")
41
+ end
42
+
43
+ def add_route_to_routes_file
44
+ route_code = ["",
45
+ " # TrixGenius: Auto-added route",
46
+ ' post "/trix_genius/correct_spelling", to: "trix_genius#correct_spelling"',
47
+ ""].join("\n")
48
+
49
+ inject_into_file File.join(destination_root, "config/routes.rb"), route_code, after: "Rails.application.routes.draw do\n"
50
+ end
51
+
52
+ def create_controller
53
+ template "trix_genius_controller.rb", File.join(destination_root, "app/controllers/trix_genius_controller.rb")
54
+ end
55
+
56
+ protected
57
+
58
+ def javascript_application_msg
59
+ <<~MSG
60
+
61
+ ⚠️ You should create the file manually:
62
+
63
+ 📄 app/javascript/application.js
64
+
65
+ 💡 With the following content:
66
+
67
+ // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
68
+ import "@hotwired/turbo-rails"
69
+ import "controllers"
70
+
71
+ import "trix"
72
+ import "@rails/actiontext"
73
+
74
+ MSG
75
+ end
76
+
77
+ def javascript_application_controller_msg
78
+ <<~MSG
79
+
80
+ ⚠️ You should create the file manually:
81
+
82
+ 📄 app/javascript/controllers/application.js
83
+
84
+ 💡 With the following content:
85
+
86
+ import { Application } from "@hotwired/stimulus"
87
+ import TrixController from "controllers/trix-controller"
88
+
89
+ const application = Application.start()
90
+
91
+ // Configure Stimulus development experience
92
+ application.debug = false
93
+ window.Stimulus = application
94
+
95
+ application.register("trix", TrixController)
96
+
97
+ export { application }
98
+ MSG
99
+
100
+ end
101
+
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,4 @@
1
+ TrixGenius.configure do |config|
2
+ config.deepseek_api_key=ENV['DEEPSEEK_API_KEY']
3
+ end
4
+
@@ -33,7 +33,7 @@ export default class extends Controller {
33
33
  const content = editor.getDocument().toString(); // Get the current content
34
34
 
35
35
  // Send the content to the backend for correction
36
- const response = await fetch("/orthography/correct", {
36
+ const response = await fetch("/trix_genius/correct_spelling", {
37
37
  method: "POST",
38
38
  headers: { "Content-Type": "application/json" },
39
39
  body: JSON.stringify({ text: content }),
@@ -0,0 +1,39 @@
1
+ class OrthographyController < ApplicationController
2
+ skip_before_action :verify_authenticity_token
3
+
4
+ # POST /correct_orthography
5
+ def correct_spelling
6
+ text = params.require(:text)
7
+
8
+ corrected_text = call_ai_service(text)
9
+
10
+ render json: { corrected_text: corrected_text }
11
+ rescue StandardError => e
12
+ Rails.logger.error("Orthography Correction Error: #{e.message}")
13
+ render json: { error: "An error occurred while correcting orthography." }, status: :unprocessable_entity
14
+ end
15
+
16
+ private
17
+
18
+ def call_ai_service(text)
19
+ headers = {
20
+ 'Content-Type' => 'application/json',
21
+ 'Authorization' => "Bearer #{ENV['DEEPSEEK_API_KEY']}"
22
+ }
23
+
24
+ body = {
25
+ model: "deepseek-chat",
26
+ messages: [{ role: "user", content: "Correct this text: #{text}" }],
27
+ temperature: 0.7,
28
+ max_tokens: 500
29
+ }.to_json
30
+
31
+ response = Faraday.post(ENV['API_URL'], body, headers)
32
+
33
+ if response.success?
34
+ return JSON.parse(response.body)['choices'][0]['message']['content'].split('"')[1]
35
+ else
36
+ "Error: #{response.status} - #{response.body}"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,122 @@
1
+ require "spec_helper"
2
+ require "generator_spec"
3
+ require "generators/trix_genius/install/install_generator"
4
+ require "stringio"
5
+
6
+ require "pry"
7
+
8
+ RSpec.describe TrixGenius::Generators::InstallGenerator, type: :generator do
9
+ include GeneratorSpec::TestCase
10
+ destination File.expand_path("../../../../tmp/dummy_app", __FILE__)
11
+
12
+ before(:all) do
13
+ prepare_destination
14
+
15
+ routes_path = File.join(destination_root, "config/routes.rb")
16
+ FileUtils.mkdir_p(File.dirname(routes_path))
17
+ File.write(routes_path, <<~RUBY)
18
+ Rails.application.routes.draw do
19
+ resources :posts
20
+ # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
21
+
22
+ # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
23
+ # Can be used by load balancers and uptime monitors to verify that the app is live.
24
+
25
+ # Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb)
26
+ # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
27
+ # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
28
+
29
+ # Defines the root path route ("/")
30
+ # root "posts#index"
31
+ end
32
+ RUBY
33
+
34
+ js_path = File.join(destination_root, "app/javascript/application.js")
35
+ js_controller_path = File.join(destination_root, "app/javascript/controllers/application.js")
36
+
37
+ FileUtils.mkdir_p(File.dirname(js_path))
38
+ File.write(js_path, <<~JS)
39
+ import "@hotwired/turbo-rails"
40
+ import "controllers"
41
+ JS
42
+
43
+ FileUtils.mkdir_p(File.dirname(js_controller_path))
44
+ File.write(js_controller_path, <<~JS)
45
+ import { Application } from "@hotwired/stimulus"
46
+ const application = Application.start()
47
+
48
+ // Configure Stimulus development experience
49
+
50
+ application.debug = false
51
+ window.Stimulus = application
52
+ export { application }
53
+ JS
54
+ end
55
+
56
+ it "Should creates the initializer" do
57
+ run_generator
58
+ assert_file "config/initializers/trix_genius.rb"
59
+ end
60
+
61
+ it "Should updates application.js with import line" do
62
+ run_generator
63
+ assert_file "app/javascript/application.js" do |content|
64
+ expect(content).to include('import "trix"')
65
+ expect(content).to include('import "@rails/actiontext"')
66
+ end
67
+ end
68
+
69
+ it "Should updates controller application.js with import line" do
70
+ run_generator
71
+ assert_file "app/javascript/controllers/application.js" do |content|
72
+ expect(content).to include('import TrixController from "controllers/trix-controller"')
73
+ expect(content).to include('application.register("trix", TrixController)')
74
+ end
75
+ end
76
+
77
+ it "Should creates the trix_genius_controller.js file" do
78
+ run_generator
79
+ assert_file "app/javascript/controllers/trix_genius_controller.js"
80
+ end
81
+
82
+ it "Should creates the trix_genius_controller.rb file" do
83
+ run_generator
84
+ assert_file "app/controllers/trix_genius_controller.rb"
85
+ end
86
+
87
+ it "Should add route to trix functionality" do
88
+ run_generator
89
+ assert_file "config/routes.rb" do |content|
90
+ expect(content).to include('post "/trix_genius/correct_spelling", to: "trix_genius#correct_spelling"')
91
+ end
92
+ end
93
+
94
+ =begin
95
+ ready to catch terminal resulto to create the Spec when application.js does't exist
96
+
97
+ it "Should launch error because app/javascript/application.js doesn't exist" do
98
+ js_path = File.join(destination_root, "app/javascript/application.js")
99
+ FileUtils.rm_f(js_path)
100
+
101
+ output = capture_stdout { run_generator }
102
+
103
+ binding.pry
104
+ expect(output).to include("You should create the file manually:")
105
+ expect(output).to include("app/javascript/application.js")
106
+ expect(output).to include("import \"trix\"")
107
+ expect(output).to include("Could not find #{js_path}")
108
+ end
109
+
110
+ def capture_stdout
111
+ previous_stdout = $stdout
112
+ fake = StringIO.new
113
+ $stdout = fake
114
+ yield
115
+ fake.string
116
+ ensure
117
+ $stdout = previous_stdout
118
+ end
119
+
120
+ =end
121
+
122
+ 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,39 @@
1
+ class OrthographyController < ApplicationController
2
+ skip_before_action :verify_authenticity_token
3
+
4
+ # POST /correct_orthography
5
+ def correct_spelling
6
+ text = params.require(:text)
7
+
8
+ corrected_text = call_ai_service(text)
9
+
10
+ render json: { corrected_text: corrected_text }
11
+ rescue StandardError => e
12
+ Rails.logger.error("Orthography Correction Error: #{e.message}")
13
+ render json: { error: "An error occurred while correcting orthography." }, status: :unprocessable_entity
14
+ end
15
+
16
+ private
17
+
18
+ def call_ai_service(text)
19
+ headers = {
20
+ 'Content-Type' => 'application/json',
21
+ 'Authorization' => "Bearer #{ENV['DEEPSEEK_API_KEY']}"
22
+ }
23
+
24
+ body = {
25
+ model: "deepseek-chat",
26
+ messages: [{ role: "user", content: "Correct this text: #{text}" }],
27
+ temperature: 0.7,
28
+ max_tokens: 500
29
+ }.to_json
30
+
31
+ response = Faraday.post(ENV['API_URL'], body, headers)
32
+
33
+ if response.success?
34
+ return JSON.parse(response.body)['choices'][0]['message']['content'].split('"')[1]
35
+ else
36
+ "Error: #{response.status} - #{response.body}"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,7 @@
1
+ import "@hotwired/turbo-rails"
2
+ import "controllers"
3
+ import "trix"
4
+ import "@rails/actiontext"
5
+
6
+
7
+
@@ -0,0 +1,13 @@
1
+ import { Application } from "@hotwired/stimulus"
2
+ import TrixController from "controllers/trix-controller"
3
+
4
+ const application = Application.start()
5
+
6
+ // Configure Stimulus development experience
7
+
8
+ application.debug = false
9
+ window.Stimulus = application
10
+
11
+ application.register("trix", TrixController)
12
+
13
+ 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("/trix_genius/correct_spelling", {
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,17 @@
1
+ Rails.application.routes.draw do
2
+
3
+ # TrixGenius: Auto-added route
4
+ post "/trix_genius/correct_spelling", to: "trix_genius#correct_spelling"
5
+ resources :posts
6
+ # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
7
+
8
+ # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
9
+ # Can be used by load balancers and uptime monitors to verify that the app is live.
10
+
11
+ # Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb)
12
+ # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
13
+ # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
14
+
15
+ # Defines the root path route ("/")
16
+ # root "posts#index"
17
+ end
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.12
4
+ version: 0.0.14
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-10 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -57,6 +57,34 @@ dependencies:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
59
  version: '8.0'
60
+ - !ruby/object:Gem::Dependency
61
+ name: faraday
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '2.12'
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '2.12'
74
+ - !ruby/object:Gem::Dependency
75
+ name: generator_spec
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ type: :development
82
+ prerelease: false
83
+ version_requirements: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
60
88
  description: Trix-Genius adds AI-powered buttons and other custom controls to Trix
61
89
  editor using Stimulus.
62
90
  email: ggerman@gmail.com
@@ -64,10 +92,20 @@ executables: []
64
92
  extensions: []
65
93
  extra_rdoc_files: []
66
94
  files:
67
- - lib/generators/trix_genius/install_generator.rb
68
- - lib/generators/trix_genius/templates/trix_genius_controller.js
95
+ - lib/generators/trix_genius/install/install_generator.rb
96
+ - lib/generators/trix_genius/install/templates/trix_genius.rb
97
+ - lib/generators/trix_genius/install/templates/trix_genius_controller.js
98
+ - lib/generators/trix_genius/install/templates/trix_genius_controller.rb
69
99
  - lib/trix-genius.rb
70
100
  - lib/trix_genius/engine.rb
101
+ - spec/generators/trix_genius/install/install_generator_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/tmp/dummy_app/app/controllers/trix_genius_controller.rb
104
+ - spec/tmp/dummy_app/app/javascript/application.js
105
+ - spec/tmp/dummy_app/app/javascript/controllers/application.js
106
+ - spec/tmp/dummy_app/app/javascript/controllers/trix_genius_controller.js
107
+ - spec/tmp/dummy_app/config/initializers/trix_genius.rb
108
+ - spec/tmp/dummy_app/config/routes.rb
71
109
  homepage: https://rubystacknews.com/
72
110
  licenses:
73
111
  - 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, content, path
49
- lines.each do |line|
50
- unless content.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