blogaze 0.0.1

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.
Files changed (71) hide show
  1. data/.gitignore +20 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +24 -0
  4. data/README.md +33 -0
  5. data/Rakefile +1 -0
  6. data/bin/blogaze +11 -0
  7. data/blogaze.gemspec +24 -0
  8. data/lib/blogaze/bin/create.rb +55 -0
  9. data/lib/blogaze/bin/default.rb +47 -0
  10. data/lib/blogaze/controller/admin/comments.rb +32 -0
  11. data/lib/blogaze/controller/admin/init.rb +28 -0
  12. data/lib/blogaze/controller/admin/main.rb +20 -0
  13. data/lib/blogaze/controller/admin/pages.rb +75 -0
  14. data/lib/blogaze/controller/admin/posts.rb +103 -0
  15. data/lib/blogaze/controller/admin/settings.rb +33 -0
  16. data/lib/blogaze/controller/init.rb +51 -0
  17. data/lib/blogaze/controller/main.rb +30 -0
  18. data/lib/blogaze/controller/pages.rb +34 -0
  19. data/lib/blogaze/controller/posts.rb +43 -0
  20. data/lib/blogaze/controller/sessions.rb +39 -0
  21. data/lib/blogaze/controller/users.rb +39 -0
  22. data/lib/blogaze/db/migration/001_start.rb +40 -0
  23. data/lib/blogaze/db/migration/002_pages.rb +16 -0
  24. data/lib/blogaze/db/migration/003_pages_on_menu.rb +13 -0
  25. data/lib/blogaze/db/migration/004_comments.rb +17 -0
  26. data/lib/blogaze/db/migration/005_tags.rb +20 -0
  27. data/lib/blogaze/model/comment.rb +26 -0
  28. data/lib/blogaze/model/group.rb +13 -0
  29. data/lib/blogaze/model/init.rb +17 -0
  30. data/lib/blogaze/model/page.rb +27 -0
  31. data/lib/blogaze/model/post.rb +79 -0
  32. data/lib/blogaze/model/tag.rb +19 -0
  33. data/lib/blogaze/model/tags_relationship.rb +13 -0
  34. data/lib/blogaze/model/user.rb +41 -0
  35. data/lib/blogaze/routes.rb +26 -0
  36. data/lib/blogaze/tasks/db.rake +43 -0
  37. data/lib/blogaze/tasks.rb +1 -0
  38. data/lib/blogaze/theme.rb +46 -0
  39. data/lib/blogaze/version.rb +11 -0
  40. data/lib/blogaze.rb +46 -0
  41. data/proto/Rakefile +6 -0
  42. data/proto/app.rb +15 -0
  43. data/proto/config/config.default.rb +11 -0
  44. data/proto/config/database.default.rb +21 -0
  45. data/proto/config.ru +4 -0
  46. data/proto/public/css/ie.css +36 -0
  47. data/proto/public/css/master.less +188 -0
  48. data/proto/public/css/print.css +29 -0
  49. data/proto/public/css/screen.css +265 -0
  50. data/proto/public/js/jquery.js +18 -0
  51. data/proto/public/js/less.js +16 -0
  52. data/proto/start.rb +9 -0
  53. data/proto/themes/default/admin/comments/index.xhtml +23 -0
  54. data/proto/themes/default/admin/index.xhtml +12 -0
  55. data/proto/themes/default/admin/pages/edit.xhtml +30 -0
  56. data/proto/themes/default/admin/pages/index.xhtml +22 -0
  57. data/proto/themes/default/admin/pages/new.xhtml +26 -0
  58. data/proto/themes/default/admin/posts/edit.xhtml +22 -0
  59. data/proto/themes/default/admin/posts/index.xhtml +22 -0
  60. data/proto/themes/default/admin/posts/new.xhtml +22 -0
  61. data/proto/themes/default/admin/settings/index.xhtml +31 -0
  62. data/proto/themes/default/index.xhtml +35 -0
  63. data/proto/themes/default/layouts/admin.xhtml +44 -0
  64. data/proto/themes/default/layouts/default.xhtml +51 -0
  65. data/proto/themes/default/pages/notfound.xhtml +6 -0
  66. data/proto/themes/default/pages/page.xhtml +6 -0
  67. data/proto/themes/default/posts/view.xhtml +53 -0
  68. data/proto/themes/default/sessions/new.xhtml +25 -0
  69. data/proto/themes/default/users/new.xhtml +22 -0
  70. data/proto/themes/default.rb +4 -0
  71. metadata +180 -0
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ proto/config/config.rb
20
+ proto/config/database.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blog.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2011, Jack Polgar
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of Blogaze nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL JACK POLGAR BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ Blogaze
2
+ ========
3
+
4
+ Simple blog powered by the Ramaze framework.
5
+
6
+ WARNING
7
+ -------
8
+
9
+ Blogaze is currently in development, use at your own risk.
10
+
11
+ Setup
12
+ ------
13
+
14
+ 1. Rename the config files in the `config` directory to remove `.default` from the filenames.
15
+ 2. Enter your database information in the `config/database.rb` file.
16
+ 3. Run `rake db:migrate` and `rake db:defaults`
17
+ 4. Run `ruby start.rb` or `thin start` or whatever your preferred way is.
18
+
19
+ The default admin account username is `admin` and the password is `myadmin`.
20
+
21
+ Todo
22
+ ------
23
+
24
+ Things that still need to be done.
25
+
26
+ 1. Post tags
27
+ 2. User manager
28
+ 3. Profile manager
29
+
30
+ Gem?
31
+ ------
32
+
33
+ Someday.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/blogaze ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ require 'blogaze'
3
+ require 'shebang'
4
+
5
+ $:.unshift(__DIR__('../lib')) unless $:.include?(__DIR__('../lib'))
6
+
7
+ require 'blogaze/version'
8
+ require 'blogaze/bin/create'
9
+ require 'blogaze/bin/default'
10
+
11
+ Shebang.run
data/blogaze.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'blogaze/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "blogaze"
8
+ gem.version = Blogaze::VERSION
9
+ gem.authors = ["Jack Polgar"]
10
+ gem.email = ["nrx@nirix.net"]
11
+ gem.summary = 'Blogaze is a simple blog.'
12
+ gem.description = 'Blogaze is a simple blog powered by Ramaze and Sequel.'
13
+ gem.homepage = "http://blogaze.org"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'ramaze', ['~> 2012.12.08']
21
+ gem.add_dependency 'sequel', ['~> 3.43.0']
22
+ gem.add_dependency 'maruku', ['~> 0.6.1']
23
+ gem.add_dependency 'time-lord', ['~> 0.2.5']
24
+ end
@@ -0,0 +1,55 @@
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 Bin
11
+ class Create < Shebang::Command
12
+ command :create
13
+ banner 'Creates the files for a Blogaze installation'
14
+ usage 'blogaze create [DIR]'
15
+
16
+ # Path to the prototype application to use for new installations.
17
+ PROTOTYPE = __DIR__('../../../proto')
18
+
19
+ def index
20
+ if ARGV[0] == '' or ARGV[0].nil?
21
+ puts "Missing argument [NAME]"
22
+ return
23
+ end
24
+
25
+ destination = File.join(Dir.pwd, ARGV[0])
26
+
27
+ if File.directory?(destination) and !option(:f)
28
+ puts "Directory already exists with name: #{ARGV[0]}"
29
+ return
30
+ else
31
+ puts 'Copying files...'
32
+ FileUtils.cp_r(PROTOTYPE, destination)
33
+
34
+ ['config.default.rb', 'database.default.rb'].each do |config|
35
+ FileUtils.mv(destination + "/config/#{config}", destination + "/config/" + config.gsub('.default', ''))
36
+ end
37
+
38
+ puts 'Done.'
39
+ puts
40
+ puts "You will need to enter your database information"
41
+ puts "into the 'config/database.rb' file then run the"
42
+ puts "following commands:"
43
+ puts
44
+ puts " rake db:migrate"
45
+ puts " rake db:defaults"
46
+ puts
47
+ puts "The default admin account is:"
48
+ puts " Username: admin"
49
+ puts " Password: myadmin"
50
+ puts
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,47 @@
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 Bin
11
+ class Default < Shebang::Command
12
+ command :default
13
+ banner 'Blogaze is a simple blog powered by Ramaze.'
14
+ usage 'blogaze [COMMAND]'
15
+
16
+ o :h, :help , 'Shows this help message' , :method => :help
17
+ o :v, :version, 'Shows the current version', :method => :version
18
+
19
+ ##
20
+ # Lists commands.
21
+ #
22
+ def initialize
23
+ super
24
+ puts "Commands"
25
+ puts " blogaze create [NAME] - Create a Blogaze installation in [NAME] directory."
26
+ puts
27
+ end
28
+
29
+ ##
30
+ # Shows help
31
+ #
32
+ def index
33
+ help
34
+ end
35
+
36
+ protected
37
+
38
+ ##
39
+ # Shows version
40
+ #
41
+ def version
42
+ puts Blogaze::VERSION
43
+ exit
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,32 @@
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 Admin
11
+ class Comments < Controller
12
+ map '/admin/comments'
13
+
14
+ def index
15
+ @comments = Comment.all
16
+ respond(view_file('admin/comments/index'))
17
+ end
18
+
19
+ def approve(comment_id)
20
+ Comment[comment_id].update(:in_moderation => 0).save
21
+ flash[:success] = "Comment approved"
22
+ redirect r('/')
23
+ end
24
+
25
+ def delete(comment_id)
26
+ Comment[comment_id].delete
27
+ flash[:success] = "Comment deleted"
28
+ redirect r('/')
29
+ end
30
+ end
31
+ end
32
+ end
@@ -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 Admin
11
+ class Controller < ::Blogaze::Controller
12
+ layout 'admin'
13
+ helper :blue_form
14
+
15
+ def initialize
16
+ super
17
+
18
+ if !@userinfo.respond_to?('group') or !@userinfo.group.is_admin
19
+ redirect '/login'
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ Dir.glob(File.dirname(__FILE__) + '/*.rb').each do |controller|
26
+ require(controller)
27
+ end
28
+ end
@@ -0,0 +1,20 @@
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 Admin
11
+ class Dashboard < Controller
12
+ map '/admin'
13
+
14
+ def index
15
+ @title = "Admin - #{@settings[:title]}"
16
+ respond(view_file('admin/index'))
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,75 @@
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 Admin
11
+ class Pages < Controller
12
+ map '/admin/pages'
13
+
14
+ def index
15
+ @pages = Page.order(:title.asc).all
16
+ respond(view_file('admin/pages/index'))
17
+ end
18
+
19
+ def new
20
+ @title = "New Page - Pages - Admin - #{@settings[:title]}"
21
+ @page = Page.new
22
+ respond(view_file('admin/pages/new'))
23
+ end
24
+
25
+ def create
26
+ @title = "New Page - Pages - Admin - #{@settings[:title]}"
27
+ data = {
28
+ :title => request[:title],
29
+ :slug => request[:slug],
30
+ :body => request[:body],
31
+ :on_menu => request[:on_menu]
32
+ }
33
+
34
+ @page = Page.new(data)
35
+
36
+ if @page.valid?
37
+ @page.save
38
+ flash[:success] = "Page created successfully"
39
+ redirect Pages.r('/')
40
+ else
41
+ respond(view_file('admin/pages/new'))
42
+ end
43
+ end
44
+
45
+ def edit(page_id)
46
+ @title = "Edit Page - Pages - Admin - #{@settings[:title]}"
47
+ @page = Page[page_id]
48
+ respond(view_file('admin/pages/edit'))
49
+ end
50
+
51
+ def save(page_id)
52
+ @title = "Edit Page - Pages - Admin - #{@settings[:title]}"
53
+ @page = Page[page_id]
54
+ @page.title = request[:title]
55
+ @page.slug = request[:slug]
56
+ @page.body = request[:body]
57
+ @page.on_menu = request[:on_menu]
58
+
59
+ if @page.valid?
60
+ @page.save
61
+ flash[:success] = "Page saved successfully"
62
+ redirect Pages.r('/')
63
+ else
64
+ respond(view_file('admin/pages/edit'))
65
+ end
66
+ end
67
+
68
+ def delete(page_id)
69
+ Page[page_id].delete
70
+ flash[:success] = "Page deleted successfully"
71
+ redirect Pages.r('/')
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,103 @@
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 Admin
11
+ class Posts < Controller
12
+ map '/admin/posts'
13
+
14
+ before :new, :create do
15
+ if !@userinfo.group.create_posts
16
+ flash[:error] = "You don't have permission to do that."
17
+ redirect '/login'
18
+ end
19
+ end
20
+
21
+ before :edit, :save do
22
+ if !@userinfo.group.edit_posts
23
+ flash[:error] = "You don't have permission to do that."
24
+ redirect '/login'
25
+ end
26
+ end
27
+
28
+ before :delete do
29
+ if !@userinfo.group.delete_posts
30
+ flash[:error] = "You don't have permission to do that."
31
+ redirect '/login'
32
+ end
33
+ end
34
+
35
+ def index
36
+ @title = "Posts - Admin - #{@settings[:title]}"
37
+ @posts = Post.order(:id.desc).all
38
+ respond(view_file('admin/posts/index'))
39
+ end
40
+
41
+ def new
42
+ @title = "New Post - Posts - Admin - #{@settings[:title]}"
43
+ @post = Post.new
44
+ respond(view_file('admin/posts/new'))
45
+ end
46
+
47
+ def create
48
+ @title = "New Post - Posts - Admin - #{@settings[:title]}"
49
+ data = {
50
+ :title => request[:title],
51
+ :body => request[:body],
52
+ :user_id => @userinfo.id,
53
+ :post_tags => request[:post_tags].is_a?(String) ? request[:post_tags].gsub(', ', ',').split(',') : []
54
+ }
55
+ @post = Post.new(data)
56
+
57
+ if @post.valid?
58
+ @post.save
59
+ flash[:success] = "Post created successfully"
60
+ redirect Posts.r('/')
61
+ else
62
+ @post.post_tags = @post.post_tags.join(', ')
63
+ respond(view_file('admin/posts/new'))
64
+ end
65
+ end
66
+
67
+ def edit(post_id)
68
+ @title = "Edit Post - Posts - Admin - #{@settings[:title]}"
69
+ @post = Post[post_id]
70
+
71
+ post_tags = []
72
+ @post.tags.each do |tag|
73
+ post_tags.push tag.name
74
+ end
75
+ @post.post_tags = post_tags.join(', ')
76
+
77
+ respond(view_file('admin/posts/edit'))
78
+ end
79
+
80
+ def save(post_id)
81
+ @title = "Edit Post - Posts - Admin - #{@settings[:title]}"
82
+ @post = Post[post_id]
83
+ @post.title = request[:title]
84
+ @post.body = request[:body]
85
+ @post.post_tags = request[:post_tags].is_a?(String) ? request[:post_tags].gsub(', ', ',').split(',') : []
86
+
87
+ if @post.valid?
88
+ @post.save
89
+ flash[:success] = "Post saved successfully"
90
+ redirect Posts.r('/')
91
+ else
92
+ respond(view_file('admin/posts/edit'))
93
+ end
94
+ end
95
+
96
+ def delete(post_id)
97
+ Post[post_id].delete
98
+ flash[:success] = "Post deleted successfully"
99
+ redirect Posts.r('/')
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,33 @@
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 Admin
11
+ class Settings < Controller
12
+ map '/admin/settings'
13
+
14
+ def index
15
+ # Get themes
16
+ @themes = []
17
+
18
+ ::Blogaze::Theme.registered.each do |theme|
19
+ @themes.push theme[0].to_s
20
+ end
21
+
22
+ respond(view_file('admin/settings/index'))
23
+ end
24
+
25
+ def save
26
+ request[:settings].each do |setting, value|
27
+ ::Blogaze.database[:settings].where(:setting => setting).update(:value => value)
28
+ end
29
+ redirect Settings.r('/')
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,51 @@
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
+ class Controller < Ramaze::Controller
11
+ layout :default
12
+ helper :xhtml, :maruku, :blue_form, :formatting
13
+ engine :etanni
14
+
15
+ def initialize
16
+ super
17
+
18
+ # Get user info
19
+ if session[:logged_in]
20
+ @userinfo = User[1]
21
+ end
22
+
23
+ # Get settings
24
+ get_settings
25
+
26
+ Theme.use @settings[:theme]
27
+ end
28
+
29
+ def view_file(path)
30
+ path = path.to_s if not path.is_a?(String)
31
+ view_path = File.join(Theme.current.templates, "#{path}.xhtml")
32
+ layout_path = File.join(Theme.current.templates + "/layouts/#{ancestral_trait[:layout]}.xhtml")
33
+ return render_file(layout_path, :content => render_file(view_path))
34
+ end
35
+
36
+ def get_settings
37
+ @settings = {}
38
+ Blogaze.database[:settings].all.each do |setting|
39
+ @settings[setting[:setting].to_sym] = setting[:value]
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ # Here go your requires for subclasses of Controller:
46
+ Dir.glob(File.dirname(__FILE__) + '/*.rb').each do |controller|
47
+ require(controller)
48
+ end
49
+
50
+ # Admin controllers
51
+ require __DIR__('admin/init')
@@ -0,0 +1,30 @@
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
+ class MainController < Controller
11
+ map '/'
12
+ helper :paginate
13
+
14
+ def index(page = 1)
15
+ # Check if we should change the title to include
16
+ # what page we're on.
17
+ if page.to_i > 1
18
+ @title = "Page #{page} - #{@settings[:title]}"
19
+ else
20
+ @title = @settings[:title]
21
+ end
22
+
23
+ # Get the data and paginate it.
24
+ data = Post.order(:published_at.desc)
25
+ @posts = paginate(data, :limit => @settings[:posts_per_page].to_i, :page => page.to_i)
26
+
27
+ respond(view_file(:index))
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,34 @@
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
+ class Pages < Controller
11
+ map '/pages'
12
+
13
+ def view(slug = nil)
14
+ if slug == nil
15
+ slug = request.env["REQUEST_PATH"]
16
+ end
17
+
18
+ # Chomp chomp chomp, let's trim any unwanted
19
+ # forward slashes from the begning and end of the url.
20
+ slug = slug.chomp("/").reverse.chomp("/").reverse
21
+
22
+ @page = Page[:slug => slug]
23
+
24
+ # Check if the page exists, if not render the
25
+ # not found page.
26
+ if !@page.respond_to?('title')
27
+ respond(view_file('pages/notfound'))
28
+ else
29
+ @title = "#{@page.title} - #{@settings[:title]}"
30
+ respond(view_file('pages/page'))
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,43 @@
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
+ class Posts < Controller
11
+ map '/posts'
12
+
13
+ def view(slug)
14
+ @post = Post.filter(:slug => slug).first
15
+ return respond(view_file('pages/notfound')) if @post.nil?
16
+
17
+ # Set title
18
+ @title = @post.title + ' - ' + @settings[:title]
19
+
20
+ # Instead of a controller just for comment creation
21
+ # let's just put it here, that way we can display
22
+ # errors with the new comment form.
23
+ if request[:new_comment].to_i == 1
24
+ data = {
25
+ :post_id => @post.id,
26
+ :author => request[:author],
27
+ :body => request[:body],
28
+ :in_moderation => @settings[:moderate_comments]
29
+ }
30
+ @comment = Comment.new(data)
31
+ if @comment.valid?
32
+ @comment.save
33
+ flash[:success] = "Your comment has been posted"
34
+ redirect @post.href
35
+ end
36
+ else
37
+ @comment = Comment.new
38
+ end
39
+
40
+ respond(view_file('posts/view'))
41
+ end
42
+ end
43
+ end