simple-pages-rails 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/simple_pages/pages.js.coffee +14 -0
- data/app/controllers/simple_pages/application_controller.rb +9 -0
- data/app/controllers/simple_pages/pages_controller.rb +1 -7
- data/app/models/simple_pages/page.rb +8 -0
- data/app/views/simple_pages/pages/_form.html.erb +29 -4
- data/app/views/simple_pages/pages/edit.html.erb +6 -1
- data/app/views/simple_pages/pages/new.html.erb +6 -1
- data/config/locales/pages.en.yml +2 -1
- data/config/locales/pages.zh-TW.yml +2 -1
- data/config/locales/simple_pages.en.yml +4 -3
- data/config/locales/simple_pages.zh-TW.yml +1 -0
- data/db/migrate/20130318034034_add_cluster_to_simple_pages.rb +5 -0
- data/lib/simple-pages-rails/version.rb +1 -1
- data/lib/simple_pages.rb +4 -0
- data/lib/simple_pages/controllers/page_cluster.rb +27 -0
- data/lib/simple_pages/controllers/page_layout_at.rb +2 -2
- data/lib/simple_pages/models/page_cluster.rb +32 -0
- data/lib/simple_pages/models/page_url.rb +2 -8
- metadata +7 -4
@@ -2,3 +2,17 @@ $ ->
|
|
2
2
|
$('.pages .chzn-select').chosen
|
3
3
|
allow_single_deselect: true
|
4
4
|
no_results_text: 'No results matched'
|
5
|
+
|
6
|
+
$('.pages')
|
7
|
+
.on 'focusout', '#page_url', ->
|
8
|
+
if $(this).val().length > 0
|
9
|
+
if ! /^([\w\-]{3,})$/.test($(this).val())
|
10
|
+
alert('Invalid URL!')
|
11
|
+
$(this).val('')
|
12
|
+
.on 'submit', '.simple_form', (event) ->
|
13
|
+
url = $('#page_url')
|
14
|
+
if url.val().length > 0
|
15
|
+
if ! /^([\w\-]{3,})$/.test(url.val())
|
16
|
+
alert('Invalid URL!')
|
17
|
+
url.val('')
|
18
|
+
return false
|
@@ -10,5 +10,14 @@ module SimplePages
|
|
10
10
|
if SimplePages.extra_page_layout.present?
|
11
11
|
has_page_layout_at SimplePages.extra_page_layout
|
12
12
|
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def load_author_options
|
17
|
+
load_authors
|
18
|
+
@author_options = @authors.map do |author|
|
19
|
+
[author.name, author.simple_page_owner_option]
|
20
|
+
end
|
21
|
+
end
|
13
22
|
end
|
14
23
|
end
|
@@ -59,17 +59,11 @@ module SimplePages
|
|
59
59
|
def load_page_options
|
60
60
|
load_author_options
|
61
61
|
load_page_layout_at_options
|
62
|
+
load_page_cluster_options
|
62
63
|
end
|
63
64
|
|
64
65
|
private
|
65
66
|
|
66
|
-
def load_author_options
|
67
|
-
load_authors
|
68
|
-
@author_options = @authors.map do |author|
|
69
|
-
[author.name, author.simple_page_owner_option]
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
67
|
def pagination_options
|
74
68
|
{ page: params[:page], per_page: SimplePages.pages_per_page }
|
75
69
|
end
|
@@ -9,6 +9,14 @@ module SimplePages
|
|
9
9
|
scope :published, lambda { where('published_at <= ?', Time.zone.now) }
|
10
10
|
scope :layout_at, lambda { |location| where(layout_at: location) }
|
11
11
|
|
12
|
+
def layout_at=(values)
|
13
|
+
if values.blank?
|
14
|
+
super nil
|
15
|
+
else
|
16
|
+
super values
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
12
20
|
SimplePages.page_modules.each { |module_name| include module_name }
|
13
21
|
end
|
14
22
|
end
|
@@ -3,9 +3,34 @@
|
|
3
3
|
<%= f.input :url, input_html: { class: 'span10' } %>
|
4
4
|
<% end %>
|
5
5
|
<%= f.input :title, input_html: { class: 'span10' } %>
|
6
|
-
<%= f.input :excerpt,
|
6
|
+
<%= f.input :excerpt,
|
7
|
+
as: :text,
|
8
|
+
input_html: {
|
9
|
+
rows: 5,
|
10
|
+
class: 'span10'
|
11
|
+
} %>
|
7
12
|
<%= f.input :content, input_html: { class: 'ckeditor' } %>
|
8
|
-
<%= f.input :owner,
|
9
|
-
|
10
|
-
|
13
|
+
<%= f.input :owner,
|
14
|
+
collection: author_options,
|
15
|
+
selected: selected_page_author(f.object),
|
16
|
+
input_html: {
|
17
|
+
class: 'chzn-select'
|
18
|
+
} %>
|
19
|
+
<%= f.input :published_at,
|
20
|
+
as: :string,
|
21
|
+
input_html: {
|
22
|
+
value: local_published_at(f.object),
|
23
|
+
class: 'datetimepicker'
|
24
|
+
} %>
|
25
|
+
<%= f.input :layout_at,
|
26
|
+
as: :select,
|
27
|
+
collection: layout_at_options,
|
28
|
+
include_blank: false %>
|
29
|
+
<%= f.input :cluster,
|
30
|
+
as: :select,
|
31
|
+
collection: cluster_options,
|
32
|
+
input_html: {
|
33
|
+
multiple: true,
|
34
|
+
class: 'chzn-select'
|
35
|
+
} %>
|
11
36
|
</div>
|
@@ -15,7 +15,12 @@
|
|
15
15
|
<div>
|
16
16
|
<%= simple_form_for @page, as: :page, html: { class: 'form-horizontal' } do |f| %>
|
17
17
|
<%= f.error_notification %>
|
18
|
-
<%= render 'form',
|
18
|
+
<%= render 'form', {
|
19
|
+
f: f,
|
20
|
+
cluster_options: @cluster_options,
|
21
|
+
layout_at_options: @layout_at_options,
|
22
|
+
author_options: @author_options
|
23
|
+
} %>
|
19
24
|
<div class="form-actions">
|
20
25
|
<%= submit_button f %>
|
21
26
|
</div>
|
@@ -12,7 +12,12 @@
|
|
12
12
|
<div>
|
13
13
|
<%= simple_form_for @page, as: :page, html: { class: 'form-horizontal' } do |f| %>
|
14
14
|
<%= f.error_notification %>
|
15
|
-
<%= render 'form',
|
15
|
+
<%= render 'form', {
|
16
|
+
f: f,
|
17
|
+
cluster_options: @cluster_options,
|
18
|
+
layout_at_options: @layout_at_options,
|
19
|
+
author_options: @author_options
|
20
|
+
} %>
|
16
21
|
<div class="form-actions">
|
17
22
|
<%= submit_button f %>
|
18
23
|
</div>
|
data/config/locales/pages.en.yml
CHANGED
@@ -22,6 +22,7 @@ en:
|
|
22
22
|
content: 'Content'
|
23
23
|
author: 'Author'
|
24
24
|
layout_at: 'Layout at'
|
25
|
+
cluster: 'Cluster'
|
25
26
|
published_at: 'Published at'
|
26
27
|
owner: 'Author'
|
27
28
|
|
@@ -30,7 +31,7 @@ en:
|
|
30
31
|
page:
|
31
32
|
hints:
|
32
33
|
page:
|
33
|
-
url: 'Only characters(a-zA-Z), numbers(0-9),
|
34
|
+
url: 'At least 3 characters. Only characters(a-zA-Z), numbers(0-9), underline(_) and hyphen(-) are allowed.<bt>It will be given if left blank.'
|
34
35
|
published_at: 'It will not show up if blank.'
|
35
36
|
placeholders:
|
36
37
|
page:
|
@@ -22,6 +22,7 @@ zh-TW:
|
|
22
22
|
content: '內容'
|
23
23
|
author: '作者'
|
24
24
|
layout_at: '呈現於'
|
25
|
+
cluster: '群組'
|
25
26
|
published_at: '發布於'
|
26
27
|
owner: '作者'
|
27
28
|
|
@@ -30,7 +31,7 @@ zh-TW:
|
|
30
31
|
page:
|
31
32
|
hints:
|
32
33
|
page:
|
33
|
-
url: '
|
34
|
+
url: '至少三個字元,僅限使用英文字母( a-zA-Z )、數字( 0-9 )、底線( _ )與破折號( - )。<br>若不輸入,則由系統自行賦予。'
|
34
35
|
published_at: '若沒有設定時間,則不會顯示在網站中。'
|
35
36
|
placeholders:
|
36
37
|
page:
|
data/lib/simple_pages.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'simple_pages/engine'
|
2
|
+
require 'simple_pages/controllers/page_cluster'
|
2
3
|
require 'simple_pages/controllers/page_layout_at'
|
3
4
|
require 'simple_pages/models/page_attachment'
|
4
5
|
require 'simple_pages/models/page_author'
|
6
|
+
require 'simple_pages/models/page_cluster'
|
5
7
|
require 'simple_pages/models/page_locale'
|
6
8
|
require 'simple_pages/models/page_owner'
|
7
9
|
require 'simple_pages/models/page_url'
|
@@ -9,6 +11,7 @@ require 'simple_pages/models/page_url'
|
|
9
11
|
module SimplePages
|
10
12
|
mattr_accessor :controller_modules
|
11
13
|
@@controller_modules = [
|
14
|
+
SimplePages::Controllers::PageCluster,
|
12
15
|
SimplePages::Controllers::PageLayoutAt
|
13
16
|
]
|
14
17
|
|
@@ -26,6 +29,7 @@ module SimplePages
|
|
26
29
|
SimplePages::Models::PageUrl,
|
27
30
|
SimplePages::Models::PageOwner,
|
28
31
|
SimplePages::Models::PageLocale,
|
32
|
+
SimplePages::Models::PageCluster,
|
29
33
|
SimplePages::Models::PageAttachment
|
30
34
|
]
|
31
35
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module SimplePages
|
4
|
+
module Controllers
|
5
|
+
module PageCluster
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
included do
|
8
|
+
helper_method :pages_cluster_for
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def pages_cluster_for(name, location)
|
17
|
+
SimplePages::Page.with_cluster(name).layout_at(location).published
|
18
|
+
end
|
19
|
+
|
20
|
+
def load_page_cluster_options
|
21
|
+
@cluster_options = ::Role.all.map do |role|
|
22
|
+
[t(role.name, scope: 'roles.names'), role.name]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -6,7 +6,7 @@ module SimplePages
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
included do
|
8
8
|
cattr_accessor :page_layout_at
|
9
|
-
self.page_layout_at = %w{header footer}
|
9
|
+
self.page_layout_at = %w{general header footer}
|
10
10
|
|
11
11
|
helper_method :pages_layout_at
|
12
12
|
end
|
@@ -21,7 +21,7 @@ module SimplePages
|
|
21
21
|
protected
|
22
22
|
|
23
23
|
def pages_layout_at(location)
|
24
|
-
SimplePages::Page.layout_at(location).published
|
24
|
+
SimplePages::Page.without_cluster.layout_at(location).published
|
25
25
|
end
|
26
26
|
|
27
27
|
def load_page_layout_at_options
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module SimplePages
|
4
|
+
module Models
|
5
|
+
module PageCluster
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
included do
|
8
|
+
serialize :cluster
|
9
|
+
attr_accessible :cluster
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def without_cluster
|
14
|
+
where(cluster: "--- \n...\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
def with_cluster(name)
|
18
|
+
where('cluster LIKE ?', "%#{name}%")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def cluster=(values)
|
23
|
+
values = values.delete_if { |v| v.blank? }
|
24
|
+
if values.blank?
|
25
|
+
super nil
|
26
|
+
else
|
27
|
+
super values
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -6,20 +6,14 @@ module SimplePages
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
included do
|
8
8
|
attr_accessible :url
|
9
|
-
validates :url, format: { with:
|
9
|
+
validates :url, format: { with: /^([\w\-]{3,})$/ }, allow_blank: true
|
10
10
|
acts_as_url :title, sync_url: true, only_when_blank: true
|
11
11
|
end
|
12
12
|
|
13
13
|
module ClassMethods
|
14
14
|
def find_or_create_by_url(attrs)
|
15
15
|
url = attrs.delete :url
|
16
|
-
|
17
|
-
if page.nil?
|
18
|
-
page = create(attrs)
|
19
|
-
page.url = url
|
20
|
-
page.save
|
21
|
-
end
|
22
|
-
page
|
16
|
+
where(url: url).first_or_create(attrs)
|
23
17
|
end
|
24
18
|
end
|
25
19
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-pages-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
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:
|
12
|
+
date: 2013-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -241,6 +241,7 @@ files:
|
|
241
241
|
- config/locales/simple_pages.zh-TW.yml
|
242
242
|
- config/routes.rb
|
243
243
|
- db/migrate/20121206042138_create_simple_pages.rb
|
244
|
+
- db/migrate/20130318034034_add_cluster_to_simple_pages.rb
|
244
245
|
- lib/generators/simple_pages/USAGE
|
245
246
|
- lib/generators/simple_pages/install_generator.rb
|
246
247
|
- lib/generators/simple_pages/templates/cancan_ext.rb
|
@@ -249,10 +250,12 @@ files:
|
|
249
250
|
- lib/simple-pages-rails.rb
|
250
251
|
- lib/simple-pages-rails/version.rb
|
251
252
|
- lib/simple_pages.rb
|
253
|
+
- lib/simple_pages/controllers/page_cluster.rb
|
252
254
|
- lib/simple_pages/controllers/page_layout_at.rb
|
253
255
|
- lib/simple_pages/engine.rb
|
254
256
|
- lib/simple_pages/models/page_attachment.rb
|
255
257
|
- lib/simple_pages/models/page_author.rb
|
258
|
+
- lib/simple_pages/models/page_cluster.rb
|
256
259
|
- lib/simple_pages/models/page_locale.rb
|
257
260
|
- lib/simple_pages/models/page_owner.rb
|
258
261
|
- lib/simple_pages/models/page_url.rb
|
@@ -321,7 +324,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
321
324
|
version: '0'
|
322
325
|
segments:
|
323
326
|
- 0
|
324
|
-
hash:
|
327
|
+
hash: 1460486982569856472
|
325
328
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
326
329
|
none: false
|
327
330
|
requirements:
|
@@ -330,7 +333,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
330
333
|
version: '0'
|
331
334
|
segments:
|
332
335
|
- 0
|
333
|
-
hash:
|
336
|
+
hash: 1460486982569856472
|
334
337
|
requirements: []
|
335
338
|
rubyforge_project:
|
336
339
|
rubygems_version: 1.8.24
|