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
+ Deface::Override.new(
2
+ original: 'e004c3e716cca1f673d5142bdd7c16dc2dc5b403',
3
+ virtual_path: 'spree/layouts/admin',
4
+ name: 'include_rich_text_js',
5
+ insert_bottom: '[data-hook="admin_footer_scripts"]',
6
+ text: '<%= render partial: "shared/rich_editor_javascript" %>'
7
+ )
@@ -0,0 +1,8 @@
1
+ <% @editor_setting = Spree::EditorSetting.new %>
2
+ <% is_enabled = @editor_setting[:enabled] %>
3
+ <% current_editor = @editor_setting[:current_editor] %>
4
+ <% ids = @editor_setting[:ids].split %>
5
+
6
+ <% if is_enabled and ids.any? %>
7
+ <%= render "shared/editor_engines/#{@editor_setting[:current_editor].underscore}", ids: ids %>
8
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <%= javascript_include_tag 'ckeditor/init' %>
2
+
3
+ <script>
4
+ $(function() {
5
+ <% ids.each do |id| %>
6
+ if ($("#<%= id %>").length > 0) {
7
+ CKEDITOR.replace("<%= id %>");
8
+ }
9
+ <% end %>
10
+ });
11
+ </script>
@@ -0,0 +1,24 @@
1
+ <%= javascript_include_tag 'tinymce-jquery' %>
2
+
3
+ <script>
4
+ $(function () {
5
+ /* Inject each textarea id with .tinymce class required for TinyMCE 4 */
6
+ $('<%= raw ids.each.map{|id| "textarea##{id}" }.join(", ") %>').addClass('tinymce');
7
+ });
8
+
9
+ $(document).ready(function () {
10
+ $('<%= raw ids.each.map{|id| "textarea##{id}" }.join(", ") %>').tinymce(
11
+ <%= raw TinyMCE::Rails.configuration.options.to_json %>);
12
+ });
13
+ </script>
14
+
15
+ <style type="text/css">
16
+ /* Reset TinyMCE menu styles */
17
+ .mce-tinymce button {
18
+ font-size: inherit !important;
19
+ text-transform: inherit !important;
20
+ }
21
+ .mce-tinymce button:hover {
22
+ background-color: inherit !important;
23
+ }
24
+ </style>
@@ -0,0 +1,35 @@
1
+ <%= render :partial => 'spree/admin/shared/configuration_menu' %>
2
+
3
+ <% content_for :page_title do %>
4
+ <%= Spree.t(:rich_editor) %>
5
+ <% end %>
6
+
7
+ <%= form_tag admin_editor_settings_path, method: :put do %>
8
+ <fieldset class="general no-border-top">
9
+
10
+ <div class="field">
11
+ <%= label_tag(:current_editor, Spree.t(:rich_editor_engine)) %>
12
+ <br />
13
+ <%= select_tag(:current_editor, options_for_select(Spree::EditorSetting.editors, SpreeEditor::Config[:current_editor]), class: 'select2') %>
14
+ </div>
15
+
16
+ <div class="field">
17
+ <%= label_tag(:enabled) do %>
18
+ <%= preference_field_tag(:enabled, SpreeEditor::Config[:enabled], type: :boolean) %>
19
+ <%= Spree.t(:enable_rich_editor) %>
20
+ <% end %>
21
+ </div>
22
+
23
+ <div class="field">
24
+ <%= label_tag(:ids, Spree.t(:rich_editor_ids_description)) %>
25
+ <br />
26
+ <%= preference_field_tag(:ids, SpreeEditor::Config[:ids], class: 'control-form') %>
27
+ </div>
28
+
29
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
30
+ <%= button Spree.t('actions.update'), 'update' %>
31
+ </div>
32
+
33
+
34
+ </fieldset>
35
+ <% end %>
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
+ ENGINE_PATH = File.expand_path('../../lib/solidus_editor/engine', __FILE__)
5
+
6
+ require 'rails/all'
7
+ require 'rails/engine/commands'
@@ -0,0 +1,21 @@
1
+ # Use this hook to configure ckeditor
2
+ if Object.const_defined?('Ckeditor')
3
+ Ckeditor.setup do |config|
4
+ # ==> ORM configuration
5
+ # Load and configure the ORM. Supports :active_record (default), :mongo_mapper and
6
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
7
+ # available as additional gems.
8
+ require 'ckeditor/orm/active_record'
9
+
10
+ # Allowed image file types for upload.
11
+ # Set to nil or [] (empty array) for all file types
12
+ config.image_file_types = %w(jpg jpeg png gif tiff)
13
+
14
+ # Allowed attachment file types for upload.
15
+ # Set to nil or [] (empty array) for all file types
16
+ # config.attachment_file_types = %w(doc docx xls odt ods pdf rar zip tar swf)
17
+
18
+ # Setup authorization to be run as a before filter
19
+ config.authorize_with :cancan, Spree::Ability
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ ---
2
+ en:
3
+ spree:
4
+ enable_rich_editor: Enable Rich Editor
5
+ rich_editor: Rich Editor
6
+ rich_editor_description: Configure Rich Editor settings.
7
+ rich_editor_engine: Rich Editor engine
8
+ rich_editor_ids: Rich Editor Identificators
9
+ rich_editor_ids_description: "List textarea's ids splitted by spaces here"
@@ -0,0 +1,9 @@
1
+ ---
2
+ es:
3
+ spree:
4
+ enable_rich_editor: Activar editor avanzado
5
+ rich_editor: Editor avanzado
6
+ rich_editor_description: Configurar opciones del editor.
7
+ rich_editor_engine: Motor del editor avanzado
8
+ rich_editor_ids: Identificadores del editor avanzado
9
+ rich_editor_ids_description: "Listar aquí los ids de los textareas, separados por espacios"
@@ -0,0 +1,9 @@
1
+ ---
2
+ it:
3
+ spree:
4
+ enable_rich_editor: Abilita Editor di Testo
5
+ rich_editor: Editor di Testo
6
+ rich_editor_description: Configura Editor di Testo.
7
+ rich_editor_engine: Motore dell'Editor di Testo
8
+ rich_editor_ids: ID per l'Editor di Testo
9
+ rich_editor_ids_description: Elenca qui gli ID delle textarea divisi da spazi
@@ -0,0 +1,9 @@
1
+ ---
2
+ nl:
3
+ spree:
4
+ enable_rich_editor: "HTML Editor inschakelen"
5
+ rich_editor: "HTML Editor"
6
+ rich_editor_description: "Configureer HTML Editor."
7
+ rich_editor_engine: "HTML Editor implementatie"
8
+ rich_editor_ids: "HTML Editor id's"
9
+ rich_editor_ids_description: "HTML Editor koppelen aan de volgende id's (gescheiden door spaties)"
@@ -0,0 +1,9 @@
1
+ ---
2
+ ru:
3
+ spree:
4
+ enable_rich_editor: Включить визуальный редактор
5
+ rich_editor: Визуальный редактор
6
+ rich_editor_description: Настройка визуального редактора.
7
+ rich_editor_engine: Реализация визуального редактора
8
+ rich_editor_ids: Идентификаторы
9
+ rich_editor_ids_description: "Перечислите идентификаторы элементов textarea через пробел"
@@ -0,0 +1,9 @@
1
+ ---
2
+ sv:
3
+ spree:
4
+ enable_rich_editor: Aktivera Texthanterare
5
+ rich_editor: Texthanterare
6
+ rich_editor_description: Konfigurera Texthanterare inställningar.
7
+ rich_editor_engine: Texthanterare motor
8
+ rich_editor_ids: Texthanterare identifierare
9
+ rich_editor_ids_description: "Lista textfältens id-taggar separerade med blanksteg"
@@ -0,0 +1,5 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ namespace :admin do
3
+ resource :editor_settings, only: [:edit, :update]
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ module SolidusEditor
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../../../../templates', __FILE__)
5
+
6
+ def add_stylesheets
7
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_editor\n", before: /\*\//, verbose: true
8
+ end
9
+
10
+ def copy_tinymce_file
11
+ copy_file 'config/tinymce.yml', 'config/tinymce.yml'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module SolidusEditor
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../../../../templates', __FILE__)
5
+
6
+ def add_stylesheets
7
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_editor\n", before: /\*\//, verbose: true
8
+ end
9
+
10
+ def copy_tinymce_file
11
+ copy_file 'config/tinymce.yml', 'config/tinymce.yml'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ require 'solidus_backend'
2
+ require 'ckeditor'
3
+ require 'coffee_script'
4
+ require 'sass/rails'
5
+ require 'solidus_core'
6
+ require 'solidus_editor/version'
7
+ require 'spree_editor/config'
8
+ require 'solidus_editor/engine'
9
+ require 'tinymce-rails'
@@ -0,0 +1,25 @@
1
+ module SolidusEditor
2
+ class Engine < Rails::Engine
3
+ isolate_namespace Spree
4
+ engine_name 'solidus_editor'
5
+
6
+ initializer 'solidus_editor.preferences', before: :load_config_initializers do
7
+ SpreeEditor::Config = Spree::EditorSetting.new
8
+
9
+ if Spree::Config.has_preference? :show_raw_product_description
10
+ Spree::Config[:show_raw_product_description] = SpreeEditor::Config[:enabled]
11
+ end
12
+ end
13
+
14
+ config.autoload_paths += %W(#{config.root}/lib)
15
+
16
+ def self.activate
17
+ cache_klasses = %W(#{config.root}/app/**/*_decorator*.rb)
18
+ Dir.glob(cache_klasses) do |klass|
19
+ Rails.configuration.cache_classes ? require(klass) : load(klass)
20
+ end
21
+ end
22
+
23
+ config.to_prepare(&method(:activate).to_proc)
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ module SolidusEditor
2
+ module_function
3
+
4
+ # Returns the version of the currently loaded SpreeEditor as a
5
+ # <tt>Gem::Version</tt>.
6
+ def version
7
+ Gem::Version.new VERSION::STRING
8
+ end
9
+
10
+ module VERSION
11
+ MAJOR = 1
12
+ MINOR = 0
13
+ TINY = 0
14
+ PRE = nil
15
+
16
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module SpreeEditor
2
+
3
+ end
@@ -0,0 +1,40 @@
1
+ # Spree Editor TinyMCE Configuration
2
+ #
3
+ # These are the options that will automatically be passed into the tinyMCE.init function
4
+ # whenever TinyMCE is loaded in one of your spree pages. Please edit this file to
5
+ # customise your TinyMCE setup in your spree installation. If you wish to see the full
6
+ # range of configuration options then please go here:
7
+ #
8
+ # http://www.tinymce.com/wiki.php/configuration
9
+
10
+ # TinyMCE Options
11
+ mode: "exact"
12
+ theme: "modern"
13
+ language: "<%= I18n.locale.to_s.split('-')[0].downcase %>"
14
+ skin: "lightgray"
15
+ schema: "html5-strict"
16
+ element_format: "html"
17
+ resize: true
18
+ plugins:
19
+ - layer
20
+ - table
21
+ - insertdatetime
22
+ - preview
23
+ - media
24
+ - searchreplace
25
+ - contextmenu
26
+ - paste
27
+ - directionality
28
+ - fullscreen
29
+ - noneditable
30
+ - visualchars
31
+ - nonbreaking
32
+ - template
33
+
34
+ # Each line is a toolbar
35
+ toolbar:
36
+ - cut copy paste pastetext pasteword | search replace | undo redo | link unlink anchor image cleanup help code | insertdate inserttime preview
37
+ - bold italic underline strikethrough | justifyleft justifycenter justifyright justifyfull | sub sup | bullist numlist | outdent indent blockquote"
38
+ - styleselect formatselect fontselect fontsizeselect | forecolor backcolor
39
+ - tablecontrols | hr removeformat visualaid
40
+ - fullscreen | charmap media | visualchars blockquote
@@ -0,0 +1,46 @@
1
+ RSpec.describe Spree::Admin::EditorSettingsController, type: :controller do
2
+ stub_authorization!
3
+
4
+ before do
5
+ reset_spree_preferences
6
+ user = create(:admin_user)
7
+ allow(controller).to receive(:try_spree_current_user).and_return(user)
8
+ end
9
+
10
+ context '#update' do
11
+ it 'redirects to editor settings page' do
12
+ spree_put :update, preferences: { enabled: true }
13
+ expect(response).to redirect_to spree.edit_admin_editor_settings_path
14
+ end
15
+
16
+ context 'For parameters:
17
+ current_editor: CKEditor
18
+ enabled: true
19
+ ids: product_description page_body' do
20
+
21
+ subject { SpreeEditor::Config }
22
+
23
+ it 'sets preferred_current_editor to "CKEditor"' do
24
+ spree_put :update, preferences: { current_editor: 'CKEditor' }
25
+ expect(subject.preferred_current_editor).to eq('CKEditor')
26
+ end
27
+
28
+ it 'sets preferred_enabled to true' do
29
+ spree_put :update, preferences: { enabled: true }
30
+ expect(subject.preferred_enabled).to be(true)
31
+ end
32
+
33
+ it 'sets preferred_ids to product_description page_body' do
34
+ spree_put :update, preferences: { ids: 'product_description page_body' }
35
+ expect(subject.preferred_ids).to eq('product_description page_body')
36
+ end
37
+ end
38
+ end
39
+
40
+ context '#edit' do
41
+ it 'renders the edit template' do
42
+ spree_get :edit
43
+ expect(response).to be_success
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,12 @@
1
+ RSpec.feature 'Rich Editor Settings', :js do
2
+ stub_authorization!
3
+
4
+ context '#edit' do
5
+ scenario 'have default elements' do
6
+ visit spree.edit_admin_editor_settings_path
7
+
8
+ expect(page).to have_field 'ids', with: 'product_description page_body'
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,27 @@
1
+ require 'simplecov'
2
+ SimpleCov.start 'rails'
3
+
4
+ ENV['RAILS_ENV'] ||= 'test'
5
+
6
+ begin
7
+ require File.expand_path('../dummy/config/environment', __FILE__)
8
+ rescue LoadError
9
+ abort 'Could not load dummy application. Please ensure you have run `bundle exec rake test_app`'
10
+ end
11
+
12
+ require 'rspec/rails'
13
+ require 'i18n-spec'
14
+ require 'ffaker'
15
+
16
+ RSpec.configure do |config|
17
+ config.infer_spec_type_from_file_location!
18
+ config.mock_with :rspec
19
+ config.raise_errors_for_deprecations!
20
+ config.use_transactional_fixtures = false
21
+
22
+ config.expect_with :rspec do |expectations|
23
+ expectations.syntax = :expect
24
+ end
25
+ end
26
+
27
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |file| require file }
@@ -0,0 +1,17 @@
1
+ require 'capybara/rspec'
2
+ require 'capybara/rails'
3
+ require 'capybara/poltergeist'
4
+
5
+ RSpec.configure do |config|
6
+ Capybara.javascript_driver = :poltergeist
7
+
8
+ Capybara.register_driver(:poltergeist) do |app|
9
+ Capybara::Poltergeist::Driver.new app, js_errors: true, timeout: 40
10
+ end
11
+
12
+ config.before(:each, :js) do
13
+ if Capybara.javascript_driver == :selenium
14
+ page.driver.browser.manage.window.maximize
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ require 'database_cleaner'
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:suite) do
5
+ DatabaseCleaner.clean_with :truncation
6
+ end
7
+
8
+ config.before do
9
+ DatabaseCleaner.strategy = :transaction
10
+ end
11
+
12
+ config.before(:each, :js) do
13
+ DatabaseCleaner.strategy = :truncation
14
+ end
15
+
16
+ config.before do
17
+ DatabaseCleaner.start
18
+ end
19
+
20
+ config.after do
21
+ DatabaseCleaner.clean
22
+ end
23
+
24
+ Capybara.javascript_driver = :poltergeist
25
+ end