etabliocms_pages 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/etabliocms_pages/admin/pages_controller.rb +5 -3
- data/app/models/etabliocms_pages/content.rb +14 -0
- data/app/models/etabliocms_pages/page.rb +34 -6
- data/app/views/etabliocms_pages/admin/pages/_content_fields.html.erb +30 -0
- data/app/views/etabliocms_pages/admin/pages/_form.html.erb +29 -23
- data/app/views/etabliocms_pages/admin/pages/edit.html.erb +1 -1
- data/app/views/etabliocms_pages/admin/pages/new.html.erb +1 -1
- data/config/locales/pages.cs.yml +17 -1
- data/db/migrate/{20120223140555_create_pages.etabliocms_core_engine.rb → 20120223140555_create_pages.etabliocms_pages_engine.rb} +0 -0
- data/db/migrate/20120301175455_create_contents.etabliocms_pages_engine.rb +26 -0
- data/lib/etabliocms_pages.rb +7 -0
- data/lib/etabliocms_pages/engine.rb +8 -0
- data/lib/etabliocms_pages/version.rb +1 -1
- metadata +14 -11
@@ -3,15 +3,17 @@ module EtabliocmsPages
|
|
3
3
|
class PagesController < EtabliocmsCore::Admin::BaseController
|
4
4
|
|
5
5
|
def new
|
6
|
-
@page = Page.new
|
6
|
+
@page = EtabliocmsPages::Page.new
|
7
|
+
@page.build_contents_for_available_locales
|
7
8
|
end
|
8
9
|
|
9
10
|
def create
|
10
|
-
@page = Page.new(params[:
|
11
|
+
@page = Page.new(params[:etabliocms_pages_page])
|
11
12
|
if @page.save
|
12
13
|
flash[:notice] = t('page.created')
|
13
14
|
redirect_to :action => 'index'
|
14
15
|
else
|
16
|
+
@page.build_contents_for_available_locales
|
15
17
|
render :action => 'new'
|
16
18
|
end
|
17
19
|
end
|
@@ -22,7 +24,7 @@ module EtabliocmsPages
|
|
22
24
|
|
23
25
|
def update
|
24
26
|
@page = Page.find(params[:id])
|
25
|
-
if @page.update_attributes(params[:
|
27
|
+
if @page.update_attributes(params[:etabliocms_pages_page])
|
26
28
|
flash[:notice] = t('page.updated')
|
27
29
|
redirect_to :action => 'index'
|
28
30
|
else
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module EtabliocmsPages
|
2
|
+
class Content < ActiveRecord::Base
|
3
|
+
|
4
|
+
validates :title, :presence => true
|
5
|
+
validates :locale, :presence => true
|
6
|
+
|
7
|
+
belongs_to :page, :inverse_of => :contents
|
8
|
+
|
9
|
+
serialize :areas, Hash
|
10
|
+
|
11
|
+
has_slug :to_param => "path"
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -1,26 +1,48 @@
|
|
1
1
|
module EtabliocmsPages
|
2
2
|
class Page < ActiveRecord::Base
|
3
3
|
|
4
|
+
delegate :title, :areas, :slug, :to => :content, :allow_nil => true
|
5
|
+
def content
|
6
|
+
contents.where(:locale => I18n.locale).first
|
7
|
+
end
|
8
|
+
|
4
9
|
acts_as_nested_set
|
5
10
|
attr_accessor :child_of
|
6
11
|
after_save :update_position
|
7
12
|
|
8
|
-
|
9
|
-
|
13
|
+
has_many :contents, :class_name => "EtabliocmsPages::Content", :inverse_of => :page, :order => "locale asc", :dependent => :destroy
|
14
|
+
accepts_nested_attributes_for :contents, :reject_if => proc { |attributes| attributes['title'].blank? }
|
10
15
|
|
11
|
-
|
16
|
+
validate :at_least_one_content_has_title
|
12
17
|
|
13
18
|
def path
|
14
|
-
self_and_ancestors.map
|
19
|
+
self_and_ancestors.map{|p| p.slug }.join("/")
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_param
|
23
|
+
path
|
24
|
+
end
|
25
|
+
|
26
|
+
def titles
|
27
|
+
contents.map(&:title).join(" / ")
|
28
|
+
end
|
29
|
+
|
30
|
+
def locales
|
31
|
+
contents.map(&:locale).join(", ")
|
15
32
|
end
|
16
33
|
|
17
34
|
def other_pages_for_select
|
18
35
|
pages = EtabliocmsPages::Page.order("lft ASC")
|
19
36
|
pages = pages.where("id != ?", id) unless new_record?
|
20
|
-
pages.map { |d| [d.
|
37
|
+
pages.map { |d| [d.titles, d.id] }
|
38
|
+
end
|
39
|
+
|
40
|
+
def build_contents_for_available_locales
|
41
|
+
I18n.available_locales.each do |available_locale|
|
42
|
+
contents.build(:locale => available_locale) unless contents.detect { |c| c.locale == available_locale.to_s }
|
43
|
+
end
|
21
44
|
end
|
22
45
|
|
23
|
-
scope :for_locale, lambda { |locale| where(:locale => locale) }
|
24
46
|
scope :visible, where(:visible => true)
|
25
47
|
|
26
48
|
private
|
@@ -38,6 +60,12 @@ module EtabliocmsPages
|
|
38
60
|
self.child_of = nil
|
39
61
|
end
|
40
62
|
|
63
|
+
def at_least_one_content_has_title
|
64
|
+
if contents.select { |c| c.title.present? }.blank?
|
65
|
+
errors[:base] << I18n.t('activerecord.errors.messages.at_least_one_content_has_title')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
41
69
|
end
|
42
70
|
|
43
71
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<% content = f.object %>
|
2
|
+
<div class="fields" id="tabs-<%= content.object_id %>">
|
3
|
+
|
4
|
+
<%= render "layouts/errors", :target => content %>
|
5
|
+
|
6
|
+
<%= f.hidden_field :locale, :value => content.locale %>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<%= f.label :title %>
|
10
|
+
<%= f.text_field :title, :class => 'text-field' %>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<% EtabliocmsPages.areas.each do |area| %>
|
14
|
+
<p>
|
15
|
+
<%= label_tag "#{content.object_id}_#{area}", t("helpers.label.etabliocms_pages_page.contents.#{area}") %>
|
16
|
+
<%= f.textile_text_area "areas[#{area}]",
|
17
|
+
:id => "#{content.object_id}_#{area}",
|
18
|
+
:value => content.areas[area].to_s, :width => 460, :height => 200 %>
|
19
|
+
</p>
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<% if !@page.new_record? && respond_to?(:page_path) %>
|
23
|
+
<p>
|
24
|
+
<% I18n.locale = content.locale %>
|
25
|
+
<strong>Náhled: </strong>
|
26
|
+
<%= link_to @page.title, page_path(@page), :"data-popup" => "true" %>
|
27
|
+
</p>
|
28
|
+
<% end %>
|
29
|
+
|
30
|
+
</div>
|
@@ -1,48 +1,54 @@
|
|
1
1
|
<%= render "layouts/errors", :target => @page %>
|
2
2
|
|
3
3
|
<fieldset>
|
4
|
-
<legend><%= t('page.
|
5
|
-
|
6
|
-
<p>
|
7
|
-
<%= f.label :title, :id => "page_title_label" %>
|
8
|
-
<%= f.text_field :title, :class => 'text-field' %>
|
9
|
-
</p>
|
4
|
+
<legend><%= t('page.admin_legend_basic') %></legend>
|
10
5
|
|
11
6
|
<p>
|
12
7
|
<%= f.label :child_of, :id => "page_child_of_label" %>
|
13
8
|
<%= f.select :child_of, [[t('hierarchy.top_level'), nil]] + @page.other_pages_for_select,
|
14
|
-
:selected => @page.parent ? [@page.parent.
|
15
|
-
</p>
|
16
|
-
|
17
|
-
<p>
|
18
|
-
<%= f.label :locale, :id => "page_locale_label" %>
|
19
|
-
<%= f.select :locale, [[t('admin.locale.cs'), 'cs'], [t('admin.locale.en'), 'en']] %>
|
9
|
+
:selected => @page.parent ? [@page.parent.titles, @page.parent_id] : nil %>
|
20
10
|
</p>
|
21
11
|
|
22
|
-
|
23
12
|
<p>
|
24
13
|
<%= f.label :visible, :id => "page_visible_label" %>
|
25
14
|
<%= f.boolean_yes_no_select :visible %>
|
26
15
|
</p>
|
27
16
|
|
28
|
-
<p>
|
29
|
-
<%= f.textile_text_area :text, :width => 560, :height => 200 %>
|
30
|
-
</p>
|
31
|
-
|
32
17
|
<p>
|
33
18
|
<%= f.label :url, :id => "page_url_label" %>
|
34
19
|
<%= f.text_field :url, :class => 'text-field' %>
|
35
20
|
</p>
|
36
21
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
22
|
+
</fieldset>
|
23
|
+
|
24
|
+
<fieldset>
|
25
|
+
<legend><%= t('page.admin_legend_contents') %></legend>
|
26
|
+
|
27
|
+
<div id="contents">
|
28
|
+
<ul>
|
29
|
+
<%@page.contents.sort_by{|a| a.locale.to_s }.each do |content| %>
|
30
|
+
<li><a href="#tabs-<%= content.object_id %>"><%= t("admin.locales.#{content.locale}") %></a></li>
|
31
|
+
<% end %>
|
32
|
+
</ul>
|
33
|
+
|
34
|
+
<%= f.fields_for :contents do |builder| %>
|
35
|
+
<%= render "content_fields", :f => builder %>
|
36
|
+
<% end %>
|
37
|
+
</div>
|
43
38
|
|
39
|
+
</fieldset>
|
40
|
+
|
41
|
+
<fieldset>
|
42
|
+
|
43
|
+
<% I18n.locale = I18n.default_locale %>
|
44
44
|
<p>
|
45
45
|
<%= submit_tag t('admin.save'), :class => 'submit' %>
|
46
46
|
</p>
|
47
47
|
|
48
48
|
</fieldset>
|
49
|
+
|
50
|
+
<script>
|
51
|
+
$(function() {
|
52
|
+
$("#contents").tabs();
|
53
|
+
});
|
54
|
+
</script>
|
@@ -2,6 +2,6 @@
|
|
2
2
|
|
3
3
|
<h1><%= @page.title %></h1>
|
4
4
|
|
5
|
-
<%= form_for
|
5
|
+
<%= form_for @page, :url => admin_page_path(@page.id), :html => {:method => :put, :id => "admin-form"} do |f| -%>
|
6
6
|
<%= render :partial => 'form', :locals => { :f => f } %>
|
7
7
|
<% end %>
|
@@ -2,6 +2,6 @@
|
|
2
2
|
|
3
3
|
<h1><%= t('page.new') %></h1>
|
4
4
|
|
5
|
-
<%= form_for
|
5
|
+
<%= form_for @page, :url => admin_pages_url, :html => {:method => :post, :id => "admin-form"} do |f| -%>
|
6
6
|
<%= render :partial => 'form', :locals => { :f => f } %>
|
7
7
|
<% end %>
|
data/config/locales/pages.cs.yml
CHANGED
@@ -9,10 +9,26 @@ cs:
|
|
9
9
|
moved: Stránka byla úspěšně přesunuta.
|
10
10
|
not_moved: Stránka nebyla přesunuta.
|
11
11
|
destroy_confirmation: Skutečně chcete smazat tuto stránku?
|
12
|
-
|
12
|
+
admin_legend_basic: Základní údaje o stránce
|
13
|
+
admin_legend_contents: Obsah stránky
|
13
14
|
edit: "Editace stránky %{title}"
|
14
15
|
new: Nová stránka
|
16
|
+
helpers:
|
17
|
+
label:
|
18
|
+
etabliocms_pages_page:
|
19
|
+
child_of: Rodič
|
20
|
+
text: Text
|
21
|
+
visible: Viditelné
|
22
|
+
page_title: Meta title
|
23
|
+
page_description: Meta description
|
24
|
+
contents:
|
25
|
+
title: Nadpis
|
26
|
+
locale: Jazyk
|
27
|
+
text: Text
|
15
28
|
activerecord:
|
29
|
+
errors:
|
30
|
+
messages:
|
31
|
+
at_least_one_content_has_title: Alespoň jedna jazyková mutace musí mít nadpis.
|
16
32
|
attributes:
|
17
33
|
"etabliocms_pages/page":
|
18
34
|
title: Nadpis
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class CreateContents < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def change
|
4
|
+
create_table :contents do |t|
|
5
|
+
t.string :title, :null => false
|
6
|
+
t.string :slug, :null => false
|
7
|
+
|
8
|
+
t.text :areas
|
9
|
+
t.string :locale, :null => false
|
10
|
+
t.integer :page_id, :null => false
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
EtabliocmsPages::Page.all.each do |page|
|
15
|
+
page.contents.create(:title => page.title,
|
16
|
+
:slug => page.slug,
|
17
|
+
:locale => page.locale,
|
18
|
+
:areas => {:text => page.text})
|
19
|
+
end
|
20
|
+
remove_column :pages, :title
|
21
|
+
remove_column :pages, :slug
|
22
|
+
remove_column :pages, :locale
|
23
|
+
remove_column :pages, :text
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/lib/etabliocms_pages.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'awesome_nested_set'
|
2
|
+
|
1
3
|
module EtabliocmsPages
|
2
4
|
|
3
5
|
class Engine < ::Rails::Engine
|
@@ -9,6 +11,12 @@ module EtabliocmsPages
|
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
14
|
+
initializer "etabliocms_pages.initialize" do |app|
|
15
|
+
EtabliocmsPages.setup do |config|
|
16
|
+
config.areas ||= [:text]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
12
20
|
end
|
13
21
|
|
14
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etabliocms_pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &8748920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.2.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *8748920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: etabliocms_core
|
27
|
-
requirement: &
|
27
|
+
requirement: &8748500 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *8748500
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: awesome_nested_set
|
38
|
-
requirement: &
|
38
|
+
requirement: &8747940 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - =
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.1.2
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *8747940
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3
|
49
|
-
requirement: &
|
49
|
+
requirement: &8747440 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *8747440
|
58
58
|
description: Small CMS - module for pages
|
59
59
|
email:
|
60
60
|
- patrikjira@gmail.com
|
@@ -64,15 +64,18 @@ extra_rdoc_files: []
|
|
64
64
|
files:
|
65
65
|
- app/views/layouts/_sidebar_pages.html.erb
|
66
66
|
- app/views/etabliocms_pages/admin/pages/_form.html.erb
|
67
|
+
- app/views/etabliocms_pages/admin/pages/_content_fields.html.erb
|
67
68
|
- app/views/etabliocms_pages/admin/pages/new.html.erb
|
68
69
|
- app/views/etabliocms_pages/admin/pages/edit.html.erb
|
69
70
|
- app/views/etabliocms_pages/admin/pages/index.html.erb
|
70
71
|
- app/assets/images/admin/sidebar-pages.png
|
71
72
|
- app/controllers/etabliocms_pages/admin/pages_controller.rb
|
73
|
+
- app/models/etabliocms_pages/content.rb
|
72
74
|
- app/models/etabliocms_pages/page.rb
|
73
75
|
- config/routes.rb
|
74
76
|
- config/locales/pages.cs.yml
|
75
|
-
- db/migrate/20120223140555_create_pages.
|
77
|
+
- db/migrate/20120223140555_create_pages.etabliocms_pages_engine.rb
|
78
|
+
- db/migrate/20120301175455_create_contents.etabliocms_pages_engine.rb
|
76
79
|
- lib/etabliocms_pages/version.rb
|
77
80
|
- lib/etabliocms_pages/engine.rb
|
78
81
|
- lib/etabliocms_pages.rb
|