fullstack-cms 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/helpers/menus_helper.rb +10 -24
- data/app/helpers/pages_helper.rb +15 -1
- data/app/models/linkable.rb +1 -1
- data/app/models/menu.rb +4 -5
- data/app/models/page.rb +3 -9
- data/app/models/pageable.rb +77 -26
- data/app/models/uid.rb +22 -0
- data/app/views/admin/linkables/fields.js.coffee +1 -5
- data/app/views/admin/links/_associated_fields.html.erb +6 -4
- data/app/views/admin/pages/_collection.html.erb +15 -5
- data/fullstack-cms.gemspec +3 -2
- data/lib/fullstack/cms/configuration.rb +2 -1
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/app/helpers/menus_helper.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
module MenusHelper
|
2
2
|
|
3
|
-
def find_or_create_menu(uid)
|
4
|
-
|
3
|
+
def find_or_create_menu(uid, locale = nil)
|
4
|
+
if locale
|
5
|
+
Menu.find_or_create_by_uid_and_locale(uid, locale.to_s, :name => "#{uid}".gsub("-", "_").humanize)
|
6
|
+
else
|
7
|
+
Menu.find_or_create_by_uid(uid, :name => "#{uid}".gsub("-", "_").humanize)
|
8
|
+
end
|
5
9
|
end
|
6
10
|
|
7
|
-
def nav_items_for(uid)
|
8
|
-
menu = find_or_create_menu(uid)
|
11
|
+
def nav_items_for(uid, locale = nil)
|
12
|
+
menu = find_or_create_menu(uid, locale)
|
9
13
|
html = ""
|
10
14
|
|
11
15
|
menu.links.each do |link|
|
12
16
|
unless block_given?
|
13
|
-
html << nav_item(link.label, link_url(link))
|
17
|
+
html << nav_item(link.label, link_url(link), :rel => link.nofollow ? "nofollow" : nil)
|
14
18
|
else
|
15
19
|
html << yield(link)
|
16
20
|
end
|
@@ -25,25 +29,7 @@ module MenusHelper
|
|
25
29
|
|
26
30
|
|
27
31
|
def link_url(link)
|
28
|
-
url
|
29
|
-
if url.blank?
|
30
|
-
"#"
|
31
|
-
|
32
|
-
elsif url.starts_with?("content://")
|
33
|
-
klass_name, id = url.gsub("content://", "").split("#")
|
34
|
-
klass = klass_name.constantize
|
35
|
-
resource = klass.find(id)
|
36
|
-
if resource
|
37
|
-
page_path_for(resource)
|
38
|
-
else
|
39
|
-
"#"
|
40
|
-
end
|
41
|
-
|
42
|
-
else
|
43
|
-
url
|
44
|
-
|
45
|
-
end
|
46
|
-
|
32
|
+
link.url.present? ? CGI::escape(link.url) : (link.linked ? page_path_for(link.linked) : "#")
|
47
33
|
end
|
48
34
|
|
49
35
|
|
data/app/helpers/pages_helper.rb
CHANGED
@@ -23,7 +23,7 @@ module PagesHelper
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def page_path_for(resource_or_page)
|
26
|
-
page = resource_or_page.is_a?(Page) ? resource_or_page :
|
26
|
+
page = resource_or_page.is_a?(Page) ? resource_or_page : page_by_resource(resource_or_page)
|
27
27
|
path = page.try(:path)
|
28
28
|
if path.blank?
|
29
29
|
"#not-found"
|
@@ -50,4 +50,18 @@ module PagesHelper
|
|
50
50
|
request.path == "/"
|
51
51
|
end
|
52
52
|
|
53
|
+
|
54
|
+
private
|
55
|
+
def page_by_resource(resource)
|
56
|
+
resource_type = resource.class.name.underscore
|
57
|
+
|
58
|
+
if Fullstack::Cms.config.localize
|
59
|
+
locale = resource.respond_to?(:locale) ? resource.send(:locale) : I18n.locale.to_s
|
60
|
+
Page.find_by_resource_type_and_locale(resource_type, locale)
|
61
|
+
|
62
|
+
else
|
63
|
+
Page.find_by_resource_type(resource_type)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
53
67
|
end
|
data/app/models/linkable.rb
CHANGED
data/app/models/menu.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class Menu < ActiveRecord::Base
|
2
|
-
|
3
|
-
|
4
|
-
field :name, :string
|
2
|
+
include Uid
|
3
|
+
include Localized if Fullstack::Cms.config.localize
|
5
4
|
|
6
|
-
|
5
|
+
field :name, :string
|
6
|
+
|
7
7
|
has_many :links, :as => :link_owner, :dependent => :delete_all, :order=>'position ASC'
|
8
8
|
accepts_nested_attributes_for :links, :allow_destroy => true
|
9
9
|
|
@@ -11,7 +11,6 @@ class Menu < ActiveRecord::Base
|
|
11
11
|
validates_presence_of :uid
|
12
12
|
|
13
13
|
timestamps
|
14
|
-
|
15
14
|
end
|
16
15
|
|
17
16
|
|
data/app/models/page.rb
CHANGED
@@ -1,20 +1,14 @@
|
|
1
1
|
class Page < ActiveRecord::Base
|
2
2
|
include Content
|
3
3
|
include Nestable
|
4
|
+
include Localized if Fullstack::Cms.config.localize
|
5
|
+
include Uid
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
include Localized
|
8
|
-
index [:uid, :locale]
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
validates_presence_of :uid, :name
|
7
|
+
validates_presence_of :name
|
13
8
|
|
14
9
|
field :name
|
15
10
|
field :uid
|
16
11
|
field :scope
|
17
|
-
index :uid, :unique => true
|
18
12
|
|
19
13
|
field :path
|
20
14
|
field :resource_type
|
data/app/models/pageable.rb
CHANGED
@@ -48,7 +48,11 @@ module Pageable
|
|
48
48
|
module ClassMethods
|
49
49
|
def page(name, path, options = {}, &block)
|
50
50
|
|
51
|
-
|
51
|
+
# =================
|
52
|
+
# = Parse options =
|
53
|
+
# =================
|
54
|
+
|
55
|
+
localize = options.delete(:localize) == false ? false : Fullstack::Cms.config.localize
|
52
56
|
|
53
57
|
this_controller_name = "#{self.name.underscore}".gsub("_controller", "")
|
54
58
|
uid = "#{this_controller_name}##{name}"
|
@@ -66,37 +70,32 @@ module Pageable
|
|
66
70
|
i18n_scope = "pages.#{self.name.underscore.split('/').last}##{name}"
|
67
71
|
title = options.delete(:title) || I18n.t("#{i18n_scope}.title", :default => "#{name}".humanize)
|
68
72
|
|
73
|
+
# ======================
|
74
|
+
# = Create page record =
|
75
|
+
# ======================
|
76
|
+
|
69
77
|
if Page.table_exists?
|
70
|
-
|
71
|
-
|
72
|
-
|
78
|
+
if localize
|
79
|
+
I18n.available_locales.each do |locale|
|
80
|
+
_page!(uid, _localize_path(path, locale), name, title, parent_uid, resource_type, locale.to_s)
|
81
|
+
end
|
73
82
|
else
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
if parent_uid
|
78
|
-
parent = unless Fullstack::Cms.config.localize_pages
|
79
|
-
Page.find_by_uid(parent_uid)
|
80
|
-
else
|
81
|
-
Page.find_by_uid_and_locale(parent_uid, I18n.locale || Fullstack::Cms.config.default_locale)
|
82
|
-
end
|
83
|
-
|
84
|
-
page.move_to_child_of(parent) unless page.parent == parent
|
85
|
-
end
|
86
|
-
|
87
|
-
if resource_type
|
88
|
-
page.update_attribute(:resource_type, resource_type) unless page.resource_type == resource_type
|
83
|
+
_page!(uid, path, name, title, parent_uid, resource_type)
|
89
84
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
85
|
+
end
|
86
|
+
|
87
|
+
# ===================
|
88
|
+
# = Map page routes =
|
89
|
+
# ===================
|
90
|
+
|
91
|
+
if localize
|
92
|
+
I18n.available_locales.each do |locale|
|
93
|
+
map(name, _localize_path(path, locale), options.reverse_merge({:locale => locale.to_s, :as => "#{name}_#{locale}"}), &block)
|
93
94
|
end
|
94
|
-
|
95
|
+
else
|
96
|
+
map(name, path, options, &block)
|
95
97
|
end
|
96
98
|
|
97
|
-
map(name, path, options = {}, &block)
|
98
|
-
@pages ||= ActiveSupport::HashWithIndifferentAccess.new
|
99
|
-
@pages[name] = page
|
100
99
|
end
|
101
100
|
|
102
101
|
def page_names
|
@@ -107,6 +106,58 @@ module Pageable
|
|
107
106
|
@pages ||= ActiveSupport::HashWithIndifferentAccess.new
|
108
107
|
end
|
109
108
|
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def _localize_path(path, locale)
|
113
|
+
path_segments = path.split("/")
|
114
|
+
|
115
|
+
path_segments.reject!(&:blank?)
|
116
|
+
path_segments.map! {|s|
|
117
|
+
if s =~ /^:/
|
118
|
+
s
|
119
|
+
else
|
120
|
+
I18n.t(s, :scope => "routing", :default => s, :locale => locale)
|
121
|
+
end
|
122
|
+
}
|
123
|
+
|
124
|
+
path_segments.unshift(locale.to_s)
|
125
|
+
"/" + path_segments.join("/")
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
def _page!(uid, path, name, title, parent_uid, resource_type, locale = nil)
|
130
|
+
# puts "_page!(#{[uid, path, name, title, parent_uid, resource_type, locale].map(&:inspect).join(",")})"
|
131
|
+
|
132
|
+
_page = if locale.nil?
|
133
|
+
Page.find_or_create_by_uid(uid, :title => title, :name => name)
|
134
|
+
else
|
135
|
+
Page.find_or_create_by_uid_and_locale(uid, locale.to_s, :title => title, :name => name)
|
136
|
+
end
|
137
|
+
|
138
|
+
if parent_uid
|
139
|
+
parent = if locale.nil?
|
140
|
+
Page.find_by_uid(parent_uid)
|
141
|
+
else
|
142
|
+
Page.find_by_uid_and_locale(parent_uid, locale.to_s)
|
143
|
+
end
|
144
|
+
|
145
|
+
_page.move_to_child_of(parent) unless _page.parent == parent
|
146
|
+
end
|
147
|
+
|
148
|
+
if resource_type
|
149
|
+
_page.update_attribute(:resource_type, resource_type) unless _page.resource_type == resource_type
|
150
|
+
end
|
151
|
+
|
152
|
+
if _page.path != path
|
153
|
+
_page.update_attribute(:path, path)
|
154
|
+
end
|
155
|
+
|
156
|
+
@pages ||= ActiveSupport::HashWithIndifferentAccess.new
|
157
|
+
@pages[name] = _page
|
158
|
+
|
159
|
+
end
|
160
|
+
|
110
161
|
end
|
111
162
|
|
112
163
|
def load_current_page
|
data/app/models/uid.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Uid
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
|
6
|
+
field :uid, :string
|
7
|
+
validates_presence_of :uid
|
8
|
+
|
9
|
+
unless Fullstack::Cms.config.localize
|
10
|
+
|
11
|
+
index :uid, :unique => true
|
12
|
+
scope :uid, lambda {|uid| where(:uid => uid).first}
|
13
|
+
|
14
|
+
else
|
15
|
+
|
16
|
+
index [:uid, :locale], :unique => true
|
17
|
+
scope :uid, lambda {|uid| where(:uid => uid, :locale => (I18n.locale || Fullstack::Cms::config.default_locale).to_s).first}
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -6,8 +6,4 @@ $("#<%= @target %>").find("select[data-remote]").each ->
|
|
6
6
|
data
|
7
7
|
<% else %>
|
8
8
|
$("select:not([data-remote]):not(.datetime-selector)").chosen()
|
9
|
-
<% end %>
|
10
|
-
|
11
|
-
# localize messages and labels
|
12
|
-
# get rid of the black screen after window closing
|
13
|
-
# double add problem
|
9
|
+
<% end %>
|
@@ -22,7 +22,7 @@
|
|
22
22
|
<div class="linked-id-field-placeholder" id="linked_id_field_placeholder_<%= @linked_id_field_placeholder_uid = 1 + (@linked_id_field_placeholder_uid || 0)
|
23
23
|
%>" data-current-id="<%= f.object.linked_id %>" data-current-type="<%= f.object.linked_type %>">
|
24
24
|
</div>
|
25
|
-
<%= f.input :url, :label => false, :input_html => {:style => "display: none", :class => "linked-url-field"} %>
|
25
|
+
<%= f.input :url, :label => false, :input_html => {:style => ("display: none" if f.object.persisted?), :class => "linked-url-field"} %>
|
26
26
|
<% end %>
|
27
27
|
|
28
28
|
|
@@ -65,9 +65,11 @@
|
|
65
65
|
$(".linked-fields").each ->
|
66
66
|
linked_fields = $(@)
|
67
67
|
update_linked_fields(linked_fields)
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
|
69
|
+
$(".linked-type-field").live "change", ->
|
70
|
+
update_linked_fields($(@).closest(".linked-fields"))
|
71
|
+
|
72
|
+
|
71
73
|
<% end %>
|
72
74
|
<% end %>
|
73
75
|
<% end -%>
|
@@ -1,7 +1,17 @@
|
|
1
|
-
|
2
|
-
<%
|
3
|
-
|
4
|
-
|
1
|
+
<%= tabs do |t| %>
|
2
|
+
<% I18n.available_locales.each do |locale| %>
|
3
|
+
<%= t.pane t("locale_names.#{locale}", :default => "#{locale}".humanize) do %>
|
4
|
+
|
5
|
+
|
6
|
+
<ul class="nav">
|
7
|
+
<% Page.where(:locale => "#{locale}").roots.each do |root| %>
|
8
|
+
<% Page.each_with_level(root.self_and_descendants) do |page, level| %>
|
9
|
+
<%= nav_item page.name, edit_admin_page_path(page), :icon => (page.root? ? "home" : "file"), :style => "line-height: 36px; padding-left:#{20 * level}px" %>
|
10
|
+
<% end %>
|
11
|
+
<% end %>
|
12
|
+
</ul>
|
13
|
+
|
14
|
+
|
15
|
+
<% end %>
|
5
16
|
<% end %>
|
6
17
|
<% end %>
|
7
|
-
</ul>
|
data/fullstack-cms.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "fullstack-cms"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["mcasimir"]
|
12
|
-
s.date = "2012-09-
|
12
|
+
s.date = "2012-09-03"
|
13
13
|
s.description = "CMS system built on fullstack"
|
14
14
|
s.email = "maurizio.cas@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -51,6 +51,7 @@ Gem::Specification.new do |s|
|
|
51
51
|
"app/models/text.rb",
|
52
52
|
"app/models/text_page_part.rb",
|
53
53
|
"app/models/text_with_title_page_part.rb",
|
54
|
+
"app/models/uid.rb",
|
54
55
|
"app/views/admin/base/_fields.html.erb",
|
55
56
|
"app/views/admin/base/_form.html.erb",
|
56
57
|
"app/views/admin/base/_simple_form.html.erb",
|
@@ -7,7 +7,8 @@ module Fullstack
|
|
7
7
|
@config ||= OpenStruct.new
|
8
8
|
@config.resources ||= []
|
9
9
|
@config.linkables ||= []
|
10
|
-
@config.
|
10
|
+
@config.localize = @config.localize.nil? ? true : @config.localize
|
11
|
+
@config.localize_routes = @config.localize_routes.nil? ? true : @config.localize_routes
|
11
12
|
@config.default_locale ||= "#{I18n.default_locale}" || "en"
|
12
13
|
@config
|
13
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fullstack-cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fullstack-admin
|
@@ -245,6 +245,7 @@ files:
|
|
245
245
|
- app/models/text.rb
|
246
246
|
- app/models/text_page_part.rb
|
247
247
|
- app/models/text_with_title_page_part.rb
|
248
|
+
- app/models/uid.rb
|
248
249
|
- app/views/admin/base/_fields.html.erb
|
249
250
|
- app/views/admin/base/_form.html.erb
|
250
251
|
- app/views/admin/base/_simple_form.html.erb
|
@@ -329,7 +330,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
329
330
|
version: '0'
|
330
331
|
segments:
|
331
332
|
- 0
|
332
|
-
hash:
|
333
|
+
hash: 293567694538273846
|
333
334
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
334
335
|
none: false
|
335
336
|
requirements:
|