cartoonist-pages 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,9 +16,7 @@ class Admin::PageController < AdminCartoonistController
16
16
  end
17
17
 
18
18
  def create
19
- path = params[:path].downcase
20
- raise "Invalid path" unless path =~ /^[-_a-z0-9]+$/
21
- page = Page.create :title => params[:title], :path => path, :content => params[:content], :locked => true
19
+ page = Page.create_page params
22
20
  redirect_to "/admin/page/#{page.id}/edit"
23
21
  end
24
22
 
@@ -29,38 +27,19 @@ class Admin::PageController < AdminCartoonistController
29
27
  end
30
28
 
31
29
  def update
32
- path = params[:path].downcase
33
- raise "Invalid path" unless path =~ /^[-_a-z0-9]+$/
34
- page = Page.find params[:id].to_i
35
- raise "Cannot update locked page!" if page.locked
36
- page.title = params[:title]
37
- page.path = path
38
- page.content = params[:content]
39
- page.locked = true
40
- page.comments = !!params[:comments]
41
- page.in_sitemap = !!params[:in_sitemap]
42
-
43
- if params[:posted]
44
- page.posted_at = Date.today
45
- else
46
- page.posted_at = nil
47
- end
48
-
49
- page.save!
30
+ page = Page.update_page params
50
31
  redirect_to "/admin/page/#{page.id}/edit"
51
32
  end
52
33
 
53
34
  def lock
54
35
  page = Page.find params[:id].to_i
55
- page.locked = true
56
- page.save!
36
+ page.lock!
57
37
  redirect_to "/admin/page/#{page.id}/edit"
58
38
  end
59
39
 
60
40
  def unlock
61
41
  page = Page.find params[:id].to_i
62
- page.locked = false
63
- page.save!
42
+ page.unlock!
64
43
  redirect_to "/admin/page/#{page.id}/edit"
65
44
  end
66
45
  end
@@ -1,16 +1,6 @@
1
1
  module Admin::PageHelper
2
- def lock_toggle_target
3
- if @page.locked
4
- "unlock"
5
- else
6
- "lock"
7
- end
8
- end
9
-
10
2
  def lock_disabled
11
- if @page.locked
12
- 'disabled="disabled"'.html_safe
13
- end
3
+ @page.lock_disabled_html
14
4
  end
15
5
 
16
6
  def format_posted_at(fmt)
data/app/models/page.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  class Page < ActiveRecord::Base
2
2
  include Postable
3
3
  include Entity
4
+ include Lockable
4
5
  entity_type :page
5
6
  entity_url &:url
6
7
  entity_preview_url &:preview_url
@@ -35,6 +36,34 @@ class Page < ActiveRecord::Base
35
36
  end
36
37
 
37
38
  class << self
39
+ def create_page(params)
40
+ path = params[:path].downcase
41
+ raise "Invalid path" unless path =~ /^[-_a-z0-9]+$/
42
+ Page.create :title => params[:title], :path => path, :content => params[:content], :locked => true
43
+ end
44
+
45
+ def update_page(params)
46
+ path = params[:path].downcase
47
+ raise "Invalid path" unless path =~ /^[-_a-z0-9]+$/
48
+ page = Page.find params[:id].to_i
49
+ page.ensure_unlocked!
50
+ page.title = params[:title]
51
+ page.path = path
52
+ page.content = params[:content]
53
+ page.locked = true
54
+ page.comments = !!params[:comments]
55
+ page.in_sitemap = !!params[:in_sitemap]
56
+
57
+ if params[:posted]
58
+ page.posted_at = Date.today
59
+ else
60
+ page.posted_at = nil
61
+ end
62
+
63
+ page.save!
64
+ page
65
+ end
66
+
38
67
  def search(query)
39
68
  ordered.where "LOWER(title) LIKE :query OR LOWER(path) LIKE :query OR LOWER(content) LIKE :query", :query => "%#{query.downcase}%"
40
69
  end
@@ -1,5 +1,5 @@
1
1
  <% Cartoonist::Entity.hooks_with(:edit_entity_before_partial).each do |hook| %>
2
- <%= render :partial => hook.edit_entity_before_partial, :locals => { :entity => @page } %>
2
+ <%= partial hook.edit_entity_before_partial, :entity => @page %>
3
3
  <hr />
4
4
  <% end %>
5
5
 
@@ -8,8 +8,8 @@
8
8
  </p>
9
9
 
10
10
  <p>
11
- <%= form_tag "/admin/page/#{@page.id}/#{lock_toggle_target}", :method => :post do %>
12
- <input type="submit" value="<%= lock_toggle_target %>" />
11
+ <%= form_tag "/admin/page/#{@page.id}/#{@page.toggle_lock_target}", :method => :post do %>
12
+ <input type="submit" value="<%= @page.toggle_lock_target %>" />
13
13
  <% end %>
14
14
  </p>
15
15
 
@@ -64,5 +64,5 @@
64
64
 
65
65
  <% Cartoonist::Entity.hooks_with(:edit_entity_after_partial).each do |hook| %>
66
66
  <hr />
67
- <%= render :partial => hook.edit_entity_after_partial, :locals => { :entity => @page } %>
67
+ <%= partial hook.edit_entity_after_partial, :entity => @page %>
68
68
  <% end %>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <% content_for :content do %>
4
4
  <% Cartoonist::Entity.hooks_with(:show_entity_before_partial).each do |hook| %>
5
- <%= render :partial => hook.show_entity_before_partial, :locals => { :entity => @page } %>
5
+ <%= partial hook.show_entity_before_partial, :entity => @page %>
6
6
  <hr />
7
7
  <% end %>
8
8
 
@@ -13,7 +13,7 @@
13
13
  </div>
14
14
 
15
15
  <% Cartoonist::Entity.hooks_with(:show_entity_after_partial).each do |hook| %>
16
- <%= render :partial => hook.show_entity_after_partial, :locals => { :entity => @page } %>
16
+ <%= partial hook.show_entity_after_partial, :entity => @page %>
17
17
  <hr />
18
18
  <% end %>
19
19
  <% end %>
@@ -2,7 +2,7 @@ module CartoonistPages
2
2
  class Version
3
3
  class << self
4
4
  def to_s
5
- "0.0.16"
5
+ "0.0.17"
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,48 +1,54 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cartoonist-pages
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.17
4
5
  prerelease:
5
- version: 0.0.16
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Mike Virata-Stone
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-12-15 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2013-02-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: jquery-rails
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
18
+ requirements:
21
19
  - - ~>
22
- - !ruby/object:Gem::Version
20
+ - !ruby/object:Gem::Version
23
21
  version: 2.1.4
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: cartoonist
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.1.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: cartoonist
32
+ requirement: !ruby/object:Gem::Requirement
30
33
  none: false
31
- requirements:
32
- - - "="
33
- - !ruby/object:Gem::Version
34
- version: 0.0.16
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.0.17
35
38
  type: :runtime
36
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.0.17
37
46
  description: This core plugin for Cartoonist adds arbitrary pages.
38
47
  email: reasonnumber@gmail.com
39
48
  executables: []
40
-
41
49
  extensions: []
42
-
43
50
  extra_rdoc_files: []
44
-
45
- files:
51
+ files:
46
52
  - app/assets/javascripts/admin/page.js.coffee
47
53
  - app/controllers/admin/page_controller.rb
48
54
  - app/controllers/page_controller.rb
@@ -62,30 +68,26 @@ files:
62
68
  - lib/cartoonist-pages/version.rb
63
69
  homepage: http://reasonnumber.com/cartoonist
64
70
  licenses: []
65
-
66
71
  post_install_message:
67
72
  rdoc_options: []
68
-
69
- require_paths:
73
+ require_paths:
70
74
  - lib
71
- required_ruby_version: !ruby/object:Gem::Requirement
75
+ required_ruby_version: !ruby/object:Gem::Requirement
72
76
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: "0"
77
- required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
82
  none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: "0"
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
83
87
  requirements: []
84
-
85
88
  rubyforge_project:
86
89
  rubygems_version: 1.8.24
87
90
  signing_key:
88
91
  specification_version: 3
89
92
  summary: Cartoonist Pages
90
93
  test_files: []
91
-