constructor-pages 0.2.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.
- data/app/assets/images/constructor_pages/arrow_down.png +0 -0
- data/app/assets/images/constructor_pages/arrow_up.png +0 -0
- data/app/assets/images/constructor_pages/information.png +0 -0
- data/app/assets/images/constructor_pages/page_white_edit.png +0 -0
- data/app/assets/images/constructor_pages/photos.png +0 -0
- data/app/controllers/constructor_pages/fields_controller.rb +60 -0
- data/app/controllers/constructor_pages/pages_controller.rb +207 -0
- data/app/controllers/constructor_pages/templates_controller.rb +71 -0
- data/app/helpers/constructor_pages/fields_helper.rb +18 -0
- data/app/helpers/constructor_pages/pages_helper.rb +15 -0
- data/app/helpers/constructor_pages/templates_helper.rb +11 -0
- data/app/models/constructor_pages/field.rb +60 -0
- data/app/models/constructor_pages/page.rb +117 -0
- data/app/models/constructor_pages/template.rb +30 -0
- data/app/models/constructor_pages/types/boolean_type.rb +12 -0
- data/app/models/constructor_pages/types/date_type.rb +16 -0
- data/app/models/constructor_pages/types/float_type.rb +12 -0
- data/app/models/constructor_pages/types/html_type.rb +12 -0
- data/app/models/constructor_pages/types/image_type.rb +18 -0
- data/app/models/constructor_pages/types/integer_type.rb +12 -0
- data/app/models/constructor_pages/types/string_type.rb +12 -0
- data/app/models/constructor_pages/types/text_type.rb +12 -0
- data/app/views/constructor_pages/fields/_form.haml +28 -0
- data/app/views/constructor_pages/fields/edit.haml +6 -0
- data/app/views/constructor_pages/fields/new.haml +6 -0
- data/app/views/constructor_pages/fields/types/_boolean.haml +1 -0
- data/app/views/constructor_pages/fields/types/_date.haml +1 -0
- data/app/views/constructor_pages/fields/types/_float.haml +1 -0
- data/app/views/constructor_pages/fields/types/_html.haml +1 -0
- data/app/views/constructor_pages/fields/types/_image.haml +4 -0
- data/app/views/constructor_pages/fields/types/_integer.haml +1 -0
- data/app/views/constructor_pages/fields/types/_string.haml +1 -0
- data/app/views/constructor_pages/fields/types/_text.haml +1 -0
- data/app/views/constructor_pages/pages/_breadcrumbs.haml +7 -0
- data/app/views/constructor_pages/pages/_form.haml +98 -0
- data/app/views/constructor_pages/pages/_menu.haml +8 -0
- data/app/views/constructor_pages/pages/_submenu.haml +6 -0
- data/app/views/constructor_pages/pages/edit.haml +6 -0
- data/app/views/constructor_pages/pages/error_404.haml +23 -0
- data/app/views/constructor_pages/pages/index.haml +50 -0
- data/app/views/constructor_pages/pages/new.haml +6 -0
- data/app/views/constructor_pages/pages/show.haml +5 -0
- data/app/views/constructor_pages/pages/sitemap.haml +12 -0
- data/app/views/constructor_pages/templates/_form.haml +48 -0
- data/app/views/constructor_pages/templates/edit.haml +6 -0
- data/app/views/constructor_pages/templates/index.haml +38 -0
- data/app/views/constructor_pages/templates/new.haml +6 -0
- data/config/initializers/dragonfly.rb +9 -0
- data/config/locales/ru.yml +39 -0
- data/config/routes.rb +34 -0
- data/constructor-pages.gemspec +21 -0
- data/db/migrate/10_create_html_types.rb +15 -0
- data/db/migrate/11_create_image_types.rb +16 -0
- data/db/migrate/12_add_default_template.rb +13 -0
- data/db/migrate/1_create_pages.rb +27 -0
- data/db/migrate/2_create_templates.rb +18 -0
- data/db/migrate/3_create_fields.rb +17 -0
- data/db/migrate/4_create_string_types.rb +15 -0
- data/db/migrate/5_create_float_types.rb +15 -0
- data/db/migrate/6_create_boolean_types.rb +15 -0
- data/db/migrate/7_create_integer_types.rb +15 -0
- data/db/migrate/8_create_text_types.rb +15 -0
- data/db/migrate/9_create_date_types.rb +15 -0
- data/lib/constructor-pages.rb +7 -0
- data/lib/constructor_pages/engine.rb +6 -0
- data/public/hello.txt +1 -0
- data/spec/factories.rb +7 -0
- data/spec/models/page_model_spec.rb +113 -0
- metadata +210 -0
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ConstructorPages
|
4
|
+
class FieldsController < ConstructorCore::AdminController
|
5
|
+
# TODO
|
6
|
+
include ConstructorCore::DeviseHelper
|
7
|
+
|
8
|
+
layout 'constructor_core/application_admin'
|
9
|
+
|
10
|
+
def new
|
11
|
+
@field = Field.new
|
12
|
+
@field.template = Template.find(params[:template_id])
|
13
|
+
end
|
14
|
+
|
15
|
+
def edit
|
16
|
+
@field = Field.find(params[:id])
|
17
|
+
@field.template = Template.find(params[:template_id])
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
@field = Field.new params[:field]
|
22
|
+
|
23
|
+
if @field.save
|
24
|
+
redirect_to edit_template_path(@field.template_id), :notice => "Поле «#{@field.name}» успешно добавлено."
|
25
|
+
else
|
26
|
+
render :action => 'new', :template_id => @field.template_id
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
@field = Field.find params[:id]
|
32
|
+
|
33
|
+
if @field.update_attributes params[:field]
|
34
|
+
redirect_to edit_template_url(@field.template.id), :notice => "Поле «#{@field.name}» успешно обновлено."
|
35
|
+
else
|
36
|
+
render :action => "edit"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def destroy
|
41
|
+
@field = Field.find(params[:id])
|
42
|
+
name = @field.name
|
43
|
+
template = @field.template.id
|
44
|
+
@field.destroy
|
45
|
+
redirect_to edit_template_url(template), :notice => "Поле «#{name}» успешно удалено."
|
46
|
+
end
|
47
|
+
|
48
|
+
def move_up
|
49
|
+
@field = Field.find(params[:id])
|
50
|
+
@field.move_higher
|
51
|
+
redirect_to :back, :notice => 'Поле успешно перемещено.'
|
52
|
+
end
|
53
|
+
|
54
|
+
def move_down
|
55
|
+
@field = Field.find(params[:id])
|
56
|
+
@field.move_lower
|
57
|
+
redirect_to :back, :notice => 'Поле успешно перемещено.'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ConstructorPages
|
4
|
+
class PagesController < ConstructorCore::AdminController
|
5
|
+
# TODO
|
6
|
+
include ConstructorCore::DeviseHelper
|
7
|
+
|
8
|
+
caches_page :show
|
9
|
+
|
10
|
+
before_filter :authenticate_user!, :except => [:show, :search, :sitemap]
|
11
|
+
before_filter {@roots = Page.roots}
|
12
|
+
layout 'constructor_core/application_admin', :except => [:show, :search, :sitemap]
|
13
|
+
before_filter :cache, :only => [:create, :update, :destroy, :move_up, :move_down]
|
14
|
+
|
15
|
+
# TODO
|
16
|
+
def index
|
17
|
+
@user_signed_in = user_signed_in?
|
18
|
+
end
|
19
|
+
|
20
|
+
def sitemap
|
21
|
+
@pages = Page.all
|
22
|
+
@title = "Карта сайта"
|
23
|
+
end
|
24
|
+
|
25
|
+
def new
|
26
|
+
@page = Page.new
|
27
|
+
@template = Template.first.id
|
28
|
+
@multipart = false
|
29
|
+
|
30
|
+
if params[:page]
|
31
|
+
@parent = Page.find(params[:page])
|
32
|
+
@page.parent_id = @parent.id
|
33
|
+
|
34
|
+
if @parent.template.child_id.nil? and !@parent.template.leaf?
|
35
|
+
@template = @parent.template.descendants.first.id
|
36
|
+
else
|
37
|
+
@template = @parent.template.child_id
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def show
|
43
|
+
if params[:all].nil?
|
44
|
+
@page = Page.first
|
45
|
+
else
|
46
|
+
@request = '/' + params[:all]
|
47
|
+
@page = Page.where(:full_url => @request).first
|
48
|
+
end
|
49
|
+
|
50
|
+
if @page.nil? or !@page.active
|
51
|
+
render :action => "error_404", :layout => false
|
52
|
+
return
|
53
|
+
end
|
54
|
+
|
55
|
+
if @page.url != @page.link and !@page.link.empty?
|
56
|
+
redirect_to @page.link
|
57
|
+
end
|
58
|
+
|
59
|
+
instance_variable_set('@'+@page.template.code_name.to_s, @page)
|
60
|
+
|
61
|
+
@children_of_current_root = Page.children_of(@page.root)
|
62
|
+
@children_of_current_page = Page.children_of(@page)
|
63
|
+
|
64
|
+
respond_to do |format|
|
65
|
+
format.html { render :template => "html_templates/#{@page.template.code_name}" }
|
66
|
+
format.json {
|
67
|
+
_template = render_to_string :partial => "json_templates/#{@page.template.code_name}.json.erb", :layout => false, :locals => {@page.template.code_name.to_sym => @page, :page => @page}
|
68
|
+
_js = render_to_string :partial => "js_partials/#{@page.template.code_name}.js"
|
69
|
+
|
70
|
+
render :json => @page, :template => _template.gsub(/\n/, '\\\\n'), :js => _js
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def search
|
76
|
+
if params[:all].nil?
|
77
|
+
@page = Page.first
|
78
|
+
else
|
79
|
+
@request = '/' + params[:all]
|
80
|
+
@page = Page.where(:full_url => @request).first
|
81
|
+
end
|
82
|
+
|
83
|
+
instance_variable_set('@'+@page.template.code_name.to_s, @page)
|
84
|
+
|
85
|
+
what_search = params[:what_search]
|
86
|
+
params_selection = request.query_parameters
|
87
|
+
|
88
|
+
template = Template.find_by_code_name(what_search.singularize)
|
89
|
+
|
90
|
+
if template.nil?
|
91
|
+
render :action => "error_404", :layout => false
|
92
|
+
return
|
93
|
+
end
|
94
|
+
|
95
|
+
@pages = @page.descendants.where(:template_id => template.id)
|
96
|
+
|
97
|
+
params_selection.each_pair do |code_name, value|
|
98
|
+
if value.numeric?
|
99
|
+
value = value.to_f
|
100
|
+
elsif value.boolean?
|
101
|
+
value = value.to_bool
|
102
|
+
end
|
103
|
+
|
104
|
+
@pages = @pages.select do |page|
|
105
|
+
if code_name == 'name'
|
106
|
+
page.name == value
|
107
|
+
else
|
108
|
+
page.field(code_name) == value
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
instance_variable_set('@'+template.code_name.pluralize, @pages)
|
114
|
+
|
115
|
+
@children_of_current_root = Page.children_of(@page.root)
|
116
|
+
@children_of_current_page = Page.children_of(@page)
|
117
|
+
|
118
|
+
render :template => "templates/#{template.code_name}_search"
|
119
|
+
end
|
120
|
+
|
121
|
+
def edit
|
122
|
+
@page = Page.find(params[:id])
|
123
|
+
@page.template ||= Template.first
|
124
|
+
@template = @page.template.id
|
125
|
+
|
126
|
+
@multipart = @page.template.fields.map{|f| f.type_value == "image"}.include?(true) ? true : false
|
127
|
+
end
|
128
|
+
|
129
|
+
def create
|
130
|
+
@page = Page.new params[:page]
|
131
|
+
|
132
|
+
if @page.save
|
133
|
+
redirect_to pages_url, :notice => "Страница «#{@page.name}» успешно добавлена."
|
134
|
+
else
|
135
|
+
render :action => "new"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def update
|
140
|
+
@page = Page.find params[:id]
|
141
|
+
|
142
|
+
@page.template.fields.each do |field|
|
143
|
+
f = "constructor_pages/types/#{field.type_value}_type".classify.constantize.where(
|
144
|
+
:field_id => field.id,
|
145
|
+
:page_id => @page.id).first_or_create
|
146
|
+
|
147
|
+
if params[:fields]
|
148
|
+
f.value = 0 if field.type_value == 'boolean'
|
149
|
+
|
150
|
+
if params[:fields][field.type_value]
|
151
|
+
if field.type_value == "date"
|
152
|
+
value = params[:fields][field.type_value][field.id.to_s]
|
153
|
+
f.value = Date.new(value["date(1i)"].to_i, value["date(2i)"].to_i, value["date(3i)"].to_i).to_s
|
154
|
+
else
|
155
|
+
f.value = params[:fields][field.type_value][field.id.to_s]
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
f.save
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
if @page.update_attributes params[:page]
|
164
|
+
redirect_to pages_url, :notice => "Страница «#{@page.name}» успешно обновлена."
|
165
|
+
else
|
166
|
+
render :action => "edit"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def destroy
|
171
|
+
@page = Page.find(params[:id])
|
172
|
+
title = @page.name
|
173
|
+
@page.destroy
|
174
|
+
redirect_to pages_url, :notice => "Страница «#{title}» успешно удалена."
|
175
|
+
end
|
176
|
+
|
177
|
+
def move_up
|
178
|
+
from = Page.find(params[:id])
|
179
|
+
ls = from.left_sibling
|
180
|
+
if not ls.nil? and from.move_possible?(ls)
|
181
|
+
from.move_left
|
182
|
+
end
|
183
|
+
|
184
|
+
redirect_to :back
|
185
|
+
end
|
186
|
+
|
187
|
+
def move_down
|
188
|
+
from = Page.find(params[:id])
|
189
|
+
rs = from.right_sibling
|
190
|
+
if not rs.nil? and from.move_possible?(rs)
|
191
|
+
from.move_right
|
192
|
+
end
|
193
|
+
|
194
|
+
redirect_to :back
|
195
|
+
end
|
196
|
+
|
197
|
+
private
|
198
|
+
|
199
|
+
def cache
|
200
|
+
expire_page :action => :show
|
201
|
+
cache_dir = ActionController::Base.page_cache_directory
|
202
|
+
unless cache_dir == Rails.root.to_s+"/public"
|
203
|
+
FileUtils.rm_r(Dir.glob(cache_dir+"/*")) rescue Errno::ENOENT
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ConstructorPages
|
4
|
+
class TemplatesController < ConstructorCore::AdminController
|
5
|
+
# TODO
|
6
|
+
include ConstructorCore::DeviseHelper
|
7
|
+
|
8
|
+
before_filter {@roots = Template.roots}
|
9
|
+
layout 'constructor_core/application_admin'
|
10
|
+
|
11
|
+
def new
|
12
|
+
@template = Template.new
|
13
|
+
|
14
|
+
if params[:template]
|
15
|
+
@parent = Template.find(params[:template])
|
16
|
+
@template.parent_id = @parent.id
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def edit
|
21
|
+
@template = Template.find(params[:id])
|
22
|
+
end
|
23
|
+
|
24
|
+
def create
|
25
|
+
@template = Template.new params[:template]
|
26
|
+
|
27
|
+
if @template.save
|
28
|
+
redirect_to templates_url, :notice => "Шаблон «#{@template.name}» успешно добавлен."
|
29
|
+
else
|
30
|
+
render :action => "new"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def update
|
35
|
+
@template = Template.find params[:id]
|
36
|
+
|
37
|
+
if @template.update_attributes params[:template]
|
38
|
+
redirect_to templates_url, :notice => "Шаблон «#{@template.name}» успешно обновлен."
|
39
|
+
else
|
40
|
+
render :action => "edit"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
@template = Template.find(params[:id])
|
46
|
+
name = @template.name
|
47
|
+
@template.destroy
|
48
|
+
redirect_to templates_url, :notice => "Шаблон «#{name}» успешно удален."
|
49
|
+
end
|
50
|
+
|
51
|
+
def move_up
|
52
|
+
from = Template.find(params[:id])
|
53
|
+
ls = from.left_sibling
|
54
|
+
if not ls.nil? and from.move_possible?(ls)
|
55
|
+
from.move_left
|
56
|
+
end
|
57
|
+
|
58
|
+
redirect_to :back
|
59
|
+
end
|
60
|
+
|
61
|
+
def move_down
|
62
|
+
from = Template.find(params[:id])
|
63
|
+
rs = from.right_sibling
|
64
|
+
if not rs.nil? and from.move_possible?(rs)
|
65
|
+
from.move_right
|
66
|
+
end
|
67
|
+
|
68
|
+
redirect_to :back
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ConstructorPages
|
4
|
+
module FieldsHelper
|
5
|
+
def types_value
|
6
|
+
[
|
7
|
+
["Строка", "string"],
|
8
|
+
["Целое число", "integer"],
|
9
|
+
["Дробное число", "float"],
|
10
|
+
["Булево", "boolean"],
|
11
|
+
["Дата", "date"],
|
12
|
+
["Текст", "text"],
|
13
|
+
["HTML", "html"],
|
14
|
+
["Изображение", "image"]
|
15
|
+
]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ConstructorPages
|
2
|
+
module PagesHelper
|
3
|
+
def for_select(roots)
|
4
|
+
result = []
|
5
|
+
roots.each do |r|
|
6
|
+
r.self_and_descendants.each {|i| result.push(["#{'--'*i.level} #{i.name}", i.id, {'data-full_url' => i.full_url}])}
|
7
|
+
end
|
8
|
+
result
|
9
|
+
end
|
10
|
+
|
11
|
+
def templates
|
12
|
+
Template.all.map{|t| ["#{'--'*t.level} #{t.name}", t.id]}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ConstructorPages
|
4
|
+
class Field < ActiveRecord::Base
|
5
|
+
attr_accessible :name, :code_name, :type_value, :template_id
|
6
|
+
validates_presence_of :name
|
7
|
+
|
8
|
+
validate :method_uniqueness
|
9
|
+
|
10
|
+
validates_uniqueness_of :code_name, :scope => :template_id
|
11
|
+
|
12
|
+
after_create :create_page_field
|
13
|
+
after_destroy :destroy_page_field
|
14
|
+
|
15
|
+
belongs_to :template
|
16
|
+
|
17
|
+
has_one :string_type, :class_name => "Types::StringType"
|
18
|
+
has_one :integer_type, :class_name => "Types::IntegerType"
|
19
|
+
has_one :float_type, :class_name => "Types::FloatType"
|
20
|
+
has_one :boolean_type, :class_name => "Types::BooleanType"
|
21
|
+
has_one :text_type, :class_name => "Types::TextType"
|
22
|
+
has_one :date_type, :class_name => "Types::DateType"
|
23
|
+
has_one :html_type, :class_name => "Types::HtmlType"
|
24
|
+
has_one :image_type, :class_name => "Types::ImageType"
|
25
|
+
|
26
|
+
acts_as_list :scope => :template_id
|
27
|
+
default_scope :order => :position
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def method_uniqueness
|
32
|
+
if Page.first.respond_to?(code_name.pluralize) \
|
33
|
+
or Page.first.respond_to?(code_name.singularize) \
|
34
|
+
or template.self_and_ancestors.map{|t| t.code_name}.include?(code_name.pluralize) \
|
35
|
+
or template.self_and_ancestors.map{|t| t.code_name}.include?(code_name.singularize) \
|
36
|
+
or template.descendants.map{|t| t.code_name}.include?(code_name.pluralize) \
|
37
|
+
or template.descendants.map{|t| t.code_name}.include?(code_name.singularize)
|
38
|
+
errors.add(:base, "Такой метод уже используется")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_page_field
|
43
|
+
self.template.pages.each do |page|
|
44
|
+
"constructor_pages/types/#{type_value}_type".classify.constantize.create(
|
45
|
+
:page_id => page.id,
|
46
|
+
:field_id => id
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def destroy_page_field
|
52
|
+
self.template.pages.each do |page|
|
53
|
+
"constructor_pages/types/#{type_value}_type".classify.constantize.destroy_all(
|
54
|
+
:page_id => page.id,
|
55
|
+
:field_id => id
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|