actiontext-lite 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '085a22708a88f2d4a0d799d9b4bd65f63cca2dae6d54926180de89fe3fdc88bd'
4
+ data.tar.gz: ec257f87178800c84a40a2a3a3dc00e59f94ac8817bb30527dc8bbcf9e151bc8
5
+ SHA512:
6
+ metadata.gz: a30dcab1155c0e59be0fcbb7b664cd458194aaaa8159a9aac36abfba52b61d4376b3eb74bc47f86935f65dbaf3bfa541ff9c6437f9d95cc7a5f43f47aa9f5732
7
+ data.tar.gz: cf4a716991719bc4906a0761c7196871e2a2aa9debc7c32560620fa3c1275c71b98c03578b5c794705fe49c57340fc17d597919e65424d9e863b4a9a3fe91c8b
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ 0.0.1
2
+ -----
3
+
4
+ - First release.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Jason Lee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # ActionText Lite
2
+
3
+ Lite version of the ActionText.
4
+
5
+ ## Why use Lite version?
6
+
7
+ - Action Text integration Trix by default, but that not useful, our users and editors does not like it 😩.
8
+ - Active Storage as attachments, sometimes not the best choice, we need public image URLs, so we need CarrierWave.
9
+ - Action Text has default HTML sanitize rules, but it too strict, we need text color, image width, and other style attributes... 🥺
10
+
11
+ ## Features
12
+
13
+ - Same API with ActionText core features, just add Gem to use, no need change codes.🎊
14
+ - Give you a clean rich text feature, there is no Trix, no complex HTML sanitize, no ActiveStoreage attachments.
15
+
16
+ ## Using
17
+
18
+ Add gem into your Gemfile:
19
+
20
+ ```rb
21
+ gem "actiontext-lite"
22
+ ```
23
+
24
+ Generate ActionText migrations:
25
+
26
+ > 🎁ActionText Lite used same table name `action_text_rich_texts` like ActionText, so it can be easily combined with existing ActionText projects.
27
+
28
+ ```bash
29
+ $ rails action_text_lite:install
30
+ ```
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "actiontext-lite/version"
4
+ require "actiontext-lite/rich_text"
5
+ require "actiontext-lite/attribute"
6
+ require "actiontext-lite/engine"
7
+
8
+ module ActionTextLite
9
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionTextLite
4
+ # Fork ActionText has_rich_text method from:
5
+ # https://github.com/rails/actiontext/blob/18974137be2c4027dfcf430668edd712e7ec011b/lib/action_text/attribute.rb
6
+ module Attribute
7
+ extend ActiveSupport::Concern
8
+
9
+ class_methods do
10
+ def has_rich_text(name)
11
+ class_eval <<-CODE, __FILE__, __LINE__ + 1
12
+ def #{name}
13
+ self.rich_text_#{name} ||= ActionTextLite::RichText.new(name: "#{name}", record: self)
14
+ end
15
+
16
+ def #{name}=(body)
17
+ self.#{name}.body = body
18
+ end
19
+ CODE
20
+
21
+ has_one :"rich_text_#{name}", -> { where(name: name) }, class_name: "ActionTextLite::RichText", as: :record, inverse_of: :record
22
+ scope :"with_rich_text_#{name}", -> { includes("rich_text_#{name}") }
23
+
24
+ after_save do
25
+ public_send(name).save if public_send(name).changed?
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionTextLite
4
+ class Engine < Rails::Engine
5
+ isolate_namespace ActionTextLite
6
+
7
+ initializer "action_text_lite.attribute" do
8
+ ActiveSupport.on_load(:active_record) do
9
+ include ActionTextLite::Attribute
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionTextLite
4
+ class RichText < ActiveRecord::Base
5
+ self.table_name = "action_text_rich_texts"
6
+
7
+ delegate :nil?, to: :body
8
+ delegate :blank?, :empty?, :present?, to: :body
9
+
10
+ belongs_to :record, polymorphic: true, touch: true
11
+
12
+ def to_s
13
+ body || ""
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionTextLite
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :action_text_lite do
4
+ desc "Copy over the migration"
5
+ task install: %w( copy_migrations )
6
+
7
+ task :copy_migrations do
8
+ Rake::Task["railties:install:migrations"].reenable # Otherwise you can't run 2 migration copy tasks in one invocation
9
+ Rake::Task["action_text:install:migrations"].invoke
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: actiontext-lite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jason Lee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actiontext
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ description: Lite version of the ActionText.
28
+ email:
29
+ - huacnlee@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - LICENSE
36
+ - README.md
37
+ - lib/actiontext-lite.rb
38
+ - lib/actiontext-lite/attribute.rb
39
+ - lib/actiontext-lite/engine.rb
40
+ - lib/actiontext-lite/rich_text.rb
41
+ - lib/actiontext-lite/version.rb
42
+ - lib/tasks/actiontext-lite.rake
43
+ homepage: http://github.com/huacnlee/actiontext-lite
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.0.3
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Lite version of the ActionText.
66
+ test_files: []