qbrick 2.6.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c9cc5b026051806ef35cb0e40a3e8d7d2075802
4
- data.tar.gz: aed46d071929a30222d47dd1c8a2b62da1a8532e
3
+ metadata.gz: fc399634917aca2db211deb27063aa7711c7b1bc
4
+ data.tar.gz: 9d8d3256e5bd97d3775680d7766cc6c55219d7ad
5
5
  SHA512:
6
- metadata.gz: 84f5765abf6f575c7f134983463b72dd46f5b5bd8ae96b5985b585ca444f9c48dc44072f45535b0c3a4a3504beca0f8990612e8b96e565457fc7ff4448aeccd3
7
- data.tar.gz: a9a58904375ed0e74816d4123a2ae63fa3732e40455324c58f169ad2c567d62a2184a257a83b145cd04c03927f3778bb756dea4134eccf196b5b1cfcd8f85b88
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 :find_page_by_url, only: :show
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 find_page_by_url
49
- url = frontend_locale.to_s
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
@@ -6,7 +6,7 @@ module Qbrick
6
6
 
7
7
  respond_to do |format|
8
8
  format.html
9
- format.xml { @pages = Qbrick::Page.published }
9
+ format.xml { @pages = Qbrick::Page.all }
10
10
  end
11
11
  end
12
12
  end
@@ -1,11 +1,8 @@
1
1
  module SitemapsHelper
2
- def locales_with_block(page)
2
+ def with_every_locale(page)
3
3
  I18n.available_locales.each do |locale|
4
4
  I18n.with_locale locale do
5
- if page.url.present?
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
@@ -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, :url, :published
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(:url) => nil }
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, :create_url
29
- after_save :update_child_urls
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 all_urls
59
- url_columns = column_names.select { |col| col.start_with? 'url_' }
60
- pluck(*url_columns).flatten.compact.sort.uniq.map { |r| "/#{r}" }
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
- end
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
- url.present? && title.present? && slug.present?
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("url_#{locale}").present? && send("title_#{locale}").present? && send("slug_#{locale}").present?
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
- url_with_locale
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
- url_with_locale
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 url_without_locale
123
- path_segments.join('/')
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 url_with_locale
129
+ def create_path
127
130
  opts = { locale: I18n.locale }
128
- url = url_without_locale
129
- opts[:url] = url if url.present?
130
- page_path(opts)
131
- end
131
+ path = path_segments.join '/'
132
+ opts[:url] = path if path.present?
132
133
 
133
- def create_url
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 update_child_urls
146
- return unless children.any?
147
- children.each { |child| child.update_attribute(:url, child.create_url) }
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
- {}.tap do |json|
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{ :class => (:active if I18n.locale.to_s == locale.to_s) }
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(:action => params[:action], :content_locale => locale), 'data-toggle' => 'tooltip', 'title' => t('.not_translated'), :class => 'not-translated'
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 :url, as: :string, input_html: { disabled: 'disabled' }
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{ :tabindex => '-1', :role => 'dialog' }
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', :brick_list => @page
50
+ = render 'brick_type_dropdown', brick_list: @page
51
51
 
52
- = render 'qbrick/cms/bricks/brick_list', :brick_list => @page
52
+ = render 'qbrick/cms/bricks/brick_list', brick_list: @page
53
53
 
54
54
  = render 'qbrick/cms/bricks/sort_form'
@@ -1,7 +1,7 @@
1
1
  .link
2
2
  = link_to page.link do
3
3
  %h4= page.title
4
- %h5= qbrick.page_url(:url => page.url_without_locale)
4
+ %h5= qbrick.page_path url: page.path
5
5
  .summary
6
6
  -if page.excerpt.present?
7
7
  .excerpt!= page.excerpt
@@ -1,7 +1,7 @@
1
1
  !!! XML
2
2
  %urlset{xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9"}
3
3
  - for page in @pages
4
- - locales_with_block page do |url|
4
+ - with_every_locale page do |url|
5
5
  %url
6
6
  %loc= url
7
7
  %lastmod= page.updated_at.utc
@@ -10,4 +10,4 @@ de:
10
10
  models:
11
11
  qbrick/admin:
12
12
  one: Administrator
13
- other: Administartoren
13
+ other: Administratoren
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: [:update, :index]
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: [:edit, :index] do
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: [:create, :index, :destroy]
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('|')}/ do
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: [:index],
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
@@ -60,6 +60,7 @@ module Qbrick
60
60
  #
61
61
  def collect_fulltext
62
62
  return '' unless respond_to?(:bricks)
63
+
63
64
  bricks.localized.reduce('') do |text, brick|
64
65
  text << brick.collect_fulltext
65
66
  end
@@ -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| "#{attr_name}_#{l.to_s.underscore}" }
56
+ column_names & I18n.available_locales.map { |l| attr_name_for_locale attr_name, l }
53
57
  end
54
58
  end
55
59
 
@@ -1,3 +1,3 @@
1
1
  module Qbrick
2
- VERSION = '2.6.0'
2
+ VERSION = '2.6.1'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  namespace :qbrick do
2
2
  namespace :db do
3
- desc "Load qbrick seeds"
4
- task :seed => :environment do
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
- url_de: 'de/foobar-de', title_en: 'foobar en', url_en: 'en/foobar-en')
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
- url_de: 'de/barfoo-de', title_en: 'barfoo en', url_en: 'en/barfoo-en')
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
- url_de: 'de/unpublished-de', title_en: 'unpublished en',
13
- url_en: 'en/unpublished-en')
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, use_route: :qbrick
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', url: 'de/foobar-de')
26
- get :index, use_route: :qbrick
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, use_route: :qbrick
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
- url_de: 'de/foobar-de', title_en: 'foobar en', url_en: 'en/foobar-en')
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
- url_de: 'de/barfoo-de', title_en: 'barfoo en', url_en: 'en/barfoo-en')
46
+ path_de: 'de/barfoo-de', title_en: 'barfoo en', path_en: 'en/barfoo-en')
45
47
 
46
- get :index, use_route: :qbrick
48
+ get :index
47
49
  @json = JSON.parse(response.body)
48
50
  @page_hash = @json.first
49
51
  end