9 Коммитов

Автор SHA1 Сообщение Дата
Mattia Roccoberton
4e20e658ac v0.2.8 2020-09-03 11:53:48 +02:00
Mattia Roccoberton
135a56dc03 Add specs for editor in nested resources 2020-09-03 11:50:23 +02:00
Mattia Roccoberton
668bd642e5 Add Rubocop 2020-09-03 11:26:54 +02:00
Mattia Roccoberton
ab8c4fd73f Remove SimpleCov 2020-09-03 11:24:55 +02:00
Mattia Roccoberton
d60ed0f723 Update screenshot 2020-09-03 11:20:35 +02:00
Mattia Roccoberton
98b29d6f69 Minor style improvements 2020-09-03 11:20:12 +02:00
Mattia Roccoberton
962b48bb30 README improvements 2020-09-01 11:48:47 +02:00
Mattia Roccoberton
03b2d0e4e8 Merge pull request #13 from blocknotes/circleci-project-setup
Add CircleCI setup
2020-09-01 11:45:00 +02:00
Mattia Roccoberton
593ad3841a Add .circleci/config.yml 2020-09-01 11:40:23 +02:00
19 изменённых файлов: 168 добавлений и 93 удалений

33
.circleci/config.yml Обычный файл
Просмотреть файл

@@ -0,0 +1,33 @@
version: 2.1
orbs:
ruby: circleci/ruby@0.1.2
jobs:
build:
docker:
- image: circleci/ruby:2.6.6-stretch-node-browsers
executor: ruby/default
steps:
- checkout
- restore_cache:
key: gem-cache-{{ checksum "activeadmin_quill_editor.gemspec" }}
- run:
name: Setup Bundler
command: gem install bundler
- run:
name: Bundle Install
command: bundle install --path vendor/bundle
- save_cache:
key: gem-cache-{{ checksum "activeadmin_quill_editor.gemspec" }}
paths: vendor/bundle
- run:
name: Run Specs
command: |
bin/rspec \
--profile 10 \
--format RspecJunitFormatter \
--out test_results/rspec.xml \
--format progress \
$(circleci tests glob "spec/**/*_spec.rb")
- store_test_results:
path: test_results

2
.gitignore поставляемый
Просмотреть файл

@@ -2,10 +2,10 @@
*.orig
/.rspec_failures
/.rubocop-*
/Gemfile.lock
/_misc/
/coverage/
/spec/dummy/db/*.sqlite3*
/spec/dummy/log/
/spec/dummy/storage/

Просмотреть файл

@@ -1,73 +1,27 @@
require:
- rubocop-rspec
Rails:
Enabled: true
inherit_from:
- https://relaxed.ruby.style/rubocop.yml
AllCops:
TargetRubyVersion: 2.3.8
TargetRailsVersion: 5.2
Exclude:
- db/schema.rb
- bin/*
- node_modules/**/*
# Temporary files
- tmp/**/*
- spec/dummy/**/*
NewCops: enable
Rails/InverseOf:
Gemspec/RequiredRubyVersion:
Enabled: false
Style/Documentation:
Naming/FileName:
Enabled: false
Metrics/ClassLength:
# Default value is 100
Max: 150
Metrics/LineLength:
# Default is 80
Layout/LineLength:
Enabled: true
Max: 120
Metrics/ModuleLength:
# Default is 100
Max: 150
Style/HashEachMethods:
Enabled: true
Metrics/ParameterLists:
# Default is 5
Max: 6
Style/HashTransformKeys:
Enabled: true
RSpec/ExampleLength:
# Default is 10
Max: 20
Style/FrozenStringLiteralComment:
# Deface DOES edit strings in place
Exclude:
- 'app/overrides/**/*'
RSpec/MultipleExpectations:
# Default is 3
Max: 5
RSpec/NestedGroups:
# Default is 3
Max: 6
Metrics/AbcSize:
Max: 25
Metrics/BlockLength:
# This value double the rubocop default
Max: 50
Metrics/CyclomaticComplexity:
# This value double the rubocop default
Max: 12
Metrics/MethodLength:
# This value double the rubocop default
Max: 20
Metrics/PerceivedComplexity:
# Default is 7
Max: 10
Style/HashTransformValues:
Enabled: true

Просмотреть файл

@@ -1,3 +1,5 @@
# frozen_string_literal: true
source 'https://rubygems.org'
gemspec

Просмотреть файл

@@ -1,4 +1,4 @@
Copyright (c) 2017 Mattia Roccoberton
Copyright (c) 2017-2020 Mattia Roccoberton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

Просмотреть файл

@@ -1,18 +1,17 @@
# ActiveAdmin Quill Editor [![Gem Version](https://badge.fury.io/rb/activeadmin_quill_editor.svg)](https://badge.fury.io/rb/activeadmin_quill_editor)
# ActiveAdmin Quill Editor [![Gem Version](https://badge.fury.io/rb/activeadmin_quill_editor.svg)](https://badge.fury.io/rb/activeadmin_quill_editor) [![CircleCI](https://circleci.com/gh/blocknotes/activeadmin_quill_editor.svg?style=svg)](https://circleci.com/gh/blocknotes/activeadmin_quill_editor)
An Active Admin plugin to use [Quill Rich Text Editor](https://github.com/quilljs/quill)
![screenshot](screenshot.jpg)
![screenshot](screenshot.png)
## Install
- Update your Gemfile: `gem 'activeadmin_quill_editor'` (and execute *bundle*)
- Add at the end of your ActiveAdmin styles (_app/assets/stylesheets/active_admin.scss_):
- After installing Active Admin, add to your Gemfile: `gem 'activeadmin_quill_editor'` (and execute *bundle*)
- Add at the end of your Active Admin styles (_app/assets/stylesheets/active_admin.scss_):
```scss
@import 'activeadmin/quill_editor/quill.snow';
@import 'activeadmin/quill_editor_input';
```
- Add at the end of your ActiveAdmin javascripts (_app/assets/javascripts/active_admin.js_):
- Add at the end of your Active Admin javascripts (_app/assets/javascripts/active_admin.js_):
```js
//= require activeadmin/quill_editor/quill
//= require activeadmin/quill_editor_input
@@ -21,14 +20,17 @@ An Active Admin plugin to use [Quill Rich Text Editor](https://github.com/quillj
Why 2 separated scripts? In this way you can include a different version of *quill editor* if you like.
## Options
> **UPDATE FROM VERSION <= 2.0**: please add to your _app/assets/stylesheets/active_admin.scss_ the line `@import 'activeadmin/quill_editor/quill.snow';`
## Options
**data-options**: permits to set *quill editor* options directly - see [options list](https://quilljs.com/docs/configuration/)
## Examples
### Basic usage
```ruby
# ActiveAdmin article form conf:
# Active Admin article form conf:
form do |f|
f.inputs 'Article' do
f.input :title
@@ -39,26 +41,23 @@ Why 2 separated scripts? In this way you can include a different version of *qui
end
```
Toolbar buttons configuration:
### Toolbar buttons configuration
```ruby
f.input :description, as: :quill_editor, input_html: {data: {options: {modules: {toolbar: [['bold', 'italic', 'underline'], ['link']]}, placeholder: 'Type something...', theme: 'snow'}}}
```
## Notes
- Upload functions (Images, Documents, Files, etc.) are not implemented yet
## Do you like it? Star it!
If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
Take a look at [other ActiveAdmin components](https://github.com/blocknotes?utf8=✓&tab=repositories&q=activeadmin&type=source) that I made if you are curious.
Take a look at [other Active Admin components](https://github.com/blocknotes?utf8=✓&tab=repositories&q=activeadmin&type=source) that I made if you are curious.
## Contributors
- [Mattia Roccoberton](http://blocknot.es): author
- The good guys that opened issues and pull requests from time to time
## License
[MIT](LICENSE.txt)
- The gem is available as open-source under the terms of the [MIT](LICENSE.txt)

Просмотреть файл

@@ -1,3 +1,13 @@
# frozen_string_literal: true
require 'bundler/gem_tasks'
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task default: :spec
rescue LoadError
puts '! LoadError: no RSpec available'
end

Просмотреть файл

@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'puma', '~> 4.3.5'
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4.1'
spec.add_development_dependency 'rspec-rails', '~> 4.0.1'
spec.add_development_dependency 'rubocop', '~> 0.90.0'
spec.add_development_dependency 'selenium-webdriver', '~> 3.142.7'
spec.add_development_dependency 'simplecov', '~> 0.19.0'
spec.add_development_dependency 'sqlite3', '~> 1.4.2'
end

Просмотреть файл

@@ -1,10 +1,20 @@
body.active_admin .quill-editor {
display: inline-block;
width: calc(80% - 22px);
width: calc(80% - 2px);
button:hover {
background-image: none;
background-color: rgba(0, 0, 0, 0.1);
button {
text-shadow: none;
box-shadow: none;
&:hover {
background-image: none;
background-color: transparent;
}
}
.ql-container {
border: 1px solid #c9d0d6;
border-radius: 0 0 3px 3px;
}
.ql-editor {
@@ -37,4 +47,9 @@ body.active_admin .quill-editor {
padding-left: 1.5em;
}
}
.ql-toolbar {
border: 1px solid #c9d0d6;
border-radius: 3px 3px 0 0;
}
}

29
bin/rubocop Исполняемый файл
Просмотреть файл

@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'rubocop' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
bundle_binstub = File.expand_path("../bundle", __FILE__)
if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end
require "rubygems"
require "bundler/setup"
load Gem.bin_path("rubocop", "rubocop")

Просмотреть файл

@@ -2,6 +2,6 @@
module ActiveAdmin
module QuillEditor
VERSION = '0.2.4'
VERSION = '0.2.8'
end
end

Двоичные данные
screenshot.jpg

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 33 KiB

Двоичные данные
screenshot.png Обычный файл

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 52 KiB

Просмотреть файл

@@ -1,9 +1,12 @@
# frozen_string_literal: true
ActiveAdmin.register Author do
menu priority: 1
permit_params :name, :email, :age, :avatar, profile_attributes: %i[id description _destroy]
permit_params :name,
:email,
:age,
:avatar,
profile_attributes: %i[id description _destroy],
posts_attributes: %i[id title description]
index do
selectable_column
@@ -28,6 +31,7 @@ ActiveAdmin.register Author do
row :created_at
row :updated_at
row :profile
row :posts
end
active_admin_comments
end
@@ -44,6 +48,10 @@ ActiveAdmin.register Author do
f.has_many :profile, allow_destroy: true do |ff|
ff.input :description
end
f.has_many :posts do |fp|
fp.input :title
fp.input :description, as: :quill_editor
end
f.actions
end
end

Просмотреть файл

@@ -25,6 +25,14 @@ ActiveAdmin.register Post do
row :tags
row :created_at
row :updated_at
row :images do |resurce|
resurce.images.each do |image|
div do
link_to image.filename, image, target: '_blank'
end
end
nil
end
end
active_admin_comments
end

Просмотреть файл

@@ -12,6 +12,7 @@ class Author < ApplicationRecord
has_one_attached :avatar
accepts_nested_attributes_for :profile, allow_destroy: true
accepts_nested_attributes_for :posts, allow_destroy: true
validates :email, format: { with: /\A[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\z/i, message: 'Invalid email' }

Просмотреть файл

@@ -10,6 +10,10 @@ class Post < ApplicationRecord
has_many :post_tags, inverse_of: :post, dependent: :destroy
has_many :tags, through: :post_tags
has_many_attached :images
accepts_nested_attributes_for :post_tags, allow_destroy: true
validates :title, allow_blank: false, presence: true
scope :published, -> { where(published: true) }

Просмотреть файл

@@ -13,12 +13,6 @@ require 'capybara/rails'
Dir[File.expand_path('support/**/*.rb', __dir__)].sort.each { |f| require f }
require 'simplecov'
SimpleCov.start :rails do
filters.clear
add_filter %r{^/spec/}
end
# Force deprecations to raise an exception.
ActiveSupport::Deprecation.behavior = :raise

Просмотреть файл

@@ -9,7 +9,7 @@ RSpec.describe 'Quill editor', type: :system do
end
after do
post.destroy
Post.destroy_all
author.destroy
end
@@ -18,6 +18,7 @@ RSpec.describe 'Quill editor', type: :system do
visit "/admin/posts/#{post.id}/edit"
expect(page).to have_css('#post_description_input .ql-editor', text: 'Some content...')
find('#post_description_input .ql-editor').click
find('#post_description_input .ql-editor').base.send_keys('more text')
find('[type="submit"]').click
@@ -25,4 +26,21 @@ RSpec.describe 'Quill editor', type: :system do
expect(post.reload.description).to eq '<p>Some content...more text</p>'
end
end
context 'with a Quill editor in a nested resource' do
it 'updates some HTML content of a new nested resource' do
visit "/admin/authors/#{author.id}/edit"
expect(page).to have_css('.posts.has_many_container .ql-editor', text: 'Some content...')
find('.posts.has_many_container .has_many_add').click
expect(page).to have_css('.posts.has_many_container .ql-editor', count: 2)
fill_in('author[posts_attributes][1][title]', with: 'A new post')
find('#author_posts_attributes_1_description_input .ql-editor').base.send_keys('new post text')
find('[type="submit"]').click
expect(page).to have_content('was successfully updated')
expect(author.posts.last.description).to eq '<p>new post text</p>'
end
end
end