olelo 0.9.3 → 0.9.4

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 (92) hide show
  1. data/.travis.yml +4 -0
  2. data/Rakefile +6 -12
  3. data/bin/olelo +13 -8
  4. data/config.ru +21 -15
  5. data/config/aspects.rb +45 -32
  6. data/config/config.yml.default +1 -0
  7. data/config/initializers/00-mime_types.rb +22 -17
  8. data/config/initializers/01-slim.rb +2 -2
  9. data/lib/olelo.rb +1 -8
  10. data/lib/olelo/application.rb +33 -34
  11. data/lib/olelo/attributes.rb +4 -4
  12. data/lib/olelo/extensions.rb +0 -7
  13. data/lib/olelo/helper.rb +13 -25
  14. data/lib/olelo/html_safe.rb +0 -4
  15. data/lib/olelo/locale.yml +6 -3
  16. data/lib/olelo/menu.rb +1 -1
  17. data/lib/olelo/page.rb +21 -18
  18. data/lib/olelo/version.rb +1 -1
  19. data/olelo.gemspec +5 -3
  20. data/plugins/aspects/changelog.rb +5 -5
  21. data/plugins/aspects/documentbrowser.rb +5 -5
  22. data/plugins/{gallery → aspects/gallery}/gallery.css +0 -0
  23. data/plugins/{gallery → aspects/gallery}/gallery.scss +0 -0
  24. data/plugins/{gallery → aspects/gallery}/main.rb +3 -3
  25. data/plugins/aspects/highlight.rb +1 -1
  26. data/plugins/aspects/image.rb +1 -1
  27. data/plugins/aspects/imageinfo.rb +3 -3
  28. data/plugins/aspects/main.rb +21 -21
  29. data/plugins/aspects/pageinfo.rb +2 -2
  30. data/plugins/aspects/source.rb +1 -1
  31. data/plugins/aspects/subpages.rb +7 -7
  32. data/plugins/aspects/text.rb +1 -1
  33. data/plugins/authentication/portal.rb +2 -2
  34. data/plugins/authentication/yamlfile.rb +1 -1
  35. data/plugins/blog/main.rb +10 -10
  36. data/plugins/editor/preview.rb +3 -3
  37. data/plugins/filters/creole.rb +1 -1
  38. data/plugins/filters/editsection.rb +2 -2
  39. data/plugins/filters/html2xml.rb +6 -0
  40. data/plugins/filters/main.rb +1 -1
  41. data/plugins/filters/remind/main.rb +15 -0
  42. data/plugins/filters/remind/rem2html +562 -0
  43. data/plugins/filters/s5/main.rb +1 -1
  44. data/plugins/login/persistent.rb +1 -1
  45. data/plugins/misc/system.rb +4 -0
  46. data/plugins/misc/variables.rb +1 -1
  47. data/plugins/misc/webdav.rb +10 -10
  48. data/plugins/repositories/git_grep.rb +2 -2
  49. data/plugins/repositories/gitrb_repository.rb +10 -10
  50. data/plugins/repositories/rugged_repository.rb +7 -7
  51. data/plugins/tags/code.rb +1 -1
  52. data/plugins/tags/footnotes.rb +4 -3
  53. data/plugins/tags/gist.rb +2 -2
  54. data/plugins/tags/html.rb +11 -11
  55. data/plugins/tags/include.rb +6 -6
  56. data/plugins/tags/main.rb +10 -10
  57. data/plugins/tags/math.rb +2 -2
  58. data/plugins/tags/redirect.rb +3 -3
  59. data/plugins/tags/scripting.rb +12 -12
  60. data/plugins/tags/sort.rb +1 -1
  61. data/plugins/tags/tabs.rb +1 -1
  62. data/plugins/treeview/main.rb +3 -3
  63. data/plugins/treeview/script.js +5 -5
  64. data/plugins/treeview/script/00-jquery.treeview.js +6 -6
  65. data/plugins/treeview/script/init.js +1 -1
  66. data/plugins/utils/assets.rb +4 -4
  67. data/plugins/utils/cache.rb +10 -6
  68. data/plugins/utils/store.rb +4 -4
  69. data/static/script.js +124 -126
  70. data/static/script/{02-jquery.js → 01-jquery.js} +0 -0
  71. data/static/script/02-olelo.storage.js +54 -0
  72. data/static/script/10-olelo.historytable.js +2 -2
  73. data/static/script/13-olelo.tabwidget.js +2 -2
  74. data/test/helper.rb +5 -4
  75. data/test/page_test.rb +1 -1
  76. data/test/request_test.rb +42 -38
  77. data/test/string_extensions_test.rb +0 -6
  78. data/test/templates_test.rb +1 -1
  79. data/test/util_test.rb +1 -1
  80. data/views/changes.slim +2 -2
  81. data/views/compare.slim +4 -4
  82. data/views/delete.slim +2 -2
  83. data/views/deleted.slim +1 -1
  84. data/views/edit.slim +31 -26
  85. data/views/history.slim +5 -5
  86. data/views/layout.slim +1 -1
  87. data/views/login.slim +30 -32
  88. data/views/move.slim +3 -3
  89. data/views/profile.slim +2 -2
  90. data/views/show.slim +1 -1
  91. metadata +43 -104
  92. data/static/script/01-jstorage.js +0 -217
@@ -7,7 +7,7 @@ module Olelo
7
7
  include Routing
8
8
  include ApplicationHelper
9
9
 
10
- patterns :path => Page::PATH_PATTERN
10
+ patterns path: Page::PATH_PATTERN
11
11
  attr_reader :page
12
12
  attr_setter :on_error
13
13
 
@@ -31,8 +31,6 @@ module Olelo
31
31
 
32
32
  # Executed before each request
33
33
  before :routing do
34
- Olelo.logger.debug env
35
-
36
34
  User.current = User.find(session[:olelo_user])
37
35
  if !User.current
38
36
  invoke_hook(:auto_login)
@@ -54,23 +52,23 @@ module Olelo
54
52
 
55
53
  hook :menu do |menu|
56
54
  if menu.name == :actions && page && !page.new?
57
- menu.item(:view, :href => build_path(page.path), :accesskey => 'v')
58
- edit_menu = menu.item(:edit, :href => build_path(page, :action => :edit), :accesskey => 'e', :rel => 'nofollow')
59
- edit_menu.item(:new, :href => build_path(page, :action => :new), :accesskey => 'n', :rel => 'nofollow')
55
+ menu.item(:view, href: build_path(page.path), accesskey: 'v')
56
+ edit_menu = menu.item(:edit, href: build_path(page, action: :edit), accesskey: 'e', rel: 'nofollow')
57
+ edit_menu.item(:new, href: build_path(page, action: :new), accesskey: 'n', rel: 'nofollow')
60
58
  if !page.root?
61
- edit_menu.item(:move, :href => build_path(page, :action => :move), :rel => 'nofollow')
62
- edit_menu.item(:delete, :href => build_path(page, :action => :delete), :rel => 'nofollow')
59
+ edit_menu.item(:move, href: build_path(page, action: :move), rel: 'nofollow')
60
+ edit_menu.item(:delete, href: build_path(page, action: :delete), rel: 'nofollow')
63
61
  end
64
- history_menu = menu.item(:history, :href => build_path(page, :action => :history), :accesskey => 'h')
62
+ history_menu = menu.item(:history, href: build_path(page, action: :history), accesskey: 'h')
65
63
 
66
64
  if @menu_versions
67
65
  head = !page.head? && (Olelo::Page.find(page.path) rescue nil)
68
66
  if page.previous_version || head || page.next_version
69
- history_menu.item(:older, :href => build_path(page, original_params.merge(:version => page.previous_version)),
70
- :accesskey => 'o') if page.previous_version
71
- history_menu.item(:head, :href => build_path(page.path, original_params), :accesskey => 'c') if head
72
- history_menu.item(:newer, :href => build_path(page, original_params.merge(:version => page.next_version)),
73
- :accesskey => 'n') if page.next_version
67
+ history_menu.item(:older, href: build_path(page, original_params.merge(version: page.previous_version)),
68
+ accesskey: 'o') if page.previous_version
69
+ history_menu.item(:head, href: build_path(page.path, original_params), accesskey: 'c') if head
70
+ history_menu.item(:newer, href: build_path(page, original_params.merge(version: page.next_version)),
71
+ accesskey: 'n') if page.next_version
74
72
  end
75
73
  end
76
74
  end
@@ -79,8 +77,8 @@ module Olelo
79
77
  # Handle 404s
80
78
  error NotFound do |error|
81
79
  Olelo.logger.debug(error)
82
- cache_control :no_cache => true
83
- halt render(:not_found, :locals => {:error => error})
80
+ cache_control no_cache: true
81
+ halt render(:not_found, locals: {error: error})
84
82
  end
85
83
 
86
84
  error StandardError do |error|
@@ -94,8 +92,8 @@ module Olelo
94
92
  # Show wiki error page
95
93
  error Exception do |error|
96
94
  Olelo.logger.error(error)
97
- cache_control :no_cache => true
98
- halt render(:error, :locals => {:error => error})
95
+ cache_control no_cache: true
96
+ halt render(:error, locals: {error: error})
99
97
  end
100
98
 
101
99
  get '/login' do
@@ -150,7 +148,7 @@ module Olelo
150
148
  raise NotFound
151
149
  end
152
150
  @version = @diff.to
153
- cache_control :version => @version
151
+ cache_control version: @version
154
152
  render :changes
155
153
  end
156
154
 
@@ -162,7 +160,7 @@ module Olelo
162
160
  @history = page.history((@page_nr - 1) * per_page, limit)
163
161
  @page_count = @page_nr + @history.length / per_page
164
162
  @history = @history[0...per_page]
165
- cache_control :version => page.version
163
+ cache_control version: page.version
166
164
  render :history
167
165
  end
168
166
 
@@ -183,12 +181,12 @@ module Olelo
183
181
  destination = params[:destination].cleanpath
184
182
  raise :reserved_path.t if self.class.reserved_path?(destination)
185
183
  page.move(destination)
186
- Page.commit(:page_moved.t(:page => page.path, :destination => destination))
184
+ Page.commit(:page_moved.t(page: page.path, destination: destination))
187
185
  redirect build_path(page.path)
188
186
  end
189
187
  end
190
188
 
191
- get '/compare/:versions(/:path)', :versions => '(?:\w+)\.{2,3}(?:\w+)' do
189
+ get '/compare/:versions(/:path)', versions: '(?:\w+)\.{2,3}(?:\w+)' do
192
190
  @page = Page.find!(params[:path])
193
191
  versions = params[:versions].split(/\.{2,3}/)
194
192
  begin
@@ -202,11 +200,12 @@ module Olelo
202
200
 
203
201
  get '/compare(/:path)' do
204
202
  versions = params[:versions] || []
205
- redirect build_path(params[:path], :action => versions.size < 2 ? :history : "compare/#{versions.first}...#{versions.last}")
203
+ redirect build_path(params[:path], action: versions.size < 2 ? :history : "compare/#{versions.first}...#{versions.last}")
206
204
  end
207
205
 
208
206
  get '/edit(/:path)' do
209
207
  @page = Page.find!(params[:path])
208
+ flash.info!(:info_binary.t(page: page.title, type: "#{page.mime.comment} (#{page.mime})")) unless page.mime.text?
210
209
  render :edit
211
210
  end
212
211
 
@@ -220,7 +219,7 @@ module Olelo
220
219
  def post_edit
221
220
  raise 'No content' if !params[:content]
222
221
  params[:content].gsub!("\r\n", "\n")
223
- message = :page_edited.t(:page => page.title)
222
+ message = :page_edited.t(page: page.title)
224
223
  message << " - #{params[:comment]}" if !params[:comment].blank?
225
224
 
226
225
  page.content = if params[:pos]
@@ -249,7 +248,7 @@ module Olelo
249
248
  errors << :no_changes.t if !page.modified?
250
249
  end
251
250
  page.save
252
- Page.commit(:page_uploaded.t(:page => page.title))
251
+ Page.commit(:page_uploaded.t(page: page.title))
253
252
  end
254
253
 
255
254
  def post_attributes
@@ -260,31 +259,31 @@ module Olelo
260
259
  errors << :no_changes.t if !page.modified?
261
260
  end
262
261
  page.save
263
- Page.commit(:attributes_edited.t(:page => page.title))
262
+ Page.commit(:attributes_edited.t(page: page.title))
264
263
  end
265
264
 
266
265
  def show_page
267
266
  @menu_versions = true
268
- render(:show, :locals => {:content => page.try(:content)})
267
+ render(:show, locals: {content: page.try(:content)})
269
268
  end
270
269
 
271
- get '/(:path)', :tail => true do
270
+ get '/(:path)', tail: true do
272
271
  begin
273
272
  @page = Page.find!(params[:path])
274
- cache_control :version => page.version
273
+ cache_control version: page.version
275
274
  show_page
276
275
  rescue NotFound
277
- redirect build_path(params[:path], :action => :new)
276
+ redirect build_path(params[:path], action: :new)
278
277
  end
279
278
  end
280
279
 
281
280
  get '/version/:version(/:path)' do
282
281
  @page = Page.find!(params[:path], params[:version])
283
- cache_control :version => page.version
282
+ cache_control version: page.version
284
283
  show_page
285
284
  end
286
285
 
287
- post '/(:path)', :tail => true do
286
+ post '/(:path)', tail: true do
288
287
  action, @close = params[:action].to_s.split('-', 2)
289
288
  if respond_to? "post_#{action}"
290
289
  on_error :edit
@@ -306,12 +305,12 @@ module Olelo
306
305
  end
307
306
  end
308
307
 
309
- delete '/:path', :tail => true do
308
+ delete '/:path', tail: true do
310
309
  Page.transaction do
311
310
  @page = Page.find!(params[:path])
312
311
  on_error :delete
313
312
  page.delete
314
- Page.commit(:page_deleted.t(:page => page.path))
313
+ Page.commit(:page_deleted.t(page: page.path))
315
314
  render :deleted
316
315
  end
317
316
  end
@@ -19,12 +19,12 @@ module Olelo
19
19
  end
20
20
 
21
21
  def label
22
- @label ||= Locale.translate(key, :fallback => titlecase(name))
22
+ @label ||= Locale.translate(key, fallback: titlecase(name))
23
23
  end
24
24
 
25
25
  def label_tag
26
26
  type = self.class.name.split('::').last.downcase
27
- title = Locale.translate("type_#{type}", :fallback => titlecase(type))
27
+ title = Locale.translate("type_#{type}", fallback: titlecase(type))
28
28
  %{<label for="#{key}" title="#{escape_html title}">#{escape_html label}</label>}
29
29
  end
30
30
 
@@ -119,7 +119,7 @@ module Olelo
119
119
  def field_tag(attr)
120
120
  %{<input class="observe" type="text" id="#{key}" name="#{key}" value="#{escape_html(values[attr] || attr)}"/>
121
121
  <script type="text/javascript">
122
- $('##{key}').combobox({ source: #{escape_javascript values.values.sort.to_json} });
122
+ $('##{key}').combobox({ source: #{escape_javascript MultiJson.dump(values.values.sort)} });
123
123
  </script>}
124
124
  end
125
125
 
@@ -149,7 +149,7 @@ module Olelo
149
149
  end
150
150
 
151
151
  def label
152
- @label ||= name.blank? ? '' : Locale.translate("group_#{path}", :fallback => titlecase(name))
152
+ @label ||= name.blank? ? '' : Locale.translate("group_#{path}", fallback: titlecase(name))
153
153
  end
154
154
 
155
155
  # Build form for this group
@@ -157,14 +157,7 @@ class Object
157
157
  end
158
158
  end
159
159
 
160
- class NilClass; def blank?; true; end; end
161
- class FalseClass; def blank?; true; end; end
162
- class TrueClass; def blank?; false; end; end
163
-
164
160
  class String
165
- # Faster blank?
166
- alias blank? empty?
167
-
168
161
  # Try to force encoding
169
162
  #
170
163
  # Force encoding of string and revert
@@ -34,11 +34,9 @@ module Olelo
34
34
  env['olelo.flash']
35
35
  end
36
36
 
37
- def flash_messages(action = nil)
38
- if !action || action?(action)
39
- li = [:error, :warn, :info].map {|level| flash[level].to_a.map {|msg| %{<li class="#{level}">#{escape_html msg}</li>} } }.flatten
40
- %{<ul class="flash">#{li.join}</ul>}.html_safe if !li.empty?
41
- end
37
+ def flash_messages
38
+ li = [:error, :warn, :info].map {|level| flash[level].to_a.map {|msg| %{<li class="#{level}">#{escape_html msg}</li>} } }.flatten
39
+ %{<ul class="flash">#{li.join}</ul>}.html_safe if !li.empty?
42
40
  end
43
41
  end
44
42
 
@@ -50,7 +48,7 @@ module Olelo
50
48
  if page
51
49
  render_page(page)
52
50
  else
53
- %{<a href="#{escape_html build_path(path, :action => :new)}">#{escape_html :create_page.t(:page => path)}</a>}
51
+ %{<a href="#{escape_html build_path(path, action: :new)}">#{escape_html :create_page.t(page: path)}</a>}
54
52
  end
55
53
  end
56
54
 
@@ -62,7 +60,7 @@ module Olelo
62
60
  return if page_count <= 1
63
61
  li = []
64
62
  li << if page_nr > 1
65
- %{<a href="#{escape_html build_path(path, options.merge(:page => page_nr - 1))}">&#9666;</a>}
63
+ %{<a href="#{escape_html build_path(path, options.merge(page: page_nr - 1))}">&#9666;</a>}
66
64
  else
67
65
  %{<span class="disabled">&#9666;</span>}
68
66
  end
@@ -76,20 +74,20 @@ module Olelo
76
74
  max = max + 2 < page_count ? max : page_count
77
75
  min = min > 3 ? min : 1
78
76
  if min != 1
79
- li << %{<a href="#{escape_html build_path(path, options.merge(:page => 1))}">1</a>} << %{<span class="ellipsis"/>}
77
+ li << %{<a href="#{escape_html build_path(path, options.merge(page: 1))}">1</a>} << %{<span class="ellipsis"/>}
80
78
  end
81
79
  (min..max).each do |i|
82
80
  li << if i == page_nr
83
81
  %{<span class="current">#{i}</span>}
84
82
  else
85
- %{<a href="#{escape_html build_path(path, options.merge(:page => i))}">#{i}</a>}
83
+ %{<a href="#{escape_html build_path(path, options.merge(page: i))}">#{i}</a>}
86
84
  end
87
85
  end
88
86
  if max != page_count
89
- li << %{<span class="ellipsis"/>} << %{<a href="#{escape_html build_path(path, options.merge(:page => page_count))}">#{page_count}</a>}
87
+ li << %{<span class="ellipsis"/>} << %{<a href="#{escape_html build_path(path, options.merge(page: page_count))}">#{page_count}</a>}
90
88
  end
91
89
  li << if page_nr < page_count
92
- %{<a href="#{escape_html build_path(path, options.merge(:page => page_nr + 1))}">&#9656;</a>}
90
+ %{<a href="#{escape_html build_path(path, options.merge(page: page_nr + 1))}">&#9656;</a>}
93
91
  else
94
92
  %{<span class="disabled">&#9656;</span>}
95
93
  end
@@ -101,8 +99,8 @@ module Olelo
101
99
  end
102
100
 
103
101
  def format_diff(diff)
104
- summary = PatchSummary.new(:links => true)
105
- formatter = PatchFormatter.new(:links => true, :header => true)
102
+ summary = PatchSummary.new(links: true)
103
+ formatter = PatchFormatter.new(links: true, header: true)
106
104
  PatchParser.parse(diff.patch, summary, formatter)
107
105
  (summary.html + formatter.html).html_safe
108
106
  end
@@ -110,11 +108,11 @@ module Olelo
110
108
  def breadcrumbs(page)
111
109
  path = page.try(:path) || ''
112
110
  li = [%{<li>
113
- <a accesskey="z" href="#{escape_html build_path(nil, :version => page)}">#{escape_html :root.t}</a></li>}]
111
+ <a accesskey="z" href="#{escape_html build_path(nil, version: page)}">#{escape_html :root.t}</a></li>}]
114
112
  path.split('/').inject('') do |parent,elem|
115
113
  current = parent/elem
116
114
  li << %{<li>
117
- <a href="#{escape_html build_path(current, :version => page)}">#{escape_html elem}</a></li>}
115
+ <a href="#{escape_html build_path(current, version: page)}">#{escape_html elem}</a></li>}
118
116
  current
119
117
  end
120
118
  ('<ul class="breadcrumbs">' << li.join('<li>/</li>') << '</ul>').html_safe
@@ -141,16 +139,6 @@ module Olelo
141
139
  end
142
140
  '/' + (Config['base_path'] / path)
143
141
  end
144
-
145
- def edit_content(page)
146
- if params[:content]
147
- params[:content]
148
- elsif !(String === page.content) || !valid_xml_chars?(page.content)
149
- :error_binary.t(:page => page.title, :type => "#{page.mime.comment} (#{page.mime})")
150
- else
151
- params[:pos] ? page.content[params[:pos].to_i, params[:len].to_i].to_s : page.content
152
- end
153
- end
154
142
  end
155
143
 
156
144
  module HttpHelper
@@ -19,10 +19,6 @@ class String
19
19
  end
20
20
  end
21
21
 
22
- def html_safe?
23
- false
24
- end
25
-
26
22
  def html_safe
27
23
  HtmlString.new(self)
28
24
  end
@@ -32,13 +32,14 @@ en:
32
32
  edit_page_section: 'Editing #{page} (Section)'
33
33
  email: 'E-Mail'
34
34
  empty_password: 'Empty password'
35
- error_binary: '#{page} is a binary #{type} and cannot be edited like a text file.'
35
+ info_binary: '#{page} is a binary #{type} and cannot be edited like a text file.'
36
36
  error_occurred: 'Oh snap! An error occurred.'
37
37
  file: 'File'
38
38
  groups: 'Groups'
39
39
  history: 'History'
40
40
  history_of: 'History of #{page}'
41
41
  invalid_email: 'E-Mail is invalid'
42
+ invalid_mime_type: 'Invalid mime type'
42
43
  invalid_name: 'Name is invalid'
43
44
  invalid_path: 'Invalid path'
44
45
  last_modified: 'Last modified'
@@ -120,13 +121,14 @@ de:
120
121
  edit_page_section: 'Bearbeite #{page} (Bereich)'
121
122
  email: 'E-Mail'
122
123
  empty_password: 'Leeres Passwort'
123
- error_binary: '#{page} ist eine Datei mit dem Typ #{type} und kann nicht wie eine Textdatei bearbeitet werden.'
124
+ info_binary: '#{page} ist eine Datei mit dem Typ #{type} und kann nicht wie eine Textdatei bearbeitet werden.'
124
125
  error_occurred: 'Hoppla! Es ist ein Fehler aufgetreten.'
125
126
  file: 'Datei'
126
127
  groups: 'Gruppen'
127
128
  history: 'Historie'
128
129
  history_of: 'Historie von #{page}'
129
130
  invalid_email: 'E-Mail ist ungültig'
131
+ invalid_mime_type: 'Mime-Typ ist ungültig'
130
132
  invalid_name: 'Name ist ungültig'
131
133
  invalid_path: 'Ungültiger Pfad'
132
134
  last_modified: 'Letzte Änderung'
@@ -214,13 +216,14 @@ cs_CZ:
214
216
  edit_page_section: 'Editovat #{page} (Sekci)'
215
217
  email: 'e-mail'
216
218
  empty_password: 'Prázdné heslo'
217
- error_binary: 'Stránka #{page} je binární typ #{type} a nemůže být editována jako textový soubor.'
219
+ info_binary: 'Stránka #{page} je binární typ #{type} a nemůže být editována jako textový soubor.'
218
220
  error_occurred: 'Ouvej! Vyskytla se chyba.'
219
221
  file: 'Soubor'
220
222
  groups: 'Skupiny'
221
223
  history: 'Historie'
222
224
  history_of: 'Historie stránky #{page}'
223
225
  invalid_email: 'e-mail je neplatný'
226
+ invalid_mime_type: 'mime-type je neplatný'
224
227
  invalid_name: 'Jméno je neplatné'
225
228
  invalid_path: 'Neplatná cesta'
226
229
  last_modified: 'Poslední modifikace'
@@ -91,7 +91,7 @@ module Olelo
91
91
 
92
92
  def build_menu
93
93
  attrs = options.dup
94
- label = attrs.delete(:label) || Locale.translate("menu_#{path.join('_')}", :fallback => titlecase(name))
94
+ label = attrs.delete(:label) || Locale.translate("menu_#{path.join('_')}", fallback: titlecase(name))
95
95
  klass = [*attrs.delete(:class)].flatten.compact
96
96
  klass = klass.empty? ? '' : %{class="#{klass.join(' ')}" }
97
97
  attrs = attrs.map {|k,v| %{#{k}="#{escape_html v}"} }.join(' ')
@@ -109,7 +109,7 @@ module Olelo
109
109
  raise 'Page is new' if new?
110
110
  destination = destination.to_s.cleanpath
111
111
  Page.check_path(destination)
112
- raise :already_exists.t(:page => destination) if Page.find(destination)
112
+ raise :already_exists.t(page: destination) if Page.find(destination)
113
113
  with_hooks(:move, destination) { repository.move(path, destination) }
114
114
  after_commit {|tree_version| update(destination, tree_version) }
115
115
  end
@@ -158,6 +158,7 @@ module Olelo
158
158
  @attributes = a
159
159
  @mime = nil
160
160
  end
161
+ raise :invalid_mime_type.t if attributes['mime'] && attributes['mime'] != mime.to_s
161
162
  end
162
163
 
163
164
  def saved_content
@@ -181,7 +182,7 @@ module Olelo
181
182
 
182
183
  def save
183
184
  raise 'Page is not head' unless head?
184
- raise :already_exists.t(:page => path) if new? && Page.find(path)
185
+ raise :already_exists.t(page: path) if new? && Page.find(path)
185
186
  with_hooks(:save) do
186
187
  repository.set_content(path, content)
187
188
  repository.set_attributes(path, attributes)
@@ -229,22 +230,24 @@ module Olelo
229
230
  end
230
231
 
231
232
  def detect_mime
232
- return MimeMagic.new(attributes['mime']) if attributes['mime']
233
- Config['mime'].each do |mime|
234
- mime = if mime == 'extension'
235
- MimeMagic.by_extension(extension)
236
- elsif %w(content magic).include?(mime)
237
- if !new?
238
- if content.blank?
239
- children.empty? ? EMPTY_MIME : DIRECTORY_MIME
240
- else
241
- MimeMagic.by_magic(content)
242
- end
243
- end
244
- else
245
- MimeMagic.new(mime)
246
- end
247
- return mime if mime
233
+ [attributes['mime'], *Config['mime'], 'application/octet-stream'].each do |method|
234
+ mime =
235
+ case method
236
+ when nil
237
+ when 'extension'
238
+ MimeMagic.by_extension(extension)
239
+ when 'content', 'magic'
240
+ unless new?
241
+ if content.blank?
242
+ children.empty? ? EMPTY_MIME : DIRECTORY_MIME
243
+ else
244
+ MimeMagic.by_magic(content)
245
+ end
246
+ end
247
+ else
248
+ MimeMagic.new(method)
249
+ end
250
+ return mime if mime && (!mime.text? || valid_xml_chars?(content))
248
251
  end
249
252
  end
250
253