Browse Source

Setup ckeditor

pull/6/head
Angel Aviel Domaoan 4 years ago committed by Angel Aviel Domaoan
parent
commit
a2567121f3
  1. 2
      Gemfile
  2. 96
      Gemfile.lock
  3. 23
      app/assets/javascripts/frameworks/main.ckeditor.js
  4. 117
      app/assets/javascripts/frameworks/main.js.erb
  5. 2
      app/views/layouts/application.html.erb
  6. 3
      config/application.rb
  7. 28
      config/initializers/assets.rb
  8. BIN
      public/icons.png
  9. BIN
      public/images/sprites.png

2
Gemfile

@ -13,7 +13,7 @@ gem "foreman"
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
gem "sass-rails", "~> 5.1"
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks

96
Gemfile.lock

@ -100,8 +100,8 @@ GEM
bindex (0.8.1)
binding_of_caller (1.0.0)
debug_inspector (>= 0.0.1)
bootsnap (1.9.3)
msgpack (~> 1.0)
bootsnap (1.10.2)
msgpack (~> 1.2)
builder (3.2.4)
byebug (11.1.3)
cable_ready (4.5.0)
@ -166,18 +166,37 @@ GEM
warden (~> 1.2.3)
ed25519 (1.3.0)
erubi (1.10.0)
faraday (2.0.1)
faraday-net_http (~> 2.0)
faraday (1.9.3)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-net_http (2.0.1)
ffi (1.15.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.3)
multipart-post (>= 1.2, < 3)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
ffi (1.15.5)
figaro (1.2.0)
thor (>= 0.14.0, < 2)
foreman (0.87.2)
globalid (1.0.0)
activesupport (>= 5.0)
highline (2.0.3)
i18n (1.8.11)
i18n (1.9.0)
concurrent-ruby (~> 1.0)
jbuilder (2.11.5)
actionview (>= 5.0.0)
@ -194,7 +213,7 @@ GEM
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
listen (3.7.0)
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.13.0)
@ -207,27 +226,26 @@ GEM
method_source (1.0.0)
mini_mime (1.1.2)
minitest (5.15.0)
msgpack (1.4.2)
msgpack (1.4.4)
multipart-post (2.1.1)
net-scp (3.0.0)
net-ssh (>= 2.6.5, < 7.0.0)
net-ssh (6.1.0)
nio4r (2.5.8)
nokogiri (1.13.0-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.13.0-x86_64-linux)
nokogiri (1.13.1-x86_64-linux)
racc (~> 1.4)
nokogiri-styles (0.1.2)
nokogiri
okcomputer (1.18.4)
options (2.3.2)
orm_adapter (0.5.0)
paper_trail (12.1.0)
paper_trail (12.2.0)
activerecord (>= 5.2)
request_store (~> 1.1)
parallel (1.21.0)
parser (3.1.0.0)
ast (~> 2.4.1)
pg (1.2.3)
pg (1.3.0)
pr_geohash (1.0.0)
progress_bar (1.3.3)
highline (>= 1.6, < 3)
@ -235,7 +253,7 @@ GEM
public_suffix (4.0.6)
public_uid (2.1.1)
activerecord (> 4.2)
puma (5.5.2)
puma (5.6.1)
nio4r (~> 2.0)
racc (1.6.0)
rack (2.2.3)
@ -271,14 +289,14 @@ GEM
method_source
rake (>= 0.13)
thor (~> 1.0)
rainbow (3.0.0)
rainbow (3.1.1)
rake (13.0.6)
rb-fsevent (0.11.0)
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (4.5.1)
regexp_parser (2.2.0)
request_store (1.5.0)
request_store (1.5.1)
rack (>= 1.4)
responders (3.0.1)
actionpack (>= 5.0)
@ -288,9 +306,9 @@ GEM
rsolr (2.4.0)
builder (>= 2.1.2)
faraday (>= 0.9.0)
rubocop (1.24.1)
rubocop (1.25.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
@ -303,37 +321,38 @@ GEM
rubocop (>= 0.90, < 2.0)
rubocop-packaging (0.5.1)
rubocop (>= 0.89, < 2.0)
rubocop-performance (1.13.1)
rubocop-performance (1.13.2)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.13.1)
rubocop-rails (2.13.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sass-rails (5.1.0)
railties (>= 5.2.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
secure_headers (6.3.3)
selenium-webdriver (4.1.0)
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2)
semantic_range (3.0.0)
sentry-ruby (4.8.1)
sentry-ruby (4.9.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
faraday (>= 1.0)
sentry-ruby-core (= 4.8.1)
sentry-ruby-core (4.8.1)
faraday (~> 1.0)
sentry-ruby-core (= 4.9.2)
sentry-ruby-core (4.9.2)
concurrent-ruby
faraday
sidekiq (6.4.0)
@ -341,7 +360,7 @@ GEM
rack (~> 2.0)
redis (>= 4.2.0)
spring (3.1.1)
sprockets (4.0.2)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.4.2)
@ -389,7 +408,7 @@ GEM
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.1.0)
view_component (2.47.0)
view_component (2.48.0)
activesupport (>= 5.0.0, < 8.0)
method_source (~> 1.0)
warden (1.2.9)
@ -416,7 +435,6 @@ GEM
zeitwerk (2.5.3)
PLATFORMS
x86_64-darwin-20
x86_64-linux
DEPENDENCIES
@ -467,7 +485,7 @@ DEPENDENCIES
rubocop-packaging
rubocop-performance
rubocop-rails
sass-rails (>= 6)
sass-rails (~> 5.1)
secure_headers (>= 6.3.0)
selenium-webdriver
sentry-ruby (~> 4.8)

23
app/assets/javascripts/frameworks/main.ckeditor.js vendored

@ -0,0 +1,23 @@
//= require ckeditor/config
//= require ckeditor/init
$('.i-ckeditor').each(function(){
var a, b;
a = $(this), b = a.attr('id') || ('ckeditor' + (new Date).getTime())
//<![CDATA[
if (typeof CKEDITOR != 'undefined') { CKEDITOR.replace(b); }
//]]>
})
$('.i-ckeditor-readonly').each(function(){
var a, b;
a = $(this), b = a.attr('id') || ('ckeditor' + (new Date).getTime())
var options = {};
options.readOnly = true
options.toolbar = [
{ name: 'document', items : [ 'Source', 'Maximize' ] }
]
options.resize_enabled = false;
if (typeof CKEDITOR != 'undefined') { editor = CKEDITOR.replace(b, options); }
})

117
app/assets/javascripts/frameworks/main.js.erb

@ -0,0 +1,117 @@
//= require frameworks/main.ckeditor
(function () {
$.cachedScript = function( url, options ) {
options = $.extend( options || {}, {
dataType: "script",
cache: true,
async: true,
url: url
});
return $.ajaxq(url,options);
}
$.fn.doesExist = function() {
return $(this).length > 0;
};
if($('.i-ckeditor').doesExist()){
$.cachedScript("<%= asset_path 'frameworks/main.ckeditor.js' %>");
}
if($('.i-ckeditor-readonly').doesExist()){
$.cachedScript("<%= asset_path 'frameworks/main.ckeditor.js' %>");
}
})
/*
Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
/* Filebrowser routes */
// The location of an external file browser, that should be launched when "Browse Server" button is pressed.
config.filebrowserBrowseUrl = "/ckeditor/attachment_files";
// The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Flash dialog.
config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files";
// The location of a script that handles file uploads in the Flash dialog.
config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files";
// The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Link tab of Image dialog.
config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures";
// The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Image dialog.
config.filebrowserImageBrowseUrl = "/ckeditor/pictures";
// The location of a script that handles file uploads in the Image dialog.
config.filebrowserImageUploadUrl = "/ckeditor/pictures";
// The location of a script that handles file uploads.
config.filebrowserUploadUrl = "/ckeditor/attachment_files";
// Rails CSRF token
config.filebrowserParams = function(){
var csrf_token, csrf_param, meta,
metas = document.getElementsByTagName('meta'),
params = new Object();
for ( var i = 0 ; i < metas.length ; i++ ){
meta = metas[i];
switch(meta.name) {
case "csrf-token":
csrf_token = meta.content;
break;
case "csrf-param":
csrf_param = meta.content;
break;
default:
continue;
}
}
if (csrf_param !== undefined && csrf_token !== undefined) {
params[csrf_param] = csrf_token;
}
return params;
};
config.addQueryString = function( url, params ){
var queryString = [];
if ( !params ) {
return url;
} else {
for ( var i in params )
queryString.push( i + "=" + encodeURIComponent( params[ i ] ) );
}
return url + ( ( url.indexOf( "?" ) != -1 ) ? "&" : "?" ) + queryString.join( "&" );
};
// Integrate Rails CSRF token into file upload dialogs (link, image, attachment and flash)
CKEDITOR.on( 'dialogDefinition', function( ev ){
// Take the dialog name and its definition from the event data.
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
var content, upload;
if (CKEDITOR.tools.indexOf(['link', 'image', 'attachment', 'flash'], dialogName) > -1) {
content = (dialogDefinition.getContents('Upload') || dialogDefinition.getContents('upload'));
upload = (content == null ? null : content.get('upload'));
if (upload && upload.filebrowser && upload.filebrowser['params'] === undefined) {
upload.filebrowser['params'] = config.filebrowserParams();
upload.action = config.addQueryString(upload.action, upload.filebrowser['params']);
}
}
});
};

2
app/views/layouts/application.html.erb

@ -24,5 +24,7 @@
</div>
</div>
</div>
<%= javascript_include_tag 'frameworks/main' %>
</body>
</html>

3
config/application.rb

@ -18,5 +18,8 @@ module CdaoPjet
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
# Enable the asset pipeline
config.assets.enabled = true
end
end

28
config/initializers/assets.rb

@ -12,3 +12,31 @@ Rails.application.config.assets.paths << Rails.root.join('node_modules')
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
Rails.application.config.assets.precompile += Ckeditor.assets << /ckeditor\/lang\/.*.js/
assets_filter_precompile = lambda do |filename, path|
app_filters = [/(frameworks\/main|app|init|frameworks\/main.ckeditor|frameworks)\.(css|js)/, "frameworks/main.js"]
filters = [/.*\.woff/, /.*\.eot/, /.*\.svg/, /.*\.ttf/, /.*\.swf/]
# Assets to precompile in app/assets
precompile = path =~ /app\/assets/ && app_filters.concat(filters).any? do |filter|
if filter.is_a?(Regexp)
filter.match(filename)
else
File.fnmatch(filter.to_s, filename)
end
end
# Assets to precompile for not under in app/assets
# Skip if +precompile+ is `true`
precompile = !(path =~ /app\/assets/) && filters.any? do |filter|
if filter.is_a?(Regexp)
filter.match(filename)
else
File.fnmatch(filter.to_s, filename)
end
end unless precompile
precompile
end
Rails.application.config.assets.precompile += [assets_filter_precompile]
Rails.application.config.assets.precompile += %w(ckeditor/*)

BIN
public/icons.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
public/images/sprites.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Loading…
Cancel
Save