richer_text 0.0.1 → 0.1.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 +4 -4
- data/app/helpers/richer_text/tag_helper.rb +49 -0
- data/app/javascript/controllers/richer_text_editor_controller.js +10 -0
- data/lib/generators/richer_text/install/install_generator.rb +42 -0
- data/lib/richer_text/content.rb +1 -1
- data/lib/richer_text/engine.rb +6 -0
- data/lib/richer_text/version.rb +1 -1
- data/lib/tasks/richer_text_tasks.rake +4 -4
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b63576861e360399b080b94d0bc593c516688af16f6dbfd0ea70ee922deddf34
|
4
|
+
data.tar.gz: a488d3031c92e1d0e34662bf942e48209030e2393a9227737e905ffb7041e60d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,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
|
data/lib/richer_text/content.rb
CHANGED
data/lib/richer_text/engine.rb
CHANGED
data/lib/richer_text/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
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-
|
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
|