kuhsaft 2.2.6 → 2.3.0
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 +4 -4
- data/README.md +37 -0
- data/Rakefile +6 -5
- data/app/assets/javascripts/ckeditor/plugins/adv_link/LICENSE.txt +674 -0
- data/app/assets/javascripts/ckeditor/plugins/adv_link/README.md +62 -0
- data/app/assets/javascripts/ckeditor/plugins/adv_link/dialogs/anchor.js.coffee +81 -0
- data/app/assets/javascripts/ckeditor/plugins/adv_link/dialogs/link.js.coffee +1353 -0
- data/app/assets/javascripts/ckeditor/plugins/adv_link/images/anchor.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/adv_link/images/hidpi/anchor.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/adv_link/lang/de.js +68 -0
- data/app/assets/javascripts/ckeditor/plugins/adv_link/lang/en.js +68 -0
- data/app/assets/javascripts/ckeditor/plugins/adv_link/plugin.js.coffee +282 -0
- data/app/assets/javascripts/kuhsaft/cms/application.js.coffee.erb +42 -4
- data/app/assets/stylesheets/kuhsaft/application.css.sass +0 -3
- data/app/assets/stylesheets/kuhsaft/cms/application.css.sass +26 -11
- data/app/controllers/kuhsaft/api/pages_controller.rb +14 -0
- data/app/controllers/kuhsaft/cms/admin_controller.rb +1 -1
- data/app/controllers/kuhsaft/cms/assets_controller.rb +7 -7
- data/app/controllers/kuhsaft/cms/bricks_controller.rb +15 -4
- data/app/controllers/kuhsaft/cms/pages_controller.rb +8 -15
- data/app/controllers/kuhsaft/pages_controller.rb +16 -6
- data/app/controllers/kuhsaft/sitemaps_controller.rb +13 -0
- data/app/helpers/cms_helper.rb +4 -4
- data/app/helpers/kuhsaft/admin_helper.rb +0 -1
- data/app/helpers/kuhsaft/cms/admin_helper.rb +1 -2
- data/app/helpers/kuhsaft/cms/pages_helper.rb +2 -7
- data/app/helpers/pages_helper.rb +8 -37
- data/app/helpers/sitemaps_helper.rb +12 -0
- data/app/models/kuhsaft/accordion_item_brick.rb +1 -1
- data/app/models/kuhsaft/anchor_brick.rb +1 -1
- data/app/models/kuhsaft/asset.rb +26 -23
- data/app/models/kuhsaft/asset_brick.rb +2 -1
- data/app/models/kuhsaft/brick.rb +38 -16
- data/app/models/kuhsaft/brick_type.rb +2 -2
- data/app/models/kuhsaft/brick_type_filter.rb +0 -2
- data/app/models/kuhsaft/column_brick.rb +0 -1
- data/app/models/kuhsaft/image_brick.rb +2 -2
- data/app/models/kuhsaft/image_size.rb +0 -1
- data/app/models/kuhsaft/link_brick.rb +1 -1
- data/app/models/kuhsaft/page.rb +111 -107
- data/app/models/kuhsaft/page_type.rb +1 -1
- data/app/models/kuhsaft/partition.rb +12 -12
- data/app/models/kuhsaft/placeholder_brick.rb +8 -0
- data/app/models/kuhsaft/publish_state.rb +9 -10
- data/app/models/kuhsaft/slider_brick.rb +0 -2
- data/app/models/kuhsaft/text_brick.rb +1 -1
- data/app/models/kuhsaft/two_column_brick.rb +0 -1
- data/app/models/kuhsaft/video_brick.rb +1 -2
- data/app/uploaders/kuhsaft/asset_brick_asset_uploader.rb +39 -38
- data/app/uploaders/kuhsaft/asset_uploader.rb +43 -43
- data/app/uploaders/kuhsaft/image_brick_image_uploader.rb +7 -34
- data/app/views/kuhsaft/asset_bricks/asset_brick/_edit.html.haml +3 -2
- data/app/views/kuhsaft/cms/admin/_brick_type_dropdown.html.haml +2 -2
- data/app/views/kuhsaft/cms/bricks/_brick_item.html.haml +17 -10
- data/app/views/kuhsaft/cms/bricks/_new.html.haml +34 -0
- data/app/views/kuhsaft/cms/bricks/create.js.haml +6 -0
- data/app/views/kuhsaft/cms/bricks/destroy.js.haml +4 -0
- data/app/views/kuhsaft/cms/bricks/new.js.haml +11 -0
- data/app/views/kuhsaft/cms/pages/_branch.html.haml +2 -2
- data/app/views/kuhsaft/cms/pages/_form.html.haml +29 -18
- data/app/views/kuhsaft/image_bricks/_image_brick.html.haml +9 -7
- data/app/views/kuhsaft/image_bricks/image_brick/_edit.html.haml +3 -0
- data/app/views/kuhsaft/pages/show.html.haml +1 -9
- data/app/views/kuhsaft/placeholder_bricks/_placeholder_brick.html.haml +1 -1
- data/app/views/kuhsaft/sitemaps/index.xml.haml +9 -0
- data/app/views/kuhsaft/video_bricks/_video_brick.html.haml +4 -4
- data/app/views/layouts/kuhsaft/cms/application.html.haml +4 -3
- data/config/initializers/simple_form.rb +4 -4
- data/config/initializers/simple_form_bootstrap.rb +14 -14
- data/config/locales/de.yml +203 -0
- data/config/locales/en.yml +282 -0
- data/config/locales/kuhsaft.de.yml +14 -0
- data/config/locales/kuhsaft.en.yml +60 -0
- data/config/locales/models/kuhsaft/image_brick/de.yml +1 -0
- data/config/locales/models/kuhsaft/image_brick/en.yml +16 -0
- data/config/locales/models/kuhsaft/text_brick/de.yml +3 -0
- data/config/locales/models/kuhsaft/text_brick/en.yml +16 -0
- data/config/locales/models/kuhsaft/video_brick/en.yml +15 -0
- data/config/locales/views/kuhsaft/cms/pages/de.yml +3 -0
- data/config/locales/views/kuhsaft/cms/video_bricks/de.yml +1 -1
- data/config/routes.rb +18 -9
- data/db/migrate/10_add_redirect_url_to_kuhsaft_pages.rb +1 -1
- data/db/migrate/11_update_url_and_redirect_url_value.rb +4 -4
- data/db/migrate/13_add_page_title_to_pages.rb +1 -1
- data/db/migrate/15_add_alt_text_to_bricks.rb +5 -0
- data/db/migrate/16_update_default_value_for_page_type.rb +9 -0
- data/db/migrate/17_set_page_type_to_content_for_empty_fields.rb +7 -0
- data/lib/generators/kuhsaft/assets/install_generator.rb +1 -2
- data/lib/generators/kuhsaft/translations/add_generator.rb +19 -4
- data/lib/kuhsaft.rb +1 -0
- data/lib/kuhsaft/brick_list.rb +6 -8
- data/lib/kuhsaft/engine.rb +5 -1
- data/lib/kuhsaft/orderable.rb +22 -19
- data/lib/kuhsaft/partial_extractor.rb +1 -1
- data/lib/kuhsaft/searchable.rb +8 -11
- data/lib/kuhsaft/translatable.rb +35 -19
- data/lib/kuhsaft/version.rb +1 -1
- data/lib/tasks/kuhsaft_tasks.rake +12 -0
- data/lib/templates/kuhsaft/assets/ck-config.js.coffee +7 -0
- data/lib/templates/kuhsaft/translations/add_translation.html.erb +4 -10
- data/spec/controllers/kuhsaft/api/pages_controller_spec.rb +70 -0
- data/spec/controllers/kuhsaft/pages_controller_spec.rb +18 -14
- data/spec/controllers/kuhsaft/sitemaps_controller_spec.rb +13 -0
- data/spec/dummy/app/assets/javascripts/kuhsaft/cms/ck-config.js.coffee +7 -0
- data/spec/dummy/config/application.rb +2 -1
- data/spec/dummy/config/database.yml +1 -1
- data/spec/factories.rb +3 -3
- data/spec/features/cms_pages_spec.rb +13 -13
- data/spec/features/search_spec.rb +16 -18
- data/spec/helpers/kuhsaft/cms/pages_helper_spec.rb +2 -1
- data/spec/kuhsaft_spec.rb +1 -1
- data/spec/lib/brick_list_spec.rb +1 -1
- data/spec/lib/page_tree_spec.rb +10 -6
- data/spec/lib/searchable_spec.rb +4 -4
- data/spec/lib/translatable_spec.rb +114 -44
- data/spec/models/anchor_brick_spec.rb +1 -1
- data/spec/models/asset_spec.rb +1 -1
- data/spec/models/brick_spec.rb +1 -1
- data/spec/models/page_spec.rb +48 -37
- data/spec/models/publish_state_spec.rb +9 -9
- data/spec/spec_helper.rb +43 -21
- data/spec/support/kuhsaft_spec_helper.rb +2 -2
- data/spec/support/write_expectation.rb +57 -0
- data/spec/views/kuhsaft/sitemaps/index.xml.haml_spec.rb +67 -0
- metadata +119 -4
|
@@ -3,5 +3,5 @@ de:
|
|
|
3
3
|
video_bricks:
|
|
4
4
|
video_brick:
|
|
5
5
|
edit:
|
|
6
|
-
any_source_error: 'Bitte geben Sie mindestens eine
|
|
6
|
+
any_source_error: 'Bitte geben Sie mindestens eine Videoquelle an.'
|
|
7
7
|
embed_src_optional: 'Alternativ kann ein HTML Code zum einbetten eines Videos eingefügt werden.'
|
data/config/routes.rb
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
Kuhsaft::Engine.routes.draw do
|
|
2
|
+
|
|
2
3
|
namespace :cms do
|
|
3
|
-
resources :pages, :
|
|
4
|
-
post :sort, :
|
|
4
|
+
resources :pages, except: :show do
|
|
5
|
+
post :sort, on: :collection
|
|
5
6
|
end
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
resources :bricks, except: [:edit, :index] do
|
|
9
|
+
post :sort, on: :collection
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
resources :assets
|
|
11
|
-
root :
|
|
13
|
+
root to: 'pages#index'
|
|
12
14
|
end
|
|
13
15
|
|
|
14
|
-
scope
|
|
16
|
+
scope ':locale', locale: /#{I18n.available_locales.join('|')}/ do
|
|
17
|
+
namespace :api, defaults: { format: :json } do
|
|
18
|
+
resources :pages, only: :index
|
|
19
|
+
end
|
|
20
|
+
|
|
15
21
|
resources :pages,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
get '(*url)' => 'pages#show', :
|
|
22
|
+
only: [:index],
|
|
23
|
+
defaults: { locale: I18n.locale }
|
|
24
|
+
get '(*url)' => 'pages#show', as: :page
|
|
19
25
|
end
|
|
26
|
+
|
|
27
|
+
get '/pages/:id' => 'pages#lookup_by_id'
|
|
28
|
+
get '/sitemap.format' => 'sitemaps#index', format: 'xml'
|
|
20
29
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class AddRedirectUrlToKuhsaftPages < ActiveRecord::Migration
|
|
2
2
|
def change
|
|
3
3
|
I18n.available_locales.each do |locale|
|
|
4
|
-
add_column :kuhsaft_pages, "redirect_url_#{locale}", :text
|
|
4
|
+
add_column :kuhsaft_pages, "redirect_url_#{locale.to_s.underscore}", :text
|
|
5
5
|
end
|
|
6
6
|
end
|
|
7
7
|
end
|
|
@@ -2,14 +2,14 @@ class UpdateUrlAndRedirectUrlValue < ActiveRecord::Migration
|
|
|
2
2
|
def up
|
|
3
3
|
@redirect_pages = Kuhsaft::Page.where(:page_type => 'redirect')
|
|
4
4
|
I18n.available_locales.each do |locale|
|
|
5
|
-
move_url_to_redirect_url(locale)
|
|
5
|
+
move_url_to_redirect_url(locale.to_s.underscore)
|
|
6
6
|
end
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def down
|
|
10
10
|
@redirect_pages = Kuhsaft::Page.where(:page_type => 'redirect')
|
|
11
11
|
I18n.available_locales.each do |locale|
|
|
12
|
-
move_redirect_url_to_url(locale)
|
|
12
|
+
move_redirect_url_to_url(locale.to_s.underscore)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
end
|
|
@@ -37,9 +37,9 @@ class UpdateUrlAndRedirectUrlValue < ActiveRecord::Migration
|
|
|
37
37
|
if page.parent.present?
|
|
38
38
|
complete_slug << page.parent.url.to_s
|
|
39
39
|
else
|
|
40
|
-
complete_slug =
|
|
40
|
+
complete_slug = I18n.locale.to_s.underscore
|
|
41
41
|
end
|
|
42
42
|
complete_slug << "/#{page.slug}"
|
|
43
43
|
complete_slug
|
|
44
44
|
end
|
|
45
|
-
end
|
|
45
|
+
end
|
|
@@ -16,11 +16,10 @@ module Kuhsaft
|
|
|
16
16
|
copy_file 'customizations.js.coffee', "#{custom_js_folder}/customizations.js.coffee"
|
|
17
17
|
copy_file 'ck-config.js.coffee', "#{custom_js_folder}/ck-config.js.coffee"
|
|
18
18
|
|
|
19
|
-
inject_into_file 'config/environments/production.rb', :
|
|
19
|
+
inject_into_file 'config/environments/production.rb', after: /config\.assets\.precompile.*$/ do
|
|
20
20
|
"\n config.assets.precompile += %w( kuhsaft/cms/customizations.css kuhsaft/cms/customizations.js kuhsaft/cms/ck-config.js )"
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
|
-
|
|
@@ -8,19 +8,34 @@ module Kuhsaft
|
|
|
8
8
|
include Rails::Generators::Migration
|
|
9
9
|
|
|
10
10
|
source_root(File.join(Kuhsaft::Engine.root, '/lib/templates/kuhsaft/translations'))
|
|
11
|
-
argument :locale, :
|
|
11
|
+
argument :locale, type: :string
|
|
12
12
|
|
|
13
13
|
def self.next_migration_number(dirname)
|
|
14
14
|
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def
|
|
18
|
-
|
|
17
|
+
def translated_columns
|
|
18
|
+
Kuhsaft::Page.column_names.select { |attr| attr.include?("_#{I18n.default_locale}") }
|
|
19
19
|
end
|
|
20
|
+
|
|
21
|
+
def formatted_locale
|
|
22
|
+
locale.underscore
|
|
23
|
+
end
|
|
24
|
+
|
|
20
25
|
def create_locale_migration_file
|
|
21
|
-
migration_template('add_translation.html.erb',
|
|
26
|
+
migration_template('add_translation.html.erb',
|
|
27
|
+
Rails.root.join('db', 'migrate', "add_#{formatted_locale}_translation.rb"))
|
|
22
28
|
end
|
|
23
29
|
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def get_attribute(attribute_name = '')
|
|
33
|
+
attribute_name.gsub("_#{I18n.default_locale}", "_#{formatted_locale}")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def get_type(key = '')
|
|
37
|
+
Kuhsaft::Page.columns_hash[key].type
|
|
38
|
+
end
|
|
24
39
|
end
|
|
25
40
|
end
|
|
26
41
|
end
|
data/lib/kuhsaft.rb
CHANGED
data/lib/kuhsaft/brick_list.rb
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
module Kuhsaft
|
|
2
2
|
module BrickList
|
|
3
|
-
|
|
4
3
|
def self.included(base)
|
|
5
4
|
def base.acts_as_brick_list
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
has_many :bricks,
|
|
6
|
+
class_name: 'Kuhsaft::Brick',
|
|
7
|
+
dependent: :destroy,
|
|
8
|
+
as: :brick_list
|
|
10
9
|
end
|
|
11
10
|
end
|
|
12
11
|
|
|
@@ -56,12 +55,12 @@ module Kuhsaft
|
|
|
56
55
|
|
|
57
56
|
#
|
|
58
57
|
# Return relevant fulltext information for this brick (e.g: it's name, description etc ).
|
|
59
|
-
#
|
|
58
|
+
# It will be stored in the related Page.
|
|
60
59
|
# Implement how you see fit.
|
|
61
60
|
#
|
|
62
61
|
def collect_fulltext
|
|
63
62
|
if respond_to?(:bricks)
|
|
64
|
-
bricks.localized.
|
|
63
|
+
bricks.localized.reduce('') do |text, brick|
|
|
65
64
|
text << brick.collect_fulltext
|
|
66
65
|
text
|
|
67
66
|
end
|
|
@@ -88,6 +87,5 @@ module Kuhsaft
|
|
|
88
87
|
def uploader?
|
|
89
88
|
self.class.ancestors.include? CarrierWave::Mount::Extension
|
|
90
89
|
end
|
|
91
|
-
|
|
92
90
|
end
|
|
93
91
|
end
|
data/lib/kuhsaft/engine.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
module Kuhsaft
|
|
2
|
-
|
|
3
2
|
class ImageSizeDelegator
|
|
4
3
|
def method_missing(method, *args, &block)
|
|
5
4
|
Kuhsaft::ImageSize.send(method, *args, &block)
|
|
@@ -19,5 +18,10 @@ module Kuhsaft
|
|
|
19
18
|
|
|
20
19
|
# delegate image size config to ImageSize class
|
|
21
20
|
config.image_sizes = ImageSizeDelegator.new
|
|
21
|
+
|
|
22
|
+
initializer 'kuhsaft.initialize_haml_dependency_tracker' do |app|
|
|
23
|
+
require 'action_view/dependency_tracker'
|
|
24
|
+
ActionView::DependencyTracker.register_tracker :haml, ActionView::DependencyTracker::ERBTracker
|
|
25
|
+
end
|
|
22
26
|
end
|
|
23
27
|
end
|
data/lib/kuhsaft/orderable.rb
CHANGED
|
@@ -1,50 +1,53 @@
|
|
|
1
1
|
module Kuhsaft
|
|
2
2
|
# If you use this mixin, your class must implement the following methods
|
|
3
3
|
# siblings(), returns the siblings of the same type of object
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
module Orderable
|
|
6
|
-
def self.included
|
|
6
|
+
def self.included(base)
|
|
7
7
|
base.extend(ClassMethods)
|
|
8
8
|
base.send :include, InstanceMethods
|
|
9
9
|
base.after_create :set_position
|
|
10
10
|
end
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
module InstanceMethods
|
|
13
13
|
def increment_position
|
|
14
14
|
update_attribute :position, position + 1
|
|
15
15
|
end
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
def decrement_position
|
|
18
18
|
update_attribute :position, position - 1
|
|
19
19
|
end
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
def preceding_sibling
|
|
22
22
|
siblings.where('position = ?', position - 1).first
|
|
23
23
|
end
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
def succeeding_sibling
|
|
26
26
|
siblings.where('position = ?', position + 1).first
|
|
27
27
|
end
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
def preceding_siblings
|
|
30
30
|
siblings.where('position <= ?', position).where('id != ?', id)
|
|
31
31
|
end
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
def succeeding_siblings
|
|
34
34
|
siblings.where('position >= ?', position).where('id != ?', id)
|
|
35
35
|
end
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
def position_to_top
|
|
38
38
|
update_attribute :position, 1
|
|
39
39
|
recount_siblings_position_from 1
|
|
40
40
|
end
|
|
41
|
-
|
|
42
|
-
def recount_siblings_position_from
|
|
41
|
+
|
|
42
|
+
def recount_siblings_position_from(position)
|
|
43
43
|
counter = position
|
|
44
|
-
succeeding_siblings.each
|
|
44
|
+
succeeding_siblings.each do |s|
|
|
45
|
+
counter += 1
|
|
46
|
+
s.update_attribute(:position, counter)
|
|
47
|
+
end
|
|
45
48
|
end
|
|
46
|
-
|
|
47
|
-
def reposition
|
|
49
|
+
|
|
50
|
+
def reposition(before_id)
|
|
48
51
|
if before_id.blank?
|
|
49
52
|
position_to_top
|
|
50
53
|
else
|
|
@@ -52,17 +55,17 @@ module Kuhsaft
|
|
|
52
55
|
recount_siblings_position_from position
|
|
53
56
|
end
|
|
54
57
|
end
|
|
55
|
-
|
|
58
|
+
|
|
56
59
|
def set_position
|
|
57
60
|
initial_position = siblings.blank? ? 1 : siblings.count + 1
|
|
58
61
|
update_attribute(:position, initial_position)
|
|
59
62
|
end
|
|
60
63
|
end
|
|
61
|
-
|
|
64
|
+
|
|
62
65
|
module ClassMethods
|
|
63
|
-
def position_of
|
|
64
|
-
|
|
66
|
+
def position_of(id)
|
|
67
|
+
find(id).position rescue 1
|
|
65
68
|
end
|
|
66
69
|
end
|
|
67
70
|
end
|
|
68
|
-
end
|
|
71
|
+
end
|
data/lib/kuhsaft/searchable.rb
CHANGED
|
@@ -6,8 +6,8 @@ module Kuhsaft
|
|
|
6
6
|
extend ActiveSupport::Concern
|
|
7
7
|
|
|
8
8
|
DICTIONARIES = {
|
|
9
|
-
:
|
|
10
|
-
:
|
|
9
|
+
en: 'english',
|
|
10
|
+
de: 'german'
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
def update_fulltext
|
|
@@ -19,25 +19,22 @@ module Kuhsaft
|
|
|
19
19
|
raise 'Kuhsaft::Searchable needs Kuhsaft::BrickList to be included'
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
if included_modules.include?(Translatable)
|
|
23
|
-
translate :fulltext
|
|
24
|
-
end
|
|
25
|
-
|
|
22
|
+
translate :fulltext if included_modules.include?(Translatable)
|
|
26
23
|
before_validation :update_fulltext
|
|
27
24
|
|
|
28
25
|
if ActiveRecord::Base.connection.instance_values['config'][:adapter] == 'postgresql'
|
|
29
26
|
include ::PgSearch
|
|
30
27
|
cb = lambda do |query|
|
|
31
28
|
{
|
|
32
|
-
:
|
|
29
|
+
against: {
|
|
33
30
|
locale_attr(:title) => 'A',
|
|
34
31
|
locale_attr(:page_title) => 'A',
|
|
35
32
|
locale_attr(:keywords) => 'B',
|
|
36
33
|
locale_attr(:description) => 'C',
|
|
37
|
-
locale_attr(:fulltext) => 'C'
|
|
34
|
+
locale_attr(:fulltext) => 'C'
|
|
38
35
|
},
|
|
39
|
-
:
|
|
40
|
-
:
|
|
36
|
+
query: query,
|
|
37
|
+
using: { tsearch: { dictionary: DICTIONARIES[I18n.locale] || 'simple' } }
|
|
41
38
|
}
|
|
42
39
|
end
|
|
43
40
|
pg_search_scope :search_without_excerpt, cb
|
|
@@ -57,7 +54,7 @@ module Kuhsaft
|
|
|
57
54
|
if query.is_a? Hash
|
|
58
55
|
where("#{query.first[0]} LIKE ?", "%#{query.first[1]}%")
|
|
59
56
|
else
|
|
60
|
-
stmt =
|
|
57
|
+
stmt = ''
|
|
61
58
|
stmt += "#{locale_attr(:keywords)} LIKE ? OR "
|
|
62
59
|
stmt += "#{locale_attr(:title)} LIKE ? OR "
|
|
63
60
|
stmt += "#{locale_attr(:page_title)} LIKE ? OR "
|
data/lib/kuhsaft/translatable.rb
CHANGED
|
@@ -1,38 +1,54 @@
|
|
|
1
1
|
module Kuhsaft
|
|
2
2
|
module Translatable
|
|
3
|
-
|
|
4
3
|
def self.included(base)
|
|
5
4
|
base.extend ClassMethods
|
|
6
5
|
end
|
|
7
6
|
|
|
7
|
+
extend self
|
|
8
|
+
|
|
8
9
|
module ClassMethods
|
|
9
|
-
def translate
|
|
10
|
+
def translate(*args)
|
|
10
11
|
args.each do |attr_name|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
define_localized_attr_getter attr_name
|
|
13
|
+
define_localized_attr_setter attr_name
|
|
14
|
+
define_localized_attr_finder attr_name
|
|
15
|
+
define_localized_attr_predicate_method attr_name
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def define_localized_attr_getter(attr_name)
|
|
20
|
+
define_method attr_name do
|
|
21
|
+
send "#{attr_name}_#{locale_for_attr_name}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
def define_localized_attr_predicate_method(attr_name)
|
|
26
|
+
define_method "#{attr_name}?" do
|
|
27
|
+
send "#{attr_name}_#{locale_for_attr_name}?"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
18
30
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
def define_localized_attr_setter(attr_name)
|
|
32
|
+
define_method "#{attr_name}=" do |val|
|
|
33
|
+
send "#{attr_name}_#{locale_for_attr_name}=", val
|
|
34
|
+
end
|
|
35
|
+
end
|
|
22
36
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
37
|
+
def define_localized_attr_finder(attr_name)
|
|
38
|
+
define_singleton_method "find_by_#{attr_name}" do |val|
|
|
39
|
+
send "find_by_#{attr_name}_#{locale_for_attr_name}", val
|
|
26
40
|
end
|
|
27
41
|
end
|
|
28
42
|
|
|
29
|
-
def
|
|
30
|
-
|
|
43
|
+
def locale_for_attr_name
|
|
44
|
+
I18n.locale.to_s.underscore
|
|
31
45
|
end
|
|
32
|
-
end
|
|
33
46
|
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
def locale_attr(attr_name)
|
|
48
|
+
"#{attr_name}_#{I18n.locale.to_s.underscore}"
|
|
49
|
+
end
|
|
36
50
|
end
|
|
51
|
+
|
|
52
|
+
include ClassMethods
|
|
37
53
|
end
|
|
38
54
|
end
|