constructor-cms 0.6.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -3
  3. data/Gemfile +9 -0
  4. data/README.md +2 -2
  5. data/constructor-cms.gemspec +0 -1
  6. data/core/config/initializers/devise.rb +8 -8
  7. data/core/config/locales/devise.en.yml +37 -37
  8. data/core/config/locales/devise.fr.yml +74 -0
  9. data/core/config/locales/devise.ru.yml +40 -40
  10. data/core/config/locales/en.yml +14 -14
  11. data/core/config/locales/fr.yml +15 -0
  12. data/core/config/locales/ru.yml +20 -20
  13. data/core/lib/constructor_core/version.rb +1 -1
  14. data/pages/app/controllers/constructor_pages/fields_controller.rb +7 -11
  15. data/pages/app/models/constructor_pages/page.rb +70 -40
  16. data/pages/app/views/constructor_pages/fields/_form.haml +2 -1
  17. data/pages/config/locales/en.yml +57 -54
  18. data/pages/config/locales/fr.yml +65 -0
  19. data/pages/config/locales/ru.yml +48 -44
  20. data/pages/spec/features/constructor_pages/fields_controller_spec.rb +217 -0
  21. data/pages/spec/features/constructor_pages/pages_controller_spec.rb +4 -1
  22. data/pages/spec/features/constructor_pages/templates_controller_spec.rb +4 -0
  23. data/pages/spec/helpers/constructor_pages/.keep +0 -0
  24. data/pages/spec/models/constructor_pages/page_model_spec.rb +97 -0
  25. data/pages/spec/models/constructor_pages/template_model_spec.rb +5 -0
  26. data/pages/spec/models/constructor_pages/types/boolean_type_model_spec.rb +21 -0
  27. data/pages/spec/models/constructor_pages/types/date_type_model_spec.rb +21 -0
  28. data/pages/spec/models/constructor_pages/types/float_type_model_spec.rb +21 -0
  29. data/pages/spec/models/constructor_pages/types/html_type_model_spec.rb +63 -0
  30. data/pages/spec/models/constructor_pages/types/integer_type_model_spec.rb +24 -0
  31. data/pages/spec/models/constructor_pages/types/string_type_model_spec.rb +21 -0
  32. data/pages/spec/models/constructor_pages/types/text_type_model_spec.rb +63 -0
  33. data/pages/spec/routing/constructor_pages/.keep +0 -0
  34. data/spec/spec_helper.rb +2 -0
  35. metadata +19 -20
@@ -1,3 +1,3 @@
1
1
  module ConstructorCore
2
- VERSION = '0.6.4'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -3,13 +3,11 @@
3
3
  module ConstructorPages
4
4
  class FieldsController < ApplicationController
5
5
  def new
6
- @field = Field.new
7
- @field.template = Template.find(params[:template_id])
6
+ @field = Field.new.tap {|f| f.template = Template.find(params[:template_id])}
8
7
  end
9
8
 
10
9
  def edit
11
- @field = Field.find(params[:id])
12
- @field.template = Template.find(params[:template_id])
10
+ @field = Field.find(params[:id]).tap {|f| f.template = Template.find(params[:template_id])}
13
11
  end
14
12
 
15
13
  def create
@@ -18,7 +16,7 @@ module ConstructorPages
18
16
  if @field.save
19
17
  redirect_to edit_template_path(@field.template_id), notice: t(:field_success_added, name: @field.name)
20
18
  else
21
- render :action => 'new', :template_id => @field.template_id
19
+ render action: :new, template_id: @field.template_id
22
20
  end
23
21
  end
24
22
 
@@ -26,10 +24,9 @@ module ConstructorPages
26
24
  @field = Field.find params[:id]
27
25
 
28
26
  if @field.type_value != params[:field][:type_value]
29
- @field.type_class.where(:field_id => @field.id).each do |field|
27
+ @field.type_class.where(field_id: @field.id).each do |field|
30
28
  new_field = "constructor_pages/types/#{params[:field][:type_value]}_type".classify.constantize.new(
31
- :field_id => @field.id,
32
- :page_id => field.page_id)
29
+ field_id: @field.id, page_id: field.page_id)
33
30
 
34
31
  if @field.type_value != 'image' \
35
32
  and params[:field][:type_value] != 'image' \
@@ -45,14 +42,13 @@ module ConstructorPages
45
42
  if @field.update field_params
46
43
  redirect_to edit_template_url(@field.template.id), notice: t(:field_success_updated, name: @field.name)
47
44
  else
48
- render :action => "edit"
45
+ render action: :edit
49
46
  end
50
47
  end
51
48
 
52
49
  def destroy
53
50
  @field = Field.find(params[:id])
54
- name = @field.name
55
- template = @field.template.id
51
+ name, template = @field.name, @field.template.id
56
52
  @field.destroy
57
53
  redirect_to edit_template_url(template), notice: t(:field_success_removed, name: name)
58
54
  end
@@ -5,9 +5,7 @@ module ConstructorPages
5
5
  class Page < ActiveRecord::Base
6
6
  # Adding has_many for all field types
7
7
  Field::TYPES.each do |t|
8
- class_eval %{
9
- has_many :#{t}_types, dependent: :destroy, class_name: 'Types::#{t.titleize}Type'
10
- }
8
+ class_eval %{ has_many :#{t}_types, dependent: :destroy, class_name: 'Types::#{t.titleize}Type'}
11
9
  end
12
10
 
13
11
  has_many :fields, through: :template
@@ -24,45 +22,83 @@ module ConstructorPages
24
22
 
25
23
  acts_as_nested_set
26
24
 
27
- # Used for find page by request. It return first page if no request given or request is home page
28
- # @param request for example <tt>'/conditioners/split-systems/zanussi'</tt>
29
- def self.find_by_request_or_first(request = nil)
30
- request.nil? || request == '/' ? Page.first : Page.where(full_url: request).first
31
- end
25
+ class << self
26
+ # Used for find page by request. It return first page if no request given or request is home page
27
+ # @param request for example <tt>'/conditioners/split-systems/zanussi'</tt>
28
+ def find_by_request_or_first(request = nil)
29
+ request == nil || '/' ? Page.first : Page.find_by(full_url: request)
30
+ end
32
31
 
33
- # Generate full_url from parent id and url
34
- # @param parent_id integer
35
- # @param url should looks like <tt>'hello-world-page'</tt> without leading slash
36
- def self.full_url_generate(parent_id, url = '')
37
- '/' + Page.find(parent_id).self_and_ancestors.map {|c| c.url}.append(url).join('/')
38
- end
32
+ # Generate full_url from parent id and url
33
+ # @param parent_id integer
34
+ # @param url should looks like <tt>'hello-world-page'</tt> without leading slash
35
+ def full_url_generate(parent_id, url = '')
36
+ '/' + Page.find(parent_id).self_and_ancestors.map(&:url).append(url).join('/')
37
+ end
39
38
 
40
- # Check code_name for field and template.
41
- # When missing method Page find field or page in branch with plural and singular code_name so
42
- # field and template code_name should be uniqueness for page methods
43
- def self.check_code_name(code_name)
44
- [code_name, code_name.pluralize, code_name.singularize].each do |name|
45
- return false if Page.instance_methods.include?(name.to_sym)
39
+ # Check code_name for field and template.
40
+ # When missing method Page find field or page in branch with plural and singular code_name so
41
+ # field and template code_name should be uniqueness for page methods
42
+ def check_code_name(code_name)
43
+ [code_name, code_name.pluralize, code_name.singularize].each do |name|
44
+ return false if Page.instance_methods.include?(name.to_sym)
45
+ end
46
+
47
+ true
46
48
  end
47
49
 
48
- true
50
+ def search(what_search = nil)
51
+ if @where_search
52
+ if @where_search.is_a?(String)
53
+ _page = Page.find_by full_url: @where_search
54
+ elsif @where_search.is_a?(Page)
55
+ _page = @where_search
56
+ end
57
+
58
+ @result = _page ? _page.descendants : []
59
+ else
60
+ @result = Page.all
61
+ end
62
+
63
+ if what_search
64
+ _template = Template.find_by code_name: what_search.to_s.singularize.downcase
65
+ @result = _template ? @result.where(template: _template) : []
66
+ end
67
+
68
+ if @params_search
69
+ @params_search.each_pair do |k, v|
70
+ @result = @result.select { |p| p.send(k) == v }
71
+ end
72
+ end
73
+
74
+ @where_search = @params_search = nil
75
+
76
+ @result
77
+ end
78
+
79
+ def in(where_search = nil); tap {@where_search = where_search} end
80
+ def by(params_search = nil); tap {@params_search = params_search} end
81
+
82
+ def search_in(where_search = nil); self.in(where_search).search end
83
+ def search_by(params_search = nil); self.by(params_search).search end
49
84
  end
50
85
 
86
+ def search(what_search = nil); Page.in(self).search(what_search) end
87
+ def search_by(params_search = nil); Page.by(params_search).in(self).search end
88
+
51
89
  # Get field by code_name
52
90
  def field(code_name)
53
- Field.where(code_name: code_name, template_id: template_id).first
91
+ Field.find_by code_name: code_name, template_id: template_id
54
92
  end
55
93
 
56
94
  # Get value of field by code_name
57
95
  def get_field_value(code_name)
58
- field = field(code_name)
59
- field.get_value_for(self) if field
96
+ field(code_name).tap {|f| return f.get_value_for(self) if f}
60
97
  end
61
98
 
62
99
  # Set value of field by code_name and value
63
100
  def set_field_value(code_name, value)
64
- field = field(code_name)
65
- field.set_value_for(self, value) if field
101
+ field(code_name).tap {|f| f.set_value_for(self, value) if f}
66
102
  end
67
103
 
68
104
  # Update all fields values with given params.
@@ -78,18 +114,14 @@ module ConstructorPages
78
114
 
79
115
  if _type_object
80
116
  _type_object.value = 0 if field.type_value == 'boolean' and reset_booleans
81
-
82
- if value
83
- _type_object.value = value
84
- end
85
-
117
+ _type_object.value = value if value
86
118
  _type_object.save
87
119
  end
88
120
  end
89
121
  end
90
122
 
91
123
  # Create fields values
92
- def create_fields_values; fields.each {|field| field.create_type_object(self) } end
124
+ def create_fields_values; fields.each {|f| f.create_type_object(self) } end
93
125
 
94
126
  # Remove all fields values
95
127
  def remove_fields_values
@@ -105,12 +137,12 @@ module ConstructorPages
105
137
  # It determines if code_name is singular or nor
106
138
  # @param code_name template code name
107
139
  def find_page_in_branch(code_name)
108
- _template = Template.where(code_name: code_name.singularize).first
140
+ _template = Template.find_by code_name: code_name.singularize
109
141
 
110
142
  if _template
111
143
  result = []
112
144
  result = descendants.where(template_id: _template.id) if code_name == code_name.pluralize
113
- result = ancestors.where(template_id: _template.id).first if result.empty?
145
+ result = ancestors.find_by(template_id: _template.id) if result.empty?
114
146
  result
115
147
  end
116
148
  end
@@ -126,13 +158,11 @@ module ConstructorPages
126
158
  # Default attributes are name and title. Options param allows to add more.
127
159
  # @param options default merge name and title page attributes
128
160
  def as_json(options = {})
129
- options = {name: self.name, title: self.title}.merge options
130
-
131
- fields.each do |field|
132
- options.merge!({field.code_name.to_sym => field.get_value_for(self)})
161
+ {name: self.name, title: self.title}.merge(options).tap do |options|
162
+ fields.each do |f|
163
+ options.merge!({f.code_name.to_sym => f.get_value_for(self)})
164
+ end
133
165
  end
134
-
135
- options
136
166
  end
137
167
 
138
168
  # Check if link specified
@@ -25,4 +25,5 @@
25
25
  .span12
26
26
  .form-actions
27
27
  = f.submit class: 'btn btn-primary'
28
- = link_to t(:cancel), edit_template_url(@field.template), class: 'btn'
28
+ = link_to t(:cancel), edit_template_url(@field.template), class: 'btn'
29
+ = link_to t(:delete_field), @field, method: :delete, data: {confirm: t(:are_you_sure?)}, class: 'btn btn-danger pull-right' unless @field.new_record?
@@ -1,57 +1,56 @@
1
1
  en:
2
- structure: 'Structure'
3
- templates: 'Templates'
4
- settings: 'Settings'
5
- new_field: 'New field'
6
- edit_field: 'Edit field'
7
- seo: 'SEO'
8
- display_in: 'Display in'
9
- help: 'Help'
10
- edit: 'Edit'
11
- delete: 'Delete'
12
-
13
- new_field: 'New field'
14
-
15
- code_name_already_in_use: 'This code name is already in use.'
16
- field_success_added: 'Field «%{name}» added successfully.'
17
- field_success_updated: 'Field «%{name}» updated successfully.'
18
- field_success_removed: 'Field «%{name}» removed successfully.'
19
- field_success_moved: 'Field «%{name} moved successfully.'
20
-
21
- string: 'String'
22
- integer: 'Integer'
23
- float: 'Float'
24
- boolean: 'Boolean'
25
- date: 'Date'
26
- text: 'Text'
27
- html: 'HTML'
28
- image: 'Image'
29
-
30
- menu: 'Menu'
31
- breadcrumbs: 'Breadcrumbs'
32
-
33
- are_you_sure?: 'Are you sure?'
34
-
35
- page_not_found: 'Page not found'
36
-
37
- new_page: 'New page'
38
- edit_page: 'Edit page'
39
- delete_page: 'Delete page'
40
-
41
- page_success_added: 'Page «%{name}» added successfully.'
42
- page_success_updated: 'Page «%{name}» updated successfully.'
43
- page_success_removed: 'Page «%{name}» removed successfully.'
44
-
45
- template: 'Template'
46
- new_template: 'New template'
47
- edit_template: 'Edit template'
48
- delete_template: 'Delete template'
49
-
50
- template_success_added: 'Template «%{name}» added successfully.'
51
- template_success_updated: 'Template «%{name}» updated successfully.'
52
- template_success_removed: 'Template «%{name}» removed successfully.'
53
-
54
- template_error_delete_pages: 'Delete pages with this template before'
2
+ structure: Structure
3
+ templates: Templates
4
+ settings: Settings
5
+ new_field: New field
6
+ edit_field: Edit field
7
+ seo: SEO
8
+ display_in: Display in
9
+ help: Help
10
+ edit: Edit
11
+ delete: Delete
12
+
13
+ code_name_already_in_use: This code name is already in use.
14
+ field_success_added: Field «%{name}» added successfully.
15
+ field_success_updated: Field «%{name updated successfully.
16
+ field_success_removed: Field «%{name}» removed successfully.
17
+ field_success_moved: Field «%{name} moved successfully.
18
+ delete_field: Delete field
19
+
20
+ string: String
21
+ integer: Integer
22
+ float: Float
23
+ boolean: Boolean
24
+ date: Date
25
+ text: Text
26
+ html: HTML
27
+ image: Image
28
+
29
+ menu: Menu
30
+ breadcrumbs: Breadcrumbs
31
+
32
+ are_you_sure?: Are you sure?
33
+
34
+ page_not_found: Page not found
35
+
36
+ new_page: New page
37
+ edit_page: Edit page
38
+ delete_page: Delete page
39
+
40
+ page_success_added: Page «%{name}» added successfully.
41
+ page_success_updated: Page «%{name}» updated successfully.
42
+ page_success_removed: Page «%{name}» removed successfully.
43
+
44
+ template: Template
45
+ new_template: New template
46
+ edit_template: Edit template
47
+ delete_template: Delete template
48
+
49
+ template_success_added: Template «%{name}» added successfully.
50
+ template_success_updated: Template «%{name}» updated successfully.
51
+ template_success_removed: Template «%{name}» removed successfully.
52
+
53
+ template_error_delete_pages: Delete pages with this template before
55
54
 
56
55
  activerecord:
57
56
  errors:
@@ -59,4 +58,8 @@ en:
59
58
  constructor_pages/template:
60
59
  attributes:
61
60
  base:
62
- code_name_already_in_use: 'Code name has already been taken'
61
+ code_name_already_in_use: Code name has already been taken
62
+ constructor_pages/field:
63
+ attributes:
64
+ base:
65
+ code_name_already_in_use: Code name has already been taken
@@ -0,0 +1,65 @@
1
+ fr:
2
+ structure: Structure
3
+ templates: Modèles
4
+ settings: Réglages
5
+ new_field: Nouveau champ
6
+ edit_field: Champ dédition
7
+ seo: SEO
8
+ display_in: Montrer
9
+ help: Aider
10
+ edit: Èditer
11
+ delete: Supprimer
12
+
13
+ code_name_already_in_use: Ce nom de code est déjà utilisé
14
+ field_success_added: Champ %{name} a ajouté avec succès
15
+ field_success_updated: Champ %{name} mis à jour
16
+ field_success_removed: Champ %{name} supprimé avec succès
17
+ field_success_moved: Champ %{name} passé avec succès
18
+ delete_field: Supprimer le champ
19
+
20
+ string: String
21
+ integer: Entier
22
+ float: Flotter
23
+ boolean: Booléen
24
+ date: Date
25
+ text: Texte
26
+ html: HTML
27
+ image: Image
28
+
29
+ menu: Menu
30
+ breadcrumbs: Chapelure
31
+
32
+ are_you_sure?: Etes-vous sûr?
33
+
34
+ page_not_found: Page introuvable
35
+
36
+ new_page: Nouvelle page
37
+ edit_page: Modifier cette page
38
+ delete_page: Supprimer page
39
+
40
+ page_success_added: Page %{name} a ajouté avec succès
41
+ page_success_updated: Page %{name} mis à jour avec succès
42
+ page_success_removed: Page %{name} supprimé avec succès
43
+
44
+ template: Modèle
45
+ new_template: Nouveau modèle
46
+ edit_template: Modifier le modèle
47
+ delete_template: Supprimer le modèle
48
+
49
+ template_success_added: Modèle %{name} a ajouté avec succès
50
+ template_success_updated: Modèle %{name} mis à jour
51
+ template_success_removed: Modèle %{name} supprimé avec succès.
52
+
53
+ template_error_delete_pages: Supprimer les pages avec ce modèle avant
54
+
55
+ activerecord:
56
+ errors:
57
+ models:
58
+ constructor_pages/template:
59
+ attributes:
60
+ base:
61
+ code_name_already_in_use: Nom de code a déjà été prise
62
+ constructor_pages/field:
63
+ attributes:
64
+ base:
65
+ code_name_already_in_use: Nom de code a déjà été prise
@@ -1,55 +1,55 @@
1
1
  ru:
2
- structure: 'Структура'
3
- templates: 'Шаблоны'
4
- settings: 'Настройки'
5
- new_field: 'Новое поле'
6
- edit_field: 'Редактирование поля'
7
- seo: 'Поисковая оптимизация'
8
- are_you_sure?: 'Вы уверены?'
9
- display_in: 'Отображать в'
10
- delete: 'Удалить'
2
+ structure: Структура
3
+ templates: Шаблоны
4
+ settings: Настройки
5
+ new_field: Новое поле
6
+ edit_field: Редактирование поля
7
+ seo: Поисковая оптимизация
8
+ are_you_sure?: Вы уверены?
9
+ display_in: Отображать в
10
+ delete: Удалить
11
11
 
12
- menu: 'Меню'
13
- breadcrumbs: 'Хлебные крошки'
14
- code_name_already_in_use: 'Такое кодовое имя уже используется'
15
- template: 'Шаблон'
16
- new_template: 'Создать шаблон'
17
- edit_template: 'Редактирование шаблона'
18
- delete_template: 'Удалить шаблон'
12
+ menu: Меню
13
+ breadcrumbs: Хлебные крошки
14
+ code_name_already_in_use: Такое кодовое имя уже используется
15
+ template: Шаблон
16
+ new_template: Создать шаблон
17
+ edit_template: Редактирование шаблона
18
+ delete_template: Удалить шаблон
19
19
 
20
- new_field: 'Добавить поле'
21
- code_name_already_in_use: 'Такое имя уже используется.'
22
- field_success_added: 'Поле «%{name}» успешно добавлено.'
23
- field_success_updated: 'Поле «%{name}» успешно обновлено.'
24
- field_success_removed: 'Поле «%{name}» успешно удалено.'
25
- field_success_moved: 'Поле «%{name}» успешно перемещено.'
20
+ code_name_already_in_use: Такое имя уже используется.
21
+ field_success_added: Поле «%{name}» успешно добавлено.
22
+ field_success_updated: Поле «%{name}» успешно обновлено.
23
+ field_success_removed: Поле «%{name}» успешно удалено.
24
+ field_success_moved: Поле «%{name}» успешно перемещено.
25
+ delete_field: Удалить поле
26
26
 
27
- string: 'Строка'
28
- integer: 'Целое число'
29
- float: 'Дробное число'
30
- boolean: 'Булево'
31
- date: 'Дата'
32
- text: 'Текст'
33
- html: 'HTML'
34
- image: 'Изображение'
35
- help: 'Помощь'
36
- edit: 'Редактировать'
27
+ string: Строка
28
+ integer: Целое число
29
+ float: Дробное число
30
+ boolean: Булево
31
+ date: Дата
32
+ text: Текст
33
+ html: HTML
34
+ image: Изображение
35
+ help: Помощь
36
+ edit: Редактировать
37
37
 
38
- page_not_found: 'Страница не найдена'
38
+ page_not_found: Страница не найдена
39
39
 
40
- new_page: 'Создать страницу'
41
- edit_page: 'Редактирование страницы'
42
- delete_page: 'Удалить страницу'
40
+ new_page: Создать страницу
41
+ edit_page: Редактирование страницы
42
+ delete_page: Удалить страницу
43
43
 
44
- page_success_added: 'Страница «%{name}» успешно добавлена.'
45
- page_success_updated: 'Страница «%{name}» успешно обновлена.'
46
- page_success_removed: 'Страница «%{name}» успешно удалена.'
44
+ page_success_added: Страница «%{name}» успешно добавлена.
45
+ page_success_updated: Страница «%{name}» успешно обновлена.
46
+ page_success_removed: Страница «%{name}» успешно удалена.
47
47
 
48
- template_success_added: 'Шаблон «%{name}» успешно добавлен.'
49
- template_success_updated: 'Шаблон «%{name}» успешно обновлен.'
50
- template_success_removed: 'Шаблон «%{name}» успешно удален.'
48
+ template_success_added: Шаблон «%{name}» успешно добавлен.
49
+ template_success_updated: Шаблон «%{name}» успешно обновлен.
50
+ template_success_removed: Шаблон «%{name}» успешно удален.
51
51
 
52
- template_error_delete_pages: 'Удалите страницы с данным шаблоном'
52
+ template_error_delete_pages: Удалите страницы с данным шаблоном
53
53
 
54
54
  activerecord:
55
55
  attributes:
@@ -93,4 +93,8 @@ ru:
93
93
  constructor_pages/template:
94
94
  attributes:
95
95
  base:
96
- code_name_already_in_use: 'Такое кодовое имя уже используется'
96
+ code_name_already_in_use: Такое кодовое имя уже используется
97
+ constructor_pages/field:
98
+ attributes:
99
+ base:
100
+ code_name_already_in_use: Такое кодовое имя уже используется