cortex-reaver 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,6 +33,11 @@ module CortexReaver
33
33
  self.config_file = file
34
34
  end
35
35
 
36
+ o.on '-d', '--dump file', 'Dump database' do |file|
37
+ @action = :dump
38
+ @values[:dump_file] = file
39
+ end
40
+
36
41
  o.on '-f', '--force', 'Just do it' do
37
42
  @values[:force] = true
38
43
  end
@@ -49,6 +54,12 @@ module CortexReaver
49
54
  @action = :stop
50
55
  end
51
56
 
57
+ o.on '-l', '--load file', 'Load database' do |file|
58
+ @action = :load
59
+ @values[:load_file] = file
60
+ end
61
+
62
+
52
63
  o.on '-m', '--migrate [version]',
53
64
  'Migrate the database to schema version, or to the latest version' do |version|
54
65
  @action = :migrate
@@ -73,6 +84,70 @@ module CortexReaver
73
84
 
74
85
  # Main
75
86
  case @action
87
+ when :dump
88
+ # Dump the database to disk
89
+
90
+ # Connect to current DB
91
+ reload_config
92
+ setup_db false
93
+ current_version = Sequel::Migrator.get_current_migration_version(db)
94
+
95
+ puts "Using database #{config[:database][:host]}/#{config[:database][:database]}."
96
+
97
+ # Prepare dump file
98
+ file = @values[:dump_file]
99
+ if File.file? file
100
+ exit unless confirm("Overwrite #{File.expand_path(file)} with current Cortex Reaver database?")
101
+ FileUtils.rm file
102
+ end
103
+
104
+ # Connect to dump DB
105
+ dump = Sequel.connect "sqlite:////#{File.expand_path(file)}"
106
+ Sequel::Migrator.apply dump, LIB_DIR/:migrations, current_version
107
+
108
+ # Copy tables
109
+ db.tables.each do |table|
110
+ puts "Table #{table} (#{db[table].count} rows)..."
111
+ dump_table = dump[table]
112
+ db[table].each do |row|
113
+ dump_table << row
114
+ end
115
+ end
116
+
117
+ puts "Dumped database to #{file}."
118
+
119
+ when :load
120
+ # Load an SQLite database from disk.
121
+
122
+ # Connect to dump DB
123
+ file = @values[:load_file]
124
+ dump = Sequel.connect "sqlite:////#{File.expand_path(file)}"
125
+ current_version = Sequel::Migrator.get_current_migration_version(dump)
126
+
127
+ # Connect to current DB
128
+ reload_config
129
+ setup_db false
130
+ puts "Using database #{config[:database][:host]}/#{config[:database][:database]}."
131
+
132
+ unless confirm("Overwrite current database with #{File.expand_path(file)}?")
133
+ exit
134
+ end
135
+
136
+ # Drop current migrations and move to the dump's version
137
+ system($0, '-f', '-m', '0')
138
+ Sequel::Migrator.apply db, LIB_DIR/:migrations, current_version
139
+
140
+ # Copy tables
141
+ dump.tables.each do |table|
142
+ puts "Table #{table} (#{dump[table].count} rows)..."
143
+ db_table = db[table]
144
+ dump[table].each do |row|
145
+ db_table << row
146
+ end
147
+ end
148
+
149
+ puts "Database #{file} loaded."
150
+
76
151
  when :status
77
152
  # Make a quick HTTP request to see how we're doing.
78
153
  require 'open-uri'
@@ -46,6 +46,7 @@ module CortexReaver
46
46
  # Tell Ramaze where to find public files and views
47
47
  Ramaze::Global.public_root = LIB_DIR/:public
48
48
  Ramaze::Global.view_root = config[:view_root]
49
+ Ramaze::Global.compile = config[:compile_views]
49
50
 
50
51
  # Check directories
51
52
  if config[:public_root] and not File.directory? config[:public_root]
@@ -127,7 +128,7 @@ module CortexReaver
127
128
  begin
128
129
  stop
129
130
  # Wait for Cortex Reaver to finish, and for the port to become available.
130
- sleep 5
131
+ sleep 2
131
132
  ensure
132
133
  start
133
134
  end
@@ -144,6 +145,7 @@ module CortexReaver
144
145
 
145
146
  # Run Ramaze
146
147
  Ramaze.startup(
148
+ :force => true,
147
149
  :adapter => config[:adapter],
148
150
  :host => config[:host],
149
151
  :port => config[:port]
@@ -212,14 +214,14 @@ module CortexReaver
212
214
  setup
213
215
 
214
216
  # Check port availability
215
- begin
216
- socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
217
- sockaddr = Socket.pack_sockaddr_in(*[config[:port], config[:host]])
218
- socket.bind(sockaddr)
219
- socket.close
220
- rescue => e
221
- abort "Unable to bind to port #{config[:host]}:#{config[:port]} (#{e})"
222
- end
217
+ # begin
218
+ # socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
219
+ # sockaddr = Socket.pack_sockaddr_in(*[config[:port], config[:host]])
220
+ # socket.bind(sockaddr)
221
+ # socket.close
222
+ # rescue => e
223
+ # abort "Unable to bind to port #{config[:host]}:#{config[:port]} (#{e})"
224
+ # end
223
225
 
224
226
  if config[:daemon]
225
227
  fork do
@@ -14,11 +14,13 @@ module CortexReaver
14
14
  # :mode - Cortex Reaver mode: either :development or :production
15
15
  # :daemon - Whether to daemonize or not. Defaults to :true if :mode
16
16
  # is :production, otherwise nil.
17
- # :adapter - The Ramaze adapter name (default 'mongrel')
17
+ # :adapter - The Ramaze adapter name (default 'thin')
18
18
  # :host - Host to bind to
19
19
  # :port - Port to bind to (default 7000)
20
20
  # :pidfile - Process ID file for this server. Defaults to
21
21
  # HOME_DIR/cortex_reaver_<host>_<port>.pid
22
+ # :compile_views - Whether to cache compiled view templates. Defaults to
23
+ # true in production mode.
22
24
  #
23
25
  # Site configuration options
24
26
  # :site = {
@@ -37,7 +39,7 @@ module CortexReaver
37
39
  self[:view_root] = File.join(CortexReaver::LIB_DIR, 'view')
38
40
  self[:log_root] = File.join(CortexReaver::HOME_DIR, 'log')
39
41
  self[:mode] = :production
40
- self[:adapter] = 'mongrel'
42
+ self[:adapter] = 'thin'
41
43
  self[:host] = nil
42
44
  self[:port] = 7000
43
45
 
@@ -62,6 +64,9 @@ module CortexReaver
62
64
 
63
65
  # Daemon mode
64
66
  self[:daemon] ||= true if self[:mode] == :production
67
+
68
+ # Compile views
69
+ self[:compile_views] ||= true if self[:mode] == :production
65
70
  end
66
71
  end
67
72
  end
@@ -8,7 +8,8 @@ module CortexReaver
8
8
  template :new, :form
9
9
  engine :Erubis
10
10
 
11
- helper :error,
11
+ helper :cache,
12
+ :error,
12
13
  :auth,
13
14
  :form,
14
15
  :workflow,
@@ -18,6 +19,8 @@ module CortexReaver
18
19
  :crud,
19
20
  :feeds
20
21
 
22
+ cache :index, :ttl => 60
23
+
21
24
  on_save do |comment, request|
22
25
  comment.title = request[:title]
23
26
  comment.body = request[:body]
@@ -102,6 +105,9 @@ module CortexReaver
102
105
  # Save
103
106
  raise unless @comment.save
104
107
 
108
+ # Clear action cache
109
+ action_cache.delete '/index'
110
+
105
111
  flash[:notice] = "Your comment (<a href=\"##{@comment.url.gsub(/.*#/, '')}\">#{h @comment.title}</a>) has been posted."
106
112
  redirect @comment.parent.url
107
113
  end
@@ -0,0 +1,10 @@
1
+ module CortexReaver
2
+ class DocumentationController < Ramaze::Controller
3
+ map '/documentation'
4
+ layout '/text_layout'
5
+ engine :Erubis
6
+
7
+ def formatting
8
+ end
9
+ end
10
+ end
@@ -9,7 +9,8 @@ module CortexReaver
9
9
  template :new, :form
10
10
  engine :Erubis
11
11
 
12
- helper :error,
12
+ helper :cache,
13
+ :error,
13
14
  :auth,
14
15
  :form,
15
16
  :workflow,
@@ -21,6 +22,8 @@ module CortexReaver
21
22
  :attachments,
22
23
  :feeds
23
24
 
25
+ cache :index, :ttl => 60
26
+
24
27
  on_second_save do |journal, request|
25
28
  journal.tags = request[:tags]
26
29
  add_attachments(journal, request[:attachments])
@@ -4,9 +4,20 @@ module CortexReaver
4
4
  class MainController < Ramaze::Controller
5
5
  map '/'
6
6
  layout '/text_layout'
7
- helper :workflow, :auth, :error, :navigation, :date, :tags, :form, :feeds
7
+ helper :cache,
8
+ :workflow,
9
+ :auth,
10
+ :error,
11
+ :navigation,
12
+ :date,
13
+ :tags,
14
+ :form,
15
+ :feeds
16
+
8
17
  engine :Erubis
9
18
 
19
+ cache :index, :ttl => 60
20
+
10
21
  # the index action is called automatically when no other action is specified
11
22
  def index(id = nil)
12
23
  if id and @page = Page.get(id)
@@ -44,6 +55,11 @@ module CortexReaver
44
55
  end
45
56
  end
46
57
 
58
+ # TODO: We don't implement a collective ATOM feed. Yet.
59
+ def atom
60
+ error_404
61
+ end
62
+
47
63
  private
48
64
 
49
65
  # the string returned at the end of the function is used as the html body
@@ -12,7 +12,8 @@ module CortexReaver
12
12
  template :new, :form
13
13
  engine :Erubis
14
14
 
15
- helper :error,
15
+ helper :cache,
16
+ :error,
16
17
  :auth,
17
18
  :form,
18
19
  :workflow,
@@ -25,6 +26,7 @@ module CortexReaver
25
26
  :photographs,
26
27
  :feeds
27
28
 
29
+ cache :index, :ttl => 60
28
30
 
29
31
  on_save do |photograph, request|
30
32
  photograph.title = request[:title]
@@ -8,7 +8,8 @@ module CortexReaver
8
8
  template :new, :form
9
9
  engine :Erubis
10
10
 
11
- helper :error,
11
+ helper :cache,
12
+ :error,
12
13
  :auth,
13
14
  :form,
14
15
  :workflow,
@@ -20,6 +21,8 @@ module CortexReaver
20
21
  :attachments,
21
22
  :feeds
22
23
 
24
+ cache :index, :ttl => 60
25
+
23
26
  on_second_save do |project, request|
24
27
  project.tags = request[:tags]
25
28
  add_attachments(project, request[:attachments])
@@ -8,7 +8,8 @@ module CortexReaver
8
8
  template :new, :form
9
9
  engine :Erubis
10
10
 
11
- helper :error,
11
+ helper :cache,
12
+ :error,
12
13
  :auth,
13
14
  :form,
14
15
  :workflow,
@@ -16,6 +17,9 @@ module CortexReaver
16
17
  :canonical,
17
18
  :crud
18
19
 
20
+ cache :index, :ttl => 60
21
+ cache :show, :ttl => 60
22
+
19
23
  on_save do |tag, request|
20
24
  tag.title = request[:title]
21
25
  tag.name = Tag.canonicalize request[:name], tag.id
@@ -224,6 +224,11 @@ module Ramaze
224
224
  raise unless @model.save
225
225
  end
226
226
 
227
+ # Invalidate caches
228
+ if respond_to? :action_cache
229
+ action_cache.clear
230
+ end
231
+
227
232
  flash[:notice] = "Updated #{model_class.to_s.demodulize.downcase} #{h @model.to_s}."
228
233
  redirect @model.url
229
234
  end
@@ -4,7 +4,7 @@ module Ramaze
4
4
  # lists that controller's recent elements by yielding a block with
5
5
  # each record and a builder object for the feed.
6
6
  #
7
- # Requires crud.
7
+ # Requires crud. Will attempt to cache feeds if the cache helper is available.
8
8
  module Feeds
9
9
  require 'builder'
10
10
 
@@ -19,6 +19,10 @@ module Ramaze
19
19
  def self.for_feed_block
20
20
  @for_feed_block
21
21
  end
22
+
23
+ if base.respond_to? :cache
24
+ cache :atom, :ttl => 300
25
+ end
22
26
  end
23
27
  end
24
28
 
@@ -28,7 +32,7 @@ module Ramaze
28
32
 
29
33
  private
30
34
 
31
- def atom_builder(params = {:model_class => self.model_class})
35
+ def atom_builder(params = {:model_class => self.class.const_get('MODEL')})
32
36
  response['Content-Type'] = 'application/atom+xml'
33
37
 
34
38
  x = Builder::XmlMarkup.new(:indent => 2)
@@ -41,11 +45,15 @@ module Ramaze
41
45
  recent = params[:recent] || model_class.recent
42
46
 
43
47
  # Find update time
44
- updated = recent.first.updated_on.xmlschema
48
+ if first = recent.first
49
+ updated = first.updated_on.xmlschema
50
+ else
51
+ updated = Time.now.xmlschema
52
+ end
45
53
 
46
54
  x.feed(:xmlns => 'http://www.w3.org/2005/Atom') do
47
55
  x.id = model_class.url
48
- x.title CortexReaver.config.name + ' - ' + model_class.to_s.demodulize.titleize
56
+ x.title "#{CortexReaver.config[:name]} - #{model_class.to_s.demodulize.titleize}"
49
57
  # x.subtitle
50
58
  x.updated updated
51
59
  x.link :href => model_class.url
@@ -73,7 +73,7 @@ module CortexReaver
73
73
  :title => 'About Cortex Reaver',
74
74
  :body => <<EOF
75
75
  <p>Cortex Reaver is a blog engine designed for managing photographs, projects,
76
- journal entries, and more, with support for tags, comments, and ratings. Cortex
76
+ journal entries, and more, with support for tags and comments. Cortex
77
77
  Reaver is written in <a href="http://ruby-lang.org">Ruby</a> using <a
78
78
  href="http://ramaze.net">Ramaze</a>, uses the <a
79
79
  href="http://sequel.rubyforge.org/">Sequel</a> database toolkit and the <a
@@ -1,9 +1,5 @@
1
1
  module CortexReaver
2
2
  class Project < Sequel::Model(:projects)
3
- def self.url
4
- '/projects'
5
- end
6
-
7
3
  include CortexReaver::Model::Timestamps
8
4
  include CortexReaver::Model::CachedRendering
9
5
  include CortexReaver::Model::Renderer
@@ -26,6 +22,10 @@ module CortexReaver
26
22
 
27
23
  render :body
28
24
 
25
+ def self.atom_url
26
+ '/projects/atom'
27
+ end
28
+
29
29
  def self.get(id)
30
30
  self[:name => id] || self[id]
31
31
  end
@@ -34,6 +34,10 @@ module CortexReaver
34
34
  reverse_order(:updated_on).limit(16)
35
35
  end
36
36
 
37
+ def self.url
38
+ '/projects'
39
+ end
40
+
37
41
  def atom_url
38
42
  '/projects/atom/' + name
39
43
  end
@@ -1,6 +1,6 @@
1
1
  module CortexReaver
2
2
  APP_NAME = 'Cortex Reaver'
3
- APP_VERSION = '0.0.3'
3
+ APP_VERSION = '0.0.4'
4
4
  APP_AUTHOR = 'aphyr'
5
5
  APP_EMAIL = 'aphyr@aphyr.com'
6
6
  APP_URL = 'http://aphyr.com'
@@ -0,0 +1,64 @@
1
+ <div class="documentation">
2
+ <h2>Cortex Reaver Formatting</h2>
3
+
4
+ <p>Cortex Reaver will pass through all HTML in the body of a text. Hence, you
5
+ can specify paragraphs, block-quotes, insertions and deletions, headings, and
6
+ so forth using plain HTML. However, there are also some shortcuts for your
7
+ convenience.</p>
8
+
9
+ <h3>Markdown</h3>
10
+
11
+ <p>All posts are automatically formatted with <a
12
+ href="http://daringfireball.net/projects/markdown/basics">Markdown</a>,
13
+ which transforms common plain-text conventions to HTML.</p>
14
+
15
+ <ul>
16
+ <li>Headings are specified by underlining with the equals sign (=) and the dash (-).</li>
17
+ <li>Paragraphs are delineated by a blank line between blocks of text.</li>
18
+ <li>Surrounding text with underscores (_) and asterisks (*) denotes emphasis.</li>
19
+ <li>Asterisks, pluses, and dashes (*, +, -) all create unordered lists.</li>
20
+ <li>Numbers (no matter what their order) followed by periods, yield ordered lists.</li>
21
+ <li>Indenting with the right angle bracket (&gt;) gives a blockquote.</li>
22
+ </ul>
23
+
24
+ <h3>Attachments</h3>
25
+
26
+ <p>To reference an attachment hacker.jpg, use a macro like:</p>
27
+
28
+ <code>[[hacker.jpg]]</code>
29
+
30
+ <p>This will create a link to the attachment with that name. You can give an
31
+ optional name for the link, which will be shown instead of the filename, used
32
+ for descriptions of images, and so forth.</p>
33
+
34
+ <code>[[hacker.jpg][A pathetic creature of meat and bone.]]</code>
35
+
36
+ <p>A variety of attachment macros are available.</p>
37
+
38
+ <code>
39
+ [[link:hacker.jpg]]&nbsp;&nbsp;=&gt; An HTML link to the attachment.<br />
40
+ [[image:hacker.jpg]]&nbsp;=&gt; An inline image.<br />
41
+ [[url:hacker.jpg]]&nbsp;&nbsp;=&gt; The URL for the attachment.
42
+ </code>
43
+
44
+ <p>The url macro is especially useful when you want additional control:</p>
45
+
46
+ <code>
47
+ &lt;img src="[[url:hacker.jpg]]" style="width: 40%; float: left;" /&gt;
48
+ </code>
49
+
50
+ <h3>Code</h3>
51
+
52
+ <p>Cortex Reaver escapes code using HTML entities, and if you specify a
53
+ language, can use <a href="http://coderay.rubychan.de/">CodeRay</a> to format
54
+ syntax.</p>
55
+
56
+ <code>
57
+ &lt;cr:code lang="ruby"&gt;
58
+ &nbsp;&nbsp;class &lt;&lt; self
59
+ &lt;/cr:code&gt;
60
+ </code>
61
+
62
+ <p>Cortex Reaver won't do anything to ordinary &lt;code&gt; tags, however, it
63
+ will avoid applying Markdown to anything inside them.</p>
64
+ </div>
@@ -6,7 +6,7 @@
6
6
  <%= form_p :title, :model => @journal %>
7
7
  <%= live_name_field @journal %>
8
8
  <%= live_tags_field @journal %>
9
- <%= form_p :body, :model => @journal, :type => 'textarea' %>
9
+ <%= form_p :body, :model => @journal, :type => 'textarea', :description => 'Body (<a href="/documentation/formatting" />Formatting Help</a>)' %>
10
10
  <%= attachment_form @journal %>
11
11
  <input type="submit" name="submit" />
12
12
  </form>
@@ -38,10 +38,9 @@
38
38
  # Defaults to true in production mode, false in development mode.
39
39
  # :daemon: true
40
40
 
41
- # Ramaze host, port, and adapter. Defaults to nil (listens on all interfaces), mongrel,
42
- # and port 7000.
41
+ # Ramaze host, port, and adapter. Defaults to nil (listens on all interfaces), htin, and port 7000.
43
42
  # :host: 127.0.0.1
44
- # :adapter: 'mongrel'
43
+ # :adapter: 'thin'
45
44
  # :port: 7000
46
45
 
47
46
  # Process ID file: stores each Cortex Reaver's process ID, so you can control it later.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cortex-reaver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - aphyr
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-18 00:00:00 -08:00
12
+ date: 2008-12-21 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -73,14 +73,14 @@ dependencies:
73
73
  version: 2.7.1
74
74
  version:
75
75
  - !ruby/object:Gem::Dependency
76
- name: mongrel
76
+ name: thin
77
77
  type: :runtime
78
78
  version_requirement:
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ~>
82
82
  - !ruby/object:Gem::Version
83
- version: 1.1.5
83
+ version: 1.0.0
84
84
  version:
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: exifr
@@ -137,6 +137,7 @@ files:
137
137
  - lib/cortex_reaver/controller/user.rb
138
138
  - lib/cortex_reaver/controller/main.rb
139
139
  - lib/cortex_reaver/controller/journal.rb
140
+ - lib/cortex_reaver/controller/documentation.rb
140
141
  - lib/cortex_reaver/controller/photograph.rb
141
142
  - lib/cortex_reaver/controller/page.rb
142
143
  - lib/cortex_reaver/controller/tag.rb
@@ -149,6 +150,7 @@ files:
149
150
  - lib/cortex_reaver/support/timestamps.rb
150
151
  - lib/cortex_reaver/support/renderer.rb
151
152
  - lib/cortex_reaver/support/canonical.rb
153
+ - lib/cortex_reaver/support/renderers
152
154
  - lib/cortex_reaver/support/pagination.rb
153
155
  - lib/cortex_reaver/view
154
156
  - lib/cortex_reaver/view/users
@@ -195,6 +197,8 @@ files:
195
197
  - lib/cortex_reaver/view/journals/short.rhtml
196
198
  - lib/cortex_reaver/view/journals/form.rhtml
197
199
  - lib/cortex_reaver/view/blank_layout.rhtml
200
+ - lib/cortex_reaver/view/documentation
201
+ - lib/cortex_reaver/view/documentation/formatting.rhtml
198
202
  - lib/cortex_reaver/model
199
203
  - lib/cortex_reaver/model/comment.rb
200
204
  - lib/cortex_reaver/model/project.rb