blogaze 0.0.1 → 0.0.2
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/README.md +12 -13
- data/blogaze.gemspec +1 -0
- data/lib/blogaze.rb +2 -2
- data/lib/blogaze/bin/create.rb +6 -0
- data/lib/blogaze/controllers/admin/comments.rb +43 -0
- data/lib/blogaze/controllers/admin/dashboard.rb +25 -0
- data/lib/blogaze/controllers/admin/init.rb +30 -0
- data/lib/blogaze/controllers/admin/pages.rb +95 -0
- data/lib/blogaze/controllers/admin/posts.rb +125 -0
- data/lib/blogaze/controllers/admin/settings.rb +41 -0
- data/lib/blogaze/{controller → controllers}/init.rb +1 -1
- data/lib/blogaze/controllers/main_controller.rb +35 -0
- data/lib/blogaze/controllers/pages.rb +39 -0
- data/lib/blogaze/controllers/posts.rb +77 -0
- data/lib/blogaze/controllers/sessions.rb +50 -0
- data/lib/blogaze/controllers/users.rb +41 -0
- data/lib/blogaze/models/comment.rb +28 -0
- data/lib/blogaze/{model → models}/group.rb +6 -4
- data/lib/blogaze/{model → models}/init.rb +0 -0
- data/lib/blogaze/models/page.rb +29 -0
- data/lib/blogaze/models/post.rb +95 -0
- data/lib/blogaze/models/tag.rb +25 -0
- data/lib/blogaze/{model → models}/tags_relationship.rb +6 -4
- data/lib/blogaze/models/user.rb +43 -0
- data/lib/blogaze/routes.rb +4 -0
- data/lib/blogaze/theme.rb +17 -0
- data/lib/blogaze/version.rb +1 -1
- data/proto/public/css/master.less +16 -12
- data/proto/themes/default/admin/index.xhtml +4 -4
- data/proto/themes/default/admin/settings/index.xhtml +1 -1
- data/proto/themes/default/index.xhtml +6 -3
- data/proto/themes/default/layouts/admin.xhtml +2 -2
- data/proto/themes/default/layouts/default.xhtml +1 -1
- data/proto/themes/default/posts/view.xhtml +3 -3
- metadata +37 -21
- data/lib/blogaze/controller/admin/comments.rb +0 -32
- data/lib/blogaze/controller/admin/init.rb +0 -28
- data/lib/blogaze/controller/admin/main.rb +0 -20
- data/lib/blogaze/controller/admin/pages.rb +0 -75
- data/lib/blogaze/controller/admin/posts.rb +0 -103
- data/lib/blogaze/controller/admin/settings.rb +0 -33
- data/lib/blogaze/controller/main.rb +0 -30
- data/lib/blogaze/controller/pages.rb +0 -34
- data/lib/blogaze/controller/posts.rb +0 -43
- data/lib/blogaze/controller/sessions.rb +0 -39
- data/lib/blogaze/controller/users.rb +0 -39
- data/lib/blogaze/model/comment.rb +0 -26
- data/lib/blogaze/model/page.rb +0 -27
- data/lib/blogaze/model/post.rb +0 -79
- data/lib/blogaze/model/tag.rb +0 -19
- data/lib/blogaze/model/user.rb +0 -41
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# Blogaze
|
3
|
+
# Copyright (C) 2011-2013 Jack Polgar
|
4
|
+
#
|
5
|
+
# Blogaze is released under the BSD 3-clause license.
|
6
|
+
# @license http://opensource.org/licenses/BSD-3-Clause
|
7
|
+
#
|
8
|
+
|
9
|
+
module Blogaze
|
10
|
+
module Controllers
|
11
|
+
class MainController < Controller
|
12
|
+
map '/'
|
13
|
+
helper :paginate
|
14
|
+
|
15
|
+
##
|
16
|
+
# Index page
|
17
|
+
#
|
18
|
+
def index(page = 1)
|
19
|
+
# Check if we should change the title to include
|
20
|
+
# what page we're on.
|
21
|
+
if page.to_i > 1
|
22
|
+
@title = "Page #{page} - #{@settings[:title]}"
|
23
|
+
else
|
24
|
+
@title = @settings[:title]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Get the data and paginate it.
|
28
|
+
data = ::Blogaze::Models::Post.order(:published_at.desc)
|
29
|
+
@posts = paginate(data, :limit => @settings[:posts_per_page].to_i, :page => page.to_i)
|
30
|
+
|
31
|
+
respond(view_file(:index))
|
32
|
+
end
|
33
|
+
end # MainController
|
34
|
+
end # Controllers
|
35
|
+
end # Blogaze
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Blogaze
|
3
|
+
# Copyright (C) 2011-2013 Jack Polgar
|
4
|
+
#
|
5
|
+
# Blogaze is released under the BSD 3-clause license.
|
6
|
+
# @license http://opensource.org/licenses/BSD-3-Clause
|
7
|
+
#
|
8
|
+
|
9
|
+
module Blogaze
|
10
|
+
module Controllers
|
11
|
+
class Pages < Controller
|
12
|
+
map '/pages'
|
13
|
+
|
14
|
+
##
|
15
|
+
# View page
|
16
|
+
#
|
17
|
+
def view(slug = nil)
|
18
|
+
if slug == nil
|
19
|
+
slug = request.env["REQUEST_PATH"]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Chomp chomp chomp, let's trim any unwanted
|
23
|
+
# forward slashes from the begning and end of the url.
|
24
|
+
slug = slug.chomp("/").reverse.chomp("/").reverse
|
25
|
+
|
26
|
+
@page = ::Blogaze::Models::Page[:slug => slug]
|
27
|
+
|
28
|
+
# Check if the page exists, if not render the
|
29
|
+
# not found page.
|
30
|
+
if !@page.respond_to?('title')
|
31
|
+
respond(view_file('pages/notfound'))
|
32
|
+
else
|
33
|
+
@title = "#{@page.title} - #{@settings[:title]}"
|
34
|
+
respond(view_file('pages/page'))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end # Pages
|
38
|
+
end # Controllers
|
39
|
+
end # Blogaze
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Blogaze
|
3
|
+
# Copyright (C) 2011-2013 Jack Polgar
|
4
|
+
#
|
5
|
+
# Blogaze is released under the BSD 3-clause license.
|
6
|
+
# @license http://opensource.org/licenses/BSD-3-Clause
|
7
|
+
#
|
8
|
+
|
9
|
+
module Blogaze
|
10
|
+
module Controllers
|
11
|
+
class Posts < Controller
|
12
|
+
map '/posts'
|
13
|
+
helper :paginate
|
14
|
+
|
15
|
+
##
|
16
|
+
# View post
|
17
|
+
#
|
18
|
+
def view(slug)
|
19
|
+
@post = ::Blogaze::Models::Post.filter(:slug => slug).first
|
20
|
+
return respond(view_file('pages/notfound')) if @post.nil?
|
21
|
+
|
22
|
+
# Set title
|
23
|
+
@title = @post.title + ' - ' + @settings[:title]
|
24
|
+
|
25
|
+
# Instead of a controller just for comment creation
|
26
|
+
# let's just put it here, that way we can display
|
27
|
+
# errors with the new comment form.
|
28
|
+
if request[:new_comment].to_i == 1
|
29
|
+
data = {
|
30
|
+
:post_id => @post.id,
|
31
|
+
:author => request[:author],
|
32
|
+
:body => request[:body],
|
33
|
+
:in_moderation => @settings[:moderate_comments]
|
34
|
+
}
|
35
|
+
@comment = ::Blogaze::Models::Comment.new(data)
|
36
|
+
if @comment.valid?
|
37
|
+
@comment.save
|
38
|
+
flash[:success] = "Your comment has been posted"
|
39
|
+
redirect @post.href
|
40
|
+
end
|
41
|
+
else
|
42
|
+
@comment = ::Blogaze::Models::Comment.new
|
43
|
+
end
|
44
|
+
|
45
|
+
respond(view_file('posts/view'))
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Lists posts belonging to the tag.
|
50
|
+
#
|
51
|
+
def tag(slug, page = 1)
|
52
|
+
@tag = ::Blogaze::Models::Tag[:slug => slug]
|
53
|
+
return respond(view_file('pages/notfound')) if @tag.nil?
|
54
|
+
|
55
|
+
# Get relationships with posts and put the post IDs
|
56
|
+
# into an array for use when selecting posts to be
|
57
|
+
# paginated.
|
58
|
+
post_ids = []
|
59
|
+
relations = ::Blogaze::Models::TagsRelationship.where(:object_type => 'post', :tag_id => @tag.id)
|
60
|
+
relations.each do |rel|
|
61
|
+
# Due to object_id being a Ruby method, we need to
|
62
|
+
# get the object ID the alternative way.
|
63
|
+
post_ids.push rel[:object_id]
|
64
|
+
end
|
65
|
+
|
66
|
+
puts post_ids
|
67
|
+
|
68
|
+
# Get the data and paginate it.
|
69
|
+
data = ::Blogaze::Models::Post.where(:id => post_ids).order(:published_at.desc)
|
70
|
+
puts data.sql
|
71
|
+
@posts = paginate(data, :limit => @settings[:posts_per_page].to_i, :page => page.to_i)
|
72
|
+
|
73
|
+
respond(view_file(:index))
|
74
|
+
end
|
75
|
+
end # Posts
|
76
|
+
end # Controllers
|
77
|
+
end # Blogaze
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#
|
2
|
+
# Blogaze
|
3
|
+
# Copyright (C) 2011-2013 Jack Polgar
|
4
|
+
#
|
5
|
+
# Blogaze is released under the BSD 3-clause license.
|
6
|
+
# @license http://opensource.org/licenses/BSD-3-Clause
|
7
|
+
#
|
8
|
+
|
9
|
+
module Blogaze
|
10
|
+
module Controllers
|
11
|
+
class Sessions < Controller
|
12
|
+
map '/sessions'
|
13
|
+
|
14
|
+
##
|
15
|
+
# Login page
|
16
|
+
#
|
17
|
+
def new
|
18
|
+
@title = "Login - #{@settings[:title]}"
|
19
|
+
respond(view_file('sessions/new'))
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Create session
|
24
|
+
#
|
25
|
+
def create
|
26
|
+
@title = "Login - #{@settings[:title]}"
|
27
|
+
@get_user = ::Blogaze::Models::User[:username => request[:username]]
|
28
|
+
|
29
|
+
if @get_user.respond_to?('password') and @get_user.password == Digest::SHA1.hexdigest(request[:password])
|
30
|
+
session[:logged_in] = true
|
31
|
+
session[:user_id] = @get_user.id
|
32
|
+
redirect Ramaze.options.prefix
|
33
|
+
else
|
34
|
+
@login_error = true
|
35
|
+
end
|
36
|
+
|
37
|
+
respond(view_file('sessions/new'))
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Logout
|
42
|
+
#
|
43
|
+
def destroy
|
44
|
+
session.delete(:logged_in)
|
45
|
+
session.delete(:user_id)
|
46
|
+
redirect Ramaze.options.prefix
|
47
|
+
end
|
48
|
+
end # Sessions
|
49
|
+
end # Controllers
|
50
|
+
end # Blogaze
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# Blogaze
|
3
|
+
# Copyright (C) 2011-2013 Jack Polgar
|
4
|
+
#
|
5
|
+
# Blogaze is released under the BSD 3-clause license.
|
6
|
+
# @license http://opensource.org/licenses/BSD-3-Clause
|
7
|
+
#
|
8
|
+
|
9
|
+
module Blogaze
|
10
|
+
module Controllers
|
11
|
+
class Users < Controller
|
12
|
+
map '/users'
|
13
|
+
|
14
|
+
def new
|
15
|
+
@title = "Register - #{@settings[:title]}"
|
16
|
+
@user = ::Blogaze::Models::User.new
|
17
|
+
respond(view_file('users/new'))
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
@title = "Register - #{@settings[:title]}"
|
22
|
+
data = {
|
23
|
+
:username => request[:username],
|
24
|
+
:password => request[:password],
|
25
|
+
:email => request[:email],
|
26
|
+
:group_id => 3
|
27
|
+
}
|
28
|
+
|
29
|
+
@user = ::Blogaze::Models::User.new(data)
|
30
|
+
|
31
|
+
if @user.valid?
|
32
|
+
@user.save
|
33
|
+
flash[:success] = "Account created, you may now login"
|
34
|
+
redirect '/login'
|
35
|
+
else
|
36
|
+
respond(view_file('users/new'))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end # Users
|
40
|
+
end # Controllers
|
41
|
+
end # Blogaze
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Blogaze
|
3
|
+
# Copyright (C) 2011-2013 Jack Polgar
|
4
|
+
#
|
5
|
+
# Blogaze is released under the BSD 3-clause license.
|
6
|
+
# @license http://opensource.org/licenses/BSD-3-Clause
|
7
|
+
#
|
8
|
+
|
9
|
+
module Blogaze
|
10
|
+
module Models
|
11
|
+
class Comment < Sequel::Model
|
12
|
+
plugin :validation_helpers
|
13
|
+
|
14
|
+
many_to_one :post
|
15
|
+
|
16
|
+
def validate
|
17
|
+
validates_presence [:post_id, :author, :body]
|
18
|
+
validates_integer :post_id
|
19
|
+
end
|
20
|
+
|
21
|
+
def before_create
|
22
|
+
super
|
23
|
+
self.created_at = Time.now.to_i
|
24
|
+
self.updated_at = 0
|
25
|
+
end
|
26
|
+
end # Comment
|
27
|
+
end # Models
|
28
|
+
end # Blogaze
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# Blogaze
|
3
|
+
# Copyright (C) 2011-2013 Jack Polgar
|
4
|
+
#
|
5
|
+
# Blogaze is released under the BSD 3-clause license.
|
6
|
+
# @license http://opensource.org/licenses/BSD-3-Clause
|
7
|
+
#
|
8
|
+
|
9
|
+
module Blogaze
|
10
|
+
module Models
|
11
|
+
class Page < Sequel::Model
|
12
|
+
plugin :validation_helpers
|
13
|
+
|
14
|
+
def validate
|
15
|
+
validates_presence [:title, :slug, :body]
|
16
|
+
end
|
17
|
+
|
18
|
+
def before_create
|
19
|
+
super
|
20
|
+
self.created_at = Time.now.to_i
|
21
|
+
self.updated_at = 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def before_save
|
25
|
+
self.updated_at = Time.now.to_i
|
26
|
+
end
|
27
|
+
end # Page
|
28
|
+
end # Models
|
29
|
+
end # Blogaze
|
@@ -0,0 +1,95 @@
|
|
1
|
+
#
|
2
|
+
# Blogaze
|
3
|
+
# Copyright (C) 2011-2013 Jack Polgar
|
4
|
+
#
|
5
|
+
# Blogaze is released under the BSD 3-clause license.
|
6
|
+
# @license http://opensource.org/licenses/BSD-3-Clause
|
7
|
+
#
|
8
|
+
|
9
|
+
module Blogaze
|
10
|
+
module Models
|
11
|
+
class Post < Sequel::Model
|
12
|
+
attr_accessor :post_tags
|
13
|
+
plugin :validation_helpers
|
14
|
+
|
15
|
+
many_to_one :user
|
16
|
+
one_to_many :comments do |cmt|
|
17
|
+
cmt.filter{in_moderation < 1}
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Returns the URI to the post.
|
22
|
+
#
|
23
|
+
def href
|
24
|
+
return '/' + Time.at(self.published_at).year.to_s + '/' + Time.at(self.published_at).month.to_s + '/' + self.slug
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Returns an array of the posts tags.
|
29
|
+
#
|
30
|
+
def tags
|
31
|
+
tags = []
|
32
|
+
relationships = ::Blogaze::Models::TagsRelationship.where(:object_id => self.id, :object_type => 'post')
|
33
|
+
relationships.each do |rel|
|
34
|
+
tags.push rel.tag
|
35
|
+
end
|
36
|
+
|
37
|
+
return tags
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Returns the partial body of the post.
|
42
|
+
#
|
43
|
+
def body_partial
|
44
|
+
body = self.body.split('<!-- MORE -->')
|
45
|
+
return body[0]
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate
|
49
|
+
validates_presence [:title, :body, :user_id]
|
50
|
+
validates_integer :user_id
|
51
|
+
end
|
52
|
+
|
53
|
+
def before_create
|
54
|
+
super
|
55
|
+
self.slug = Innate::Helper::CGI.u(self.title.scan(/\w+/).join('-')).downcase
|
56
|
+
self.created_at = Time.now.to_i
|
57
|
+
self.published_at = Time.now.to_i
|
58
|
+
self.updated_at = 0
|
59
|
+
end
|
60
|
+
|
61
|
+
def before_save
|
62
|
+
self.slug = Innate::Helper::CGI.u(self.title.scan(/\w+/).join('-')).downcase
|
63
|
+
self.updated_at = Time.now.to_i
|
64
|
+
end
|
65
|
+
|
66
|
+
def after_save
|
67
|
+
process_tags
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def process_tags
|
73
|
+
# Names of tags, obviously
|
74
|
+
tag_names = []
|
75
|
+
|
76
|
+
# Loop over new tags and create them and the relationships, if needed
|
77
|
+
post_tags.each do |tag|
|
78
|
+
t = Tag.find_or_create(:name => tag.strip)
|
79
|
+
tag_names.push t.name
|
80
|
+
if t and !::Blogaze::Models::TagsRelationship.where(:object_id => id, :object_type => 'post', :tag_id => t.id).first
|
81
|
+
::Blogaze::Models::TagsRelationship.new({ :object_id => id, :object_type => 'post', :tag_id => t.id }).save
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Loop over all tags and delete relationships
|
86
|
+
# for removed tags.
|
87
|
+
tags.each do |tag|
|
88
|
+
if not tag_names.include?(tag.name)
|
89
|
+
::Blogaze::Models::TagsRelationship.where({ :object_id => id, :object_type => 'post', :tag_id => tag.id }).delete
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end # Post
|
94
|
+
end # Models
|
95
|
+
end # Blogaze
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Blogaze
|
3
|
+
# Copyright (C) 2011-2013 Jack Polgar
|
4
|
+
#
|
5
|
+
# Blogaze is released under the BSD 3-clause license.
|
6
|
+
# @license http://opensource.org/licenses/BSD-3-Clause
|
7
|
+
#
|
8
|
+
|
9
|
+
module Blogaze
|
10
|
+
module Models
|
11
|
+
class Tag < Sequel::Model
|
12
|
+
##
|
13
|
+
# Returns the URI to the page
|
14
|
+
# listing posts belonging to the tag.
|
15
|
+
#
|
16
|
+
def href
|
17
|
+
"/tags/#{slug}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def before_save
|
21
|
+
self.slug = Innate::Helper::CGI.u(self.name.scan(/\w+/).join('-')).downcase
|
22
|
+
end
|
23
|
+
end # Tag
|
24
|
+
end # Models
|
25
|
+
end # Blogaze
|