ckpages 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/javascripts/ckpages/application.coffee +9 -0
  6. data/app/assets/javascripts/ckpages/ckeditor_basepath.js +1 -0
  7. data/app/assets/javascripts/ckpages/ckeditor_init.js.erb +1 -0
  8. data/app/assets/javascripts/ckpages/ckeditor_replace.js.erb +16 -0
  9. data/app/assets/javascripts/ckpages/pages.js.coffee +39 -0
  10. data/app/assets/javascripts/ckpages/plugin_uploads.js.coffee +5 -0
  11. data/app/assets/stylesheets/ckpages/application.scss +34 -0
  12. data/app/controllers/ckpages/application_controller.rb +4 -0
  13. data/app/controllers/ckpages/ascendant404_controller.rb +13 -0
  14. data/app/controllers/ckpages/ascendant_controller.rb +19 -0
  15. data/app/controllers/ckpages/pages_controller.rb +66 -0
  16. data/app/controllers/ckpages/parts_controller.rb +63 -0
  17. data/app/controllers/ckpages/plugin_uploads_controller.rb +24 -0
  18. data/app/controllers/ckpages/uploads_controller.rb +41 -0
  19. data/app/helpers/ckpages/application_helper.rb +27 -0
  20. data/app/models/ckpages/page.rb +17 -0
  21. data/app/models/ckpages/part.rb +4 -0
  22. data/app/models/ckpages/upload.rb +5 -0
  23. data/app/uploaders/ckpages/application_uploader.rb +51 -0
  24. data/app/views/application/_ckpart.html.erb +1 -0
  25. data/app/views/ckpages/pages/_form.html.erb +35 -0
  26. data/app/views/ckpages/pages/edit.html.erb +5 -0
  27. data/app/views/ckpages/pages/index.html.erb +52 -0
  28. data/app/views/ckpages/pages/new.html.erb +5 -0
  29. data/app/views/ckpages/pages/show.html.erb +96 -0
  30. data/app/views/ckpages/parts/_form.html.erb +14 -0
  31. data/app/views/ckpages/parts/edit.html.erb +6 -0
  32. data/app/views/ckpages/parts/index.html.erb +44 -0
  33. data/app/views/ckpages/parts/new.html.erb +6 -0
  34. data/app/views/ckpages/parts/show.html.erb +21 -0
  35. data/app/views/ckpages/plugin_uploads/index.html.erb +23 -0
  36. data/app/views/ckpages/public/show.html.erb +19 -0
  37. data/app/views/ckpages/public404/show.html.erb +19 -0
  38. data/app/views/ckpages/uploads/index.html.erb +35 -0
  39. data/app/views/ckpages/uploads/show.html.erb +13 -0
  40. data/app/views/layouts/ckpages/application.html.erb +24 -0
  41. data/config/initializers/carrierwave.rb +1 -0
  42. data/config/initializers/simple_form.rb +166 -0
  43. data/config/initializers/simple_form_bootstrap.rb +136 -0
  44. data/config/locales/ru.yml +42 -0
  45. data/config/locales/simple_form.en.yml +31 -0
  46. data/config/routes.rb +29 -0
  47. data/db/migrate/20150424201308_create_ckpages_pages.rb +15 -0
  48. data/db/migrate/20150425115824_create_ckpages_uploads.rb +9 -0
  49. data/db/migrate/20150425152740_add_breadcrumb_to_ckpages_pages.rb +14 -0
  50. data/db/migrate/20150511111424_create_ckpages_parts.rb +10 -0
  51. data/db/migrate/20150819230152_add_columns_to_ckpages_uploads.rb +7 -0
  52. data/lib/ckpages.rb +12 -0
  53. data/lib/ckpages/engine.rb +8 -0
  54. data/lib/ckpages/version.rb +3 -0
  55. data/lib/tasks/ckpages_tasks.rake +4 -0
  56. data/lib/templates/erb/scaffold/_form.html.erb +13 -0
  57. data/test/dummy/README.rdoc +28 -0
  58. data/test/dummy/Rakefile +6 -0
  59. data/test/dummy/app/assets/javascripts/application.js +13 -0
  60. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  61. data/test/dummy/app/controllers/application_controller.rb +5 -0
  62. data/test/dummy/app/controllers/ckpages/public404_controller.rb +3 -0
  63. data/test/dummy/app/controllers/ckpages/public_controller.rb +2 -0
  64. data/test/dummy/app/helpers/application_helper.rb +2 -0
  65. data/test/dummy/app/views/ckpages/public/show.html.erb +1 -0
  66. data/test/dummy/app/views/layouts/application.html.erb +35 -0
  67. data/test/dummy/bin/bundle +3 -0
  68. data/test/dummy/bin/rails +4 -0
  69. data/test/dummy/bin/rake +4 -0
  70. data/test/dummy/bin/setup +29 -0
  71. data/test/dummy/config.ru +4 -0
  72. data/test/dummy/config/application.rb +26 -0
  73. data/test/dummy/config/boot.rb +5 -0
  74. data/test/dummy/config/database.yml +25 -0
  75. data/test/dummy/config/environment.rb +5 -0
  76. data/test/dummy/config/environments/development.rb +41 -0
  77. data/test/dummy/config/environments/production.rb +79 -0
  78. data/test/dummy/config/environments/test.rb +42 -0
  79. data/test/dummy/config/initializers/assets.rb +11 -0
  80. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  81. data/test/dummy/config/initializers/ckpages.rb +1 -0
  82. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  83. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  84. data/test/dummy/config/initializers/inflections.rb +16 -0
  85. data/test/dummy/config/initializers/mime_types.rb +4 -0
  86. data/test/dummy/config/initializers/session_store.rb +3 -0
  87. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  88. data/test/dummy/config/locales/en.yml +23 -0
  89. data/test/dummy/config/locales/ru.yml +257 -0
  90. data/test/dummy/config/routes.rb +3 -0
  91. data/test/dummy/config/secrets.yml +22 -0
  92. data/test/dummy/db/schema.rb +61 -0
  93. data/test/dummy/public/404.html +67 -0
  94. data/test/dummy/public/422.html +67 -0
  95. data/test/dummy/public/500.html +66 -0
  96. data/test/dummy/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.js +0 -0
  97. data/test/dummy/public/assets/application-e80e8f2318043e8af94dddc2adad5a4f09739a8ebb323b3ab31cd71d45fd9113.css +16 -0
  98. data/test/dummy/public/assets/bootstrap/glyphicons-halflings-regular-13634da87d9e23f8c3ed9108ce1724d183a39ad072e73e1b3d8cbf646d2d0407.eot +0 -0
  99. data/test/dummy/public/assets/bootstrap/glyphicons-halflings-regular-42f60659d265c1a3c30f9fa42abcbb56bd4a53af4d83d316d6dd7a36903c43e5.svg +288 -0
  100. data/test/dummy/public/assets/bootstrap/glyphicons-halflings-regular-a26394f7ede100ca118eff2eda08596275a9839b959c226e15439557a5a80742.woff +0 -0
  101. data/test/dummy/public/assets/bootstrap/glyphicons-halflings-regular-e395044093757d82afcb138957d06a1ea9361bdcf0b442d06a18a8051af57456.ttf +0 -0
  102. data/test/dummy/public/assets/bootstrap/glyphicons-halflings-regular-fe185d11a49676890d47bb783312a0cda5a44c4039214094e7957b4c040ef11c.woff2 +0 -0
  103. data/test/dummy/public/assets/ckpages/application-7743f5f42fc250d6d26375695a35e216ffb9f55bc3b9136f2ab0397aed2e91aa.css +5659 -0
  104. data/test/dummy/public/assets/ckpages/application-7a1ae892892ee8f88dc20d562ed46adc99be442a63038ba9be56d42c27dea964.js +121 -0
  105. data/test/dummy/public/favicon.ico +0 -0
  106. data/test/fixtures/ckpages/pages.yml +21 -0
  107. data/test/integration/ckpages/public_test.rb +37 -0
  108. data/test/models/ckpages/page_test.rb +34 -0
  109. data/test/models/ckpages/upload_test.rb +9 -0
  110. data/test/test_helper.rb +20 -0
  111. metadata +334 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a3c7e876d0cdc1193c50f153b22583b9e1a0b735
4
+ data.tar.gz: db2f03968ffb8b80732202a61c96fc71cccf9a81
5
+ SHA512:
6
+ metadata.gz: 2d3f09ff4b96fa005f789a5d6a52261f76a6e2f6720474cad4de5e269135c2363b0e0777c6701db7efbfa2c519e1c043c456640e322c90fab7889bb1c6c7669b
7
+ data.tar.gz: 38fe713d732d5b58ae9b0305db3a5f60f6d68f09a5ef1c4496c1c537e73d8419ee559a63dd9bf6af43d4d1861c890fd517bab2b34e2042fc5c816a3af84915ed
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Ruslan Kornev
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Ckpages
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Ckpages'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,9 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require turbolinks
4
+ //= require bootstrap
5
+ //= require ./ckeditor_basepath
6
+ //= require ./ckeditor_replace
7
+ //= require ./ckeditor_init
8
+ //= require ./pages
9
+ //= require ./plugin_uploads
@@ -0,0 +1 @@
1
+ window.CKEDITOR_BASEPATH = '/ckeditor/';
@@ -0,0 +1 @@
1
+ $(document).on("ready page:load", ckeditor_replace);
@@ -0,0 +1,16 @@
1
+ var ckeditor_replace = function() {
2
+ if ($('#page_content').length > 0) {
3
+ CKEDITOR.plugins.addExternal( 'placeholder', '/placeholder/', 'plugin.js' );
4
+ CKEDITOR.plugins.addExternal( 'codemirror', '/codemirror/', 'plugin.js' );
5
+ CKEDITOR.plugins.addExternal( 'pluginupload', '/pluginupload/', 'plugin.js' );
6
+ CKEDITOR.plugins.addExternal( 'pluginajaxsave', '/pluginajaxsave/', 'plugin.js' );
7
+ CKEDITOR.replace('page_content', {
8
+ extraPlugins: 'uploadimage,image2,embed,placeholder,codemirror,pluginupload,pluginajaxsave',
9
+ uploadUrl: ckpages_uploads_path,
10
+ height: '400',
11
+ allowedContent: true,
12
+ contentsCss: '<%= stylesheet_path 'application' %>',
13
+ language: 'ru'
14
+ });
15
+ }
16
+ }
@@ -0,0 +1,39 @@
1
+ change = (event) ->
2
+ n = event.data.index
3
+ title_id = event.data.title_id
4
+ url_id = event.data.url_id
5
+
6
+ title_class = $(".page_title#{n+1}")
7
+ url_class = $(".page_url#{n+1}")
8
+
9
+ if title_id.val() && url_id.val()
10
+ title_class.show()
11
+ url_class.show()
12
+ else
13
+ title_class.hide()
14
+ url_class.hide()
15
+
16
+
17
+ $(document).on "page:change", ->
18
+ for n in [1..5]
19
+
20
+ title_id = $("#page_title#{n}")
21
+ url_id = $("#page_url" + n)
22
+
23
+ previous_title_id = $("#page_title#{n-1}")
24
+ previous_url_id = $("#page_url#{n-1}")
25
+
26
+ title_class = $(".page_title#{n}")
27
+ url_class = $(".page_url#{n}")
28
+
29
+ title_id.on('change', {index: n, title_id: title_id, url_id: url_id}, change)
30
+ url_id.on('change', {index: n, title_id: title_id, url_id: url_id}, change)
31
+
32
+ # Если у текущей группы заполнено значение, или значение имеется
33
+ # у предыдущей группы, то отображаем обрабатываемую группу
34
+ if (title_id.val() && url_id.val()) || (previous_title_id.val() && previous_url_id.val()) || n == 1
35
+ title_class.show()
36
+ url_class.show()
37
+ else
38
+ title_class.hide()
39
+ url_class.hide()
@@ -0,0 +1,5 @@
1
+ $(document).on 'click', '#insert_files_into_ckeditor', ->
2
+ text = $("#file").html()
3
+ editor = $('#ckeditor-name').text()
4
+ window.opener.CKEDITOR.instances[editor].insertHtml(text)
5
+ window.close()
@@ -0,0 +1,34 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *
14
+
15
+ *= require_tree .
16
+ *= require_self
17
+ */
18
+
19
+ @import "bootstrap-sprockets";
20
+ @import "bootstrap";
21
+
22
+ .bottom-space-sm {
23
+ margin-bottom: 10px;
24
+ }
25
+
26
+ .alert:empty {
27
+ border: none;
28
+ margin: 0;
29
+ padding: 0;
30
+ }
31
+
32
+ .img-responsive img {
33
+ @include img-responsive()
34
+ }
@@ -0,0 +1,4 @@
1
+ module Ckpages
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,13 @@
1
+ require_dependency "ckpages/application_controller"
2
+
3
+ module Ckpages
4
+ class Ascendant404Controller < ::ApplicationController
5
+ after_action :set_status_404
6
+
7
+ private
8
+
9
+ def set_status_404
10
+ response.status = 404
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ require_dependency "ckpages/application_controller"
2
+
3
+ module Ckpages
4
+ class AscendantController < ::ApplicationController
5
+ before_action :set_page, only: [:show]
6
+
7
+ def show
8
+ if @page.redirect_url?
9
+ redirect_to @page.redirect_url, status: 301
10
+ end
11
+ end
12
+
13
+ private
14
+ def set_page
15
+ path = request.original_fullpath
16
+ @page = Page.where(:path => CGI::unescape(path)).first
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,66 @@
1
+ require_dependency "ckpages/application_controller"
2
+
3
+ module Ckpages
4
+ class PagesController < ApplicationController
5
+ before_action :set_page, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /pages
8
+ def index
9
+ @pages = Page.order(id: :desc).page(params[:page])
10
+ end
11
+
12
+ # GET /pages/1
13
+ def show
14
+ end
15
+
16
+ # GET /pages/new
17
+ def new
18
+ @page = Page.new(path: '/')
19
+
20
+ if params[:path].present?
21
+ @page.path = CGI::unescape(params[:path])
22
+ end
23
+ end
24
+
25
+ # GET /pages/1/edit
26
+ def edit
27
+ end
28
+
29
+ # POST /pages
30
+ def create
31
+ @page = Page.new(page_params)
32
+
33
+ if @page.save
34
+ redirect_to @page, notice: 'Page was successfully created.'
35
+ else
36
+ render :new
37
+ end
38
+ end
39
+
40
+ # PATCH/PUT /pages/1
41
+ def update
42
+ if @page.update(page_params)
43
+ redirect_to @page, notice: 'Page was successfully updated.'
44
+ else
45
+ render :edit
46
+ end
47
+ end
48
+
49
+ # DELETE /pages/1
50
+ def destroy
51
+ @page.destroy
52
+ redirect_to pages_url, notice: 'Page was successfully destroyed.'
53
+ end
54
+
55
+ private
56
+ # Use callbacks to share common setup or constraints between actions.
57
+ def set_page
58
+ @page = Page.find(params[:id])
59
+ end
60
+
61
+ # Only allow a trusted parameter "white list" through.
62
+ def page_params
63
+ params.require(:page).permit(:path, :content, :keywords, :description, :title, :robots, :redirect_url, :title1, :url1, :title2, :url2, :title3, :url3, :title4, :url4, :title5, :url5)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,63 @@
1
+ require_dependency "ckpages/application_controller"
2
+
3
+ module Ckpages
4
+ class PartsController < ApplicationController
5
+ before_action :set_part, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /parts
8
+ def index
9
+ @parts = Part.order(id: :desc).page(params[:page])
10
+ end
11
+
12
+ # GET /parts/1
13
+ def show
14
+ end
15
+
16
+ # GET /parts/new
17
+ def new
18
+ @part = Part.new
19
+ end
20
+
21
+ # GET /parts/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /parts
26
+ def create
27
+ @part = Part.new(part_params)
28
+
29
+ if @part.save
30
+ redirect_to @part, notice: 'Part was successfully created.'
31
+ else
32
+ render :new
33
+ end
34
+ end
35
+
36
+ # PATCH/PUT /parts/1
37
+ def update
38
+ if @part.update(part_params)
39
+ redirect_to @part, notice: 'Part was successfully updated.'
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ # DELETE /parts/1
46
+ def destroy
47
+ @part.destroy
48
+ redirect_to parts_url, notice: 'Part was successfully destroyed.'
49
+ end
50
+
51
+ private
52
+ # Use callbacks to share common setup or constraints between actions.
53
+ def set_part
54
+ @part = Part.find(params[:id])
55
+ end
56
+
57
+ # Only allow a trusted parameter "white list" through.
58
+ def part_params
59
+ params.require(:part).permit(:title, :text)
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,24 @@
1
+ require_dependency "ckpages/application_controller"
2
+
3
+ module Ckpages
4
+ class PluginUploadsController < ApplicationController
5
+ layout 'ckpages/application'
6
+
7
+ def index
8
+ @plugin_upload = Upload.new
9
+ end
10
+
11
+ def create
12
+ @plugin_upload = Upload.new(plugin_upload_params)
13
+ @plugin_upload.save!
14
+ render action: :index
15
+ end
16
+
17
+ private
18
+
19
+ def plugin_upload_params
20
+ params.require(:upload).permit!
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,41 @@
1
+ require_dependency "ckpages/application_controller"
2
+
3
+ module Ckpages
4
+ class UploadsController < ApplicationController
5
+
6
+ def index
7
+ @uploads = Upload.page(params[:page])
8
+ end
9
+
10
+ def show
11
+ @upload = Upload.find(params[:id])
12
+ end
13
+
14
+ # POST /uploads
15
+ def create
16
+ @upload = Upload.new(upload_params)
17
+ #{"fileName":"image(13).png","uploaded":1,"url":"\/ckfinder\/userfiles\/files\/image(13).png","error":{"number":201,"message":"A file with the same name is already available. The uploaded file was renamed to \"image(13).png\"."}}
18
+
19
+ @upload.save
20
+
21
+ respond_to do |format|
22
+ format.json {
23
+ render plain: {fileName: @upload.file.filename, uploaded: 1, url: @upload.file.url}.to_json
24
+ }
25
+ end
26
+ end
27
+
28
+ private
29
+ def upload_params
30
+ hack_params
31
+ params.require(:upload).permit(:file)
32
+ end
33
+
34
+ # hack parameter (maybe better to change ckeditor
35
+ # post params according Rails convention)
36
+ def hack_params
37
+ file = params[:upload].clone
38
+ params[:upload] = {file: file}
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ module Ckpages
2
+ module ApplicationHelper
3
+
4
+ def ckpart title, options = {}, locals = {}, &block
5
+ @part = Ckpages::Part.find_by!(title: title)
6
+ options = options.merge(partial: 'ckpart')
7
+ render options, locals, &block
8
+ end
9
+
10
+ def dt_dd(page, attr, lmbd=nil)
11
+ if page.send("#{attr}?")
12
+ content_tag(:dt) do
13
+ Page.human_attribute_name(attr)
14
+ end +
15
+ content_tag(:dd) do
16
+ val = page.send("#{attr}")
17
+ if lmbd.nil?
18
+ val.to_s
19
+ else
20
+ lmbd.call(val)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+ end