trix-rails 0.11.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +1 -0
- data/.rubocop.yml +2 -0
- data/.rubocop_todo.yml +41 -0
- data/.travis.yml +14 -0
- data/Appraisals +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_4.2.gemfile +7 -0
- data/gemfiles/rails_5.0.gemfile +7 -0
- data/gemfiles/rails_5.1.gemfile +7 -0
- data/gemfiles/rails_5.2.gemfile +7 -0
- data/gemfiles/rails_master.gemfile +13 -0
- data/lib/formtastic/inputs/trix_editor_input.rb +17 -0
- data/lib/trix.rb +8 -0
- data/lib/trix/engine.rb +17 -0
- data/lib/trix/form.rb +61 -0
- data/lib/trix/simple_form/trix_editor_input.rb +12 -0
- data/lib/trix/version.rb +3 -0
- data/trix.gemspec +33 -0
- data/vendor/assets/javascripts/trix.js +21 -0
- data/vendor/assets/stylesheets/trix.css +295 -0
- metadata +205 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd4774a1417222c967a621f10c0725ef20b8dc3afc491ba011068a4df3a8b094
|
4
|
+
data.tar.gz: e5f43db2f13ba0cef00b7f8012ea033965a397036934ce069f145e2c1b05c786
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4960fda21ebe0e9cc94c8bec9e92a8a7e2ed85359f807c76ce9fee7fa81ba8241648d74b2ad8d38d7268e605221c4c2f490f30638a086dea8b795f1eab731f91
|
7
|
+
data.tar.gz: 20de30ec5743d70d72068563d24994cc1a126887f5a5f5d5c289aa5a575f9287eca7e43bb6e474e5ccf5f6528a473a4160059451ed47611821172d792e92f95f
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2017-07-16 12:30:37 -0300 using RuboCop version 0.35.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 22
|
12
|
+
|
13
|
+
# Offense count: 10
|
14
|
+
# Configuration parameters: AllowURI, URISchemes.
|
15
|
+
Metrics/LineLength:
|
16
|
+
Max: 104
|
17
|
+
|
18
|
+
# Offense count: 1
|
19
|
+
# Configuration parameters: CountComments.
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Max: 11
|
22
|
+
|
23
|
+
# Offense count: 10
|
24
|
+
# Configuration parameters: Exclude.
|
25
|
+
Style/Documentation:
|
26
|
+
Exclude:
|
27
|
+
- 'spec/**/*'
|
28
|
+
- 'test/**/*'
|
29
|
+
- 'lib/formtastic/inputs/trix_editor_input.rb'
|
30
|
+
- 'lib/trix.rb'
|
31
|
+
- 'lib/trix/engine.rb'
|
32
|
+
- 'lib/trix/form.rb'
|
33
|
+
- 'lib/trix/simple_form/trix_editor_input.rb'
|
34
|
+
- 'lib/trix/version.rb'
|
35
|
+
|
36
|
+
# Offense count: 1
|
37
|
+
# Cop supports --auto-correct.
|
38
|
+
# Configuration parameters: PreferredDelimiters.
|
39
|
+
Style/PercentLiteralDelimiters:
|
40
|
+
Exclude:
|
41
|
+
- 'spec/trix_editor_helper_spec.rb'
|
data/.travis.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.2.7
|
4
|
+
- 2.3.4
|
5
|
+
- 2.4.1
|
6
|
+
gemfile:
|
7
|
+
- gemfiles/rails_4.2.gemfile
|
8
|
+
- gemfiles/rails_5.0.gemfile
|
9
|
+
- gemfiles/rails_5.1.gemfile
|
10
|
+
- gemfiles/rails_master.gemfile
|
11
|
+
matrix:
|
12
|
+
allow_failures:
|
13
|
+
- gemfile: 'gemfiles/rails_master.gemfile'
|
14
|
+
before_install: gem install bundler -v 1.11.2
|
data/Appraisals
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
appraise "rails-4.2" do
|
2
|
+
gem "rails", "~> 4.2.0"
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise "rails-5.0" do
|
6
|
+
gem "rails", "~> 5.0.0"
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "rails-5.1" do
|
10
|
+
gem "rails", "~> 5.1.0"
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise "rails-5.2" do
|
14
|
+
gem "rails", "~> 5.2.0"
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise "rails-master" do
|
18
|
+
gem "rails", git: "https://github.com/rails/rails.git", branch: "master"
|
19
|
+
gem "arel", git: "https://github.com/rails/arel.git", branch: "master"
|
20
|
+
%w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
|
21
|
+
gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'master'
|
22
|
+
end
|
23
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015-2016 Jon Moss
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Trix
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/maclover7/trix.svg)](https://travis-ci.org/maclover7/trix)
|
4
|
+
|
5
|
+
Want to include Basecamp's awesome [Trix WYSIWYG
|
6
|
+
editor](http://trix-editor.org) in your Ruby on Rails application?
|
7
|
+
You've come to the right place!
|
8
|
+
|
9
|
+
Please see the appropriate guide for your environment of choice:
|
10
|
+
|
11
|
+
* [Ruby on Rails](#a-ruby-on-rails).
|
12
|
+
|
13
|
+
### a. Ruby on Rails
|
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.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'trix'
|
21
|
+
```
|
22
|
+
|
23
|
+
`bundle install` and restart your server to make the files available through the pipeline.
|
24
|
+
|
25
|
+
Import Trix styles in `app/assets/stylesheets/application.css`:
|
26
|
+
|
27
|
+
```css
|
28
|
+
*= require trix
|
29
|
+
```
|
30
|
+
|
31
|
+
Require Trix Javascript magic in `app/assets/javascripts/application.js`:
|
32
|
+
|
33
|
+
```js
|
34
|
+
//= require trix
|
35
|
+
```
|
36
|
+
|
37
|
+
Finally, any place where you would like to use the Trix editor in your
|
38
|
+
forms, just use the `trix_editor` helper:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
f.trix_editor :body
|
42
|
+
```
|
43
|
+
|
44
|
+
Any options passed to the `trix_editor` will render as HTML attributes on the `trix-editor` tag. For example:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
f.trix_editor :body, autofocus: true, data: { coffee: :delicious }
|
48
|
+
```
|
49
|
+
|
50
|
+
will render something like:
|
51
|
+
|
52
|
+
```html
|
53
|
+
<trix-editor autofocus="true" data-coffee="delicious">
|
54
|
+
```
|
55
|
+
|
56
|
+
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:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
f.input :body, as: :trix_editor
|
60
|
+
```
|
61
|
+
|
62
|
+
## Trix
|
63
|
+
|
64
|
+
For the official Trix Github repository, go
|
65
|
+
[here](https://github.com/basecamp/trix).
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/maclover7/trix.
|
70
|
+
|
71
|
+
## Upgrading Trix
|
72
|
+
1. Copy and paste Trix's `trix.js `to `vendor/assets/javascripts/trix.js`
|
73
|
+
2. Copy and paste Trix's `trix.css `to `vendor/assets/stylesheets/trix.css`
|
74
|
+
3. Update `lib/trix/version.rb` with the correct version number
|
75
|
+
4. `git commit -am 'Bump to vVERSION'`
|
76
|
+
4. `bundle exec rake release`
|
77
|
+
|
78
|
+
## License
|
79
|
+
|
80
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'trix'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
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"
|
12
|
+
|
13
|
+
gemspec path: "../"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class TrixEditorInput < Formtastic::Inputs::StringInput
|
2
|
+
def to_html
|
3
|
+
input_wrapping do
|
4
|
+
editor_tag_params = {
|
5
|
+
input: input_html_options[:id],
|
6
|
+
class: 'trix-content'
|
7
|
+
}
|
8
|
+
|
9
|
+
editor_tag = template.content_tag('trix-editor', '', editor_tag_params)
|
10
|
+
hidden_field = builder.hidden_field(method, input_html_options)
|
11
|
+
|
12
|
+
editor = template.content_tag('div', editor_tag + hidden_field, class: 'trix-editor-wrapper')
|
13
|
+
|
14
|
+
label_html + editor
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/trix.rb
ADDED
data/lib/trix/engine.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Trix
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
initializer 'trix.view_helpers' do
|
4
|
+
ActiveSupport.on_load(:action_view) do
|
5
|
+
require 'trix/form'
|
6
|
+
end
|
7
|
+
|
8
|
+
if defined? ::SimpleForm
|
9
|
+
require 'trix/simple_form/trix_editor_input'
|
10
|
+
|
11
|
+
::SimpleForm.setup do |config|
|
12
|
+
config.custom_inputs_namespaces << 'Trix::SimpleForm'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/trix/form.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
|
4
|
+
module TrixEditorHelper
|
5
|
+
mattr_accessor(:id, instance_accessor: false)
|
6
|
+
class_variable_set('@@id', 0)
|
7
|
+
|
8
|
+
def trix_editor_tag(name, value = nil, options = {})
|
9
|
+
options.symbolize_keys!
|
10
|
+
|
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)
|
16
|
+
|
17
|
+
editor_tag = content_tag('trix-editor', '', attributes)
|
18
|
+
input_tag = hidden_field_tag(name, value, id: attributes[:input])
|
19
|
+
|
20
|
+
input_tag + editor_tag
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module ActionView
|
25
|
+
module Helpers
|
26
|
+
include TrixEditorHelper
|
27
|
+
|
28
|
+
module Tags
|
29
|
+
class TrixEditor < Base
|
30
|
+
include TrixEditorHelper
|
31
|
+
delegate :dom_id, to: :'@template_object'
|
32
|
+
|
33
|
+
def render
|
34
|
+
options = @options.stringify_keys
|
35
|
+
add_default_name_and_id(options)
|
36
|
+
options['input'] ||= dom_id(object, [options['id'], :trix_input].compact.join('_'))
|
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)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module FormHelper
|
50
|
+
def trix_editor(object_name, method, options = {})
|
51
|
+
Tags::TrixEditor.new(object_name, method, self, options).render
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class FormBuilder
|
56
|
+
def trix_editor(method, options = {})
|
57
|
+
@template.trix_editor(@object_name, method, objectify_options(options))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Trix
|
2
|
+
module SimpleForm
|
3
|
+
class TrixEditorInput < ::SimpleForm::Inputs::Base
|
4
|
+
def input(_wrapper_options)
|
5
|
+
editor_tag = template.content_tag('trix-editor', '', input: input_class, class: 'trix-content')
|
6
|
+
hidden_field = @builder.hidden_field(attribute_name, input_html_options)
|
7
|
+
|
8
|
+
template.content_tag('div', editor_tag + hidden_field, class: 'trix-editor-wrapper')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/trix/version.rb
ADDED
data/trix.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'trix/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'trix-rails'
|
9
|
+
spec.version = Trix::VERSION
|
10
|
+
spec.authors = ['Kyle Fox', 'Jon Moss']
|
11
|
+
spec.email = ['kylefox@gmail.com', 'me@jonathanmoss.me']
|
12
|
+
|
13
|
+
spec.summary = 'A rich text editor for everyday writing'
|
14
|
+
spec.description = 'A rich text editor for everyday writing'
|
15
|
+
spec.homepage = 'https://github.com/kylefox/trix'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_runtime_dependency 'rails', '> 4.1', '< 6.0'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'appraisal'
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
27
|
+
spec.add_development_dependency 'formtastic', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'simple_form', '~> 4.0'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'rspec-rails'
|
31
|
+
spec.add_development_dependency 'rspec-activemodel-mocks'
|
32
|
+
spec.add_development_dependency 'rubocop', '0.35.1'
|
33
|
+
end
|