cortex-reaver 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/LICENSE +25 -0
  2. data/README +48 -0
  3. data/bin/console +11 -0
  4. data/bin/cortex_reaver +110 -0
  5. data/bin/import.rb +78 -0
  6. data/lib/cortex_reaver.rb +114 -0
  7. data/lib/cortex_reaver/config.rb +21 -0
  8. data/lib/cortex_reaver/controller/comment.rb +113 -0
  9. data/lib/cortex_reaver/controller/config.rb +14 -0
  10. data/lib/cortex_reaver/controller/journal.rb +40 -0
  11. data/lib/cortex_reaver/controller/main.rb +56 -0
  12. data/lib/cortex_reaver/controller/page.rb +34 -0
  13. data/lib/cortex_reaver/controller/photograph.rb +45 -0
  14. data/lib/cortex_reaver/controller/project.rb +40 -0
  15. data/lib/cortex_reaver/controller/tag.rb +67 -0
  16. data/lib/cortex_reaver/controller/user.rb +71 -0
  17. data/lib/cortex_reaver/helper/activity.rb +9 -0
  18. data/lib/cortex_reaver/helper/attachments.rb +139 -0
  19. data/lib/cortex_reaver/helper/auth.rb +45 -0
  20. data/lib/cortex_reaver/helper/canonical.rb +55 -0
  21. data/lib/cortex_reaver/helper/crud.rb +317 -0
  22. data/lib/cortex_reaver/helper/date.rb +29 -0
  23. data/lib/cortex_reaver/helper/error.rb +14 -0
  24. data/lib/cortex_reaver/helper/feeds.rb +88 -0
  25. data/lib/cortex_reaver/helper/form.rb +114 -0
  26. data/lib/cortex_reaver/helper/navigation.rb +142 -0
  27. data/lib/cortex_reaver/helper/photographs.rb +25 -0
  28. data/lib/cortex_reaver/helper/tags.rb +47 -0
  29. data/lib/cortex_reaver/helper/workflow.rb +27 -0
  30. data/lib/cortex_reaver/migrations/001_users.rb +24 -0
  31. data/lib/cortex_reaver/migrations/002_pages.rb +29 -0
  32. data/lib/cortex_reaver/migrations/003_journals.rb +26 -0
  33. data/lib/cortex_reaver/migrations/004_photographs.rb +24 -0
  34. data/lib/cortex_reaver/migrations/005_projects.rb +27 -0
  35. data/lib/cortex_reaver/migrations/006_tags.rb +64 -0
  36. data/lib/cortex_reaver/migrations/007_comments.rb +40 -0
  37. data/lib/cortex_reaver/migrations/008_config.rb +23 -0
  38. data/lib/cortex_reaver/model/comment.rb +109 -0
  39. data/lib/cortex_reaver/model/journal.rb +53 -0
  40. data/lib/cortex_reaver/model/page.rb +87 -0
  41. data/lib/cortex_reaver/model/photograph.rb +133 -0
  42. data/lib/cortex_reaver/model/project.rb +49 -0
  43. data/lib/cortex_reaver/model/tag.rb +72 -0
  44. data/lib/cortex_reaver/model/user.rb +147 -0
  45. data/lib/cortex_reaver/public/css/admin.css +45 -0
  46. data/lib/cortex_reaver/public/css/custom.css +0 -0
  47. data/lib/cortex_reaver/public/css/form.css +51 -0
  48. data/lib/cortex_reaver/public/css/main.css +325 -0
  49. data/lib/cortex_reaver/public/css/photo.css +113 -0
  50. data/lib/cortex_reaver/public/css/ramaze_error.css +90 -0
  51. data/lib/cortex_reaver/public/css/text.css +25 -0
  52. data/lib/cortex_reaver/public/dispatch.fcgi +11 -0
  53. data/lib/cortex_reaver/public/images/CortexReaver.gif +0 -0
  54. data/lib/cortex_reaver/public/images/atom-xml-icon.png +0 -0
  55. data/lib/cortex_reaver/public/images/body.png +0 -0
  56. data/lib/cortex_reaver/public/images/border_bottom.png +0 -0
  57. data/lib/cortex_reaver/public/images/border_bottom_left.png +0 -0
  58. data/lib/cortex_reaver/public/images/border_bottom_right.png +0 -0
  59. data/lib/cortex_reaver/public/images/border_left.png +0 -0
  60. data/lib/cortex_reaver/public/images/border_right.png +0 -0
  61. data/lib/cortex_reaver/public/images/border_top.png +0 -0
  62. data/lib/cortex_reaver/public/images/border_top_left.png +0 -0
  63. data/lib/cortex_reaver/public/images/border_top_right.png +0 -0
  64. data/lib/cortex_reaver/public/images/comment.gif +0 -0
  65. data/lib/cortex_reaver/public/images/dark_trans.png +0 -0
  66. data/lib/cortex_reaver/public/images/delete.gif +0 -0
  67. data/lib/cortex_reaver/public/images/edit.gif +0 -0
  68. data/lib/cortex_reaver/public/images/header.png +0 -0
  69. data/lib/cortex_reaver/public/images/header.xcf +0 -0
  70. data/lib/cortex_reaver/public/images/header_background.png +0 -0
  71. data/lib/cortex_reaver/public/images/parent.gif +0 -0
  72. data/lib/cortex_reaver/public/images/rss-xml-icon.png +0 -0
  73. data/lib/cortex_reaver/public/images/sections.png +0 -0
  74. data/lib/cortex_reaver/public/images/sections_highlight.png +0 -0
  75. data/lib/cortex_reaver/public/js/admin.js +36 -0
  76. data/lib/cortex_reaver/public/js/cookie.js +27 -0
  77. data/lib/cortex_reaver/public/js/jquery.js +32 -0
  78. data/lib/cortex_reaver/public/js/photo.js +33 -0
  79. data/lib/cortex_reaver/snippets/array.rb +7 -0
  80. data/lib/cortex_reaver/snippets/ramaze/dispatcher/file.rb +37 -0
  81. data/lib/cortex_reaver/support/attachments.rb +235 -0
  82. data/lib/cortex_reaver/support/cached_rendering.rb +79 -0
  83. data/lib/cortex_reaver/support/canonical.rb +107 -0
  84. data/lib/cortex_reaver/support/comments.rb +69 -0
  85. data/lib/cortex_reaver/support/pagination.rb +38 -0
  86. data/lib/cortex_reaver/support/renderer.rb +196 -0
  87. data/lib/cortex_reaver/support/sequenceable.rb +248 -0
  88. data/lib/cortex_reaver/support/tags.rb +108 -0
  89. data/lib/cortex_reaver/support/timestamps.rb +33 -0
  90. data/lib/cortex_reaver/version.rb +8 -0
  91. data/lib/cortex_reaver/view/adminbox.rhtml +56 -0
  92. data/lib/cortex_reaver/view/blank_layout.rhtml +46 -0
  93. data/lib/cortex_reaver/view/comments/comment.rhtml +34 -0
  94. data/lib/cortex_reaver/view/comments/form.rhtml +25 -0
  95. data/lib/cortex_reaver/view/comments/list.rhtml +5 -0
  96. data/lib/cortex_reaver/view/comments/post_form.rhtml +36 -0
  97. data/lib/cortex_reaver/view/config/form.rhtml +10 -0
  98. data/lib/cortex_reaver/view/error.rhtml +72 -0
  99. data/lib/cortex_reaver/view/journals/form.rhtml +12 -0
  100. data/lib/cortex_reaver/view/journals/journal.rhtml +39 -0
  101. data/lib/cortex_reaver/view/journals/list.rhtml +33 -0
  102. data/lib/cortex_reaver/view/journals/short.rhtml +3 -0
  103. data/lib/cortex_reaver/view/journals/show.rhtml +5 -0
  104. data/lib/cortex_reaver/view/pages/form.rhtml +12 -0
  105. data/lib/cortex_reaver/view/pages/list.rhtml +26 -0
  106. data/lib/cortex_reaver/view/pages/show.rhtml +12 -0
  107. data/lib/cortex_reaver/view/photographs/atom_fragment.rhtml +82 -0
  108. data/lib/cortex_reaver/view/photographs/form.rhtml +19 -0
  109. data/lib/cortex_reaver/view/photographs/grid.rhtml +36 -0
  110. data/lib/cortex_reaver/view/photographs/list.rhtml +9 -0
  111. data/lib/cortex_reaver/view/photographs/short.rhtml +3 -0
  112. data/lib/cortex_reaver/view/photographs/show.rhtml +114 -0
  113. data/lib/cortex_reaver/view/photographs/sidebar.rhtml +7 -0
  114. data/lib/cortex_reaver/view/projects/form.rhtml +13 -0
  115. data/lib/cortex_reaver/view/projects/list.rhtml +27 -0
  116. data/lib/cortex_reaver/view/projects/show.rhtml +38 -0
  117. data/lib/cortex_reaver/view/tags/form.rhtml +9 -0
  118. data/lib/cortex_reaver/view/tags/list.rhtml +28 -0
  119. data/lib/cortex_reaver/view/tags/show.rhtml +51 -0
  120. data/lib/cortex_reaver/view/text_layout.rhtml +78 -0
  121. data/lib/cortex_reaver/view/users/form.rhtml +16 -0
  122. data/lib/cortex_reaver/view/users/list.rhtml +38 -0
  123. data/lib/cortex_reaver/view/users/login.rhtml +13 -0
  124. data/lib/cortex_reaver/view/users/register.rhtml +13 -0
  125. data/lib/cortex_reaver/view/users/show.rhtml +37 -0
  126. data/lib/cortex_reaver/view/users/user.rhtml +35 -0
  127. data/lib/proto/cortex_reaver.yaml +28 -0
  128. metadata +285 -0
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2008 Aphyr <aphyr@aphyr.com>
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
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name of this project nor the names of its contributors may be
13
+ used to endorse or promote products derived from this software without
14
+ specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README ADDED
@@ -0,0 +1,48 @@
1
+ CORTEX REAVER - A dangerous Ruby blog engine, with a photographic memory.
2
+
3
+ Cortex Reaver is a blog engine for textual journals, photographs, and projects;
4
+ written using Ramaze and Sequel. Supports tags, comments, and simple
5
+ attachments. Features canonically named URLs (/journals/show/a-post-title) with
6
+ conflict resolution, useful formatting modules for content (HTML sanitizing,
7
+ attachment references, BlueCloth, etc), and custom pages.
8
+
9
+ GETTING STARTED
10
+
11
+ Dependencies
12
+
13
+ First, you'll need a database. For MySQL:
14
+
15
+ create database cortex_reaver;
16
+ grant all privileges on cortex_reaver.* to 'cortex_reaver'@'localhost'
17
+ identified by 'some-password' with grant option;
18
+
19
+ You'll need a YAML configuration file to define Cortex Reaver's configuration.
20
+ See proto/cortex_reaver.yaml. If no config file is specified on the command
21
+ line, Cortex Reaver assumes you mean cortex_reaver.yaml in the working
22
+ directory. Copy lib/proto/cortex_reaver.yaml to a fresh directory, and run
23
+
24
+ bin/cortex_reaver -m -c path/to/cortex_reaver.yaml
25
+
26
+ To wipe the database and set up a fresh schema. Then run
27
+
28
+ bin/cortex_reaver -s -c path/to/cortex_reaver.yaml
29
+
30
+ To start the server. Cortex Reaver runs on port 7000 by default, and uses the
31
+ Mongrel adapter; you can change both of those in your configuration file.
32
+
33
+ When you visit your new site, hit control-x (or visit /users/login) to bring up
34
+ a login prompt. The default username and password are both 'shodan'. Then start
35
+ posting journals, photographs, projects, and pages!
36
+
37
+ Presumably you'll want to start changing images, stylesheets, etc. around. Just
38
+ create a directory called 'public' and specify its path in your config file.
39
+ Anything in that directory overrides Cortex Reaver's default public files.
40
+
41
+ CREDITS
42
+
43
+ I am indebted to the good folks of #sequel and #ramaze for their many
44
+ suggestions in writing Cortex Reaver, and also to Ryan Grove
45
+ (http://wonko.com), the author of the excellent (and very similar) blog system
46
+ Thoth, for invaluable advice and code. Cortex Reaver should have been a fork
47
+ of Thoth, but my schema is just too complex for the changes to be maintainable
48
+ going forward.
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/cortex_reaver'
4
+ require 'irb'
5
+
6
+ CortexReaver.setup ARGV.first
7
+ include CortexReaver
8
+
9
+ # Don't let ARGV hit IRB, or it will try to run it!
10
+ ARGV.clear
11
+ IRB.start
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'optparse'
5
+ require 'ramaze'
6
+ require __DIR__ + '/../lib/cortex_reaver'
7
+
8
+ module CortexReaver
9
+ # Asks a question and returns a true_false answer
10
+ def self.confirm(question)
11
+ return true if @values[:force]
12
+
13
+ puts question + " (yes/no)"
14
+ print '> '
15
+ STDOUT.flush
16
+
17
+ if STDIN.gets.strip =~ /^y(?:es)?/i
18
+ true
19
+ else
20
+ false
21
+ end
22
+ end
23
+
24
+ # Parse options
25
+ @values = {}
26
+ parser = OptionParser.new do |o|
27
+ o.on '-c', '--config file', 'Configuration file' do |file|
28
+ @values[:config_file] = file
29
+ end
30
+
31
+ o.on '-f', '--force', 'Just do it' do
32
+ @values[:force] = true
33
+ end
34
+
35
+ o.on '-h', '--help', 'Show help' do
36
+ @action = :help
37
+ end
38
+
39
+ o.on '-s', '--start',
40
+ 'Start the CortexReaver server.' do
41
+ @action = :start
42
+ end
43
+
44
+ o.on '-m', '--migrate [version]',
45
+ 'Migrate the database to schema version, or to the latest version.' do |version|
46
+ @action = :migrate
47
+ @values[:schema_version] = version ? version.to_i : nil
48
+ end
49
+
50
+ o.on '-r', '--reset',
51
+ 'Wipes the database and sets up a clean copy of the latest version.' do
52
+ @action = :reset
53
+ end
54
+ end
55
+
56
+ parser.parse! ARGV
57
+
58
+ # Main
59
+ case @action
60
+ when :migrate
61
+ version = @values[:schema_version]
62
+
63
+ self.config_file = @values[:config_file]
64
+ self.reload_config
65
+ self.setup_db
66
+
67
+ puts "Using database #{config[:database][:host]}/#{config[:database][:database]}."
68
+
69
+ current_version = Sequel::Migrator.get_current_migration_version(db)
70
+ latest_version = Sequel::Migrator.latest_migration_version(LIB_DIR/:migrations)
71
+
72
+ if version == current_version and current_version == latest_version
73
+ puts "The database is already at the latest version (#{latest_version})."
74
+ exit
75
+ elsif version == current_version
76
+ puts "The database is already at version #{version}."
77
+ exit
78
+ end
79
+
80
+ if version == 0
81
+ message = "You are migrating to version 0. This will drop your cortex_reaver database! Are you sure you want to do this?"
82
+ elsif version
83
+ message = "Ready to migrate from version #{current_version} to version #{version}?"
84
+ else
85
+ message = "Ready to migrate from version #{current_version} to latest version (#{latest_version})?"
86
+ end
87
+
88
+ if confirm message
89
+ puts "Migrating database from version #{current_version} to version #{version}..."
90
+ Sequel::Migrator.apply(db, LIB_DIR/:migrations, version)
91
+ puts "Done."
92
+ else
93
+ exit
94
+ end
95
+
96
+ when :reset
97
+ if confirm "Are you sure you wish to wipe the database?"
98
+ # Strangely, calling Migrator.apply to go down and then up doesn't seem to work. :-/
99
+ system($0, '-f', '-m', '0')
100
+ system($0, '-f', '-m')
101
+ end
102
+
103
+ when :start
104
+ self.config_file = @values[:config_file]
105
+ start
106
+
107
+ else
108
+ abort("Unknown action: #{@action}")
109
+ end
110
+ end
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/ruby
2
+
3
+ puts `#{File.dirname(__FILE__)}/cortex_reaver -rf #{ARGV.first}`
4
+
5
+ require File.dirname(__FILE__) + '/../lib/cortex_reaver'
6
+
7
+ CortexReaver.setup ARGV.first
8
+
9
+ c = Sequel.connect('mysql://cortex_reaver:RyReajOuc7@localhost/cortex_reaver')
10
+ f = Sequel.connect('mysql://cortex_reaver:RyReajOuc7@localhost/fiachran')
11
+
12
+ # Journals
13
+ puts "Journals..."
14
+ f[:journals].each do |journal|
15
+ journal[:user_id] = journal.delete :author_id
16
+ journal[:name] = Journal.canonicalize journal[:title]
17
+ c[:journals] << journal
18
+ end
19
+
20
+ # Projects
21
+ puts "Projects..."
22
+ f[:projects].each do |project|
23
+ project[:user_id] = project.delete :author_id
24
+ project[:name] = Project.canonicalize project[:title]
25
+ c[:projects] << project
26
+ end
27
+
28
+ # Photos
29
+ puts "Photographs..."
30
+ f[:photographs].each do |photograph|
31
+ photograph[:user_id] = photograph.delete :author_id
32
+ photograph[:name] = Photograph.canonicalize photograph[:title]
33
+ c[:photographs] << photograph
34
+ end
35
+
36
+ # Comments
37
+ puts "Comments..."
38
+ f[:comments].each do |comment|
39
+ if comment[:email] == 'aphyr@aphyr.com'
40
+ comment[:user_id] = 1
41
+ end
42
+ comment[:name] = comment.delete :author
43
+ c[:comments] << comment
44
+ end
45
+
46
+ # Tags
47
+ puts "Tags..."
48
+ f[:tags].each do |tag|
49
+ tag[:title] = tag[:name]
50
+ tag[:name] = Tag.canonicalize tag[:name]
51
+ c[:tags] << tag
52
+ end
53
+
54
+ [:journals_tags, :projects_tags, :photographs_tags].each do |t|
55
+ f[t].each do |r|
56
+ c[t] << r
57
+ end
58
+ end
59
+
60
+
61
+ puts "Fixing blank comment titles"
62
+ Comment.infer_blank_titles
63
+
64
+ puts "Fixing tag counts"
65
+ Tag.filter({:name => ''} | {:title => ''}).all.each do |tag|
66
+ tag.delete
67
+ end
68
+ Tag.refresh_counts
69
+
70
+ puts "Refreshing comment counts..."
71
+ Journal.refresh_comment_counts
72
+ Photograph.refresh_comment_counts
73
+ Project.refresh_comment_counts
74
+
75
+ puts "Refreshing cached render fields..."
76
+ Journal.refresh_render_caches
77
+ Project.refresh_render_caches
78
+ Comment.refresh_render_caches
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/ruby
2
+
3
+ begin
4
+ require 'rubygems'
5
+ require 'ramaze'
6
+ require 'sequel'
7
+ require 'yaml'
8
+ rescue LoadError => e
9
+ puts e
10
+ puts "You probably need to install some packages Cortex Reaver needs. Try:
11
+ apt-get install librmagick-ruby libmysql-ruby;
12
+ gem install mongrel ramaze sequel yaml erubis BlueCloth rmagick exifr hpricot builder syntax;"
13
+ exit 255
14
+ end
15
+
16
+ module CortexReaver
17
+ ROOT = File.expand_path(__DIR__/'..')
18
+ LIB_DIR = ROOT/:lib/:cortex_reaver
19
+
20
+ # We need the configuration class before everything.
21
+ require LIB_DIR/:config
22
+
23
+ # Returns the site configuration
24
+ def self.config
25
+ @config
26
+ end
27
+
28
+ def self.config_file
29
+ @config_file || File.join(Dir.pwd, 'cortex_reaver.yaml')
30
+ end
31
+
32
+ def self.config_file=(file)
33
+ @config_file = file
34
+ end
35
+
36
+ # Sets the configuration file and reloads
37
+ def self.configure(file = nil)
38
+ if file
39
+ self.config_file = file
40
+ end
41
+ reload_config
42
+ end
43
+
44
+ def self.db
45
+ @db
46
+ end
47
+
48
+ # Load libraries
49
+ def self.load
50
+ # Prepare Ramaze
51
+ Ramaze::Global.public_root = LIB_DIR/:public
52
+ Ramaze::Global.view_root = config[:view_root]
53
+
54
+ # Load controllers and models
55
+ acquire LIB_DIR/:snippets/'**'/'*'
56
+ acquire LIB_DIR/:support/'*'
57
+ acquire LIB_DIR/:model/'*'
58
+ acquire LIB_DIR/:helper/'*'
59
+ acquire LIB_DIR/:controller/'*'
60
+ acquire LIB_DIR/'**'/'*'
61
+ end
62
+
63
+ # Reloads the site configuration
64
+ def self.reload_config
65
+ @config = CortexReaver::Config.new(config_file)
66
+ end
67
+
68
+ def self.start
69
+ # Load configuration
70
+ reload_config
71
+
72
+ # Connect to db
73
+ setup_db
74
+
75
+ # Load library
76
+ self.load
77
+
78
+ # Go!
79
+ Ramaze.start :adapter => config[:adapter], :port => config[:port]
80
+ end
81
+
82
+ # Load CortexReaver environment; do everything except start Ramaze
83
+ def self.setup(file)
84
+ # Load config
85
+ @config_file = file
86
+ reload_config
87
+
88
+ # Connect to DB
89
+ setup_db
90
+
91
+ # Load library
92
+ self.load
93
+ end
94
+
95
+ # Connect to DB
96
+ def self.setup_db
97
+ unless config
98
+ raise RuntimeError.new("no configuration available!")
99
+ end
100
+
101
+ unless (string = config[:database]).is_a? String
102
+ d = config[:database]
103
+ string = "#{d[:driver]}://#{d[:user]}:#{d[:password]}@#{d[:host]}/#{d[:database]}"
104
+ end
105
+
106
+ @db = Sequel.connect(string)
107
+ end
108
+
109
+ # Disconnect from DB
110
+ def self.shutdown_db
111
+ @db.disconnect
112
+ @db = nil
113
+ end
114
+ end
@@ -0,0 +1,21 @@
1
+ module CortexReaver
2
+ # Contains site-specific configuration information for a CortexReaver site.
3
+ class Config < Hash
4
+ # Pass a YAML file with configuration options. At a minimum, it should specify
5
+ # database = {:proto, :username, :pasword, :host, :database}
6
+ # or database = "sequel_connect_string"
7
+ def initialize(file)
8
+ # Defaults
9
+ self[:public_root] = File.join(CortexReaver::LIB_DIR, 'public')
10
+ self[:view_root] = File.join(CortexReaver::LIB_DIR, 'view')
11
+ self[:adapter] = 'mongrel'
12
+ self[:port] = 7000
13
+
14
+ begin
15
+ self.merge!(YAML.load(File.read(file)))
16
+ rescue => e
17
+ raise RuntimeError.new("unable to load local configuration file #{file}: (#{e.message})")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,113 @@
1
+ module CortexReaver
2
+ class CommentController < Ramaze::Controller
3
+ MODEL = Comment
4
+
5
+ map '/comments'
6
+ layout '/text_layout'
7
+ template :edit, :form
8
+ template :new, :form
9
+ engine :Erubis
10
+
11
+ helper :error,
12
+ :auth,
13
+ :form,
14
+ :workflow,
15
+ :navigation,
16
+ :date,
17
+ :canonical,
18
+ :crud,
19
+ :feeds
20
+
21
+ on_save do |comment, request|
22
+ comment.title = request[:title]
23
+ comment.body = request[:body]
24
+ comment.comment_id = request[:comment_id]
25
+ comment.journal_id = request[:journal_id]
26
+ comment.photograph_id = request[:photograph_id]
27
+ comment.project_id = request[:project_id]
28
+ end
29
+
30
+ on_create do |comment, request|
31
+ # User-specific properties
32
+ if session[:user]
33
+ # A user is logged in.
34
+ comment.user = session[:user]
35
+ else
36
+ # Save the anonymous comment.
37
+ comment.name = request[:name].blank? ? nil : request[:name]
38
+ comment.email = request[:email].blank? ? nil : request[:email]
39
+ comment.http = request[:http].blank? ? nil : request[:http]
40
+ end
41
+ end
42
+
43
+ for_feed do |comment, x|
44
+ x.content comment.body_cache, :type => 'html'
45
+ end
46
+
47
+ # We only really care about tracking recent comments.
48
+ def page(page)
49
+ @title = "Recent Comments"
50
+ @comments = Comment.order(:created_on).reverse.limit(16)
51
+
52
+ render_template :list
53
+ end
54
+
55
+ def post
56
+ unless request.post?
57
+ flash[:error] = "No comment to post!"
58
+ redirect_to R(:/)
59
+ end
60
+
61
+ begin
62
+ # Create comment
63
+ CortexReaver.db.transaction do
64
+ @comment = Comment.new
65
+
66
+ @comment.title = request[:title]
67
+ @comment.body = request[:body]
68
+ @comment.comment_id = request[:comment_id]
69
+ @comment.journal_id = request[:journal_id]
70
+ @comment.photograph_id = request[:photograph_id]
71
+ @comment.project_id = request[:project_id]
72
+
73
+ if session[:user]
74
+ # A user is logged in. Use their account.
75
+ @comment.user = session[:user]
76
+ else
77
+ # Use anonymous info, if it won't conflict.
78
+ if User.filter(:email => request[:email]).count > 0
79
+ # Conflicts!
80
+ flash[:error] = "Sorry, that email address belongs to a registered user. Would you like to <a href=\"/user/login\">log in</a>? Your comment will still be here when you get back."
81
+
82
+ # Save comment and go back to the parent.
83
+ session[:pending_comment] = @comment
84
+ redirect comment.parent.url
85
+ else
86
+ # Okay, set anonymous info
87
+ @comment.name = request[:name] unless request[:name].blank?
88
+ @comment.email = request[:email] unless request[:email].blank?
89
+ @comment.http = request[:http] unless request[:http].blank?
90
+ end
91
+ end
92
+
93
+ # Save
94
+ raise unless @comment.save
95
+
96
+ flash[:notice] = "Your comment (<a href=\"##{@comment.url.gsub(/.*#/, '')}\">#{h @comment.title}</a>) has been posted."
97
+ redirect @comment.parent.url
98
+ end
99
+ rescue => e
100
+ # An error occurred
101
+ Ramaze::Log.error e.inspect + e.backtrace.join("\n")
102
+ flash[:error] = "We couldn't post your comment."
103
+
104
+ if @comment.parent
105
+ session[:pending_comment] = @comment
106
+ redirect @comment.parent.url + '#post-comment'
107
+ else
108
+ redirect R(:/)
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end