karottenreibe-qwicky 0.0.2 → 0.0.3

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/HISTORY.markdown CHANGED
@@ -1,3 +1,10 @@
1
+ 0.0.3
2
+ =====
3
+
4
+ * Fixed bugs when permissions were set badly
5
+ * Made Qwicky server-ready (see README)
6
+ * Made settings freezable
7
+
1
8
  0.0.2
2
9
  =====
3
10
 
data/README.markdown CHANGED
@@ -106,7 +106,17 @@ in the directory where your database and settings are
106
106
  stored, qwicky will automatically run it through
107
107
  [Sass] [3] and apply it.
108
108
 
109
- ****
109
+ Running Qwucky on a server
110
+ ==========================
111
+
112
+ ...is almost cruelly simple.
113
+
114
+ 1. Set it up as normal, run it, set your settings.
115
+ 2. Freeze your config file by making _qwicky.yml_ non-writable
116
+ to the user that runs Qwicky.
117
+ 3. Share and enjoy!
118
+
119
+
110
120
 
111
121
  [1]: http://tomayko.com/writings/ruby-markdown-libraries-real-cheap-for-you-two-for-price-of-one
112
122
  "Post about why not to use BlueCloth"
data/bin/qwicky CHANGED
@@ -27,6 +27,10 @@ unless File.exist?(DIR) and File.directory?(DIR)
27
27
  exit -1
28
28
  end
29
29
 
30
+ CONF_FILE = "#{DIR}/qwicky.yml"
31
+ DB_URL = ENV['DATABASE_URL'] || "sqlite3://#{DIR}/qwicky.db"
32
+ STYLES_FILE = "#{DIR}/qwicky.sass"
33
+
30
34
  # Database stuff. {{{1
31
35
  class Page
32
36
  include DataMapper::Resource
@@ -36,8 +40,19 @@ class Page
36
40
  property :content, Text, :nullable => false
37
41
  end
38
42
 
39
- DataMapper::setup(:default, "sqlite3://#{DIR}/qwicky.db")
40
- DataMapper::auto_upgrade!
43
+ DataMapper::setup(:default, DB_URL)
44
+
45
+ begin
46
+ DataMapper::auto_upgrade!
47
+ rescue Sqlite3Error => e
48
+ if e.message =~ %r{unable to open database file}
49
+ $stderr.puts "Unable to create/open `#{DB_URL}'"
50
+ $stderr.puts "Please make database file readable and writable."
51
+ exit -1
52
+ else
53
+ raise
54
+ end
55
+ end
41
56
 
42
57
  # Markup stuff. {{{1
43
58
  module Markup
@@ -182,13 +197,19 @@ class Qwicky
182
197
  attr_accessor :conf, :markup
183
198
 
184
199
  def initialize
185
- FileUtils.touch("#{DIR}/qwicky.yml")
200
+ begin
201
+ FileUtils.touch(CONF_FILE) unless File.exist?(CONF_FILE)
202
+ rescue Errno::EACCES
203
+ $stderr.puts "Unable to create `#{CONF_FILE}'"
204
+ $stderr.puts "Please make directory writable or manually create a readable config file."
205
+ exit -1
206
+ end
186
207
 
187
208
  @conf = {
188
209
  'homepage' => '',
189
210
  'markup' => 'text',
190
211
  }.merge(
191
- open("#{DIR}/qwicky.yml") { |f|
212
+ open(CONF_FILE) { |f|
192
213
  YAML::load(f) || Hash.new
193
214
  }
194
215
  )
@@ -207,12 +228,12 @@ class Qwicky
207
228
 
208
229
  def format text
209
230
  markup.format(text).gsub %r{\[\[([^|\]]+)(\|([^\]]+))?\]\]} do |match|
210
- page = $3 || $1
231
+ page = $1
211
232
  nexist = Page.first(:name => page).nil?
212
233
  klass = nexist ? 'bad' : 'good'
213
- title = nexist ? "Create page #{page}" : "Page #{page}"
234
+ title = nexist ? "Create page `#{page}'" : "Page `#{page}'"
214
235
  link = '/' + page
215
- "<a href=#{link.inspect} title=#{title.inspect} class='#{klass}'>#{$1}</a>"
236
+ "<a href=#{link.inspect} title=#{title.inspect} class='#{klass}'>#{$3 || $1}</a>"
216
237
  end
217
238
  end
218
239
  end
@@ -235,7 +256,7 @@ helpers do
235
256
  end
236
257
 
237
258
  before do
238
- @editable = true
259
+ @configurable = File.writable?(CONF_FILE)
239
260
  end
240
261
 
241
262
  get '/' do
@@ -243,19 +264,25 @@ get '/' do
243
264
  end
244
265
 
245
266
  get '/..settings/?' do
246
- @editable = false
247
- @settings = APP.conf
248
- @title = 'Settings'
249
- @markups = Markup::Markup.markups
250
- haml :settings
267
+ if File.writable?(CONF_FILE)
268
+ @settings = APP.conf
269
+ @title = 'Settings'
270
+ @markups = Markup::Markup.markups
271
+ haml :settings
272
+ else
273
+ haml "%h1 Unfortunately, the config file for this Qwicky instance is not writable!"
274
+ end
251
275
  end
252
276
 
253
277
  post '/..settings/?' do
254
278
  APP.conf.merge!(params[:settings])
255
279
  APP.set_markup
256
- open("#{DIR}/qwicky.yml", 'w') { |f|
257
- f.write(YAML::dump(APP.conf))
258
- }
280
+
281
+ if File.writable?(CONF_FILE)
282
+ open(CONF_FILE, 'w') { |f|
283
+ f.write(YAML::dump(APP.conf))
284
+ }
285
+ end
259
286
 
260
287
  redirect_home
261
288
  end
@@ -273,8 +300,8 @@ end
273
300
  get '/..user.stylesheet.css' do
274
301
  content_type 'text/css'
275
302
 
276
- if File.exist?("#{DIR}/qwicky.sass")
277
- sass open("#{DIR}/qwicky.sass").read()
303
+ if File.exist?(STYLES_FILE)
304
+ sass open(STYLES_FILE).read()
278
305
  else
279
306
  ''
280
307
  end
@@ -288,7 +315,6 @@ get '/..favicon' do
288
315
  end
289
316
 
290
317
  get '/..sitemap' do
291
- @editable = false
292
318
  @title = 'Sitemap'
293
319
  @pages = Page.all.sort_by { |page| page.name }
294
320
  haml :sitemap
@@ -383,9 +409,10 @@ __END__
383
409
  %a{ :title => 'Go the the main page of this wiki', :href => '/' } Home
384
410
  &#8226;
385
411
  %a{ :title => 'View what pages this wiki has', :href => '/..sitemap' } Sitemap
386
- &#8226;
387
- %a{ :title => 'Adjust settings', :href => '/..settings' } Settings
388
- - if @editable
412
+ - if @configurable
413
+ &#8226;
414
+ %a{ :title => 'Adjust settings', :href => '/..settings' } Settings
415
+ - if @page
389
416
  %a.edit{ :title => 'Edit this wiki page', :href => "/#{@page.name}/edit" } Edit
390
417
  %form{ :action => '/', :method => 'get', :onsubmit => 'return changePage()' }
391
418
  %input#location{ :type => 'text', :name => 'location' }
@@ -405,7 +432,7 @@ __END__
405
432
  %br/
406
433
  If you want to contribute, visit
407
434
  %a{ :title => 'Here you can contribute to the project', :href => 'http://wiki.github.com/karottenreibe/qwicky/' } Qwicky's GitHub page
408
- - if @editable
435
+ - if @page
409
436
  %a.edit{ :title => 'Edit this wiki page', :href => "/#{@page.name}/edit" } Edit
410
437
 
411
438
 
data/qwicky.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{qwicky}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Fabian Streitel"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karottenreibe-qwicky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabian Streitel