richer_text 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4015b9a354c480f94ac845846dc9fdee7d4f9402f42175ebe8080ce2b0e66d87
4
- data.tar.gz: 4ee8d41ce6076773f86d2703cac148fb41f8a98cdf0feedfc0da0e584575245d
3
+ metadata.gz: 0e556adef8ae4899aaf040aeb3c66ec608b3626530f8b8df100d454dcfa00787
4
+ data.tar.gz: '0353060393bf4d90744ec357f3791681d8484b0ee4d096086032018b8cfac6bb'
5
5
  SHA512:
6
- metadata.gz: 8cfe5f6dc39db89cc2327a40aa0d4198b1785850cd2dd1d1f11a2fa941dea3a68cd771a8f40295c6f8ba8f6c6a0752ab9aa43382dc19fbd3a2261693bd5a27e9
7
- data.tar.gz: 5beab5c3cd4e36867b8d302f2cc3a08221dc739d2ab9f3812adf59f06ff1541faacd99be07947b0315f648e1bf0cfb469c3dfd1c4df5c9ac8af3551c58b6c75c
6
+ metadata.gz: 8ba88bc3470365608710e8f764945e631cae368437e4524c2bc591ca04b128e6fc0ef5f343076c5983608e37299b2fffb306539a46f9c4359db4f716f0225029
7
+ data.tar.gz: 6b77c7fdb84a7310ceb48e7f98205ec58e8b2089970249e7f610647708716fcb65ae19ae1471d731f34673670211226a9bad510f4b03241cf9f1d8eb1b6d6338
@@ -30,3 +30,7 @@
30
30
  .richer-text p {
31
31
  margin: 0;
32
32
  }
33
+
34
+ .richer-text img {
35
+ width: 100%;
36
+ }
@@ -4,12 +4,15 @@ module ActionView::Helpers
4
4
  class Tags::Editor < Tags::Base
5
5
  include Tags::Placeholderable
6
6
 
7
+ delegate :dom_id, to: ActionView::RecordIdentifier
8
+
7
9
  def render
8
10
  options = @options.stringify_keys
9
- options["value"] = options.fetch("value") { value&.to_html }
10
11
  add_default_name_and_id(options)
12
+ options["input"] ||= dom_id(object, [options["id"], :richer_text_input].compact.join("_")) if object
13
+ options["value"] = options.fetch("value") { value&.to_html }
11
14
 
12
- @template_object.richer_text_area_tag(options["name"], options["value"], options.except("value"))
15
+ @template_object.richer_text_area_tag(options.delete("name"), options["value"], options.except("value"))
13
16
  end
14
17
  end
15
18
 
@@ -26,24 +29,21 @@ module ActionView::Helpers
26
29
  end
27
30
  end
28
31
 
29
-
30
32
  module RicherText
31
33
  module TagHelper
32
34
  cattr_accessor(:id, instance_accessor: false) { 0 }
33
35
 
34
36
  def richer_text_area_tag(name, value = nil, options = {})
35
37
  options = options.symbolize_keys
36
- options[:id] ||= "editor_input_#{TagHelper.id += 1}"
37
- options[:class] ||= "editor-input"
38
+ options[:input] ||= "richer_text_input_#{RicherText::TagHelper.id += 1}"
38
39
 
39
40
  # So that we can access the content in the tiptap editor
40
41
  options[:content] ||= value
41
42
 
42
- # editor_toolbar(id: options[:id]) + content_tag("textarea", value, options)
43
- content_tag("div", data: { controller: "richer-text-editor", action: "editor:update->richer-text-editor#update" }) do
44
- hidden_field_tag(name, value, { class: "w-full", data: { richer_text_editor_target: "input" } }) +
45
- tag("richer-text-editor", options)
46
- end
43
+ input_tag = hidden_field_tag(name, value, id: options[:input])
44
+ editor_tag = tag("richer-text-editor", options)
45
+
46
+ input_tag + editor_tag
47
47
  end
48
48
  end
49
49
  end
@@ -1,3 +1,3 @@
1
1
  <div class="richer-text">
2
- <%= sanitize(content.to_html, tags: %w(div h1 h2 blockquote s del strong i em br pre code ol ul li table tbody th td tr p), attributes: %w(id class style data-color colspan rowspan)) %>
2
+ <%= sanitize(content.to_html, tags: %w(div img h1 h2 blockquote s del strong i em br pre code ol ul li table tbody th td tr p), attributes: %w(id class style data-color src alt colspan rowspan)) %>
3
3
  </div>
@@ -44,14 +44,6 @@ module RicherText
44
44
  prepend_to_file stylesheets.first, %(@import "@afomera/richer-text/dist/css/richer-text";\n@import "highlight.js/styles/github-dark";\n@import "richer-text";\n)
45
45
  end
46
46
  end
47
-
48
- def generate_stimulus_controller
49
- say "Copying Stimulus controller", :green
50
- copy_file "app/javascript/controllers/richer_text_editor_controller.js", "app/javascript/controllers/richer_text_editor_controller.js"
51
-
52
- say "Updating Stimulus manifest", :green
53
- rails_command "stimulus:manifest:update"
54
- end
55
47
  end
56
48
  end
57
49
  end
@@ -1,5 +1,4 @@
1
1
  require "rails"
2
- require "nokogiri"
3
2
 
4
3
  module RicherText
5
4
  class Engine < ::Rails::Engine
@@ -12,8 +11,8 @@ module RicherText
12
11
  end
13
12
 
14
13
  initializer "richer_text.helper" do
15
- ActiveSupport.on_load(:action_controller_base) do
16
- helper RicherText::Engine.helpers
14
+ ActiveSupport.on_load(:action_controller) do
15
+ helper RicherText::TagHelper
17
16
  end
18
17
  end
19
18
  end
@@ -1,3 +1,3 @@
1
1
  module RicherText
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/richer_text.rb CHANGED
@@ -12,4 +12,5 @@ module RicherText
12
12
  autoload :Rendering
13
13
  autoload :Fragment
14
14
  autoload :Serialization
15
+ autoload :TagHelper
15
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: richer_text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Fomera
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-02 00:00:00.000000000 Z
11
+ date: 2023-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -40,7 +40,6 @@ files:
40
40
  - app/controllers/richer_text/application_controller.rb
41
41
  - app/helpers/richer_text/application_helper.rb
42
42
  - app/helpers/richer_text/tag_helper.rb
43
- - app/javascript/controllers/richer_text_editor_controller.js
44
43
  - app/jobs/richer_text/application_job.rb
45
44
  - app/mailers/richer_text/application_mailer.rb
46
45
  - app/models/richer_text/application_record.rb
@@ -1,10 +0,0 @@
1
- import { Controller } from "@hotwired/stimulus"
2
-
3
- // Connects to data-controller="richer-text-editor"
4
- export default class extends Controller {
5
- static targets = ["input"];
6
-
7
- update(event) {
8
- this.inputTarget.value = event.detail.html;
9
- }
10
- }