solidus_editor 1.0.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.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.hound.yml +28 -0
  4. data/.rspec +4 -0
  5. data/.rubocop.yml +8 -0
  6. data/.travis.yml +21 -0
  7. data/CONTRIBUTING.md +83 -0
  8. data/Gemfile +17 -0
  9. data/Guardfile +10 -0
  10. data/LICENSE.md +26 -0
  11. data/README.md +99 -0
  12. data/Rakefile +21 -0
  13. data/app/assets/javascripts/spree/backend/solidus_editor.js +1 -0
  14. data/app/assets/stylesheets/spree/backend/solidus_editor.css +6 -0
  15. data/app/controllers/spree/admin/editor_settings_controller.rb +21 -0
  16. data/app/models/ckeditor/asset.rb +4 -0
  17. data/app/models/ckeditor/attachment_file.rb +13 -0
  18. data/app/models/ckeditor/picture.rb +13 -0
  19. data/app/models/spree/editor_setting.rb +11 -0
  20. data/app/overrides/add_rich_editor_tab.rb +7 -0
  21. data/app/overrides/include_rich_text_js.rb +7 -0
  22. data/app/views/shared/_rich_editor_javascript.html.erb +8 -0
  23. data/app/views/shared/editor_engines/_ck_editor.html.erb +11 -0
  24. data/app/views/shared/editor_engines/_tiny_mce.html.erb +24 -0
  25. data/app/views/spree/admin/editor_settings/edit.html.erb +35 -0
  26. data/bin/rails +7 -0
  27. data/config/initializers/ckeditor.rb +21 -0
  28. data/config/locales/en.yml +9 -0
  29. data/config/locales/es.yml +9 -0
  30. data/config/locales/it.yml +9 -0
  31. data/config/locales/nl.yml +9 -0
  32. data/config/locales/ru.yml +9 -0
  33. data/config/locales/sv.yml +9 -0
  34. data/config/routes.rb +5 -0
  35. data/lib/generators/solidus_editor/install/install_generator.rb +15 -0
  36. data/lib/generators/spree_editor/install/install_generator.rb +15 -0
  37. data/lib/solidus_editor.rb +9 -0
  38. data/lib/solidus_editor/engine.rb +25 -0
  39. data/lib/solidus_editor/version.rb +18 -0
  40. data/lib/spree_editor/config.rb +3 -0
  41. data/lib/templates/config/tinymce.yml +40 -0
  42. data/spec/controllers/spree/admin/editor_settings_controller_spec.rb +46 -0
  43. data/spec/features/admin/editor_settings_spec.rb +12 -0
  44. data/spec/spec_helper.rb +27 -0
  45. data/spec/support/capybara.rb +17 -0
  46. data/spec/support/database_cleaner.rb +25 -0
  47. data/spec/support/factory_girl.rb +5 -0
  48. data/spec/support/spree.rb +12 -0
  49. data/spec/translations/locale_spec.rb +15 -0
  50. data/spree_editor.gemspec +41 -0
  51. data/vendor/assets/javascripts/tinymce/langs/cs.js +174 -0
  52. data/vendor/assets/javascripts/tinymce/langs/da.js +156 -0
  53. data/vendor/assets/javascripts/tinymce/langs/de.js +173 -0
  54. data/vendor/assets/javascripts/tinymce/langs/fi.js +173 -0
  55. data/vendor/assets/javascripts/tinymce/langs/fr.js +174 -0
  56. data/vendor/assets/javascripts/tinymce/langs/id.js +71 -0
  57. data/vendor/assets/javascripts/tinymce/langs/it.js +155 -0
  58. data/vendor/assets/javascripts/tinymce/langs/nb.js +174 -0
  59. data/vendor/assets/javascripts/tinymce/langs/nl.js +174 -0
  60. data/vendor/assets/javascripts/tinymce/langs/pt-BR.js +174 -0
  61. data/vendor/assets/javascripts/tinymce/langs/pt.js +173 -0
  62. data/vendor/assets/javascripts/tinymce/langs/ro.js +174 -0
  63. data/vendor/assets/javascripts/tinymce/langs/ru.js +173 -0
  64. data/vendor/assets/javascripts/tinymce/langs/sv.js +174 -0
  65. data/vendor/assets/javascripts/tinymce/langs/tr.js +174 -0
  66. data/vendor/assets/javascripts/tinymce/langs/vi.js +96 -0
  67. data/vendor/assets/javascripts/tinymce/langs/zh-CN.js +173 -0
  68. metadata +348 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d308b4d5299a2742e796bca49e0c64e7f191dca
4
+ data.tar.gz: e9388636b98d6c598fcdc890a5df7d1241f13ef7
5
+ SHA512:
6
+ metadata.gz: 3b5139ad7c3090c0cc997b9a07d2f3dbfed67bdd7df98029a67da0faeda4c565bf4a875113398969eb9b3fdca896a704032fe4e877e87b7f37b4547ea7815d6a
7
+ data.tar.gz: daf696a7c81bf4d240e9134e3842a73c8715be6826b224218e1774fa9a5cd493fc0e8b5bb9a554ea6e94d5e16c30078a5024714f6c35ed6f34e8ce69d43cb47a
@@ -0,0 +1,13 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ tmp
6
+ *.gem
7
+ Gemfile.lock
8
+ .rvmrc
9
+ .sass-cache
10
+ coverage
11
+ spec/dummy
12
+ .ruby-version
13
+ .ruby-gemset
@@ -0,0 +1,28 @@
1
+ ---
2
+ # Too picky.
3
+ LineLength:
4
+ Enabled: false
5
+
6
+ # This should truly be on for well documented gems.
7
+ Documentation:
8
+ Enabled: false
9
+
10
+ # Neatly aligned code is to swell.
11
+ SingleSpaceBeforeFirstArg:
12
+ Enabled: false
13
+
14
+ # Don't mess with RSpec DSL.
15
+ Blocks:
16
+ Exclude:
17
+ - 'spec/**/*'
18
+
19
+ # We really like the readability with newline in beginning of classes.
20
+ EmptyLinesAroundBlockBody:
21
+ Enabled: false
22
+
23
+ EmptyLinesAroundClassBody:
24
+ Enabled: false
25
+
26
+ # Avoid contradictory style rules by enforce single quotes.
27
+ StringLiterals:
28
+ EnforcedStyle: single_quotes
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ -f documentation
3
+ -r spec_helper
4
+ -r pry
@@ -0,0 +1,8 @@
1
+ ---
2
+ inherit_from: .hound.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - spec/dummy/**/*
7
+ - bin/*
8
+ - Guardfile
@@ -0,0 +1,21 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ rvm:
5
+ - 2.3.1
6
+ env:
7
+ matrix:
8
+ - SOLIDUS_BRANCH=v1.0 DB=postgres
9
+ - SOLIDUS_BRANCH=v1.1 DB=postgres
10
+ - SOLIDUS_BRANCH=v1.2 DB=postgres
11
+ - SOLIDUS_BRANCH=v1.3 DB=postgres
12
+ - SOLIDUS_BRANCH=v1.4 DB=postgres
13
+ - SOLIDUS_BRANCH=v2.0 DB=postgres
14
+ - SOLIDUS_BRANCH=master DB=postgres
15
+ - SOLIDUS_BRANCH=v1.0 DB=mysql
16
+ - SOLIDUS_BRANCH=v1.1 DB=mysql
17
+ - SOLIDUS_BRANCH=v1.2 DB=mysql
18
+ - SOLIDUS_BRANCH=v1.3 DB=mysql
19
+ - SOLIDUS_BRANCH=v1.4 DB=mysql
20
+ - SOLIDUS_BRANCH=v2.0 DB=mysql
21
+ - SOLIDUS_BRANCH=master DB=mysql
@@ -0,0 +1,83 @@
1
+ # Contributing
2
+
3
+ Spree Editor is an open source project and we encourage contributions. Please see the [contributors guidelines](http://spreecommerce.com/documentation/contributing_to_spree.html) for more information before contributing.
4
+
5
+ In the spirit of [free software][1], **everyone** is encouraged to help improve this project.
6
+
7
+ Here are some ways *you* can contribute:
8
+
9
+ * by using prerelease versions
10
+ * by reporting [bugs][2]
11
+ * by suggesting new features
12
+ * by writing [translations][3]
13
+ * by writing or editing documentation
14
+ * by writing specifications
15
+ * by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
16
+ * by refactoring code
17
+ * by resolving [issues][2]
18
+ * by reviewing patches
19
+
20
+ ---
21
+
22
+ ## Filing an issue
23
+
24
+ When filing an issue on this extension, please first do these things:
25
+
26
+ * Verify you can reproduce this issue in a brand new application.
27
+ * Run through the steps to reproduce the issue again.
28
+
29
+ In the issue itself please provide:
30
+
31
+ * A comprehensive list of steps to reproduce the issue.
32
+ * What you're *expecting* to happen compared with what's *actually* happening.
33
+ * The version of Spree *and* the version of Rails.
34
+ * A list of all extensions.
35
+ * Any relevant stack traces ("Full trace" preferred)
36
+ * Your `Gemfile`
37
+
38
+ In 99% of cases, this information is enough to determine the cause and solution to the problem that is being described.
39
+
40
+ Any issue that is open for 14 days without actionable information or activity will be marked as "stalled" and then closed. Stalled issues can be re-opened if the information requested is provided.
41
+
42
+ ---
43
+
44
+ ## Pull requests
45
+
46
+ We gladly accept pull requests to fix bugs and, in some circumstances, add new features to this extension.
47
+
48
+ Here's a quick guide:
49
+
50
+ 1. Fork the repo.
51
+
52
+ 2. Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate.
53
+
54
+ 3. Create new branch then make changes and add tests for your changes. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, we need tests!
55
+
56
+ 4. Push to your fork and submit a pull request. If the changes will apply cleanly to the latest stable branches and master branch, you will only need to submit one pull request.
57
+
58
+ At this point you're waiting on us. We may suggest some changes or improvements or alternatives.
59
+
60
+ Some things that will increase the chance that your pull request is accepted, taken straight from the Ruby on Rails guide:
61
+
62
+ * Use Rails idioms and helpers.
63
+ * Include tests that fail without your code, and pass with it.
64
+ * Update the documentation, the surrounding one, examples elsewhere, guides, whatever is affected by your contribution.
65
+
66
+ ---
67
+
68
+ ## TL;DR
69
+
70
+ * Fork the repo
71
+ * Clone your repo
72
+ * Run `bundle install`
73
+ * Run `bundle exec rake test_app` to create the test application in `spec/dummy`
74
+ * Make your changes
75
+ * Ensure specs pass by running `bundle exec rspec spec`
76
+ * Ensure all syntax ok by running `rubocop .`
77
+ * Submit your pull request
78
+
79
+ And in case we didn't emphasize it enough: **we love tests!**
80
+
81
+ [1]: http://www.fsf.org/licensing/essays/free-sw.html
82
+ [2]: https://github.com/spree-contrib/solidus_editor/issues
83
+ [3]: https://github.com/spree-contrib/solidus_editor/tree/master/config/locales
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+
3
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
4
+ gem "solidus", github: "solidusio/solidus", branch: branch
5
+
6
+ if branch == 'master' || branch >= "v2.0"
7
+ gem "rails-controller-testing", group: :test
8
+ end
9
+
10
+ gem 'pg'
11
+ gem 'mysql2'
12
+
13
+ group :development, :test do
14
+ gem "pry-rails"
15
+ end
16
+
17
+ gemspec
@@ -0,0 +1,10 @@
1
+ guard "rspec", cmd: "bundle exec rspec", all_on_start: false, all_after_pass: false do
2
+ watch("spec/spec_helper.rb") { "spec" }
3
+ watch("config/routes.rb") { "spec/controllers" }
4
+ watch(%r{^spec/(.+)_spec\.rb$}) { |m| "spec/#{m[1]}_spec.rb"}
5
+ watch(%r{^app/(.+)_decorator\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch(%r{^app/(.*)(\.erb)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" }
10
+ end
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2016 James Whelton and contributors.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,99 @@
1
+ # Solidus Editor
2
+
3
+ This extension provides an inline rich-text editor for Solidus. It is based off [spree_editor](https://github.com/spree-contrib/spree_editor). It implements different types of editors:
4
+
5
+ - [CKEditor][1]
6
+ - [TinyMCE][2]
7
+
8
+ Please not that this extension is just a simple integration of some pretty complex gems: [`ckeditor`][9] and [`tinymce-rails`][10].
9
+
10
+ If you have issues, please check their issues trackers first.
11
+
12
+ ---
13
+
14
+ ## Installation
15
+
16
+ 1. Add the Solidus Editor gem to your `Gemfile`:
17
+ ```ruby
18
+ gem 'solidus_editor', github: 'solidusio-contrib/solidus_editor', branch: 'master'
19
+ ```
20
+
21
+ 2. Run:
22
+ ```sh
23
+ $ bundle install
24
+ $ rails g solidus_editor:install
25
+ ```
26
+
27
+ 3. If using CKEditor, and would like to enable file uploads run the ckeditor generator:
28
+ ```sh
29
+ $ rails g ckeditor:install --orm=active_record --backend=paperclip && rake db:migrate
30
+ ```
31
+
32
+ 4. In order to secure your file uploads to only be accessed by admins you will also need to configure config/initializers/ckeditor.rb:
33
+ ```ruby
34
+ config.authorize_with :cancan, Spree::Ability
35
+ ```
36
+
37
+ 5. In order to precompile CKEditor's generated assets, you will need to add a line in config/initializers/assets.rb:
38
+ ```ruby
39
+ Rails.application.config.assets.precompile += %w( ckeditor/*)
40
+ ```
41
+ ---
42
+
43
+ ## Configuration
44
+
45
+ Preferences can be updated within the admin panel under "configuration" then "rich editor".
46
+
47
+ Or you may set them with an initializer within your application:
48
+
49
+ ```ruby
50
+ SpreeEditor::Config.tap do |config|
51
+ config.ids = 'product_description page_body event_body'
52
+
53
+ # change the editor to CKEditor
54
+ config.current_editor = 'CKEditor'
55
+ end
56
+ ```
57
+
58
+ The default preference is:
59
+
60
+ ```ruby
61
+ {
62
+ enabled: true,
63
+ current_editor: 'TinyMCE',
64
+ ids: 'product_description page_body'
65
+ }
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Language-Support
71
+
72
+ To obtain support for multiple languages with TinyMCE add tinymce-rails-langs to your Gemfile:
73
+
74
+ ```ruby
75
+ gem 'tinymce-rails-langs'
76
+ ```
77
+
78
+ TinyMCE will not be loaded unless it finds a language package matching your `Spree::Config.default_locale`.
79
+
80
+ ---
81
+
82
+ ## Contributing
83
+
84
+ See corresponding [guidelines][8]
85
+
86
+ ---
87
+
88
+ Copyright (c) 2016 [James Whelton][5] and other [contributors][6], released under the [New BSD License][7]
89
+
90
+ [1]: http://ckeditor.com
91
+ [2]: http://www.tinymce.com
92
+ [3]: http://www.fsf.org/licensing/essays/free-sw.html
93
+ [4]: https://github.com/solidusio-contrib/solidus_editor/issues
94
+ [5]: https://github.com/Whelton
95
+ [6]: https://github.com/solidusio-contrib/solidus_editor/graphs/contributors
96
+ [7]: https://github.com/solidusio-contrib/solidus_editor/blob/master/LICENSE.md
97
+ [8]: https://github.com/solidusio-contrib/v/blob/master/CONTRIBUTING.md
98
+ [9]: https://github.com/galetahub/ckeditor
99
+ [10]: https://github.com/spohlenz/tinymce-rails
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/common_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default do
10
+ if Dir["spec/dummy"].empty?
11
+ Rake::Task[:test_app].invoke
12
+ Dir.chdir("../../")
13
+ end
14
+ Rake::Task[:spec].invoke
15
+ end
16
+
17
+ desc 'Generates a dummy app for testing'
18
+ task :test_app do
19
+ ENV['LIB_NAME'] = 'solidus_editor'
20
+ Rake::Task['common:test_app'].invoke
21
+ end
@@ -0,0 +1 @@
1
+ //= require spree/backend
@@ -0,0 +1,6 @@
1
+ /*
2
+ *= require spree/backend
3
+ */
4
+
5
+ form.edit_product div.left { width: 67%; }
6
+ form.edit_product div.right { width: 30%; }
@@ -0,0 +1,21 @@
1
+ module Spree
2
+ module Admin
3
+ class EditorSettingsController < ResourceController
4
+ def update
5
+ config = Spree::EditorSetting.new
6
+ preferences = params && params.key?(:preferences) ? params.delete(:preferences) : params
7
+ preferences.each do |name, value|
8
+ next unless config.has_preference? name
9
+ config[name] = value
10
+ end
11
+
12
+ if Spree::Config.has_preference? :show_raw_product_description
13
+ Spree::Config[:show_raw_product_description] = config[:enabled]
14
+ end
15
+
16
+ flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:rich_editor))
17
+ redirect_to edit_admin_editor_settings_path
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ class Ckeditor::Asset < ActiveRecord::Base
2
+ include Ckeditor::Orm::ActiveRecord::AssetBase
3
+ include Ckeditor::Backend::Paperclip
4
+ end
@@ -0,0 +1,13 @@
1
+ class Ckeditor::AttachmentFile < Ckeditor::Asset
2
+ has_attached_file :data
3
+
4
+ Ckeditor::AttachmentFile.attachment_definitions[:data][:path] = '/:class/:id/:style/:basename.:extension'
5
+ Ckeditor::AttachmentFile.attachment_definitions[:data][:url] = '/:class/:id/:style/:basename.:extension'
6
+
7
+ validates_attachment_size :data, less_than: 100.megabytes
8
+ validates_attachment_presence :data
9
+
10
+ def url_thumb
11
+ @url_thumb ||= Ckeditor::Utils.filethumb(filename)
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class Ckeditor::Picture < Ckeditor::Asset
2
+ has_attached_file :data, styles: { content: '800>', thumb: '118x100#' }
3
+
4
+ Ckeditor::Picture.attachment_definitions[:data][:path] = '/:class/:id/:style/:basename.:extension'
5
+ Ckeditor::Picture.attachment_definitions[:data][:url] = '/:class/:id/:style/:basename.:extension'
6
+
7
+ validates_attachment_size :data, less_than: 2.megabytes
8
+ validates_attachment_presence :data
9
+
10
+ def url_content
11
+ url(:content)
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ class EditorSetting < Preferences::Configuration
3
+ preference :enabled, :boolean, default: true
4
+ preference :current_editor, :string, default: 'TinyMCE'
5
+ preference :ids, :string, default: 'product_description page_body'
6
+
7
+ def self.editors
8
+ %w(TinyMCE CKEditor)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ Deface::Override.new(
2
+ original: '35a14f18ffd91f105e1133ec54aec7ce25fcd79e',
3
+ virtual_path: 'spree/admin/shared/_configuration_menu',
4
+ name: 'add_rich_editor_tab',
5
+ insert_bottom: '[data-hook="admin_configurations_sidebar_menu"]',
6
+ text: '<%= configurations_sidebar_menu_item Spree.t(:rich_editor), edit_admin_editor_settings_path %>'
7
+ )