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.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -0
  3. data/Rakefile +6 -5
  4. data/app/assets/javascripts/ckeditor/plugins/adv_link/LICENSE.txt +674 -0
  5. data/app/assets/javascripts/ckeditor/plugins/adv_link/README.md +62 -0
  6. data/app/assets/javascripts/ckeditor/plugins/adv_link/dialogs/anchor.js.coffee +81 -0
  7. data/app/assets/javascripts/ckeditor/plugins/adv_link/dialogs/link.js.coffee +1353 -0
  8. data/app/assets/javascripts/ckeditor/plugins/adv_link/images/anchor.png +0 -0
  9. data/app/assets/javascripts/ckeditor/plugins/adv_link/images/hidpi/anchor.png +0 -0
  10. data/app/assets/javascripts/ckeditor/plugins/adv_link/lang/de.js +68 -0
  11. data/app/assets/javascripts/ckeditor/plugins/adv_link/lang/en.js +68 -0
  12. data/app/assets/javascripts/ckeditor/plugins/adv_link/plugin.js.coffee +282 -0
  13. data/app/assets/javascripts/kuhsaft/cms/application.js.coffee.erb +42 -4
  14. data/app/assets/stylesheets/kuhsaft/application.css.sass +0 -3
  15. data/app/assets/stylesheets/kuhsaft/cms/application.css.sass +26 -11
  16. data/app/controllers/kuhsaft/api/pages_controller.rb +14 -0
  17. data/app/controllers/kuhsaft/cms/admin_controller.rb +1 -1
  18. data/app/controllers/kuhsaft/cms/assets_controller.rb +7 -7
  19. data/app/controllers/kuhsaft/cms/bricks_controller.rb +15 -4
  20. data/app/controllers/kuhsaft/cms/pages_controller.rb +8 -15
  21. data/app/controllers/kuhsaft/pages_controller.rb +16 -6
  22. data/app/controllers/kuhsaft/sitemaps_controller.rb +13 -0
  23. data/app/helpers/cms_helper.rb +4 -4
  24. data/app/helpers/kuhsaft/admin_helper.rb +0 -1
  25. data/app/helpers/kuhsaft/cms/admin_helper.rb +1 -2
  26. data/app/helpers/kuhsaft/cms/pages_helper.rb +2 -7
  27. data/app/helpers/pages_helper.rb +8 -37
  28. data/app/helpers/sitemaps_helper.rb +12 -0
  29. data/app/models/kuhsaft/accordion_item_brick.rb +1 -1
  30. data/app/models/kuhsaft/anchor_brick.rb +1 -1
  31. data/app/models/kuhsaft/asset.rb +26 -23
  32. data/app/models/kuhsaft/asset_brick.rb +2 -1
  33. data/app/models/kuhsaft/brick.rb +38 -16
  34. data/app/models/kuhsaft/brick_type.rb +2 -2
  35. data/app/models/kuhsaft/brick_type_filter.rb +0 -2
  36. data/app/models/kuhsaft/column_brick.rb +0 -1
  37. data/app/models/kuhsaft/image_brick.rb +2 -2
  38. data/app/models/kuhsaft/image_size.rb +0 -1
  39. data/app/models/kuhsaft/link_brick.rb +1 -1
  40. data/app/models/kuhsaft/page.rb +111 -107
  41. data/app/models/kuhsaft/page_type.rb +1 -1
  42. data/app/models/kuhsaft/partition.rb +12 -12
  43. data/app/models/kuhsaft/placeholder_brick.rb +8 -0
  44. data/app/models/kuhsaft/publish_state.rb +9 -10
  45. data/app/models/kuhsaft/slider_brick.rb +0 -2
  46. data/app/models/kuhsaft/text_brick.rb +1 -1
  47. data/app/models/kuhsaft/two_column_brick.rb +0 -1
  48. data/app/models/kuhsaft/video_brick.rb +1 -2
  49. data/app/uploaders/kuhsaft/asset_brick_asset_uploader.rb +39 -38
  50. data/app/uploaders/kuhsaft/asset_uploader.rb +43 -43
  51. data/app/uploaders/kuhsaft/image_brick_image_uploader.rb +7 -34
  52. data/app/views/kuhsaft/asset_bricks/asset_brick/_edit.html.haml +3 -2
  53. data/app/views/kuhsaft/cms/admin/_brick_type_dropdown.html.haml +2 -2
  54. data/app/views/kuhsaft/cms/bricks/_brick_item.html.haml +17 -10
  55. data/app/views/kuhsaft/cms/bricks/_new.html.haml +34 -0
  56. data/app/views/kuhsaft/cms/bricks/create.js.haml +6 -0
  57. data/app/views/kuhsaft/cms/bricks/destroy.js.haml +4 -0
  58. data/app/views/kuhsaft/cms/bricks/new.js.haml +11 -0
  59. data/app/views/kuhsaft/cms/pages/_branch.html.haml +2 -2
  60. data/app/views/kuhsaft/cms/pages/_form.html.haml +29 -18
  61. data/app/views/kuhsaft/image_bricks/_image_brick.html.haml +9 -7
  62. data/app/views/kuhsaft/image_bricks/image_brick/_edit.html.haml +3 -0
  63. data/app/views/kuhsaft/pages/show.html.haml +1 -9
  64. data/app/views/kuhsaft/placeholder_bricks/_placeholder_brick.html.haml +1 -1
  65. data/app/views/kuhsaft/sitemaps/index.xml.haml +9 -0
  66. data/app/views/kuhsaft/video_bricks/_video_brick.html.haml +4 -4
  67. data/app/views/layouts/kuhsaft/cms/application.html.haml +4 -3
  68. data/config/initializers/simple_form.rb +4 -4
  69. data/config/initializers/simple_form_bootstrap.rb +14 -14
  70. data/config/locales/de.yml +203 -0
  71. data/config/locales/en.yml +282 -0
  72. data/config/locales/kuhsaft.de.yml +14 -0
  73. data/config/locales/kuhsaft.en.yml +60 -0
  74. data/config/locales/models/kuhsaft/image_brick/de.yml +1 -0
  75. data/config/locales/models/kuhsaft/image_brick/en.yml +16 -0
  76. data/config/locales/models/kuhsaft/text_brick/de.yml +3 -0
  77. data/config/locales/models/kuhsaft/text_brick/en.yml +16 -0
  78. data/config/locales/models/kuhsaft/video_brick/en.yml +15 -0
  79. data/config/locales/views/kuhsaft/cms/pages/de.yml +3 -0
  80. data/config/locales/views/kuhsaft/cms/video_bricks/de.yml +1 -1
  81. data/config/routes.rb +18 -9
  82. data/db/migrate/10_add_redirect_url_to_kuhsaft_pages.rb +1 -1
  83. data/db/migrate/11_update_url_and_redirect_url_value.rb +4 -4
  84. data/db/migrate/13_add_page_title_to_pages.rb +1 -1
  85. data/db/migrate/15_add_alt_text_to_bricks.rb +5 -0
  86. data/db/migrate/16_update_default_value_for_page_type.rb +9 -0
  87. data/db/migrate/17_set_page_type_to_content_for_empty_fields.rb +7 -0
  88. data/lib/generators/kuhsaft/assets/install_generator.rb +1 -2
  89. data/lib/generators/kuhsaft/translations/add_generator.rb +19 -4
  90. data/lib/kuhsaft.rb +1 -0
  91. data/lib/kuhsaft/brick_list.rb +6 -8
  92. data/lib/kuhsaft/engine.rb +5 -1
  93. data/lib/kuhsaft/orderable.rb +22 -19
  94. data/lib/kuhsaft/partial_extractor.rb +1 -1
  95. data/lib/kuhsaft/searchable.rb +8 -11
  96. data/lib/kuhsaft/translatable.rb +35 -19
  97. data/lib/kuhsaft/version.rb +1 -1
  98. data/lib/tasks/kuhsaft_tasks.rake +12 -0
  99. data/lib/templates/kuhsaft/assets/ck-config.js.coffee +7 -0
  100. data/lib/templates/kuhsaft/translations/add_translation.html.erb +4 -10
  101. data/spec/controllers/kuhsaft/api/pages_controller_spec.rb +70 -0
  102. data/spec/controllers/kuhsaft/pages_controller_spec.rb +18 -14
  103. data/spec/controllers/kuhsaft/sitemaps_controller_spec.rb +13 -0
  104. data/spec/dummy/app/assets/javascripts/kuhsaft/cms/ck-config.js.coffee +7 -0
  105. data/spec/dummy/config/application.rb +2 -1
  106. data/spec/dummy/config/database.yml +1 -1
  107. data/spec/factories.rb +3 -3
  108. data/spec/features/cms_pages_spec.rb +13 -13
  109. data/spec/features/search_spec.rb +16 -18
  110. data/spec/helpers/kuhsaft/cms/pages_helper_spec.rb +2 -1
  111. data/spec/kuhsaft_spec.rb +1 -1
  112. data/spec/lib/brick_list_spec.rb +1 -1
  113. data/spec/lib/page_tree_spec.rb +10 -6
  114. data/spec/lib/searchable_spec.rb +4 -4
  115. data/spec/lib/translatable_spec.rb +114 -44
  116. data/spec/models/anchor_brick_spec.rb +1 -1
  117. data/spec/models/asset_spec.rb +1 -1
  118. data/spec/models/brick_spec.rb +1 -1
  119. data/spec/models/page_spec.rb +48 -37
  120. data/spec/models/publish_state_spec.rb +9 -9
  121. data/spec/spec_helper.rb +43 -21
  122. data/spec/support/kuhsaft_spec_helper.rb +2 -2
  123. data/spec/support/write_expectation.rb +57 -0
  124. data/spec/views/kuhsaft/sitemaps/index.xml.haml_spec.rb +67 -0
  125. metadata +119 -4
@@ -26,3 +26,6 @@ de:
26
26
  Beschreibung des Inhaltes dieser Seite. Diese Beschreibung ist einmalig und nur auf dieser Seite
27
27
  vorhanden. Auf den anderen Seiten hat es andere Beschreibungen.
28
28
  </em>
29
+ expand_all: Alle aufklappen
30
+ collapse_all: Alle zuklappen
31
+ none: Keine
@@ -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 Video Quelle an.'
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, :except => :show do
4
- post :sort, :on => :collection
4
+ resources :pages, except: :show do
5
+ post :sort, on: :collection
5
6
  end
6
- resources :bricks, :except => [:new, :edit, :index] do
7
- post :sort, :on => :collection
7
+
8
+ resources :bricks, except: [:edit, :index] do
9
+ post :sort, on: :collection
8
10
  end
9
11
 
10
12
  resources :assets
11
- root :to => 'pages#index'
13
+ root to: 'pages#index'
12
14
  end
13
15
 
14
- scope ":locale", :locale => /#{I18n.available_locales.join('|')}/ do
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
- :only => [:index],
17
- :defaults => { :locale => I18n.locale }
18
- get '(*url)' => 'pages#show', :as => :page
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 = "#{I18n.locale}"
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
@@ -1,7 +1,7 @@
1
1
  class AddPageTitleToPages < ActiveRecord::Migration
2
2
  def change
3
3
  I18n.available_locales.each do |locale|
4
- add_column :kuhsaft_pages, "page_title_#{locale}", :text
4
+ add_column :kuhsaft_pages, "page_title_#{locale.to_s.underscore}", :text
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,5 @@
1
+ class AddAltTextToBricks < ActiveRecord::Migration
2
+ def change
3
+ add_column :kuhsaft_bricks, :alt_text, :string
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class UpdateDefaultValueForPageType < ActiveRecord::Migration
2
+ def up
3
+ change_column :kuhsaft_pages, :page_type, :string, :default => Kuhsaft::PageType::CONTENT
4
+ end
5
+
6
+ def down
7
+ change_column_default(:kuhsaft_pages, :page_type, nil)
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ class SetPageTypeToContentForEmptyFields < ActiveRecord::Migration
2
+ def change
3
+ Kuhsaft::Page.where( "page_type is NULL or page_type = ''" ).each do |page|
4
+ page.update_attribute(:page_type, Kuhsaft::PageType::CONTENT)
5
+ end
6
+ end
7
+ 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', :after => /config\.assets\.precompile.*$/ do
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, :type => :string
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 get_locale
18
- locale.downcase.underscore
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', Rails.root.join('db', 'migrate', "add_#{get_locale}_translation.rb"))
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
@@ -12,6 +12,7 @@ module Kuhsaft
12
12
  require 'bourbon'
13
13
  require 'jquery-rails'
14
14
  require 'jquery-ui-rails'
15
+ require 'remotipart'
15
16
  require 'ancestry'
16
17
  require 'bootstrap-sass'
17
18
  require 'haml'
@@ -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
- self.has_many :bricks,
7
- :class_name => 'Kuhsaft::Brick',
8
- :dependent => :destroy,
9
- :as => :brick_list
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
- # It will be stored in the related Page.
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.inject('') do |text, brick|
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
@@ -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
@@ -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 base
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 position
41
+
42
+ def recount_siblings_position_from(position)
43
43
  counter = position
44
- succeeding_siblings.each { |s| counter += 1; s.update_attribute(:position, counter) }
44
+ succeeding_siblings.each do |s|
45
+ counter += 1
46
+ s.update_attribute(:position, counter)
47
+ end
45
48
  end
46
-
47
- def reposition before_id
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 id
64
- self.find(id).position rescue 1
66
+ def position_of(id)
67
+ find(id).position rescue 1
65
68
  end
66
69
  end
67
70
  end
68
- end
71
+ end
@@ -7,7 +7,7 @@ module Kuhsaft
7
7
  filename.slice!(0)
8
8
  partials << filename
9
9
  end
10
- partials.collect {|d| [I18n.t(d), d]}
10
+ partials.map { |d| [I18n.t(d), d] }
11
11
  end
12
12
 
13
13
  def collect_partials(path)
@@ -6,8 +6,8 @@ module Kuhsaft
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  DICTIONARIES = {
9
- :en => 'english',
10
- :de => 'german',
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
- :against => {
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
- :query => query,
40
- :using => { :tsearch => { :dictionary => DICTIONARIES[I18n.locale] || 'simple' }}
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 "
@@ -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 *args
10
+ def translate(*args)
10
11
  args.each do |attr_name|
11
- define_method attr_name do
12
- send "#{attr_name}_#{I18n.locale}"
13
- end
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
- define_method "#{attr_name}?" do
16
- send "#{attr_name}_#{I18n.locale}?"
17
- end
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
- define_method "#{attr_name}=" do |val|
20
- send "#{attr_name}_#{I18n.locale}=", val
21
- end
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
- define_singleton_method "find_by_#{attr_name}" do |val|
24
- send "find_by_#{attr_name}_#{I18n.locale}", val
25
- end
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 locale_attr attr_name
30
- "#{attr_name}_#{I18n.locale}"
43
+ def locale_for_attr_name
44
+ I18n.locale.to_s.underscore
31
45
  end
32
- end
33
46
 
34
- def locale_attr attr_name
35
- "#{attr_name}_#{I18n.locale}"
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