Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to current CMS head #1

Merged
merged 50 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9f34812
Support importing/exporting specific seed data classes. Issue #838
morgant Jul 27, 2018
d1241eb
Fix for failing tests when no seeds import/export class(es) specified…
morgant Jul 27, 2018
3d8d9db
Added seed tests for importing & exporting single & multiple classes.…
morgant Jul 27, 2018
542d768
Fix page seed import with attached file path containing white space c…
morgant Aug 5, 2018
34dee0a
Add precompiled assets explicitly (#840)
glebm Aug 7, 2018
8340f7c
Only use thumbnail on images that are actually variable
strfry Sep 19, 2018
752905a
Add test for handling SVG files in view
strfry Sep 28, 2018
951f243
Strip newlines/whitespace from fragment before processing mime_type (…
strfry Oct 1, 2018
28c628a
added option to customize the returned content json data
melvinsembrano Oct 2, 2018
03502a5
add config to sample config and doc
melvinsembrano Oct 2, 2018
808733a
remove logging
melvinsembrano Oct 2, 2018
11f4255
fix rubocop
melvinsembrano Oct 2, 2018
a4f3776
remove unecessary test
melvinsembrano Oct 2, 2018
5e468e0
don't raise if verify_authenticity_token not exists (Rails 5) (#847)
jgauby Oct 8, 2018
0625b1d
Order all pages by position (#842)
strfry Oct 8, 2018
29195c5
Added polish translations for "translations" section (#848)
olhor Oct 14, 2018
43a1dce
Merge branch 'import_seeds_by_class' of https://github.com/morgant/co…
GBH Nov 24, 2018
c61e7ac
pr tweaks
GBH Nov 24, 2018
3ea6d01
Merge branch 'morgant-import_seeds_by_class'
GBH Nov 24, 2018
4222ab0
Merge branch 'v2/patch/svg_images' of https://github.com/hicknhack-so…
GBH Nov 24, 2018
a00d623
pr tweak
GBH Nov 24, 2018
bff6950
Merge branch 'master' of https://github.com/melvinsembrano/comfortabl…
GBH Nov 24, 2018
b09fddf
adjustments to page.to_json options
GBH Nov 24, 2018
8d8f40f
Sass -> SassC (#852)
glebm Nov 24, 2018
2fabfc7
update_attributes is replaced with update
GBH Nov 25, 2018
6197bf8
Merge branch 'master' of github.com:comfy/comfortable-mexican-sofa
GBH Nov 25, 2018
b729251
changing how page.translate works. render call will also do translati…
GBH Nov 25, 2018
7f3acb3
Allow html classes to be specified for any file content tags. This me…
Dec 8, 2018
90eae4c
fix rubocop complaints
Dec 8, 2018
ae6e5ed
Fix indentation for first page navigation (#863)
alvesdan Jan 7, 2019
8e38c01
Write label attribute before save using filename
oscarsan Jan 25, 2019
815d1ed
add test when creating file without label
oscarsan Jan 28, 2019
c4668e3
correct typo on function name
oscarsan Jan 28, 2019
fbb1f1c
remove trailing spaces
oscarsan Jan 29, 2019
50e8cac
remove the pry
oscarsan Jan 29, 2019
d46e45f
fix for variant url
Mar 3, 2019
eb5a528
just deleted all lines previously commented out
Mar 3, 2019
ba0755f
bumping travis rubys
GBH Mar 16, 2019
0423152
Merge branch 'variant_repr_fix' of https://github.com/vs-de/comfortab…
GBH Mar 16, 2019
b489114
fixing link to the variant
GBH Mar 16, 2019
1884c82
adjusting pr to accept html class attributes on images
GBH Mar 16, 2019
63dbe78
Merge branch 'file_label_save' of https://github.com/oscarsan/comfort…
GBH Mar 16, 2019
3b11cfd
cleaning up file label setter a bit
GBH Mar 16, 2019
5436eac
files require labels
GBH Mar 16, 2019
1a97aa7
fix so ci runs
GBH Mar 16, 2019
8b9252f
Bump comfortable_mexican_sofa to 2.0.18
GBH Mar 16, 2019
07fa555
Fix default classes for comfy cms seeds import and export task (#878)
jaggednz Mar 27, 2019
e753296
reworked options_for_select a bit
GBH Mar 31, 2019
7d07636
coppers
GBH Mar 31, 2019
38a3142
adding readme about version 1 working on rails 5.2
GBH Mar 31, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: ruby
rvm:
- 2.3.7
- 2.4.4
- 2.5.1
- 2.3.8
- 2.4.5
- 2.5.5
- 2.6.2
- ruby-head
gemfile:
- test/gemfiles/5.2.gemfile
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ If you want to add a Blog functionality to your app take a look at

CMS for Rails 5.1 doesn't have published gem, but you may use [rails 5.1 branch](https://github.com/comfy/comfortable-mexican-sofa/tree/rails5.1) directly.

If you want to use CMS version 1.12 on Rails 5.2 use [1.13 branch](https://github.com/comfy/comfortable-mexican-sofa/tree/1.13) directly.

With Rails 4.2 and 5.0 use gem version [1.12.10](https://rubygems.org/gems/comfortable_mexican_sofa/versions/1.12.10)

With Rails 3.0 use gem version [1.8.5](https://rubygems.org/gems/comfortable_mexican_sofa/versions/1.8.5)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comfy/admin/cms/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create
end

def update
@category.update_attributes!(category_params)
@category.update!(category_params)
rescue ActiveRecord::RecordInvalid
head :ok
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comfy/admin/cms/layouts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create
end

def update
@layout.update_attributes!(layout_params)
@layout.update!(layout_params)
flash[:success] = I18n.t("comfy.admin.cms.layouts.updated")
redirect_to action: :edit, id: @layout
rescue ActiveRecord::RecordInvalid
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comfy/admin/cms/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create
end

def update
@site.update_attributes!(site_params)
@site.update!(site_params)
flash[:success] = I18n.t("comfy.admin.cms.sites.updated")
redirect_to action: :edit, id: @site
rescue ActiveRecord::RecordInvalid
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comfy/admin/cms/snippets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create
end

def update
@snippet.update_attributes!(snippet_params)
@snippet.update!(snippet_params)
flash[:success] = I18n.t("comfy.admin.cms.snippets.updated")
redirect_to action: :edit, id: @snippet
rescue ActiveRecord::RecordInvalid
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comfy/admin/cms/translations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create
end

def update
@translation.update_attributes!(translation_params)
@translation.update!(translation_params)
flash[:success] = I18n.t("comfy.admin.cms.translations.updated")
redirect_to action: :edit, id: @translation
rescue ActiveRecord::RecordInvalid
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comfy/cms/assets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Comfy::Cms::AssetsController < Comfy::Cms::BaseController

skip_before_action :verify_authenticity_token
skip_before_action :verify_authenticity_token, raise: false

before_action :load_cms_layout,
:use_null_session
Expand Down
17 changes: 6 additions & 11 deletions app/controllers/comfy/cms/content_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def show
respond_to do |format|
format.html { render_page }
format.json do
json_page = @cms_page.as_json(except: [:content_cache])
json_page[:content] = render_to_string(
@cms_page.content = render_to_string(
inline: @cms_page.content_cache,
layout: false
)
json_page = @cms_page.as_json(ComfortableMexicanSofa.config.page_to_json_options)
render json: json_page
end
end
Expand All @@ -44,7 +44,7 @@ def render_page(status = :ok)
# it's possible to control mimetype of a page by creating a `mime_type` field
def mime_type
mime_block = @cms_page.fragments.detect { |f| f.identifier == "mime_type" }
mime_block&.content || "text/html"
mime_block&.content&.strip || "text/html"
end

def app_layout
Expand Down Expand Up @@ -73,15 +73,10 @@ def load_cms_page
# Getting page and setting content_cache and fragments data if we need to
# serve translation data
def find_cms_page_by_full_path(full_path)
@cms_page = @cms_site.pages.published.find_by!(full_path: full_path)
@cms_layout = @cms_page.layout
@cms_page = @cms_site.pages.published.find_by!(full_path: full_path)

# There are translations for this page and locale is not the default site
# locale, so we need to grab translation data.
if @cms_page.translations.any? && @cms_site.locale != I18n.locale.to_s
@cms_page.translate!(I18n.locale)
@cms_layout = @cms_page.layout
end
@cms_page.translate!
@cms_layout = @cms_page.layout

@cms_page

Expand Down
15 changes: 8 additions & 7 deletions app/models/comfy/cms/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ class Comfy::Cms::File < ActiveRecord::Base
belongs_to :site

# -- Callbacks ---------------------------------------------------------------
before_validation :assign_label, on: :create
before_create :assign_position
after_save :process_attachment

# -- Validations -------------------------------------------------------------
validates :label, presence: true
validates :file, presence: true, on: :create

# -- Scopes ------------------------------------------------------------------
Expand All @@ -34,20 +36,19 @@ class Comfy::Cms::File < ActiveRecord::Base
where("active_storage_blobs.content_type LIKE 'image/%'").references(:blob)
}

# -- Instance Methods --------------------------------------------------------
def label
l = read_attribute(:label)
return l if l.present?
attachment.attached? ? attachment.filename.to_s : nil
end

protected

def assign_position
max = Comfy::Cms::File.maximum(:position)
self.position = max ? max + 1 : 0
end

# TODO: Change db schema not to set blank string
def assign_label
return if label.present?
self.label = file&.original_filename
end

def process_attachment
return if @file.blank?
attachment.attach(@file)
Expand Down
24 changes: 16 additions & 8 deletions app/models/comfy/cms/layout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,24 @@ class Comfy::Cms::Layout < ActiveRecord::Base

# -- Class Methods -----------------------------------------------------------
# Tree-like structure for layouts
def self.options_for_select(site, layout = nil, current_layout = nil, depth = 0, spacer = ". . ")
out = []
[current_layout || site.layouts.roots.order(:position)].flatten.each do |l|
next if layout == l
out << ["#{spacer * depth}#{l.label}", l.id]
l.children.order(:position).each do |child|
out += options_for_select(site, layout, child, depth + 1, spacer)
def self.options_for_select(site, current_layout = nil)
options = []

options_for_layout = ->(layout, depth = 0) do
return if layout == current_layout

options << ["#{'. . ' * depth}#{layout.label}", layout.id]

layout.children.order(:position).each do |child_layout|
options_for_layout.call(child_layout, depth + 1)
end
end
out.compact

site.layouts.roots.order(:position).each do |layout|
options_for_layout.call(layout)
end

options
end

# List of available application layouts
Expand Down
41 changes: 21 additions & 20 deletions app/models/comfy/cms/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class Comfy::Cms::Page < ActiveRecord::Base
include Comfy::Cms::WithFragments
include Comfy::Cms::WithCategories

cms_acts_as_tree counter_cache: :children_count
cms_acts_as_tree counter_cache: :children_count, order: :position
cms_has_revisions_for :fragments_attributes

attr_accessor :content

# -- Relationships -----------------------------------------------------------
belongs_to :site
belongs_to :target_page,
Expand Down Expand Up @@ -45,28 +47,22 @@ class Comfy::Cms::Page < ActiveRecord::Base

# -- Class Methods -----------------------------------------------------------
# Tree-like structure for pages
def self.options_for_select(site:, page: nil, current_page: nil, depth: 0, exclude_self: true, spacer: ". . ")
return [] if (current_page ||= site.pages.root) == page && exclude_self || !current_page
out = []
def self.options_for_select(site:, current_page: nil, exclude_self: false)
options = []

unless current_page == page
out << ["#{spacer * depth}#{current_page.label}", current_page.id]
end
options_for_page = ->(page, depth = 0) do
return if exclude_self && page == current_page

options << ["#{'. . ' * depth}#{page.label}", page.id]

if current_page.children_count.nonzero?
current_page.children.each do |child|
out += options_for_select(
site: site,
page: page,
current_page: child,
depth: depth + 1,
exclude_self: exclude_self,
spacer: spacer
)
page.children.order(:position).each do |child_page|
options_for_page.call(child_page, depth + 1)
end
end

out.compact
options_for_page.call(site.pages.root)

options
end

# -- Instance Methods --------------------------------------------------------
Expand All @@ -88,8 +84,13 @@ def url(relative: false)

# This method will mutate page object by transfering attributes from translation
# for a given locale.
def translate!(locale)
translation = translations.published.find_by!(locale: locale)
def translate!
# If site locale same as page's or there's no translastions, we do nothing
if site.locale == I18n.locale.to_s || translations.blank?
return
end

translation = translations.published.find_by!(locale: I18n.locale)
self.layout = translation.layout
self.label = translation.label
self.content_cache = translation.content_cache
Expand Down
2 changes: 1 addition & 1 deletion app/views/comfy/admin/cms/files/_file.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%li{data: {id: file.id}}
:ruby
file_tag = cms_file_link_tag(file)
thumb_url = url_for(file.attachment.variant(combine_options: Comfy::Cms::File::VARIANT_SIZE[:thumb])) if file.attachment.image?
thumb_url = url_for(file.attachment.variant(combine_options: Comfy::Cms::File::VARIANT_SIZE[:thumb])) if file.attachment.variable?
.row
.col-md-5.item
.item-controls.d-none.d-lg-block
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.fragment-attachments
- attachments.each do |attachment|
:ruby
thumb_url = if attachment.image?
thumb_url = if attachment.variable?
url_for(attachment.variant(combine_options: Comfy::Cms::File::VARIANT_SIZE[:thumb]))
end
filename = attachment.filename.to_s
Expand Down
4 changes: 2 additions & 2 deletions app/views/comfy/admin/cms/pages/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- if @page.parent.present?
= form.text_field :slug, data: { slug: true }, prepend: @page.parent.full_path

- if (options = ::Comfy::Cms::Page.options_for_select(site: @site, page: @page, exclude_self: true)).present?
- if (options = ::Comfy::Cms::Page.options_for_select(site: @site, current_page: @page, exclude_self: true)).present?
= form.select :parent_id, options, bootstrap: {custom_control: true}

- if (options = ::Comfy::Cms::Layout.options_for_select(@site)).present?
Expand All @@ -18,7 +18,7 @@

= render "comfy/admin/cms/categories/form", form: form

- if (options = ::Comfy::Cms::Page.options_for_select(site: @site, page: @page)).present?
- if (options = ::Comfy::Cms::Page.options_for_select(site: @site, current_page: @page)).present?
= form.select :target_page_id, [["---- #{t('.select_target_page')} ----", nil]] + options, bootstrap: {custom_control: true}

= form.check_box :is_published
Expand Down
2 changes: 1 addition & 1 deletion app/views/kaminari/comfy/_first_page.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- unless current_page.first?
%li.page-item
= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, class: 'page-link', remote: remote
= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, class: 'page-link', remote: remote
2 changes: 1 addition & 1 deletion comfortable_mexican_sofa.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ Gem::Specification.new do |s|
s.add_dependency "mini_magick", ">= 4.8.0"
s.add_dependency "rails", ">= 5.2.0"
s.add_dependency "rails-i18n", ">= 5.0.0"
s.add_dependency "sass-rails", ">= 5.0.0"
s.add_dependency "sassc-rails", ">= 2.0.0"
end
4 changes: 4 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@
config.active_job.queue_adapter = :inline

config.action_view.raise_on_missing_translations = true

# TODO: This is temporary fix so TravisCI runs until Rails 5.2.3 is out.
# See: https://github.com/rails/rails/pull/35607
config.secret_key_base = SecureRandom.hex(64)
end
6 changes: 6 additions & 0 deletions config/initializers/comfortable_mexican_sofa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
# Reveal partials that can be overwritten in the admin area.
# Default is false.
# config.reveal_cms_partials = false
#
# Customize the returned content json data
# include fragments in content json
# config.content_json_options = {
# include: [:fragments]
# }
end

# Default credentials for ComfortableMexicanSofa::AccessControl::AdminAuthentication
Expand Down
Loading