trix-editmode 0.0.1 → 0.0.2

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: 0b14038426199c3db34130c9e9e8a9c94120798c9e3d12d1472b84d3d9bc1a6e
4
- data.tar.gz: d1a9d9a19d91004090b83ac35ec1f921db1ef8bc2dea28c5ebe40602473a1df7
3
+ metadata.gz: 1198953e0578f1507e62dbba3898167f8805d9468e28115952da5bcb2165789e
4
+ data.tar.gz: 7f12d5cc828fab7adf13725ce31e39d057e2a591ab0e53a723d033177add5d83
5
5
  SHA512:
6
- metadata.gz: db5469001acc102c4d1d251e809145b2f615c856a8c57a24cf11683cf51e7450a69251aec57cf123f793f55b39382c944f374882cf8a03c2e1687cbc2ba2331d
7
- data.tar.gz: 626d107e2a23de657f2e6c347fa73d57bf0a613d7ecdd9cd61557e5834e8e9da2c3ee3696fa121e6a695d46076d17cd839ecae19fc1574d9c3554c8697e41d89
6
+ metadata.gz: de0108d691d01f19541d68db66119928f4af87763b6459258681260a8cd7cfc27c9f00ffbe0fb396bff8be3a19e7eb0885dc54bc83eb4a98603f684181f6a2bb
7
+ data.tar.gz: 2e9670722bab97a486a7c796e40e05d9b7d48287a6b470a94a6e8c226fa5e5915059c36f753ee6eabfaa4fae8a4309bc42a7a235db9eb26693f8d032752ef057
@@ -0,0 +1,29 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+
5
+ ---
6
+
7
+ **Describe the bug**
8
+ A clear and concise description of what the bug is.
9
+
10
+ **To Reproduce**
11
+ Steps to reproduce the behavior:
12
+ 1. Go to '...'
13
+ 2. Click on '....'
14
+ 3. Scroll down to '....'
15
+ 4. See error
16
+
17
+ **Expected behavior**
18
+ What did you expect to happen? Be as specific as possible.
19
+
20
+ **Actual behavior**
21
+ What actually happened? Be as specific as possible.
22
+
23
+ **Screenshots or Video**
24
+ If applicable, add screenshots or video to help explain your problem.
25
+
26
+ **Environment (please complete the following information):**
27
+ - Rails version: x.x.x
28
+ - trix-rails version: x.x.x
29
+ - Browser:
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+
5
+ ---
6
+
7
+ **Is your feature request related to a problem? Please describe.**
8
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9
+
10
+ **Describe the solution you'd like**
11
+ A clear and concise description of what you want to happen.
12
+
13
+ **Describe alternatives you've considered**
14
+ A clear and concise description of any alternative solutions or features you've considered.
15
+
16
+ **Additional context**
17
+ Add any other context or screenshots about the feature request here.
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  /gemfiles/*.gemfile.lock
11
11
  .ruby-version
12
+ *.gem
@@ -1,14 +1,21 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.7
4
- - 2.3.4
5
- - 2.4.1
3
+ - 2.3.8
4
+ - 2.4.7
5
+ - 2.5.6
6
+ - 2.6.4
6
7
  gemfile:
7
- - gemfiles/rails_4.2.gemfile
8
8
  - gemfiles/rails_5.0.gemfile
9
9
  - gemfiles/rails_5.1.gemfile
10
+ - gemfiles/rails_5.2.gemfile
11
+ - gemfiles/rails_5.2.1.gemfile
12
+ - gemfiles/rails_6.0.0.gemfile
10
13
  - gemfiles/rails_master.gemfile
11
14
  matrix:
12
15
  allow_failures:
13
16
  - gemfile: 'gemfiles/rails_master.gemfile'
14
- before_install: gem install bundler -v 1.11.2
17
+ - gemfile: gemfiles/rails_6.0.0.gemfile
18
+ rvm: 2.3.8
19
+ - gemfile: gemfiles/rails_6.0.0.gemfile
20
+ rvm: 2.4.7
21
+ before_install: gem install bundler -v '~> 2.0'
data/Appraisals CHANGED
@@ -1,18 +1,26 @@
1
- appraise "rails-4.2" do
2
- gem "rails", "~> 4.2.0"
1
+ appraise 'rails-5.0' do
2
+ gem 'rails', '~> 5.0.0'
3
3
  end
4
4
 
5
- appraise "rails-5.0" do
6
- gem "rails", "~> 5.0.0"
5
+ appraise 'rails-5.1' do
6
+ gem 'rails', '~> 5.1.0'
7
7
  end
8
8
 
9
- appraise "rails-5.1" do
10
- gem "rails", "~> 5.1.0"
9
+ appraise 'rails-5.2' do
10
+ gem 'rails', '~> 5.2.0'
11
11
  end
12
12
 
13
- appraise "rails-master" do
14
- gem "rails", git: "https://github.com/rails/rails.git", branch: "master"
15
- gem "arel", git: "https://github.com/rails/arel.git", branch: "master"
13
+ appraise 'rails-5.2.1' do
14
+ gem 'rails', '~> 5.2.1'
15
+ end
16
+
17
+ appraise 'rails-6.0.0' do
18
+ gem 'rails', '6.0.0'
19
+ end
20
+
21
+ appraise 'rails-master' do
22
+ gem 'rails', git: 'https://github.com/rails/rails.git', branch: 'master'
23
+ gem 'arel', git: 'https://github.com/rails/arel.git', branch: 'master'
16
24
  %w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
17
25
  gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'master'
18
26
  end
@@ -0,0 +1,51 @@
1
+ # trix-rails changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project adheres to [Semantic Versioning](http://semver.org/).
5
+
6
+ ## Master
7
+
8
+ Not released
9
+
10
+ ## 2.2.0
11
+
12
+ Released September 13, 2019
13
+
14
+ * ✅ Upgrade to [Trix 1.2.0](https://github.com/basecamp/trix/releases/tag/1.2.0)
15
+ * 💪 Bump to version 2.2.0
16
+ * 🚫 Remove appraisals for Rails 4.2 (support will be removed in trix-rails 3.x)
17
+
18
+ ## 2.1.0
19
+
20
+ Released September 9, 2019
21
+
22
+ * 🐛🔨 Add customizable input name for trix-editor in simple form ([#12](https://github.com/kylefox/trix/pull/12)). Thanks [@ptrr](https://github.com/ptrr)!
23
+ * 💪 Modify Gemspec to support Rails 6 ([#17](https://github.com/kylefox/trix/pull/17)). Thanks [@king601](https://github.com/king601)!
24
+ * 💪 Bump to version 2.1.0
25
+
26
+ ## 2.0.0
27
+
28
+ Released September 29, 2018
29
+
30
+ * ✅ Upgrade to [Trix 1.0.0](https://github.com/basecamp/trix/releases/tag/1.0.0) 🎉
31
+ * ☝️ Note: following this project's [versioning policy](https://github.com/kylefox/trix/issues/4), the major version for `trix-rails` is likewise bumped when Trix receives a major version bump.
32
+ * 🐛🔨 simple_form helper outputs hidden input tag before trix editor tag ([#10](https://github.com/kylefox/trix/pull/10)). Thanks [@bensie](https://github.com/bensie)!
33
+ * 💪 Add appraisals for Rails 5.2.1
34
+
35
+
36
+ ## 1.0.1
37
+
38
+ Released September 20, 2018
39
+
40
+ * ✅ Upgrade to Trix 0.12.1.
41
+ * 🐛🔨 Formtastic helper outputs hidden input tag before trix editor tag ([#9](https://github.com/kylefox/trix/pull/9)). Thanks [@ch000](https://github.com/ch000)!
42
+
43
+ ## 1.0.0
44
+
45
+ Released September 2, 2018
46
+
47
+ * ✅ Bumped to version 1.0.0 — `trix-rails` version numbers are now independent of [Trix](https://github.com/basecamp/trix) itself. See [this issue](https://github.com/kylefox/trix/issues/4) for more detail.
48
+ * ✅ Upgrade to Trix 0.12.0.
49
+ * ✅ Added support for Ruby 2.5.1.
50
+ * 🚫 Dropped support for Ruby 2.2.
51
+ * 🐛🔨 Allow additional options when using simple_form ([#8](https://github.com/kylefox/trix/pull/8)). Thanks [@phylor](https://github.com/phylor)!
data/README.md CHANGED
@@ -1,26 +1,24 @@
1
- # Trix
1
+ # Trix for Ruby on Rails
2
2
 
3
- [![Build Status](https://travis-ci.org/maclover7/trix.svg)](https://travis-ci.org/maclover7/trix)
3
+ [![Build Status](https://api.travis-ci.org/kylefox/trix.svg)](https://travis-ci.org/kylefox/trix)
4
4
 
5
5
  Want to include Basecamp's awesome [Trix WYSIWYG
6
6
  editor](http://trix-editor.org) in your Ruby on Rails application?
7
7
  You've come to the right place!
8
8
 
9
- Please see the appropriate guide for your environment of choice:
9
+ Compatible with Rails 5.0 and up.
10
10
 
11
- * [Ruby on Rails](#a-ruby-on-rails).
11
+ _Note: trix-rails 2.x is technically compatible with Rails 4.2 and up, but is no longer tested or maintained. Support for < Rails 5.0 will be dropped in trix-rails 3.x_
12
12
 
13
- ### a. Ruby on Rails
13
+ # Installation
14
14
 
15
- `trix` is easy to drop into Rails with the asset pipeline.
16
-
17
- In your Gemfile you need to add the `trix` gem.
15
+ Add `trix-rails` to your `Gemfile`:
18
16
 
19
17
  ```ruby
20
- gem 'trix'
18
+ gem 'trix-rails', require: 'trix'
21
19
  ```
22
20
 
23
- `bundle install` and restart your server to make the files available through the pipeline.
21
+ Run `bundle install` and restart your server to make the files available through the pipeline.
24
22
 
25
23
  Import Trix styles in `app/assets/stylesheets/application.css`:
26
24
 
@@ -34,35 +32,92 @@ Require Trix Javascript magic in `app/assets/javascripts/application.js`:
34
32
  //= require trix
35
33
  ```
36
34
 
37
- Finally, any place where you would like to use the Trix editor in your
38
- forms, just use the `trix_editor` helper:
35
+ # Usage
36
+
37
+ You can use `trix-rails` as a standalone tag, in a form builder, or with popular form libraries.
38
+
39
+ ## Standalone Tag
40
+
41
+ Create a simple `<trix-editor>` tag:
39
42
 
40
43
  ```ruby
41
- f.trix_editor :body
44
+ trix_editor_tag(name, value = nil, options = {})
42
45
  ```
43
46
 
44
- If you are using the [Formtastic](https://github.com/justinfrench/formtastic) gem or the [Simple Form](https://github.com/plataformatec/simple_form) gem, you can do this:
47
+ For example:
48
+
49
+ ```erb
50
+ <%= trix_editor_tag :post, :body, required: true %>
51
+ ```
52
+
53
+ ## Form builder
54
+
55
+ Create a Trix editor for a `form_for` or `form_with` attribute:
56
+
57
+ ```ruby
58
+ trix_editor(method, options = {})
59
+ ```
60
+
61
+ For example:
62
+
63
+ ```erb
64
+ <%= post_form.trix_editor :body, required: true, autofocus: true %>
65
+ ```
66
+
67
+ ## Formtastic and Simple Form
68
+
69
+ If you're using [Formtastic](https://github.com/justinfrench/formtastic) or [Simple Form](https://github.com/plataformatec/simple_form), you can do this:
45
70
 
46
71
  ```ruby
47
72
  f.input :body, as: :trix_editor
48
73
  ```
49
74
 
50
- ## Trix
75
+ ## Options
51
76
 
52
- For the official Trix Github repository, go
53
- [here](https://github.com/basecamp/trix).
77
+ Any `options` provided will be passed along to the [`content_tag`](https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag) call that outputs the `<trix-editor>` tag.
54
78
 
55
- ## Contributing
79
+ For example:
56
80
 
57
- Bug reports and pull requests are welcome on GitHub at https://github.com/maclover7/trix.
81
+ ```erb
82
+ <%= post_form.trix_editor :body, autofocus: true, data: { coffee: :delicious } %>
83
+ ```
84
+
85
+ will render:
86
+
87
+ ```html
88
+ <trix-editor autofocus="true" data-coffee="delicious">
89
+ ```
90
+
91
+ # Contributing
92
+
93
+ Bug reports and feature requests are welcome. They're _much_ more likely to be addressed if they are accompanied by a pull request 😘
94
+
95
+ * [Report a bug](https://github.com/kylefox/trix/issues/new?template=bug_report.md)
96
+ * [Request a feature](https://github.com/kylefox/trix/issues/new?template=feature_request.md)
97
+
98
+ ## Testing
99
+
100
+ All pull requests should include tests, where applicable. Pull requests without tests may be rejected.
101
+
102
+ `trix-rails` uses [Appraisal](https://github.com/thoughtbot/appraisal) to test against supported versions of Rails. You can run the specs against all supported versions with:
103
+
104
+ ```shell
105
+ bundle exec appraisal rake spec
106
+ ```
58
107
 
59
108
  ## Upgrading Trix
60
- 1. Copy and paste Trix's `trix.js `to `vendor/assets/javascripts/trix.js`
61
- 2. Copy and paste Trix's `trix.css `to `vendor/assets/stylesheets/trix.css`
62
- 3. Update `lib/trix/version.rb` with the correct version number
63
- 4. `git commit -am 'Bump to vVERSION'`
64
- 4. `bundle exec rake release`
65
109
 
66
- ## License
110
+ To upgrade Trix, simply copy the _compiled_ styles from [`trix/dist`](https://github.com/basecamp/trix/tree/master/dist) into this repository:
111
+
112
+ - Copy [`trix.js`](https://raw.githubusercontent.com/basecamp/trix/master/dist/trix.js) to `vendor/assets/javascripts/trix.js`
113
+ - Copy [`trix.css`](https://raw.githubusercontent.com/basecamp/trix/master/dist/trix.css) to `vendor/assets/stylesheets/trix.css`
114
+
115
+ # License (MIT)
116
+
117
+ `trix-rails` is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
118
+
119
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
120
+
121
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
67
122
 
68
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
123
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -4,4 +4,4 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.2.0"
6
6
 
7
- gemspec :path => "../"
7
+ gemspec path: "../"
@@ -4,4 +4,4 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.0.0"
6
6
 
7
- gemspec :path => "../"
7
+ gemspec path: "../"
@@ -4,4 +4,4 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.1.0"
6
6
 
7
- gemspec :path => "../"
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.2.1"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.2.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "6.0.0"
6
+
7
+ gemspec path: "../"
@@ -2,12 +2,12 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", :git => "https://github.com/rails/rails.git", :branch => "master"
6
- gem "arel", :git => "https://github.com/rails/arel.git", :branch => "master"
7
- gem "rspec-core", :git => "https://github.com/rspec/rspec-core.git", :branch => "master"
8
- gem "rspec-expectations", :git => "https://github.com/rspec/rspec-expectations.git", :branch => "master"
9
- gem "rspec-mocks", :git => "https://github.com/rspec/rspec-mocks.git", :branch => "master"
10
- gem "rspec-rails", :git => "https://github.com/rspec/rspec-rails.git", :branch => "master"
11
- gem "rspec-support", :git => "https://github.com/rspec/rspec-support.git", :branch => "master"
5
+ gem "rails", git: "https://github.com/rails/rails.git", branch: "master"
6
+ gem "arel", git: "https://github.com/rails/arel.git", branch: "master"
7
+ gem "rspec-core", git: "https://github.com/rspec/rspec-core.git", branch: "master"
8
+ gem "rspec-expectations", git: "https://github.com/rspec/rspec-expectations.git", branch: "master"
9
+ gem "rspec-mocks", git: "https://github.com/rspec/rspec-mocks.git", branch: "master"
10
+ gem "rspec-rails", git: "https://github.com/rspec/rspec-rails.git", branch: "master"
11
+ gem "rspec-support", git: "https://github.com/rspec/rspec-support.git", branch: "master"
12
12
 
13
- gemspec :path => "../"
13
+ gemspec path: "../"
@@ -9,7 +9,7 @@ class TrixEditorInput < Formtastic::Inputs::StringInput
9
9
  editor_tag = template.content_tag('trix-editor', '', editor_tag_params)
10
10
  hidden_field = builder.hidden_field(method, input_html_options)
11
11
 
12
- editor = template.content_tag('div', editor_tag + hidden_field, class: 'trix-editor-wrapper')
12
+ editor = template.content_tag('div', hidden_field + editor_tag, class: 'trix-editor-wrapper')
13
13
 
14
14
  label_html + editor
15
15
  end
@@ -8,13 +8,11 @@ module TrixEditorHelper
8
8
  def trix_editor_tag(name, value = nil, options = {})
9
9
  options.symbolize_keys!
10
10
 
11
- css_class = Array.wrap(options[:class]).join(' ')
12
- attributes = { class: "formatted_content trix-content #{css_class}".squish }
13
- attributes[:autofocus] = true if options[:autofocus]
14
- attributes[:input] = options[:input] || "trix_input_#{TrixEditorHelper.id += 1}"
15
-
16
- valid_html_options = [:placeholder, :spellcheck, :toolbar, :tabindex]
17
- attributes.merge!(options.slice(*valid_html_options))
11
+ css_class = Array.wrap(options.delete(:class)).join(' ')
12
+ attributes = {
13
+ class: "formatted_content trix-content #{css_class}".squish,
14
+ input: "trix_input_#{TrixEditorHelper.id += 1}"
15
+ }.merge(options)
18
16
 
19
17
  editor_tag = content_tag('trix-editor', '', attributes)
20
18
  input_tag = hidden_field_tag(name, value, id: attributes[:input])
@@ -36,7 +34,14 @@ module ActionView
36
34
  options = @options.stringify_keys
37
35
  add_default_name_and_id(options)
38
36
  options['input'] ||= dom_id(object, [options['id'], :trix_input].compact.join('_'))
39
- trix_editor_tag(options.delete('name'), value_before_type_cast(object), options)
37
+
38
+ value = if Rails.gem_version >= Gem::Version.new('5.2.x')
39
+ options.delete('value') { value_before_type_cast }
40
+ else
41
+ value_before_type_cast(object)
42
+ end
43
+
44
+ trix_editor_tag(options.delete('name'), value, options)
40
45
  end
41
46
  end
42
47
  end
@@ -2,10 +2,13 @@ module Trix
2
2
  module SimpleForm
3
3
  class TrixEditorInput < ::SimpleForm::Inputs::Base
4
4
  def input(_wrapper_options)
5
- editor_tag = template.content_tag('trix-editor', '', input: input_class, class: 'trix-content')
5
+ trix_options = options.slice(:spellcheck, :toolbar, :tabindex, :input)
6
+ editor_options = { input: input_class, class: 'trix-content' }.merge(trix_options)
7
+
8
+ editor_tag = template.content_tag('trix-editor', '', editor_options)
6
9
  hidden_field = @builder.hidden_field(attribute_name, input_html_options)
7
10
 
8
- template.content_tag('div', editor_tag + hidden_field, class: 'trix-editor-wrapper')
11
+ template.content_tag('div', hidden_field + editor_tag, class: 'trix-editor-wrapper')
9
12
  end
10
13
  end
11
14
  end