constructor-pages 0.5.8 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/constructor_pages/fields_controller.rb +11 -2
- data/app/controllers/constructor_pages/pages_controller.rb +20 -12
- data/app/controllers/constructor_pages/templates_controller.rb +13 -7
- data/app/models/constructor_pages/field.rb +1 -3
- data/app/models/constructor_pages/page.rb +15 -21
- data/app/models/constructor_pages/template.rb +0 -3
- data/app/models/constructor_pages/types/boolean_type.rb +1 -2
- data/app/models/constructor_pages/types/date_type.rb +1 -6
- data/app/models/constructor_pages/types/float_type.rb +1 -2
- data/app/models/constructor_pages/types/html_type.rb +1 -2
- data/app/models/constructor_pages/types/image_type.rb +3 -2
- data/app/models/constructor_pages/types/integer_type.rb +1 -2
- data/app/models/constructor_pages/types/string_type.rb +1 -2
- data/app/models/constructor_pages/types/text_type.rb +1 -2
- data/app/views/constructor_pages/fields/types/_date.haml +1 -1
- data/app/views/constructor_pages/pages/_form.haml +2 -2
- data/app/views/constructor_pages/pages/index.haml +4 -4
- data/app/views/constructor_pages/templates/_form.haml +2 -2
- data/config/locales/ru.yml +0 -1
- data/constructor-pages.gemspec +2 -1
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3259f9691d8cbc03a1a0125470d5755657a0bf3
|
4
|
+
data.tar.gz: 3dbcf5cf69714b79c4070c4a2386ffca74587811
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e6088570f1810b6b26b0bf6b02405c4b758785913f0f8d9aeb35f01f6e5784398d32335c0e4b33f6b34150b8099f94a91086adf99d283393d5f61f03fde2cc1
|
7
|
+
data.tar.gz: f3bbd308a22d42ae3e958e61dc3a40384fe2f1d91736c52dd351d6839b37e20b098ecfa42529892e64e592d6fa56861c1dfdd73910886145c669ddd676d5bde0
|
@@ -13,7 +13,7 @@ module ConstructorPages
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def create
|
16
|
-
@field = Field.new
|
16
|
+
@field = Field.new field_params
|
17
17
|
|
18
18
|
if @field.save
|
19
19
|
redirect_to edit_template_path(@field.template_id), notice: t(:field_success_added, name: @field.name)
|
@@ -42,7 +42,7 @@ module ConstructorPages
|
|
42
42
|
field.destroy
|
43
43
|
end
|
44
44
|
end
|
45
|
-
if @field.
|
45
|
+
if @field.update field_params
|
46
46
|
redirect_to edit_template_url(@field.template.id), notice: t(:field_success_updated, name: @field.name)
|
47
47
|
else
|
48
48
|
render :action => "edit"
|
@@ -61,6 +61,15 @@ module ConstructorPages
|
|
61
61
|
|
62
62
|
private
|
63
63
|
|
64
|
+
def field_params
|
65
|
+
params.require(:field).permit(
|
66
|
+
:name,
|
67
|
+
:code_name,
|
68
|
+
:template_id,
|
69
|
+
:type_value
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
64
73
|
def move_to(to)
|
65
74
|
@field = Field.find(params[:id])
|
66
75
|
to == :up ? @field.move_higher : @field.move_lower
|
@@ -3,10 +3,8 @@
|
|
3
3
|
module ConstructorPages
|
4
4
|
class PagesController < ConstructorCore::ApplicationController
|
5
5
|
include MoveHelper
|
6
|
-
caches_page :show
|
7
6
|
|
8
7
|
before_filter {@roots = Page.roots}
|
9
|
-
before_filter :cache, only: [:create, :update, :destroy, :move_up, :move_down]
|
10
8
|
|
11
9
|
def new
|
12
10
|
@page, @template_id, @multipart = Page.new, Template.first.id, false
|
@@ -92,7 +90,7 @@ module ConstructorPages
|
|
92
90
|
end
|
93
91
|
|
94
92
|
def create
|
95
|
-
@page = Page.new
|
93
|
+
@page = Page.new page_params
|
96
94
|
|
97
95
|
if @page.save
|
98
96
|
redirect_to pages.pages_url, notice: t(:page_success_added, name: @page.name)
|
@@ -108,7 +106,7 @@ module ConstructorPages
|
|
108
106
|
@page.remove_fields_values
|
109
107
|
end
|
110
108
|
|
111
|
-
if @page.
|
109
|
+
if @page.update page_params
|
112
110
|
@page.create_fields_values
|
113
111
|
@page.update_fields_values params[:fields]
|
114
112
|
|
@@ -129,16 +127,26 @@ module ConstructorPages
|
|
129
127
|
|
130
128
|
private
|
131
129
|
|
132
|
-
def
|
133
|
-
|
130
|
+
def page_params
|
131
|
+
params.require(:page).permit(
|
132
|
+
:active,
|
133
|
+
:name,
|
134
|
+
:url,
|
135
|
+
:title,
|
136
|
+
:keywords,
|
137
|
+
:description,
|
138
|
+
:auto_url,
|
139
|
+
:parent_id,
|
140
|
+
:template_id,
|
141
|
+
:in_nav,
|
142
|
+
:in_map,
|
143
|
+
:in_menu,
|
144
|
+
:link
|
145
|
+
)
|
134
146
|
end
|
135
147
|
|
136
|
-
def
|
137
|
-
|
138
|
-
cache_dir = ActionController::Base.page_cache_directory
|
139
|
-
unless cache_dir == Rails.root.to_s+"/public"
|
140
|
-
FileUtils.rm_r(Dir.glob(cache_dir+"/*")) rescue Errno::ENOENT
|
141
|
-
end
|
148
|
+
def error_404
|
149
|
+
render file: "#{Rails.root}/public/404", layout: false, status: 404
|
142
150
|
end
|
143
151
|
end
|
144
152
|
end
|
@@ -8,11 +8,6 @@ module ConstructorPages
|
|
8
8
|
|
9
9
|
def new
|
10
10
|
@template = Template.new
|
11
|
-
|
12
|
-
if params[:template]
|
13
|
-
@parent = Template.find(params[:template])
|
14
|
-
@template.parent_id = @parent.id
|
15
|
-
end
|
16
11
|
end
|
17
12
|
|
18
13
|
def edit
|
@@ -20,7 +15,7 @@ module ConstructorPages
|
|
20
15
|
end
|
21
16
|
|
22
17
|
def create
|
23
|
-
@template = Template.new
|
18
|
+
@template = Template.new template_params
|
24
19
|
|
25
20
|
if @template.save
|
26
21
|
redirect_to templates_url, notice: t(:template_success_added, name: @template.name)
|
@@ -32,7 +27,7 @@ module ConstructorPages
|
|
32
27
|
def update
|
33
28
|
@template = Template.find params[:id]
|
34
29
|
|
35
|
-
if @template.
|
30
|
+
if @template.update template_params
|
36
31
|
redirect_to templates_url, notice: t(:template_success_updated, name: @template.name)
|
37
32
|
else
|
38
33
|
render action: :edit
|
@@ -47,5 +42,16 @@ module ConstructorPages
|
|
47
42
|
end
|
48
43
|
|
49
44
|
%w{up down}.each {|m| define_method "move_#{m}" do move_to :template, m.to_sym end}
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def template_params
|
49
|
+
params.require(:template).permit(
|
50
|
+
:name,
|
51
|
+
:code_name,
|
52
|
+
:parent_id,
|
53
|
+
:child_id
|
54
|
+
)
|
55
|
+
end
|
50
56
|
end
|
51
57
|
end
|
@@ -5,8 +5,6 @@ module ConstructorPages
|
|
5
5
|
#
|
6
6
|
# Each field has type of value such as float, integer, string...
|
7
7
|
class Field < ActiveRecord::Base
|
8
|
-
attr_accessible :name, :code_name, :type_value, :template_id, :template
|
9
|
-
|
10
8
|
# Adding code_name_uniqueness method
|
11
9
|
include CodeNameUniq
|
12
10
|
|
@@ -38,7 +36,7 @@ module ConstructorPages
|
|
38
36
|
def type_class; "constructor_pages/types/#{type_value}_type".classify.constantize end
|
39
37
|
|
40
38
|
# Return object of type_value by page
|
41
|
-
def find_type_object(page); type_class.
|
39
|
+
def find_type_object(page); type_class.where(field_id: id, page_id: page.id).first end
|
42
40
|
|
43
41
|
# Create object of type_value by page
|
44
42
|
def create_type_object(page); type_class.create(field_id: id, page_id: page.id) end
|
@@ -3,11 +3,6 @@
|
|
3
3
|
module ConstructorPages
|
4
4
|
# Page model. Pages are core for company websites, blogs etc.
|
5
5
|
class Page < ActiveRecord::Base
|
6
|
-
attr_accessible :name, :title, :keywords, :description,
|
7
|
-
:url, :full_url, :active, :auto_url,
|
8
|
-
:parent, :parent_id, :link, :in_menu, :in_map,
|
9
|
-
:in_nav, :template_id, :template
|
10
|
-
|
11
6
|
# Adding has_many for all field types
|
12
7
|
Field::TYPES.each do |t|
|
13
8
|
class_eval %{
|
@@ -19,7 +14,7 @@ module ConstructorPages
|
|
19
14
|
|
20
15
|
belongs_to :template
|
21
16
|
|
22
|
-
default_scope order
|
17
|
+
default_scope -> { order(:lft)}
|
23
18
|
|
24
19
|
validate :template_check
|
25
20
|
|
@@ -32,7 +27,7 @@ module ConstructorPages
|
|
32
27
|
# Used for find page by request. It return first page if no request given
|
33
28
|
# @param request for example <tt>'/conditioners/split-systems/zanussi'</tt>
|
34
29
|
def self.find_by_request_or_first(request = nil)
|
35
|
-
request.nil? ? Page.first : Page.
|
30
|
+
request.nil? ? Page.first : Page.where(full_url: request).first
|
36
31
|
end
|
37
32
|
|
38
33
|
# Generate full_url from parent id and url
|
@@ -47,6 +42,7 @@ module ConstructorPages
|
|
47
42
|
# field and template code_name should be uniqueness for page methods
|
48
43
|
def self.check_code_name(code_name)
|
49
44
|
[code_name, code_name.pluralize, code_name.singularize].each do |name|
|
45
|
+
# TODO: replace Page.first
|
50
46
|
if Page.first.respond_to?(name)
|
51
47
|
return false
|
52
48
|
end
|
@@ -57,7 +53,7 @@ module ConstructorPages
|
|
57
53
|
|
58
54
|
# Get field by code_name
|
59
55
|
def field(code_name)
|
60
|
-
Field.
|
56
|
+
Field.find_by code_name: code_name, template_id: template_id
|
61
57
|
end
|
62
58
|
|
63
59
|
# Get value of field by code_name
|
@@ -80,13 +76,16 @@ module ConstructorPages
|
|
80
76
|
value = params[field.code_name.to_sym]
|
81
77
|
|
82
78
|
_type_object = field.find_type_object(self)
|
83
|
-
_type_object.value = 0 if field.type_value == 'boolean' and reset_booleans
|
84
79
|
|
85
|
-
if
|
86
|
-
_type_object.value = field.type_value == '
|
87
|
-
|
80
|
+
if _type_object
|
81
|
+
_type_object.value = 0 if field.type_value == 'boolean' and reset_booleans
|
82
|
+
|
83
|
+
if value
|
84
|
+
_type_object.value = value
|
85
|
+
end
|
88
86
|
|
89
|
-
|
87
|
+
_type_object.save
|
88
|
+
end
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
@@ -107,12 +106,12 @@ module ConstructorPages
|
|
107
106
|
# It determines if code_name is singular or nor
|
108
107
|
# @param code_name template code name
|
109
108
|
def find_page_in_branch(code_name)
|
110
|
-
_template = Template.
|
109
|
+
_template = Template.where(code_name: code_name.singularize).first
|
111
110
|
|
112
111
|
if _template
|
113
112
|
result = []
|
114
113
|
result = descendants.where(template_id: _template.id) if code_name == code_name.pluralize
|
115
|
-
result = ancestors.
|
114
|
+
result = ancestors.where(template_id: _template.id).first if result.empty?
|
116
115
|
result
|
117
116
|
end
|
118
117
|
end
|
@@ -158,13 +157,8 @@ module ConstructorPages
|
|
158
157
|
self.url = ((auto_url || url.empty?) ? translit(name) : url).parameterize
|
159
158
|
end
|
160
159
|
|
161
|
-
# TODO: move out
|
162
|
-
def parse_date(value)
|
163
|
-
Date.new(value['date(1i)'].to_i, value['date(2i)'].to_i, value['date(3i)'].to_i)
|
164
|
-
end
|
165
|
-
|
166
160
|
# TODO: add more languages
|
167
|
-
#
|
161
|
+
# translit to english
|
168
162
|
def translit(str)
|
169
163
|
Russian.translit(str)
|
170
164
|
end
|
@@ -7,12 +7,9 @@ module ConstructorPages
|
|
7
7
|
# For example:
|
8
8
|
# template "Product" should has fields like "price", "description", "size" etc.
|
9
9
|
class Template < ActiveRecord::Base
|
10
|
-
|
11
10
|
# Adding code_name_uniqueness method
|
12
11
|
include CodeNameUniq
|
13
12
|
|
14
|
-
attr_accessible :name, :code_name, :child_id, :parent_id, :parent
|
15
|
-
|
16
13
|
validates_presence_of :name, :code_name
|
17
14
|
validates_uniqueness_of :code_name
|
18
15
|
validate :code_name_uniqueness
|
@@ -2,15 +2,10 @@
|
|
2
2
|
|
3
3
|
module ConstructorPages
|
4
4
|
module Types
|
5
|
+
# Date time. Render as three select lists (day, month, year).
|
5
6
|
class DateType < ActiveRecord::Base
|
6
|
-
attr_accessible :value, :field_id, :field, :page_id, :page
|
7
|
-
|
8
7
|
belongs_to :field
|
9
8
|
belongs_to :page
|
10
|
-
|
11
|
-
def russian
|
12
|
-
Russian::strftime(self.value, "%d %B %Y").gsub(/0(\d\D)/, '\1')
|
13
|
-
end
|
14
9
|
end
|
15
10
|
end
|
16
11
|
end
|
@@ -2,16 +2,17 @@
|
|
2
2
|
|
3
3
|
module ConstructorPages
|
4
4
|
module Types
|
5
|
+
# Image type. Render select file field.
|
5
6
|
class ImageType < ActiveRecord::Base
|
6
|
-
attr_accessible :value, :field_id, :field, :page_id, :page
|
7
|
-
|
8
7
|
belongs_to :field
|
9
8
|
belongs_to :page
|
10
9
|
|
11
10
|
image_accessor :value
|
12
11
|
|
13
12
|
validates :value, :presence => true
|
13
|
+
# Max size is 5 MB
|
14
14
|
validates_size_of :value, :maximum => 5.megabytes, :message => :incorrect_size
|
15
|
+
# Accept only jpeg, png, gif
|
15
16
|
validates_property :mime_type, :of => :value, :in => %w(image/jpeg image/png image/gif), :message => :incorrect_format
|
16
17
|
end
|
17
18
|
end
|
@@ -1 +1 @@
|
|
1
|
-
=
|
1
|
+
= text_field_tag "fields[#{field.code_name}]", page.get_field_value(field.code_name), type: :date
|
@@ -93,5 +93,5 @@
|
|
93
93
|
.span12
|
94
94
|
.form-actions
|
95
95
|
= f.submit :class => "btn btn-primary"
|
96
|
-
= link_to t(:cancel), pages_url, :
|
97
|
-
= link_to t(:delete_page), @page, :confirm
|
96
|
+
= link_to t(:cancel), pages_url, class: 'btn'
|
97
|
+
= link_to t(:delete_page), @page, method: :delete, data: {confirm: t(:are_you_sure?)}, class: 'btn btn-danger pull-right' unless @page.new_record?
|
@@ -21,8 +21,8 @@
|
|
21
21
|
</li>
|
22
22
|
|
23
23
|
<li>
|
24
|
-
- if page.
|
25
|
-
= link_to page.name, page.full_url, :
|
24
|
+
- if page.published?
|
25
|
+
= link_to page.name, page.full_url, class: 'btn btn-link'
|
26
26
|
- else
|
27
27
|
%button.btn.disabled= page.name
|
28
28
|
|
@@ -42,9 +42,9 @@
|
|
42
42
|
- else
|
43
43
|
= link_to "<i class='icon-chevron-down'></i> #{t :add} #{ConstructorPages::Template.find(page.template.child_id).name.downcase}".html_safe, new_child_page_path(page), :class => "btn btn-success btn-mini"
|
44
44
|
|
45
|
-
= link_to "<i class='icon-remove'></i> #{t :delete}".html_safe, page_path(page),
|
45
|
+
= link_to "<i class='icon-remove'></i> #{t :delete}".html_safe, page_path(page), method: :delete, class: 'btn btn-danger btn-mini pull-right', data: {confirm: t(:are_you_sure?)}
|
46
|
+
|
46
47
|
|
47
|
-
|
48
48
|
|
49
49
|
- level = page.level
|
50
50
|
- last_page = page
|
@@ -37,11 +37,11 @@
|
|
37
37
|
= link_to "<i class='icon-arrow-up'></i>".html_safe, field_move_up_path(field), :class => "btn btn-mini #{"disabled" if field.first?}"
|
38
38
|
|
39
39
|
= link_to "<i class='icon-pencil icon-white'></i>".html_safe, edit_field_path(field, field.template), :class => "btn btn-mini btn-primary"
|
40
|
-
= link_to "<i class='icon-remove icon-white'></i>".html_safe, field_path(field), :
|
40
|
+
= link_to "<i class='icon-remove icon-white'></i>".html_safe, field_path(field), method: :delete, data: {confirm: t(:are_you_sure?)}, class: 'btn btn-mini btn-danger'
|
41
41
|
|
42
42
|
.row-fluid
|
43
43
|
.span12
|
44
44
|
.form-actions
|
45
45
|
= f.submit :class => "btn btn-primary"
|
46
46
|
= link_to t(:cancel), templates_url, :class => "btn"
|
47
|
-
= link_to t(:delete_template), @template, :confirm
|
47
|
+
= link_to t(:delete_template), @template, method: :delete, data: {confirm: t(:are_you_sure?)}, class: 'btn btn-danger pull-right' unless @template.new_record?
|
data/config/locales/ru.yml
CHANGED
data/constructor-pages.gemspec
CHANGED
@@ -21,9 +21,10 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.add_dependency 'dragonfly'
|
23
23
|
s.add_dependency 'rack-cache'
|
24
|
-
s.add_dependency 'awesome_nested_set'
|
24
|
+
s.add_dependency 'awesome_nested_set'
|
25
25
|
s.add_dependency 'haml-rails'
|
26
26
|
s.add_dependency 'acts_as_list'
|
27
|
+
s.add_dependency 'russian'
|
27
28
|
|
28
29
|
s.add_development_dependency 'rspec-rails'
|
29
30
|
s.add_development_dependency 'capybara'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constructor-pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Zotov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: constructor-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.6.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.6.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dragonfly
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: awesome_nested_set
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: haml-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: russian
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rspec-rails
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|