qbrick 2.6.0 → 2.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/qbrick/pages_controller.rb +4 -5
- data/app/controllers/qbrick/sitemaps_controller.rb +1 -1
- data/app/helpers/sitemaps_helper.rb +2 -5
- data/app/models/qbrick/page.rb +27 -30
- data/app/views/qbrick/cms/pages/_form.html.haml +6 -6
- data/app/views/qbrick/search/_results_entry.html.haml +1 -1
- data/app/views/qbrick/sitemaps/index.xml.haml +1 -1
- data/config/locales/models/qbrick/admin/de.yml +1 -1
- data/config/routes.rb +5 -5
- data/db/migrate/25_rename_qbrick_pages_url_to_path.rb +33 -0
- data/lib/qbrick/brick_list.rb +1 -0
- data/lib/qbrick/translatable.rb +5 -1
- data/lib/qbrick/version.rb +1 -1
- data/lib/tasks/qbrick_tasks.rake +3 -2
- data/spec/controllers/qbrick/api/pages_controller_spec.rb +13 -11
- data/spec/controllers/qbrick/cms/pages_controller_spec.rb +5 -7
- data/spec/controllers/qbrick/pages_controller_spec.rb +30 -43
- data/spec/controllers/qbrick/sitemaps_controller_spec.rb +4 -5
- data/spec/factories.rb +7 -1
- data/spec/features/administrator_management_spec.rb +10 -13
- data/spec/features/cms_pages_spec.rb +19 -13
- data/spec/features/search_spec.rb +15 -17
- data/spec/helpers/qbrick/cms/pages_helper_spec.rb +10 -5
- data/spec/lib/translatable_spec.rb +17 -16
- data/spec/models/page_spec.rb +77 -52
- data/spec/spec_helper.rb +1 -1
- data/spec/views/qbrick/sitemaps/index.xml.haml_spec.rb +7 -6
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc399634917aca2db211deb27063aa7711c7b1bc
|
4
|
+
data.tar.gz: 9d8d3256e5bd97d3775680d7766cc6c55219d7ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 672f482f10108c98212b8f997ce8b2971d128e6e4da394e09882d4984f0c5349b1f7a7f8dfb6b9c1fa0c736490ae2d8df41546b846f78ef285d88b08789f722d
|
7
|
+
data.tar.gz: 0a7af236fd18bdb10ce18bbc1b4eaf57229f5cbddcbebaeeec3df3fe28e8fa81478fc27c58ed9838fb65bf64e1547c52e0336611485d5847c12ed4a054d6cda1
|
@@ -2,11 +2,12 @@ module Qbrick
|
|
2
2
|
class PagesController < ::ApplicationController
|
3
3
|
respond_to :html
|
4
4
|
before_action :set_locale
|
5
|
-
before_action :
|
5
|
+
before_action :find_page_by_path, only: :show
|
6
6
|
|
7
7
|
def index
|
8
8
|
@search = params[:search]
|
9
9
|
return if @search.blank?
|
10
|
+
|
10
11
|
@pages = Qbrick::Page.unscoped.published.content_page.search(@search)
|
11
12
|
end
|
12
13
|
|
@@ -45,10 +46,8 @@ module Qbrick
|
|
45
46
|
@page.present? && @page.redirect? && @page.redirect_url.present?
|
46
47
|
end
|
47
48
|
|
48
|
-
def
|
49
|
-
|
50
|
-
url += "/#{params[:url]}" if params[:url].present?
|
51
|
-
@page = Qbrick::Page.published.find_by_url(url)
|
49
|
+
def find_page_by_path
|
50
|
+
@page = Qbrick::Page.published.find_by_path params[:url].to_s
|
52
51
|
end
|
53
52
|
end
|
54
53
|
end
|
@@ -1,11 +1,8 @@
|
|
1
1
|
module SitemapsHelper
|
2
|
-
def
|
2
|
+
def with_every_locale(page)
|
3
3
|
I18n.available_locales.each do |locale|
|
4
4
|
I18n.with_locale locale do
|
5
|
-
if page.
|
6
|
-
url = "http://#{request.host_with_port}/#{page.url}"
|
7
|
-
yield(url)
|
8
|
-
end
|
5
|
+
yield "http://#{request.host_with_port}#{page.path_with_prefixed_locale}" if page.path.present? && page.published?
|
9
6
|
end
|
10
7
|
end
|
11
8
|
end
|
data/app/models/qbrick/page.rb
CHANGED
@@ -10,12 +10,12 @@ module Qbrick
|
|
10
10
|
acts_as_brick_list
|
11
11
|
|
12
12
|
translate :title, :page_title, :slug, :keywords, :description,
|
13
|
-
:body, :redirect_url, :
|
13
|
+
:body, :redirect_url, :path, :published
|
14
14
|
|
15
15
|
default_scope { order 'position ASC' }
|
16
16
|
|
17
17
|
scope :published, -> { where locale_attr(:published) => Qbrick::PublishState::PUBLISHED }
|
18
|
-
scope :translated, -> { where.not locale_attr(:
|
18
|
+
scope :translated, -> { where.not locale_attr(:path) => nil }
|
19
19
|
|
20
20
|
scope :content_page, -> { where page_type: Qbrick::PageType::CONTENT }
|
21
21
|
|
@@ -25,8 +25,8 @@ module Qbrick
|
|
25
25
|
locale_attr(:page_type) => Qbrick::PageType::NAVIGATION)
|
26
26
|
}
|
27
27
|
|
28
|
-
before_validation :create_slug, :
|
29
|
-
after_save :
|
28
|
+
before_validation :create_slug, :create_path
|
29
|
+
after_save :update_child_paths
|
30
30
|
|
31
31
|
validates :title, presence: true
|
32
32
|
validates :slug, presence: true
|
@@ -55,11 +55,15 @@ module Qbrick
|
|
55
55
|
find_by(identifier: identifier)
|
56
56
|
end
|
57
57
|
|
58
|
-
def
|
59
|
-
|
60
|
-
pluck(*
|
58
|
+
def all_paths
|
59
|
+
path_columns = column_names.select { |col| col.start_with? 'path_' }
|
60
|
+
pluck(*path_columns).flatten.compact.sort.uniq.map(&:path)
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
|
+
def find_by_path(given_path)
|
64
|
+
find_by locale_attr(:path) => given_path.blank? ? '' : "/#{given_path.sub(%r{^/+}, '')}"
|
65
|
+
end
|
66
|
+
end # class methods
|
63
67
|
|
64
68
|
def without_self
|
65
69
|
self.class.where.not id: id
|
@@ -86,18 +90,18 @@ module Qbrick
|
|
86
90
|
end
|
87
91
|
|
88
92
|
def translated?
|
89
|
-
|
93
|
+
path.present? && title.present? && slug.present?
|
90
94
|
end
|
91
95
|
|
92
96
|
def translated_to?(raw_locale)
|
93
97
|
locale = raw_locale.to_s.underscore
|
94
|
-
send("
|
98
|
+
send("path_#{locale}").present? && send("title_#{locale}").present? && send("slug_#{locale}").present?
|
95
99
|
end
|
96
100
|
|
97
101
|
def translated_link_for(locale)
|
98
102
|
if translated_to? locale
|
99
103
|
I18n.with_locale locale do
|
100
|
-
|
104
|
+
path_with_prefixed_locale
|
101
105
|
end
|
102
106
|
else
|
103
107
|
Qbrick::Page.roots.first.link
|
@@ -108,30 +112,26 @@ module Qbrick
|
|
108
112
|
if bricks.count == 0 && children.count > 0
|
109
113
|
children.first.link
|
110
114
|
else
|
111
|
-
|
115
|
+
path_with_prefixed_locale
|
112
116
|
end
|
113
117
|
end
|
114
118
|
|
115
|
-
# TODO: needs naming and routing refactoring (url/locale/path/slug)
|
116
119
|
def path_segments
|
117
120
|
paths = parent.present? ? parent.path_segments : []
|
118
121
|
paths << slug unless navigation?
|
119
122
|
paths
|
120
123
|
end
|
121
124
|
|
122
|
-
def
|
123
|
-
|
125
|
+
def path_with_prefixed_locale(locale = I18n.locale)
|
126
|
+
"/#{locale}#{send self.class.attr_name_for_locale(:path, locale)}"
|
124
127
|
end
|
125
128
|
|
126
|
-
def
|
129
|
+
def create_path
|
127
130
|
opts = { locale: I18n.locale }
|
128
|
-
|
129
|
-
opts[:url] =
|
130
|
-
page_path(opts)
|
131
|
-
end
|
131
|
+
path = path_segments.join '/'
|
132
|
+
opts[:url] = path if path.present?
|
132
133
|
|
133
|
-
|
134
|
-
self.url = url_with_locale[1..-1]
|
134
|
+
self.path = page_path(opts).sub(%r{^/#{I18n.locale}}, '')
|
135
135
|
end
|
136
136
|
|
137
137
|
def create_slug
|
@@ -142,9 +142,10 @@ module Qbrick
|
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
|
-
def
|
146
|
-
|
147
|
-
|
145
|
+
def update_child_paths
|
146
|
+
children.each do |child|
|
147
|
+
child.update_attribute :path, child.create_path
|
148
|
+
end
|
148
149
|
end
|
149
150
|
|
150
151
|
def nesting_name
|
@@ -170,11 +171,7 @@ module Qbrick
|
|
170
171
|
end
|
171
172
|
|
172
173
|
def as_json
|
173
|
-
{}
|
174
|
-
json['title'] = send("title_#{I18n.locale.to_s.underscore}")
|
175
|
-
json['pretty_url'] = '/' + send("url_#{I18n.locale.to_s.underscore}")
|
176
|
-
json['url'] = "/pages/#{id}"
|
177
|
-
end
|
174
|
+
{ 'title' => title, 'pretty_url' => path, 'url' => "/pages/#{id}" }
|
178
175
|
end
|
179
176
|
|
180
177
|
def clear_bricks_for_locale(locale)
|
@@ -6,11 +6,11 @@
|
|
6
6
|
= link_to t('.tab_content'), '#page-content', 'data-toggle' => :tab
|
7
7
|
|
8
8
|
- I18n.available_locales.reverse.each do |locale|
|
9
|
-
%li.pull-right{ :
|
9
|
+
%li.pull-right{ class: (:active if I18n.locale.to_s == locale.to_s) }
|
10
10
|
- if @page.translated_to?(locale)
|
11
11
|
= link_to_content_locale(locale)
|
12
12
|
- else
|
13
|
-
= link_to locale.to_s.upcase, url_for(:
|
13
|
+
= link_to locale.to_s.upcase, url_for(action: params[:action], content_locale: locale), 'data-toggle' => 'tooltip', title: t('.not_translated'), class: 'not-translated'
|
14
14
|
|
15
15
|
.tab-content
|
16
16
|
#page-metadata.tab-pane{ class: metadata_tab_active(@page) }
|
@@ -21,7 +21,7 @@
|
|
21
21
|
= form.input :parent_id, collection: Qbrick::Page.flat_tree, label_method: :nesting_name, selected: params[:parent_id].presence || @page.parent_id.presence, prompt: t('.none'), input_html: { class: :span3 }
|
22
22
|
= form.input :page_type, collection: Qbrick::PageType.all, prompt: false, default: Qbrick::PageType::CONTENT, input_html: { class: :span3 }
|
23
23
|
= form.input :redirect_url, as: :string
|
24
|
-
= form.input :
|
24
|
+
= form.input :path_with_prefixed_locale, as: :string, input_html: { disabled: 'disabled' }
|
25
25
|
= form.input :keywords, input_html: { class: :span5 }, hint: t('.hint_keywords').html_safe
|
26
26
|
- if @page == homepage
|
27
27
|
= form.input :google_verification_key
|
@@ -32,7 +32,7 @@
|
|
32
32
|
= form.button :submit, class: 'btn btn-primary'
|
33
33
|
|
34
34
|
- unless hide_content_tab?(@page)
|
35
|
-
#brick-form.modal.hide.fade{ :
|
35
|
+
#brick-form.modal.hide.fade{ tabindex: '-1', role: 'dialog' }
|
36
36
|
#page-content.tab-pane{ class: content_tab_active(@page) }
|
37
37
|
- if @page.persisted?
|
38
38
|
.clearfix
|
@@ -47,8 +47,8 @@
|
|
47
47
|
= t('.collapse_all')
|
48
48
|
|
49
49
|
= render 'brick_clone_menu'
|
50
|
-
= render 'brick_type_dropdown', :
|
50
|
+
= render 'brick_type_dropdown', brick_list: @page
|
51
51
|
|
52
|
-
= render 'qbrick/cms/bricks/brick_list', :
|
52
|
+
= render 'qbrick/cms/bricks/brick_list', brick_list: @page
|
53
53
|
|
54
54
|
= render 'qbrick/cms/bricks/sort_form'
|
data/config/routes.rb
CHANGED
@@ -2,18 +2,18 @@ Qbrick::Engine.routes.draw do
|
|
2
2
|
devise_for :admins, class_name: 'Qbrick::Admin', module: :devise
|
3
3
|
|
4
4
|
namespace :cms do
|
5
|
-
resources :settings_collections, only:
|
5
|
+
resources :settings_collections, only: %i(update index)
|
6
6
|
resources :pages, except: :show do
|
7
7
|
post :sort, on: :collection
|
8
8
|
get :mirror
|
9
9
|
end
|
10
10
|
|
11
|
-
resources :bricks, except:
|
11
|
+
resources :bricks, except: %i(edit index) do
|
12
12
|
post :sort, on: :collection
|
13
13
|
end
|
14
14
|
|
15
15
|
resources :assets
|
16
|
-
resources :ckimages, only:
|
16
|
+
resources :ckimages, only: %i(create index destroy)
|
17
17
|
|
18
18
|
resource :account, only: :edit do
|
19
19
|
collection do
|
@@ -26,13 +26,13 @@ Qbrick::Engine.routes.draw do
|
|
26
26
|
root to: 'pages#index'
|
27
27
|
end
|
28
28
|
|
29
|
-
scope ':locale', locale: /#{I18n.available_locales.join('|')}
|
29
|
+
scope '(:locale)', locale: /#{I18n.available_locales.join('|')}/, defaults: { locale: -> { I18n.default_locale } } do
|
30
30
|
namespace :api, defaults: { format: :json } do
|
31
31
|
resources :pages, only: :index
|
32
32
|
end
|
33
33
|
|
34
34
|
resources :pages,
|
35
|
-
only:
|
35
|
+
only: %i(index),
|
36
36
|
defaults: { locale: I18n.locale }
|
37
37
|
get '(*url)' => 'pages#show', as: :page
|
38
38
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class RenameQbrickPagesUrlToPath < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
I18n.available_locales.each do |locale|
|
4
|
+
rename_column :qbrick_pages, :"url_#{locale.to_s.underscore}", :"path_#{locale.to_s.underscore}"
|
5
|
+
end
|
6
|
+
|
7
|
+
pages = Qbrick::Page.unscoped.all
|
8
|
+
|
9
|
+
I18n.available_locales.each do |locale|
|
10
|
+
I18n.with_locale(locale) do
|
11
|
+
pages.each do |page|
|
12
|
+
page.update_attribute :path, page.create_path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def down
|
19
|
+
I18n.available_locales.each do |locale|
|
20
|
+
rename_column :qbrick_pages, :"path_#{locale.to_s.underscore}", :"url_#{locale.to_s.underscore}"
|
21
|
+
end
|
22
|
+
|
23
|
+
pages = Qbrick::Page.unscoped.all
|
24
|
+
|
25
|
+
I18n.available_locales.each do |locale|
|
26
|
+
I18n.with_locale(locale) do
|
27
|
+
pages.each do |page|
|
28
|
+
page.update_attribute :url, page.create_path
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/qbrick/brick_list.rb
CHANGED
data/lib/qbrick/translatable.rb
CHANGED
@@ -48,8 +48,12 @@ module Qbrick
|
|
48
48
|
"#{attr_name}_#{locale_for_attr_name}"
|
49
49
|
end
|
50
50
|
|
51
|
+
def attr_name_for_locale(attr_name, locale)
|
52
|
+
"#{attr_name}_#{locale.to_s.underscore}"
|
53
|
+
end
|
54
|
+
|
51
55
|
def translated_columns_for(attr_name)
|
52
|
-
column_names & I18n.available_locales.map { |l|
|
56
|
+
column_names & I18n.available_locales.map { |l| attr_name_for_locale attr_name, l }
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
data/lib/qbrick/version.rb
CHANGED
data/lib/tasks/qbrick_tasks.rake
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
namespace :qbrick do
|
2
2
|
namespace :db do
|
3
|
-
desc
|
4
|
-
task :
|
3
|
+
desc 'Load qbrick seeds'
|
4
|
+
task seed: :environment do
|
5
5
|
Qbrick::Engine.load_seed
|
6
6
|
end
|
7
7
|
end
|
@@ -14,6 +14,7 @@ task "assets:precompile" do
|
|
14
14
|
fingerprint = /\-[0-9a-f]{32}\./
|
15
15
|
for file in Dir["public/assets/qbrick/cms/ck-config*"]
|
16
16
|
next unless file =~ fingerprint
|
17
|
+
|
17
18
|
nondigest = file.sub fingerprint, '.'
|
18
19
|
if !File.exist?(nondigest) or File.mtime(file) > File.mtime(nondigest)
|
19
20
|
FileUtils.cp file, nondigest, verbose: true
|
@@ -1,34 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Qbrick::Api::PagesController, type: :controller do
|
4
|
+
routes { Qbrick::Engine.routes }
|
5
|
+
|
4
6
|
describe '#index' do
|
5
7
|
before do
|
6
8
|
@pages = []
|
7
9
|
@pages << @page1 = create(:page, published_de: true, published_en: true, title_de: 'foobar de',
|
8
|
-
|
10
|
+
path_de: 'de/foobar-de', title_en: 'foobar en', path_en: 'en/foobar-en')
|
9
11
|
@pages << @page2 = create(:page, published_de: true, published_en: true, title_de: 'barfoo de',
|
10
|
-
|
12
|
+
path_de: 'de/barfoo-de', title_en: 'barfoo en', path_en: 'en/barfoo-en')
|
11
13
|
@pages << @unpublished = create(:page, published: false, title_de: 'unpublished de',
|
12
|
-
|
13
|
-
|
14
|
+
path_de: 'de/unpublished-de', title_en: 'unpublished en',
|
15
|
+
path_en: 'en/unpublished-en')
|
14
16
|
end
|
15
17
|
|
16
18
|
it 'gets only published pages' do
|
17
19
|
I18n.with_locale :de do
|
18
|
-
get :index
|
20
|
+
get :index
|
19
21
|
expect(JSON.parse(response.body)).to eq([@page1, @page2].as_json)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'gets specific translated pages for each locale' do
|
24
26
|
I18n.with_locale :de do
|
25
|
-
@pages << @only_german = create(:page, published: true, title: 'foobar de',
|
26
|
-
get :index
|
27
|
+
@pages << @only_german = create(:page, published: true, title: 'foobar de', path: 'de/foobar-de')
|
28
|
+
get :index
|
27
29
|
expect(JSON.parse(response.body)).to eq([@page1, @page2, @only_german].as_json)
|
28
30
|
end
|
29
31
|
|
30
32
|
I18n.with_locale :en do
|
31
|
-
get :index
|
33
|
+
get :index
|
32
34
|
expect(JSON.parse(response.body)).to eq([@page1, @page2].as_json)
|
33
35
|
end
|
34
36
|
end
|
@@ -39,11 +41,11 @@ describe Qbrick::Api::PagesController, type: :controller do
|
|
39
41
|
I18n.with_locale :de do
|
40
42
|
@pages = []
|
41
43
|
@pages << @page1 = create(:page, published: true, title_de: 'foobar de',
|
42
|
-
|
44
|
+
path_de: 'de/foobar-de', title_en: 'foobar en', path_en: 'en/foobar-en')
|
43
45
|
@pages << @page2 = create(:page, published: true, title_de: 'barfoo de',
|
44
|
-
|
46
|
+
path_de: 'de/barfoo-de', title_en: 'barfoo en', path_en: 'en/barfoo-en')
|
45
47
|
|
46
|
-
get :index
|
48
|
+
get :index
|
47
49
|
@json = JSON.parse(response.body)
|
48
50
|
@page_hash = @json.first
|
49
51
|
end
|