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

Adds slugs to categories #954

Open
wants to merge 20 commits into
base: 1.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ before_script:
script:
- rake ci
rvm:
- 2.2.7
- 2.3.5
- 2.4.2
- 2.5.9
- 2.6.7
- 2.7.3
gemfile:
- test/gemfiles/Gemfile.rails.5.2
- test/gemfiles/Gemfile.rails.6.0
- test/gemfiles/Gemfile.rails.6.1
branches:
only:
- master
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
[![Code Climate](https://img.shields.io/codeclimate/github/comfy/comfortable-mexican-sofa.svg?style=flat)](https://codeclimate.com/github/comfy/comfortable-mexican-sofa)
[![Coverage Status](https://img.shields.io/coveralls/comfy/comfortable-mexican-sofa.svg?style=flat)](https://coveralls.io/r/comfy/comfortable-mexican-sofa?branch=master)

ComfortableMexicanSofa is a powerful Rails 4/5 CMS Engine
ComfortableMexicanSofa is a powerful Rails 5/6 CMS Engine

## Features

* Simple integration with Rails 4 apps
* Simple integration with Rails 5/6 apps
* Build your application in Rails, not in CMS
* Powerful page templating capability using [Tags](https://github.com/comfy/comfortable-mexican-sofa/wiki/Tags)
* [Multiple Sites](https://github.com/comfy/comfortable-mexican-sofa/wiki/Sites) from a single installation
Expand All @@ -24,7 +24,7 @@ ComfortableMexicanSofa is a powerful Rails 4/5 CMS Engine
Add gem definition to your Gemfile:

```ruby
gem 'comfortable_mexican_sofa', '~> 1.12.0'
gem 'comfortable_mexican_sofa', '~> 1.14.0'
```

Then from the Rails project's root run:
Expand Down
19 changes: 0 additions & 19 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,3 @@ end

require_relative 'config/application'
ComfortableMexicanSofa::Application.load_tasks

namespace :test do
Rake::TestTask.new(:lib) do |t|
t.libs << 'test'
t.pattern = 'test/lib/**/*_test.rb'
t.verbose = true
end

Rake::TestTask.new(:generators) do |t|
t.libs << 'test'
t.pattern = 'test/generators/**/*_test.rb'
t.verbose = true
end
end

Rake::Task[:test].enhance do
Rake::Task['test:lib'].invoke
Rake::Task['test:generators'].invoke
end
3 changes: 3 additions & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= link_tree ../images
//= link_directory ../javascripts/comfy/admin/cms .js
//= link_directory ../stylesheets/comfy/admin/cms .css
4 changes: 4 additions & 0 deletions app/assets/javascripts/comfy/admin/cms/base.js.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if jQuery.size == undefined
window.jQuery.fn.size = ->
this.length

window.CMS ||= {}

window.CMS.code_mirror_instances = [ ]
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 @@ -15,7 +15,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 @@ -27,7 +27,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 @@ -31,7 +31,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 @@ -27,7 +27,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
3 changes: 0 additions & 3 deletions app/models/comfy/cms/categorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ class Comfy::Cms::Categorization < ActiveRecord::Base
:polymorphic => true

# -- Validations ----------------------------------------------------------
validates :categorized_type, :categorized_id,
:presence => true
validates :category_id,
:presence => true,
:uniqueness => { :scope => [:categorized_type, :categorized_id] }

end
21 changes: 15 additions & 6 deletions app/models/comfy/cms/category.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
class Comfy::Cms::Category < ActiveRecord::Base
self.table_name = 'comfy_cms_categories'

# -- Relationships --------------------------------------------------------
belongs_to :site
has_many :categorizations,
:dependent => :destroy


# -- Callbacks ------------------------------------------------------------
before_validation :create_slug

# -- Validations ----------------------------------------------------------
validates :site_id,
:presence => true
validates :label,
:presence => true,
:uniqueness => { :scope => [:categorized_type, :site_id] }
validates :categorized_type,
:presence => true



# -- Scopes ---------------------------------------------------------------
default_scope{ order(:label) }

scope :of_type, lambda { |type|
where(:categorized_type => type)
}


protected

# Create slug from Label
def create_slug
return if label.nil? or label.empty?
self.slug = label.downcase.gsub(/[^a-z0-9\-]/, '-')
end
end
2 changes: 0 additions & 2 deletions app/models/comfy/cms/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class Comfy::Cms::File < ActiveRecord::Base
belongs_to :block, optional: true

# -- Validations ----------------------------------------------------------
validates :site_id,
:presence => true
validates_attachment_presence :file
do_not_validate_attachment_file_type :file

Expand Down
2 changes: 0 additions & 2 deletions app/models/comfy/cms/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class Comfy::Cms::Page < ActiveRecord::Base
after_find :unescape_slug_and_path

# -- Validations ----------------------------------------------------------
validates :site_id,
:presence => true
validates :label,
:presence => true
validates :slug,
Expand Down
2 changes: 1 addition & 1 deletion app/models/comfy/cms/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def url
# When removing entire site, let's not destroy content from other sites
# Since before_destroy doesn't really work, this does the trick
def destroy
self.update_attributes(:is_mirrored => false) if self.is_mirrored?
self.update(:is_mirrored => false) if self.is_mirrored?
super
end

Expand Down
2 changes: 0 additions & 2 deletions app/models/comfy/cms/snippet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class Comfy::Cms::Snippet < ActiveRecord::Base
after_destroy :clear_page_content_cache

# -- Validations ----------------------------------------------------------
validates :site_id,
:presence => true
validates :label,
:presence => true
validates :identifier,
Expand Down
6 changes: 5 additions & 1 deletion app/views/comfy/admin/cms/files/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@

= comfy_paginate @files

:ruby
session_id = request.session_options[:id]
session_id_value = session_id.respond_to?(:public_id) ? session_id.public_id : session_id.to_s

:javascript
$(function(){
window.CMS.uploader($("#cms-uploader"), {
url: '#{comfy_admin_cms_site_files_path(@site, :source => :plupload, :category => params[:category])}',
multipart_params: {
'#{request_forgery_protection_token}': '#{form_authenticity_token}',
'#{Rails.application.config.session_options[:key]}': '#{request.session_options[:id]}'
'#{Rails.application.config.session_options[:key]}': '#{session_id_value}'
}
});
});
19 changes: 9 additions & 10 deletions comfortable_mexican_sofa.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ Gem::Specification.new do |s|
s.authors = ["Oleg Khabarov"]
s.email = ["[email protected]"]
s.homepage = "http://github.com/comfy/comfortable-mexican-sofa"
s.summary = "Rails 4/5 CMS Engine"
s.summary = "Rails 4/5/6 CMS Engine"
s.description = "ComfortableMexicanSofa is a powerful Rails 4/5 CMS Engine"
s.license = 'MIT'

s.files = `git ls-files`.split("\n")
s.platform = Gem::Platform::RUBY
s.require_paths = ['lib']

s.required_ruby_version = '>= 2.2.2'
s.required_ruby_version = '>= 2.5.0'

s.add_dependency 'rails', '>= 5.2.0', '< 6'
s.add_dependency 'rails-i18n', '>= 4.0.0'
s.add_dependency 'bootstrap_form', '>= 2.2.0'
s.add_dependency 'rails', '>= 6.0.0', '< 6.2'
s.add_dependency 'rails-i18n', '>= 5.0.0'
s.add_dependency 'bootstrap_form', '>= 2.2.0', '< 3'
s.add_dependency 'active_link_to', '>= 1.0.0'
s.add_dependency 'paperclip', '>= 4.0.0'
s.add_dependency 'kt-paperclip', '>= 6.4.1'
s.add_dependency 'kramdown', '>= 1.0.0'
s.add_dependency 'jquery-rails', '>= 3.0.0'
s.add_dependency 'jquery-ui-rails', '>= 5.0.0'
s.add_dependency 'haml-rails', '>= 0.3.0'
s.add_dependency 'sass-rails', '>= 4.0.3'
s.add_dependency 'coffee-rails', '>= 3.1.0'
s.add_dependency 'codemirror-rails', '>= 3.0.0'
s.add_dependency 'haml-rails', '>= 1.0.0'
s.add_dependency 'sass-rails', '>= 5.1.0'
s.add_dependency 'coffee-rails', '>= 5.0.0'
s.add_dependency 'bootstrap-sass', '>= 3.2.0'
s.add_dependency 'plupload-rails', '>= 1.2.1'
end
5 changes: 2 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

module ComfortableMexicanSofa
class Application < Rails::Application

config.load_defaults 5.2

require_relative '../lib/comfortable_mexican_sofa'

# Settings in config/environments/* take precedence over those specified here.
Expand All @@ -26,7 +27,5 @@ class Application < Rails::Application
config.paths['config/routes.rb'] << 'config/cms_routes.rb'

config.i18n.enforce_available_locales = true

Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
end
end
1 change: 1 addition & 0 deletions db/migrate/01_create_cms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def self.up
create_table :comfy_cms_categories, :force => true do |t|
t.integer :site_id, :null => false
t.string :label, :null => false
t.string :slug, :null => false
t.string :categorized_type, :null => false
end
add_index :comfy_cms_categories, [:site_id, :categorized_type, :label], :unique => true,
Expand Down
17 changes: 17 additions & 0 deletions db/upgrade_migrations/09_upgrade_to_1_15_0.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class UpgradeTo1150 < ActiveRecord::Migration
def self.up
add_column :comfy_cms_categories, :slug, :string

Comfy::Cms::Category.find_in_batches(batch_size: 20).each do |group|
group.each do |category|
category.save
end
end

change_column_null :comfy_cms_categories, :slug, false
end

def self.down
remove_column :comfy_cms_categories, :slug
end
end
1 change: 0 additions & 1 deletion lib/comfortable_mexican_sofa/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
require 'haml-rails'
require 'sass-rails'
require 'coffee-rails'
require 'codemirror-rails'
require 'bootstrap-sass'
require 'plupload-rails'

Expand Down
2 changes: 1 addition & 1 deletion lib/comfortable_mexican_sofa/extensions/has_revisions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create_revision
# Assigning whatever is found in revision data and attemptint to save the object
def restore_from_revision(revision)
return unless revision.record == self
self.update_attributes!(revision.data)
self.update!(revision.data)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/comfortable_mexican_sofa/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ComfortableMexicanSofa
VERSION = "1.13.0"
VERSION = "1.15.0"
end
2 changes: 1 addition & 1 deletion lib/generators/comfy/scaffold/templates/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create
end

def update
@<%= file_name %>.update_attributes!(<%= file_name %>_params)
@<%= file_name %>.update!(<%= file_name %>_params)
flash[:success] = '<%= class_name.titleize %> updated'
redirect_to :action => :show, :id => @<%= file_name %>
rescue ActiveRecord::RecordInvalid
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/comfy/admin/cms/pages_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def test_creation_preview
}}
assert_response :success
assert_match /preview content/, response.body
assert_equal 'text/html', response.content_type
assert_equal 'text/html', response.media_type

assert_equal site, assigns(:cms_site)
assert_equal layout, assigns(:cms_layout)
Expand Down
10 changes: 5 additions & 5 deletions test/controllers/comfy/cms/assets_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ def test_render_css_with_site_with_path
site.update_column(:path, 'some/path')
get :render_css, params: { :site_id => site, :identifier => comfy_cms_layouts(:default).identifier }
assert_response :success
assert_match 'text/css', response.content_type
assert_match 'text/css', response.media_type
assert_equal comfy_cms_layouts(:default).css, response.body
end

def test_render_css_without_cache_buster
get :render_css, params: { :site_id => comfy_cms_sites(:default), :identifier => comfy_cms_layouts(:default).identifier }
assert_response :success
assert_match 'text/css', response.content_type
assert_match 'text/css', response.media_type
assert_nil response.headers['Cache-Control']
assert_equal comfy_cms_layouts(:default).css, response.body
end
Expand All @@ -23,7 +23,7 @@ def test_render_css_with_cache_buster
layout = comfy_cms_layouts(:default)
get :render_css, params: { :site_id => comfy_cms_sites(:default), :identifier => layout.identifier, :cache_buster => layout.cache_buster }
assert_response :success
assert_match 'text/css', response.content_type
assert_match 'text/css', response.media_type
assert_equal 'max-age=31556952, public', response.headers['Cache-Control']
assert_equal comfy_cms_layouts(:default).css, response.body
end
Expand All @@ -36,7 +36,7 @@ def test_render_css_not_found
def test_render_js_without_cache_buster
get :render_js, params: { :site_id => comfy_cms_sites(:default).id, :identifier => comfy_cms_layouts(:default).identifier }, xhr: true
assert_response :success
assert_equal 'application/javascript', response.content_type
assert_equal 'application/javascript', response.media_type
assert_nil response.headers['Cache-Control']
assert_equal comfy_cms_layouts(:default).js, response.body
end
Expand All @@ -45,7 +45,7 @@ def test_render_js_with_cache_buster
layout = comfy_cms_layouts(:default)
get :render_js, params: { :site_id => comfy_cms_sites(:default).id, :identifier => layout.identifier, :cache_buster => layout.cache_buster }, xhr: true
assert_response :success
assert_equal 'application/javascript', response.content_type
assert_equal 'application/javascript', response.media_type
assert_equal 'max-age=31556952, public', response.headers['Cache-Control']
assert_equal comfy_cms_layouts(:default).js, response.body
end
Expand Down
Loading