cm_page_builder 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +65 -0
  4. data/Rakefile +30 -0
  5. data/app/assets/config/cm_page_builder_rails_manifest.js +1 -0
  6. data/app/assets/stylesheets/cm_page_builder/rails/application.css +15 -0
  7. data/app/assets/stylesheets/cm_page_builder/rails/page_components.css +4 -0
  8. data/app/assets/stylesheets/cm_page_builder/rails/pages.css +4 -0
  9. data/app/assets/stylesheets/scaffold.css +80 -0
  10. data/app/controllers/cm_page_builder/rails/application_controller.rb +14 -0
  11. data/app/controllers/cm_page_builder/rails/pages_controller.rb +65 -0
  12. data/app/helpers/cm_page_builder/rails/application_helper.rb +6 -0
  13. data/app/helpers/cm_page_builder/rails/page_components_helper.rb +4 -0
  14. data/app/helpers/cm_page_builder/rails/pages_helper.rb +4 -0
  15. data/app/jobs/cm_page_builder/rails/application_job.rb +6 -0
  16. data/app/mailers/cm_page_builder/rails/application_mailer.rb +8 -0
  17. data/app/models/cm_page_builder/rails/application_record.rb +7 -0
  18. data/app/models/cm_page_builder/rails/page.rb +76 -0
  19. data/app/models/cm_page_builder/rails/page_component.rb +16 -0
  20. data/app/models/concerns/cm_page_builder/rails/has_cm_content.rb +20 -0
  21. data/app/views/cm_page_builder/rails/pages/_form.html.slim +13 -0
  22. data/app/views/cm_page_builder/rails/pages/edit.html.slim +5 -0
  23. data/app/views/cm_page_builder/rails/pages/show.html.slim +3 -0
  24. data/app/views/layouts/cm_page_builder/rails/application.html.erb +15 -0
  25. data/config/routes.rb +8 -0
  26. data/db/migrate/20190816103148_create_cm_page_builder_rails_pages.rb +9 -0
  27. data/db/migrate/20190816105056_create_cm_page_builder_rails_page_components.rb +13 -0
  28. data/db/migrate/20190903110322_change_page_component_primary_key.rb +11 -0
  29. data/lib/cm_page_builder/rails/application_helper.rb +33 -0
  30. data/lib/cm_page_builder/rails/engine.rb +22 -0
  31. data/lib/cm_page_builder/rails/version.rb +5 -0
  32. data/lib/cm_page_builder/rails.rb +8 -0
  33. data/lib/generators/cm_page_builder/rails/install_generator.rb +14 -0
  34. data/lib/generators/cm_page_builder/rails/templates/app/javascripts/components/cm_content_manager/Content.jsx +46 -0
  35. data/lib/tasks/cm_page_builder/rails_tasks.rake +4 -0
  36. data/spec/dummy/Rakefile +6 -0
  37. data/spec/dummy/app/assets/config/manifest.js +3 -0
  38. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  39. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  40. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  41. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  42. data/spec/dummy/app/controllers/test_containers_controller.rb +43 -0
  43. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  44. data/spec/dummy/app/javascript/packs/application.js +15 -0
  45. data/spec/dummy/app/jobs/application_job.rb +7 -0
  46. data/spec/dummy/app/models/application_record.rb +3 -0
  47. data/spec/dummy/app/models/test_container.rb +3 -0
  48. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  49. data/spec/dummy/app/views/test_containers/_form.html.slim +10 -0
  50. data/spec/dummy/app/views/test_containers/edit.html.slim +7 -0
  51. data/spec/dummy/app/views/test_containers/index.html.slim +21 -0
  52. data/spec/dummy/app/views/test_containers/new.html.slim +5 -0
  53. data/spec/dummy/app/views/test_containers/show.html.slim +3 -0
  54. data/spec/dummy/bin/rails +4 -0
  55. data/spec/dummy/bin/rake +4 -0
  56. data/spec/dummy/bin/setup +33 -0
  57. data/spec/dummy/config/application.rb +30 -0
  58. data/spec/dummy/config/boot.rb +5 -0
  59. data/spec/dummy/config/cable.yml +10 -0
  60. data/spec/dummy/config/database.yml +85 -0
  61. data/spec/dummy/config/environment.rb +5 -0
  62. data/spec/dummy/config/environments/development.rb +57 -0
  63. data/spec/dummy/config/environments/production.rb +106 -0
  64. data/spec/dummy/config/environments/test.rb +41 -0
  65. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  66. data/spec/dummy/config/initializers/assets.rb +12 -0
  67. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  69. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  70. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  71. data/spec/dummy/config/initializers/inflections.rb +16 -0
  72. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  73. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  74. data/spec/dummy/config/locales/en.yml +33 -0
  75. data/spec/dummy/config/puma.rb +35 -0
  76. data/spec/dummy/config/routes.rb +4 -0
  77. data/spec/dummy/config/spring.rb +6 -0
  78. data/spec/dummy/config/storage.yml +34 -0
  79. data/spec/dummy/config.ru +5 -0
  80. data/spec/dummy/db/migrate/20190930111315_create_test_containers.rb +9 -0
  81. data/spec/dummy/db/migrate/20190930120755_create_active_storage_tables.active_storage.rb +27 -0
  82. data/spec/dummy/db/migrate/20191114114259_create_cm_page_builder_rails_pages.cm_page_builder_rails.rb +10 -0
  83. data/spec/dummy/db/migrate/20191114114260_create_cm_page_builder_rails_page_components.cm_page_builder_rails.rb +14 -0
  84. data/spec/dummy/db/migrate/20191114114261_change_page_component_primary_key.cm_page_builder_rails.rb +12 -0
  85. data/spec/dummy/db/schema.rb +66 -0
  86. data/spec/dummy/public/404.html +67 -0
  87. data/spec/dummy/public/422.html +67 -0
  88. data/spec/dummy/public/500.html +66 -0
  89. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  90. data/spec/dummy/public/apple-touch-icon.png +0 -0
  91. data/spec/dummy/public/favicon.ico +0 -0
  92. data/spec/dummy/spec/models/test_container_spec.rb +5 -0
  93. data/spec/fixtures/files/commutatus_logo.png +0 -0
  94. data/spec/models/cm_page_builder/rails/page_spec.rb +50 -0
  95. data/spec/rails_helper.rb +62 -0
  96. data/spec/spec_helper.rb +96 -0
  97. metadata +256 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 03250c93e4b1b662bfd45e5fefd3c35c7349ecd74f050e9d505db26a68bc10e3
4
+ data.tar.gz: f9a4ededcd0ee8570a9ce9a0ad43b152b621f6d3c3e7ee1dba00f644f860f894
5
+ SHA512:
6
+ metadata.gz: 3a39c55b1277c85fb7126c2d87b8018a620c61193d8298ad6b90cff87be39fc2fabedb8baf1b46a98336fee01d87a17704a205dc75a88babcf2feeee47a467fb
7
+ data.tar.gz: 94cb326c6aa789b1272d30712b44767f8bb3e996c7a56fbddaead6ecd22b4a28e115bdc514b5ce959bbe5b6d3009d0530e716a82b04122569f59d38ba6d33d86
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 Camilo Ernesto Forero Junco
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.md ADDED
@@ -0,0 +1,65 @@
1
+ [![Gem Version](https://badge.fury.io/rb/cm_page_builder-rails.svg)](https://badge.fury.io/rb/cm_page_builder-rails)
2
+
3
+ # CmPageBuilder::Rails
4
+ This gem's purpose is to allow easy integration between the Commutatus javascript library [cm-page-builder](https://github.com/commutatus/cm-page-builder) and any Rails application that requires storing and editing content through Rails-rendered webpages.
5
+
6
+ ## Requirements
7
+
8
+ * Rails 6+
9
+ * Webpacker must be enabled in the project
10
+ * S3 as the image backend storage
11
+
12
+
13
+ ## Initial setup:
14
+
15
+ * Add the following lines to the gemfile:
16
+ ```ruby
17
+ gem 'react-rails', '~> 2.6.0'
18
+ gem 'cm_page_builder-rails'
19
+ ```
20
+ And then execute:
21
+ ```bash
22
+ $ bundle
23
+ ```
24
+ * Follow all react-rails installation instructions (https://github.com/reactjs/react-rails)
25
+ *Important:* ensure that the `hello_world` example successfully works
26
+
27
+ * Install the javascript packages with:
28
+ ```bash
29
+ yarn add cm-page-builder@1.3.0 -E
30
+ yarn add babel-runtime@^6.26.0
31
+ ```
32
+ (the emoji-mart package, a dependency of cm-page-builder, sometimes bugs out during the webpack build process without the babel-runtime)
33
+
34
+ * Run `rails cm_page_builder_rails:install:migrations`
35
+
36
+ * Run `rails generate cm_page_builder:rails:install` to install the JSX component. This assumes your webpack folder is inside `app/javascripts`
37
+
38
+ * In `config/routes.rb`, mount the endpoint with the line `mount CmPageBuilder::Rails::Engine => "/cm_page_builder"`
39
+
40
+ ## Usage
41
+ This package comes with a concern, `CmPageBuilder::Rails::HasCmContent` `include CmPageBuilder::Rails::HasCmContent`
42
+ To activate this module, add `include CmPageBuilder::Rails::HasCmContent` on top of any model file that should have an associated page builder record.
43
+
44
+ The page builder record will be accessible from the model as *page* (`@model.page`). The show path is accessible through the route `cm_page_builder_rails.page_path(@page)`, and the edit path through the route `cm_page_builder_rails.edit_page_path(@page)`
45
+
46
+ To make the fragment read-only in the form, pass the value in `status` prop as `Read`. Example,
47
+ ```ruby
48
+ = react_component('cm_content_manager/Content', { input: 'content-editor', components: @page.components, assetBaseUrl: ActiveStorage::Blob.service.bucket.url, status: 'Read'})
49
+ ```
50
+
51
+ By default, the value of the status prop is set to `Edit`.
52
+
53
+ ### Setting up CORS for aws
54
+ Do this or the direct upload capabilities won't work
55
+ https://keithpblog.org/post/active-storage-on-amazon-s3/
56
+
57
+ ### Building the gem
58
+ `gem build cm_page_builder-rails.gemspec`
59
+ `gem push cm_page_builder-rails-0.1.x.gem`
60
+
61
+ ## Contributing
62
+ Contribution directions go here.
63
+
64
+ ## License
65
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,30 @@
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 = 'CmPageBuilder::Rails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rspec/core'
25
+ require 'rspec/core/rake_task'
26
+
27
+ desc "Run all specs in spec directory (excluding plugin specs)"
28
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
29
+
30
+ task :default => :spec
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/cm_page_builder/rails .css
@@ -0,0 +1,15 @@
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 other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,80 @@
1
+ body {
2
+ background-color: #fff;
3
+ color: #333;
4
+ margin: 33px;
5
+ }
6
+
7
+ body, p, ol, ul, td {
8
+ font-family: verdana, arial, helvetica, sans-serif;
9
+ font-size: 13px;
10
+ line-height: 18px;
11
+ }
12
+
13
+ pre {
14
+ background-color: #eee;
15
+ padding: 10px;
16
+ font-size: 11px;
17
+ }
18
+
19
+ a {
20
+ color: #000;
21
+ }
22
+
23
+ a:visited {
24
+ color: #666;
25
+ }
26
+
27
+ a:hover {
28
+ color: #fff;
29
+ background-color: #000;
30
+ }
31
+
32
+ th {
33
+ padding-bottom: 5px;
34
+ }
35
+
36
+ td {
37
+ padding: 0 5px 7px;
38
+ }
39
+
40
+ div.field,
41
+ div.actions {
42
+ margin-bottom: 10px;
43
+ }
44
+
45
+ #notice {
46
+ color: green;
47
+ }
48
+
49
+ .field_with_errors {
50
+ padding: 2px;
51
+ background-color: red;
52
+ display: table;
53
+ }
54
+
55
+ #error_explanation {
56
+ width: 450px;
57
+ border: 2px solid red;
58
+ padding: 7px 7px 0;
59
+ margin-bottom: 20px;
60
+ background-color: #f0f0f0;
61
+ }
62
+
63
+ #error_explanation h2 {
64
+ text-align: left;
65
+ font-weight: bold;
66
+ padding: 5px 5px 5px 15px;
67
+ font-size: 12px;
68
+ margin: -7px -7px 0;
69
+ background-color: #c00;
70
+ color: #fff;
71
+ }
72
+
73
+ #error_explanation ul li {
74
+ font-size: 12px;
75
+ list-style: square;
76
+ }
77
+
78
+ label {
79
+ display: block;
80
+ }
@@ -0,0 +1,14 @@
1
+ module CmPageBuilder
2
+ module Rails
3
+ class ApplicationController < ::ApplicationController
4
+ protect_from_forgery with: :exception
5
+ layout CmPageBuilder::Rails.layout_template
6
+ #helper ::Rails.application.routes.url_helpers
7
+ #helper CmPageBuilder::Rails::ApplicationHelper
8
+
9
+ def current_user
10
+ main_app.scope.request.env['warden'].user
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,65 @@
1
+ require_dependency "cm_page_builder/rails/application_controller"
2
+
3
+ module CmPageBuilder::Rails
4
+ class PagesController < ApplicationController
5
+ before_action :set_page, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /pages
8
+ def index
9
+ @pages = Page.all
10
+ end
11
+
12
+ # GET /pages/1
13
+ def show
14
+ end
15
+
16
+ # GET /pages/new
17
+ def new
18
+ @page = Page.new
19
+ end
20
+
21
+ # GET /pages/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /pages
26
+ def create
27
+ components = page_params.delete('components')
28
+ @page = Page.new(page_params)
29
+
30
+ if @page.save
31
+ @page.save_content(components)
32
+ redirect_to @page, notice: 'Page was successfully created.'
33
+ else
34
+ render :new
35
+ end
36
+ end
37
+
38
+ # PATCH/PUT /pages/1
39
+ def update
40
+ components = page_params.delete(:components)
41
+ if @page.save_content(components)
42
+ redirect_to @page, notice: 'Page was successfully updated.'
43
+ else
44
+ render :edit
45
+ end
46
+ end
47
+
48
+ # DELETE /pages/1
49
+ def destroy
50
+ @page.destroy
51
+ redirect_to pages_url, notice: 'Page was successfully destroyed.'
52
+ end
53
+
54
+ private
55
+ # Use callbacks to share common setup or constraints between actions.
56
+ def set_page
57
+ @page = Page.find(params[:id])
58
+ end
59
+
60
+ # Only allow a trusted parameter "white list" through.
61
+ def page_params
62
+ params.require(:page).permit(:container_id, :container_type, :components)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,6 @@
1
+ module CmPageBuilder
2
+ module Rails
3
+ module ApplicationHelper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module CmPageBuilder::Rails
2
+ module PageComponentsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module CmPageBuilder::Rails
2
+ module PagesHelper
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module CmPageBuilder
2
+ module Rails
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module CmPageBuilder
2
+ module Rails
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module CmPageBuilder
2
+ module Rails
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,76 @@
1
+ module CmPageBuilder::Rails
2
+ class Page < ApplicationRecord
3
+ belongs_to :container, polymorphic: true
4
+ has_many :page_components, dependent: :destroy
5
+
6
+ accepts_nested_attributes_for :page_components, allow_destroy: true
7
+
8
+ def components(**args)
9
+ page_components.with_attached_component_attachment.select(:id, :uuid, :component_type, :position, :content).map do |component|
10
+ json_component = component.as_json.transform_keys! { |key| key.camelize(:lower) }
11
+ json_component["id"] = component[:uuid]
12
+ json_component["component_attachment"] = _get_attachment(component, args[:max_width])
13
+ json_component
14
+ end
15
+ end
16
+
17
+ def duplicate
18
+ dupl = self.dup
19
+ dupl.page_components = self.page_components.map do |pc|
20
+ pc.duplicate
21
+ end
22
+ dupl
23
+ end
24
+
25
+ def save_content(component_json)
26
+ components = JSON.parse component_json
27
+ deleted_components = page_components.where.not(
28
+ uuid: components.map { |component| component["id"] }
29
+ )
30
+ deleted_components.delete_all
31
+ components.each do |component|
32
+ _save_component(component)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def _get_attachment(component, max_width=nil)
39
+ attachment = component.component_attachment.attachment
40
+ return unless attachment
41
+
42
+ blob = attachment.blob
43
+ attachment_data = {
44
+ filename: attachment.filename.to_s,
45
+ filesize: blob.byte_size,
46
+ url: attachment.service_url
47
+ }
48
+ if blob.variable?
49
+ dimensions = blob.metadata
50
+ dimensions['orientation'] =
51
+ if dimensions['width'].nil? || dimensions['height'].nil?
52
+ 'portrait'
53
+ elsif dimensions['width'] > dimensions['height']
54
+ 'landscape'
55
+ else
56
+ 'portrait'
57
+ end
58
+ attachment_data[:dimensions] = dimensions
59
+ attachment_data[:url] = attachment.variant(resize_to_limit: [max_width, nil]).processed.service_url if max_width
60
+ end
61
+ attachment_data
62
+ end
63
+
64
+ def _save_component(component)
65
+ page_component = page_components.find_or_initialize_by(uuid: component["id"])
66
+ signed_id = component.dig("component_attachment", "signed_id")
67
+ component_data = {
68
+ content: component["content"],
69
+ position: component["position"],
70
+ component_type: component["componentType"]
71
+ }
72
+ component_data[:component_attachment] = signed_id if signed_id
73
+ page_component.update!(component_data)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,16 @@
1
+ module CmPageBuilder::Rails
2
+ class PageComponent < ApplicationRecord
3
+ belongs_to :page
4
+
5
+ has_one_attached :component_attachment
6
+
7
+ default_scope { order(position: :asc) }
8
+
9
+ def duplicate
10
+ dupl = self.dup
11
+ dupl.component_attachment.attach(self.component_attachment.blob) if self.component_attachment.attachment
12
+ dupl
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ module CmPageBuilder
2
+ module Rails
3
+ module HasCmContent
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ has_one :page, as: :container, dependent: :destroy, class_name:"CmPageBuilder::Rails::Page"
8
+ has_many :page_components, through: :page
9
+
10
+ delegate :save_content, to: :page
11
+
12
+
13
+ after_find do
14
+ self.create_page! unless self.page
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ = form_for @page do |f|
2
+ - if @page.errors.any?
3
+ #error_explanation
4
+ h2 = "#{pluralize(@page.errors.count, "error")} prohibited this page from being saved:"
5
+ ul
6
+ - @page.errors.full_messages.each do |message|
7
+ li = message
8
+
9
+ .field
10
+ input type='hidden' id="content-editor" name="page[components]"
11
+ = react_component("cm_content_manager/Content", { input: "content-editor", components: @page.components, assetBaseUrl: ActiveStorage::Blob.service.bucket.url})
12
+
13
+ .actions = f.submit
@@ -0,0 +1,5 @@
1
+ h1 Editing page
2
+
3
+ == render 'form'
4
+
5
+ => link_to 'Show', @page
@@ -0,0 +1,3 @@
1
+ p#notice = notice
2
+
3
+ => link_to 'Edit', edit_page_path(@page)
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Cm page builder rails</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "cm_page_builder/rails/application", media: "all" %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,8 @@
1
+
2
+
3
+ CmPageBuilder::Rails::Engine.routes.draw do
4
+ # Only individual items can be shown and edited.
5
+ # The only way to access these is through their parent record in the main application, so no index
6
+ # Their lifecycle is also associated with their parent record's, so no create and destroy
7
+ resources :pages, only: [:show, :edit, :update]
8
+ end
@@ -0,0 +1,9 @@
1
+ class CreateCmPageBuilderRailsPages < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :cm_page_builder_rails_pages do |t|
4
+ t.references :container, polymorphic: true, null: false, index: { name: 'container_composite_index' }
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+
2
+ class CreateCmPageBuilderRailsPageComponents < ActiveRecord::Migration[6.0]
3
+ def change
4
+ create_table :cm_page_builder_rails_page_components, id: :string do |t|
5
+ t.references :page, null: false
6
+ t.string :content
7
+ t.integer :position
8
+ t.string :component_type
9
+ t.timestamps
10
+ end
11
+ add_foreign_key :cm_page_builder_rails_page_components, :cm_page_builder_rails_pages, column: :page_id
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class ChangePageComponentPrimaryKey < ActiveRecord::Migration[6.0]
2
+ def change
3
+ rename_column :cm_page_builder_rails_page_components, :id, :uuid
4
+ CmPageBuilder::Rails::PageComponent.connection.execute(
5
+ <<~SQL
6
+ ALTER TABLE cm_page_builder_rails_page_components DROP CONSTRAINT cm_page_builder_rails_page_components_pkey;
7
+ SQL
8
+ )
9
+ add_column :cm_page_builder_rails_page_components, :id, :primary_key
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ module CmPageBuilder
2
+ module Rails
3
+ module ApplicationHelper
4
+
5
+
6
+ # def method_missing method, *args, &block
7
+ # pp "==========="
8
+ # if method.to_s.end_with?('_path') or method.to_s.end_with?('_url')
9
+ # if main_app.respond_to?(method)
10
+ # main_app.send(method, *args)
11
+ # else
12
+ # super
13
+ # end
14
+ # else
15
+ # super
16
+ # end
17
+ # end
18
+ #
19
+ # def respond_to?(method)
20
+ # if method.to_s.end_with?('_path') or method.to_s.end_with?('_url')
21
+ # if main_app.respond_to?(method)
22
+ # true
23
+ # else
24
+ # super
25
+ # end
26
+ # else
27
+ # super
28
+ # end
29
+ # end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ module CmPageBuilder
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace CmPageBuilder::Rails
5
+
6
+ config.generators do |g|
7
+ g.template_engine :slim
8
+ g.test_framework :rspec
9
+ end
10
+ # This part of the code makes sure that the main application's helper
11
+ # methods can be accessed from the engine
12
+ # initializer 'cm_page_builder_rails.action_controller' do |app|
13
+ # ActiveSupport.on_load :action_controller do
14
+ # helper CmPageBuilder::Rails::ApplicationHelper
15
+ # end
16
+ # # ActiveSupport.on_load(:action_controller) do
17
+ # # helper ::Rails.application.routes.url_helpers
18
+ # # end
19
+ # end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ module CmPageBuilder
2
+ module Rails
3
+ VERSION = '0.2.2'
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "cm_page_builder/rails/engine"
2
+
3
+ module CmPageBuilder
4
+ module Rails
5
+ mattr_accessor :layout_template
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CmPageBuilder::Rails
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Copy the jsx component"
7
+ source_root File.expand_path('templates', __dir__)
8
+
9
+ def copy_jsx_component
10
+ template "app/javascripts/components/cm_content_manager/Content.jsx"
11
+ end
12
+ end
13
+ end
14
+ end