simple-pages-rails 0.2.0 → 0.3.0

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.
@@ -4,31 +4,11 @@ module SimplePages
4
4
 
5
5
  attr_accessible :title, :excerpt, :content, :published_at, :layout_at
6
6
 
7
- validates :url, presence: true
8
7
  validates :title, presence: true
9
8
 
10
- acts_as_url :title
11
-
12
9
  scope :published, lambda { where('published_at <= ?', Time.zone.now) }
13
10
  scope :layout_at, lambda { |location| where(layout_at: location) }
14
11
 
15
- class << self
16
- def find_or_create_by_url(attrs)
17
- url = attrs.delete :url
18
- page = where(url: url).first
19
- if page.nil?
20
- page = create(attrs)
21
- page.url = url
22
- page.save
23
- end
24
- page
25
- end
26
- end
27
-
28
- def to_param
29
- url
30
- end
31
-
32
12
  SimplePages.page_modules.each { |module_name| include module_name }
33
13
  end
34
14
  end
@@ -1,6 +1,7 @@
1
- <%= f.error_notification %>
2
-
3
1
  <div class="form-inputs">
2
+ <% if can? :update_url, f.object %>
3
+ <%= f.input :url, input_html: { class: 'span10' } %>
4
+ <% end %>
4
5
  <%= f.input :title, input_html: { class: 'span10' } %>
5
6
  <%= f.input :excerpt, as: :text, input_html: { rows: 5, class: 'span10' } %>
6
7
  <%= f.input :content, input_html: { class: 'ckeditor' } %>
@@ -14,6 +14,7 @@
14
14
 
15
15
  <div>
16
16
  <%= simple_form_for @page, as: :page, html: { class: 'form-horizontal' } do |f| %>
17
+ <%= f.error_notification %>
17
18
  <%= render 'form', f: f, author_options: @author_options, layout_at_options: @layout_at_options %>
18
19
  <div class="form-actions">
19
20
  <%= submit_button f %>
@@ -11,6 +11,7 @@
11
11
 
12
12
  <div>
13
13
  <%= simple_form_for @page, as: :page, html: { class: 'form-horizontal' } do |f| %>
14
+ <%= f.error_notification %>
14
15
  <%= render 'form', f: f, author_options: @author_options, layout_at_options: @layout_at_options %>
15
16
  <div class="form-actions">
16
17
  <%= submit_button f %>
@@ -27,14 +27,16 @@ en:
27
27
 
28
28
  simple_form:
29
29
  labels:
30
- simple_pages_page:
30
+ page:
31
31
  hints:
32
- simple_pages_page:
32
+ page:
33
+ url: 'Only characters(a-zA-Z), numbers(0-9), dash(-) and underline(_) are allowed. It will be given if left blank.'
34
+ published_at: 'It will not show up if blank.'
33
35
  placeholders:
34
- simple_pages_page:
36
+ page:
35
37
 
36
38
  helpers:
37
39
  submit:
38
- simple_pages_page:
40
+ page:
39
41
  create: 'Create %{model}'
40
42
  update: 'Update %{model}'
@@ -27,14 +27,16 @@ zh-TW:
27
27
 
28
28
  simple_form:
29
29
  labels:
30
- simple_pages_page:
30
+ page:
31
31
  hints:
32
- simple_pages_page:
32
+ page:
33
+ url: '僅限使用英文字母( a-zA-Z )、數字( 0-9 )、破折號( - )與底線( _ )。若不輸入,則由系統自行賦予。'
34
+ published_at: '若沒有設定時間,則不會顯示在網站中。'
33
35
  placeholders:
34
- simple_pages_page:
36
+ page:
35
37
 
36
38
  helpers:
37
39
  submit:
38
- simple_pages_page:
40
+ page:
39
41
  create: '建立%{model}'
40
42
  update: '更新%{model}'
@@ -1,3 +1,3 @@
1
1
  module SimplePagesRails
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -0,0 +1,31 @@
1
+ require 'active_support/concern'
2
+
3
+ module SimplePages
4
+ module Models
5
+ module PageUrl
6
+ extend ActiveSupport::Concern
7
+ included do
8
+ attr_accessible :url
9
+ validates :url, format: { with: /[\w\d-_]{3,}/ }, allow_blank: true
10
+ acts_as_url :title, sync_url: true, only_when_blank: true
11
+ end
12
+
13
+ module ClassMethods
14
+ def find_or_create_by_url(attrs)
15
+ url = attrs.delete :url
16
+ page = where(url: url).first
17
+ if page.nil?
18
+ page = create(attrs)
19
+ page.url = url
20
+ page.save
21
+ end
22
+ page
23
+ end
24
+ end
25
+
26
+ def to_param
27
+ url
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/simple_pages.rb CHANGED
@@ -4,6 +4,7 @@ require 'simple_pages/models/page_attachment'
4
4
  require 'simple_pages/models/page_author'
5
5
  require 'simple_pages/models/page_locale'
6
6
  require 'simple_pages/models/page_owner'
7
+ require 'simple_pages/models/page_url'
7
8
 
8
9
  module SimplePages
9
10
  mattr_accessor :controller_modules
@@ -22,6 +23,7 @@ module SimplePages
22
23
 
23
24
  mattr_accessor :page_modules
24
25
  @@page_modules = [
26
+ SimplePages::Models::PageUrl,
25
27
  SimplePages::Models::PageOwner,
26
28
  SimplePages::Models::PageLocale,
27
29
  SimplePages::Models::PageAttachment
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.2.0
4
+ version: 0.3.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: 2012-12-18 00:00:00.000000000 Z
12
+ date: 2012-12-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -255,6 +255,7 @@ files:
255
255
  - lib/simple_pages/models/page_author.rb
256
256
  - lib/simple_pages/models/page_locale.rb
257
257
  - lib/simple_pages/models/page_owner.rb
258
+ - lib/simple_pages/models/page_url.rb
258
259
  - lib/tasks/simple_pages_tasks.rake
259
260
  - script/rails
260
261
  - simple-pages-rails.gemspec
@@ -320,7 +321,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
320
321
  version: '0'
321
322
  segments:
322
323
  - 0
323
- hash: -3697549356973948748
324
+ hash: -3329774996417494791
324
325
  required_rubygems_version: !ruby/object:Gem::Requirement
325
326
  none: false
326
327
  requirements:
@@ -329,7 +330,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
329
330
  version: '0'
330
331
  segments:
331
332
  - 0
332
- hash: -3697549356973948748
333
+ hash: -3329774996417494791
333
334
  requirements: []
334
335
  rubyforge_project:
335
336
  rubygems_version: 1.8.24