cartoonist-pages 0.0.3.5 → 0.0.4
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.
- data/app/controllers/page_admin_controller.rb +68 -0
- data/app/controllers/page_controller.rb +8 -0
- data/app/helpers/page_admin_helper.rb +23 -0
- data/app/models/page.rb +43 -0
- data/app/views/layouts/page.html.erb +17 -0
- data/app/views/layouts/page_admin.html.erb +8 -0
- data/app/views/page/show.html.erb +7 -0
- data/app/views/page_admin/edit.html.erb +87 -0
- data/app/views/page_admin/index.html.erb +22 -0
- data/app/views/page_admin/new.html.erb +51 -0
- data/cartoonist-pages.gemspec +3 -2
- data/config/locales/en.yml +15 -0
- data/db/migrate/20120316072549_create_pages.rb +17 -0
- data/lib/cartoonist-pages/engine.rb +32 -0
- metadata +14 -2
@@ -0,0 +1,68 @@
|
|
1
|
+
class PageAdminController < ApplicationController
|
2
|
+
before_filter :preview!, :only => [:preview]
|
3
|
+
before_filter :ensure_ssl!
|
4
|
+
before_filter :check_admin!
|
5
|
+
|
6
|
+
def preview
|
7
|
+
@page = Page.preview_from_path params[:id]
|
8
|
+
render "page/show", :layout => "page"
|
9
|
+
end
|
10
|
+
|
11
|
+
def preview_content
|
12
|
+
render :text => Markdown.render(params[:content]), :layout => false
|
13
|
+
end
|
14
|
+
|
15
|
+
def index
|
16
|
+
@unposted = Page.unposted.ordered
|
17
|
+
@posted = Page.posted.ordered
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
path = params[:path].downcase
|
22
|
+
raise "Invalid path" unless path =~ /^[-_a-z0-9]+$/
|
23
|
+
page = Page.create :title => params[:title], :path => path, :content => params[:content], :locked => true
|
24
|
+
redirect_to "/page_admin/#{page.id}/edit"
|
25
|
+
end
|
26
|
+
|
27
|
+
def edit
|
28
|
+
@page = Page.find params[:id].to_i
|
29
|
+
rescue ActiveRecord::RecordNotFound
|
30
|
+
redirect_to "/page_admin/new"
|
31
|
+
end
|
32
|
+
|
33
|
+
def update
|
34
|
+
path = params[:path].downcase
|
35
|
+
raise "Invalid path" unless path =~ /^[-_a-z0-9]+$/
|
36
|
+
page = Page.find params[:id].to_i
|
37
|
+
raise "Cannot update locked page!" if page.locked
|
38
|
+
page.title = params[:title]
|
39
|
+
page.path = path
|
40
|
+
page.content = params[:content]
|
41
|
+
page.locked = true
|
42
|
+
page.comments = !!params[:comments]
|
43
|
+
page.in_sitemap = !!params[:in_sitemap]
|
44
|
+
|
45
|
+
if params[:posted]
|
46
|
+
page.posted_at = Date.today
|
47
|
+
else
|
48
|
+
page.posted_at = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
page.save!
|
52
|
+
redirect_to "/page_admin/#{page.id}/edit"
|
53
|
+
end
|
54
|
+
|
55
|
+
def lock
|
56
|
+
page = Page.find params[:id].to_i
|
57
|
+
page.locked = true
|
58
|
+
page.save!
|
59
|
+
redirect_to "/page_admin/#{page.id}/edit"
|
60
|
+
end
|
61
|
+
|
62
|
+
def unlock
|
63
|
+
page = Page.find params[:id].to_i
|
64
|
+
page.locked = false
|
65
|
+
page.save!
|
66
|
+
redirect_to "/page_admin/#{page.id}/edit"
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PageAdminHelper
|
2
|
+
def lock_toggle_target
|
3
|
+
if @page.locked
|
4
|
+
"unlock"
|
5
|
+
else
|
6
|
+
"lock"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def lock_disabled
|
11
|
+
if @page.locked
|
12
|
+
'disabled="disabled"'.html_safe
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def format_posted_at(fmt)
|
17
|
+
if @page && @page.posted_at
|
18
|
+
@page.posted_at.to_time.strftime fmt
|
19
|
+
else
|
20
|
+
"not yet posted"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/app/models/page.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
class Page < ActiveRecord::Base
|
2
|
+
def has_comments?
|
3
|
+
comments
|
4
|
+
end
|
5
|
+
|
6
|
+
def in_sitemap?
|
7
|
+
in_sitemap
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def sitemap
|
12
|
+
posted.in_sitemap
|
13
|
+
end
|
14
|
+
|
15
|
+
def in_sitemap
|
16
|
+
where :in_sitemap => true
|
17
|
+
end
|
18
|
+
|
19
|
+
def posted
|
20
|
+
where "posted_at IS NOT NULL"
|
21
|
+
end
|
22
|
+
|
23
|
+
def unposted
|
24
|
+
where "posted_at IS NULL"
|
25
|
+
end
|
26
|
+
|
27
|
+
def ordered
|
28
|
+
order "pages.title ASC"
|
29
|
+
end
|
30
|
+
|
31
|
+
def preview_from_path(path)
|
32
|
+
page = where(:path => path).first
|
33
|
+
raise ActiveRecord::RecordNotFound.new("No page found!") unless page
|
34
|
+
page
|
35
|
+
end
|
36
|
+
|
37
|
+
def from_path(path)
|
38
|
+
page = posted.where(:path => path).first
|
39
|
+
raise ActiveRecord::RecordNotFound.new("No page found!") unless page
|
40
|
+
page
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<% content_for :content_class, "page-content" %>
|
2
|
+
|
3
|
+
<% content_for :content do %>
|
4
|
+
<div class="page">
|
5
|
+
<h1><%= content_for?(:page_title) ? yield(:page_title) : yield(:title) %></h1>
|
6
|
+
|
7
|
+
<%= yield %>
|
8
|
+
</div>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<% content_for :admin_content do %>
|
12
|
+
<% if preview? %>
|
13
|
+
<p><a href="/admin/main">admin</a></p>
|
14
|
+
<% end %>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<%= render :template => "layouts/application" %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<% content_for :subtabs do %>
|
2
|
+
<a class="subtab" href="/page_admin"><%= t "admin.page.layout.list" %></a>
|
3
|
+
<a class="subtab" href="/page_admin/new"><%= t "admin.page.layout.new" %></a>
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
<% content_for :page_title, t("admin.page.layout.section") %>
|
7
|
+
<% content_for(:content) { yield } %>
|
8
|
+
<%= render :template => "layouts/admin" %>
|
@@ -0,0 +1,87 @@
|
|
1
|
+
<p>
|
2
|
+
<a href="/page_admin/<%= @page.path %>/preview">Preview this page</a>
|
3
|
+
</p>
|
4
|
+
|
5
|
+
<p>
|
6
|
+
<%= form_tag "/page_admin/#{@page.id}/#{lock_toggle_target}", :method => :post do %>
|
7
|
+
<input type="submit" value="<%= lock_toggle_target %>" />
|
8
|
+
<% end %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<%= form_tag "/page_admin/#{@page.id}", :method => :put do %>
|
12
|
+
<p>
|
13
|
+
<label>
|
14
|
+
<input type="checkbox" name="posted" value="true" <%= checked="checked".html_safe if @page.posted_at %> <%= lock_disabled %> />
|
15
|
+
Posted at: <%= format_posted_at "%-m/%-d/%Y" %>
|
16
|
+
</label>
|
17
|
+
|
18
|
+
<label>
|
19
|
+
<input type="checkbox" name="comments" value="true" <%= checked="checked".html_safe if @page.has_comments? %> <%= lock_disabled %> />
|
20
|
+
Comments
|
21
|
+
</label>
|
22
|
+
|
23
|
+
<label>
|
24
|
+
<input type="checkbox" name="in_sitemap" value="true" <%= checked="checked".html_safe if @page.in_sitemap? %> <%= lock_disabled %> />
|
25
|
+
In Sitemap
|
26
|
+
</label>
|
27
|
+
</p>
|
28
|
+
|
29
|
+
<p>
|
30
|
+
Path:
|
31
|
+
<input type="text" name="path" size="20" value="<%= @page.path %>" <%= lock_disabled %> />
|
32
|
+
</p>
|
33
|
+
|
34
|
+
<p>
|
35
|
+
Title:
|
36
|
+
<input type="text" name="title" size="100" value="<%= @page.title %>" <%= lock_disabled %> />
|
37
|
+
</p>
|
38
|
+
|
39
|
+
<p>
|
40
|
+
<input type="submit" value="Save" <%= lock_disabled %> />
|
41
|
+
<input type="button" value="Preview" class="preview-content" />
|
42
|
+
</p>
|
43
|
+
|
44
|
+
<p>
|
45
|
+
Content:<br />
|
46
|
+
<textarea name="content" rows="20" cols="100" <%= lock_disabled %>><%= @page.content %></textarea><br />
|
47
|
+
</p>
|
48
|
+
|
49
|
+
<p>
|
50
|
+
<input type="submit" value="Save" <%= lock_disabled %> />
|
51
|
+
<input type="button" value="Preview" class="preview-content" />
|
52
|
+
</p>
|
53
|
+
<% end %>
|
54
|
+
|
55
|
+
<hr />
|
56
|
+
|
57
|
+
<div class="preview-content">
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" %>
|
61
|
+
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js" %>
|
62
|
+
<%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/themes/base/jquery-ui.css" %>
|
63
|
+
<%= javascript_tag do %>
|
64
|
+
$(function() {
|
65
|
+
$(".preview-content").click(function() {
|
66
|
+
var $this = $(this).attr("disabled", "disabled");
|
67
|
+
$.ajax({
|
68
|
+
url: "/page_admin/preview_content",
|
69
|
+
type: "post",
|
70
|
+
data: {
|
71
|
+
authenticity_token: $("form input[name='authenticity_token']").val(),
|
72
|
+
content: $("textarea[name='content']").val()
|
73
|
+
},
|
74
|
+
dataType: "text",
|
75
|
+
success: function(text) {
|
76
|
+
$(".preview-content").html(text);
|
77
|
+
$this.removeAttr("disabled");
|
78
|
+
},
|
79
|
+
error: function() {
|
80
|
+
$(".preview-content").html('<div style="color: red;">There was an error.</div>');
|
81
|
+
$this.removeAttr("disabled");
|
82
|
+
}
|
83
|
+
});
|
84
|
+
return false;
|
85
|
+
});
|
86
|
+
});
|
87
|
+
<% end %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<h2><%= t "admin.page.index.not_posted" %></h2>
|
2
|
+
|
3
|
+
<ul>
|
4
|
+
<% @unposted.each do |page| %>
|
5
|
+
<li>
|
6
|
+
<a href="/page_admin/<%= page.id %>/edit"><%= page.title %></a>
|
7
|
+
(<a href="/page_admin/<%= page.path %>/preview"><%= t "admin.page.index.preview" %></a>)
|
8
|
+
</li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
|
12
|
+
<h2><%= t "admin.page.index.posted" %></h2>
|
13
|
+
|
14
|
+
<ul>
|
15
|
+
<% @posted.each do |page| %>
|
16
|
+
<li>
|
17
|
+
<a href="/page_admin/<%= page.id %>/edit"><%= page.title %></a>
|
18
|
+
(<a href="/page_admin/<%= page.path %>/preview"><%= t "admin.page.index.preview" %></a>)
|
19
|
+
(<a href="/<%= page.path %>"><%= t "admin.page.index.show" %></a>)
|
20
|
+
</li>
|
21
|
+
<% end %>
|
22
|
+
</ul>
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<%= form_tag "/page_admin", :method => :post do %>
|
2
|
+
<p>
|
3
|
+
Path: <input type="text" name="path" autofocus="autofocus" size="20" /><br />
|
4
|
+
</p>
|
5
|
+
|
6
|
+
<p>
|
7
|
+
Title: <input type="text" name="title" size="100" /><br />
|
8
|
+
</p>
|
9
|
+
|
10
|
+
<p>
|
11
|
+
Content:<br />
|
12
|
+
<textarea name="content" rows="20" cols="100"></textarea><br />
|
13
|
+
</p>
|
14
|
+
|
15
|
+
<p>
|
16
|
+
<input type="submit" value="Save" />
|
17
|
+
<input type="button" value="Preview" class="preview-content" />
|
18
|
+
</p>
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
<hr />
|
22
|
+
|
23
|
+
<div class="preview-content">
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" %>
|
27
|
+
<%= javascript_tag do %>
|
28
|
+
$(function() {
|
29
|
+
$(".preview-content").click(function() {
|
30
|
+
var $this = $(this).attr("disabled", "disabled");
|
31
|
+
$.ajax({
|
32
|
+
url: "/page_admin/preview_content",
|
33
|
+
type: "post",
|
34
|
+
data: {
|
35
|
+
authenticity_token: $("form input[name='authenticity_token']").val(),
|
36
|
+
content: $("textarea[name='content']").val()
|
37
|
+
},
|
38
|
+
dataType: "text",
|
39
|
+
success: function(text) {
|
40
|
+
$(".preview-content").html(text);
|
41
|
+
$this.removeAttr("disabled");
|
42
|
+
},
|
43
|
+
error: function() {
|
44
|
+
$(".preview-content").html('<div style="color: red;">There was an error.</div>');
|
45
|
+
$this.removeAttr("disabled");
|
46
|
+
}
|
47
|
+
});
|
48
|
+
return false;
|
49
|
+
});
|
50
|
+
});
|
51
|
+
<% end %>
|
data/cartoonist-pages.gemspec
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cartoonist-pages"
|
3
|
-
|
4
|
-
s.
|
3
|
+
raise "Cannot find version file!" unless File.exists?(File.join(File.dirname(__FILE__), "../CARTOONIST_VERSION"))
|
4
|
+
s.version = File.read File.join(File.dirname(__FILE__), "../CARTOONIST_VERSION")
|
5
|
+
s.date = Time.now.strftime "%Y-%m-%d"
|
5
6
|
s.summary = "Cartoonist Pages"
|
6
7
|
s.description = "This core plugin for Cartoonist adds arbitrary pages."
|
7
8
|
s.authors = ["Mike Virata-Stone"]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreatePages < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :pages do |t|
|
4
|
+
t.string :title, :null => false
|
5
|
+
t.string :path, :null => false
|
6
|
+
t.date :posted_at
|
7
|
+
t.text :content, :null => false
|
8
|
+
t.boolean :locked, :null => false, :default => false
|
9
|
+
t.boolean :comments, :null => false, :default => false
|
10
|
+
t.boolean :in_sitemap, :null => false, :default => false
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :pages, :title, :unique => true
|
15
|
+
add_index :pages, :path, :unique => true
|
16
|
+
end
|
17
|
+
end
|
@@ -1,4 +1,36 @@
|
|
1
1
|
module CartoonistPages
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
+
Cartoonist::Admin::Tab.add :pages, :url => "/page_admin", :order => 2
|
4
|
+
Cartoonist::Migration.add_for self
|
5
|
+
|
6
|
+
Cartoonist::Backup.for :pages do
|
7
|
+
Page.order(:id).all
|
8
|
+
end
|
9
|
+
|
10
|
+
Cartoonist::Sitemap.add do
|
11
|
+
Page.sitemap.map do |page|
|
12
|
+
SitemapEntry.new "/#{page.path}", page.posted_at, :monthly, "0.4"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Cartoonist::Routes.add_end do
|
17
|
+
match ":id", :controller => "page", :action => "show"
|
18
|
+
end
|
19
|
+
|
20
|
+
Cartoonist::Routes.add do
|
21
|
+
resources :page_admin do
|
22
|
+
member do
|
23
|
+
post "lock"
|
24
|
+
post "post"
|
25
|
+
get "preview"
|
26
|
+
post "unlock"
|
27
|
+
post "unpost"
|
28
|
+
end
|
29
|
+
|
30
|
+
collection do
|
31
|
+
post "preview_content"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
3
35
|
end
|
4
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cartoonist-pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
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-04-
|
12
|
+
date: 2012-04-16 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: This core plugin for Cartoonist adds arbitrary pages.
|
15
15
|
email: reasonnumber@gmail.com
|
@@ -18,7 +18,19 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- .gitignore
|
21
|
+
- app/controllers/page_admin_controller.rb
|
22
|
+
- app/controllers/page_controller.rb
|
23
|
+
- app/helpers/page_admin_helper.rb
|
24
|
+
- app/models/page.rb
|
25
|
+
- app/views/layouts/page.html.erb
|
26
|
+
- app/views/layouts/page_admin.html.erb
|
27
|
+
- app/views/page/show.html.erb
|
28
|
+
- app/views/page_admin/edit.html.erb
|
29
|
+
- app/views/page_admin/index.html.erb
|
30
|
+
- app/views/page_admin/new.html.erb
|
21
31
|
- cartoonist-pages.gemspec
|
32
|
+
- config/locales/en.yml
|
33
|
+
- db/migrate/20120316072549_create_pages.rb
|
22
34
|
- lib/cartoonist-pages.rb
|
23
35
|
- lib/cartoonist-pages/engine.rb
|
24
36
|
homepage: http://reasonnumber.com/cartoonist
|