richer_text 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3e144daed92cf04465df7c11e55a30bec134bd6abd083b2ce76b078eb579323
4
- data.tar.gz: 348c16817e8d8faad41627f985bb6d4dbf7392cd67d04b9faed369cd2ade73a5
3
+ metadata.gz: b63576861e360399b080b94d0bc593c516688af16f6dbfd0ea70ee922deddf34
4
+ data.tar.gz: a488d3031c92e1d0e34662bf942e48209030e2393a9227737e905ffb7041e60d
5
5
  SHA512:
6
- metadata.gz: 4e73645fe681761bc2941cc3814f4ecc2e84c6ad55060e4a62e84351393a6e6fe089a511c4e1a92072c52c6bc9a971d754706df22b57604789d3efc0dd44359e
7
- data.tar.gz: 78bfe77159991d5449f5bfb57dd9727bc5aafa87d648f06913089e791ca69165eab938f8095c82f408a78727c1620f1011fff99803db8dcb7ff53ca22c97f8ee
6
+ metadata.gz: 7dbebb9524973cf7a949ee78b45fa80c73c97286e17d83a901281f500fde88d9bc8b03f103552545fd0fc5c066181a0a729dc4ba2e86575306c8be423b6b65d7
7
+ data.tar.gz: 45832c613c64aced07c6260163d4a1af2afe815a1af1a83beb799db24731b22e0787a262c5b0f109d0c1563510c594c1664294f5df1efe6c54a7d62b53ccd04d
@@ -0,0 +1,49 @@
1
+ require "action_view/helpers/tags/placeholderable"
2
+
3
+ module ActionView::Helpers
4
+ class Tags::Editor < Tags::Base
5
+ include Tags::Placeholderable
6
+
7
+ def render
8
+ options = @options.stringify_keys
9
+ options["value"] = options.fetch("value") { value&.to_html }
10
+ add_default_name_and_id(options)
11
+
12
+ @template_object.richer_text_area_tag(options["name"], options["value"], options.except("value"))
13
+ end
14
+ end
15
+
16
+ module FormHelper
17
+ def richer_text_area(object_name, method, options = {})
18
+ Tags::Editor.new(object_name, method, self, options).render
19
+ end
20
+ end
21
+
22
+ class FormBuilder
23
+ def richer_text_area(method, options = {})
24
+ @template.richer_text_area(@object_name, method, objectify_options(options))
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ module RicherText
31
+ module TagHelper
32
+ cattr_accessor(:id, instance_accessor: false) { 0 }
33
+
34
+ def richer_text_area_tag(name, value = nil, options = {})
35
+ options = options.symbolize_keys
36
+ options[:id] ||= "editor_input_#{TagHelper.id += 1}"
37
+ options[:class] ||= "editor-input"
38
+
39
+ # So that we can access the content in the tiptap editor
40
+ options[:content] ||= value
41
+
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
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,42 @@
1
+ require "pathname"
2
+
3
+ module RicherText
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ source_root RicherText::Engine.root
7
+
8
+ def create_migrations
9
+ rails_command "railties:install:migrations FROM=active_storage,richer_text", inline: true
10
+ end
11
+
12
+ def install_javascript_dependencies
13
+ destination = Pathname(destination_root)
14
+
15
+ if destination.join("package.json").exist?
16
+ say "Adding dependencies to package.json", :green
17
+ run "yarn add react react-dom highlight.js @afomera/richer-text"
18
+ end
19
+
20
+ say "Adding import to application.js", :green
21
+ append_to_file "app/javascript/application.js", %(import "@afomera/richer-text"\n)
22
+ end
23
+
24
+ def install_stylesheet_dependencies
25
+ destination = Pathname(destination_root)
26
+
27
+ if destination.join("app/assets/stylesheets/application.tailwind.css").exist?
28
+ say "Adding import to application.tailwind.css", :green
29
+ prepend_to_file "app/assets/stylesheets/application.tailwind.css", %(@import "@afomera/richer-text/dist/css/richer-text.css";\n@import "highlight.js/styles/github-dark.css";\n)
30
+ end
31
+ end
32
+
33
+ def generate_stimulus_controller
34
+ say "Copying Stimulus controller", :green
35
+ copy_file "app/javascript/controllers/richer_text_editor_controller.js", "app/javascript/controllers/richer_text_editor_controller.js"
36
+
37
+ say "Updating Stimulus manifest", :green
38
+ rails_command "stimulus:manifest:update"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -15,7 +15,7 @@ module RicherText
15
15
  end
16
16
 
17
17
  def to_s
18
- to_html
18
+ to_html.html_safe # TODO: add some kind of sanitization
19
19
  end
20
20
 
21
21
  def to_html
@@ -10,5 +10,11 @@ module RicherText
10
10
  include RicherText::Attribute
11
11
  end
12
12
  end
13
+
14
+ initializer "richer_text.helper" do
15
+ ActiveSupport.on_load(:action_controller_base) do
16
+ helper RicherText::Engine.helpers
17
+ end
18
+ end
13
19
  end
14
20
  end
@@ -1,3 +1,3 @@
1
1
  module RicherText
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,4 +1,4 @@
1
- # desc "Explaining what the task does"
2
- # task :richer_text do
3
- # # Task goes here
4
- # end
1
+ desc "Installs RicherText into your application"
2
+ task "richer_text:install" do
3
+ Rails::Command.invoke :generate, ["richer_text:install"]
4
+ 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.0.1
4
+ version: 0.1.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-07-28 00:00:00.000000000 Z
11
+ date: 2023-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,6 +38,8 @@ files:
38
38
  - app/assets/stylesheets/richer_text/application.css
39
39
  - app/controllers/richer_text/application_controller.rb
40
40
  - app/helpers/richer_text/application_helper.rb
41
+ - app/helpers/richer_text/tag_helper.rb
42
+ - app/javascript/controllers/richer_text_editor_controller.js
41
43
  - app/jobs/richer_text/application_job.rb
42
44
  - app/mailers/richer_text/application_mailer.rb
43
45
  - app/models/richer_text/application_record.rb
@@ -45,6 +47,7 @@ files:
45
47
  - app/views/layouts/richer_text/application.html.erb
46
48
  - config/routes.rb
47
49
  - db/migrate/20230107020316_create_richer_text_rich_texts.rb
50
+ - lib/generators/richer_text/install/install_generator.rb
48
51
  - lib/richer_text.rb
49
52
  - lib/richer_text/attribute.rb
50
53
  - lib/richer_text/content.rb