Skip to content

Commit

Permalink
refactoring:
Browse files Browse the repository at this point in the history
- move history to plugins/history
- move views to lib/olelo
- load locales from virtualfs
- remove :request around hook
  • Loading branch information
minad committed Nov 12, 2012
1 parent 6cb73e4 commit ad572d2
Show file tree
Hide file tree
Showing 55 changed files with 459 additions and 298 deletions.
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ file('static/script.js' => Dir.glob('static/script/*.js')) { |t| shrink_js(t) }
file('plugins/treeview/script.js' => Dir.glob('plugins/treeview/script/*.js')) {|t| shrink_js(t) }
file('plugins/misc/fancybox/script.js' => Dir.glob('plugins/misc/fancybox/script/*.js')) {|t| shrink_js(t) }
file('plugins/editor/markup/script.js' => Dir.glob('plugins/editor/markup/script/*.js')) {|t| shrink_js(t) }
file('plugins/history/script.js' => Dir.glob('plugins/history/script/*.js')) {|t| shrink_js(t) }

namespace :gen do
desc('Shrink JS files')
task js: %w(static/script.js plugins/treeview/script.js plugins/misc/fancybox/script.js plugins/editor/markup/script.js)
task js: %w(static/script.js plugins/treeview/script.js plugins/misc/fancybox/script.js plugins/editor/markup/script.js plugins/history/script.js)

desc('Compile CSS files')
task css: %w(static/themes/atlantis/style.css
Expand Down
1 change: 0 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Olelo::Config.instance['app_path'] = app_path
Olelo::Config.instance['config_path'] = ::File.join(app_path, 'config')
Olelo::Config.instance['initializers_path'] = ::File.join(app_path, 'config', 'initializers')
Olelo::Config.instance['plugins_path'] = ::File.join(app_path, 'plugins')
Olelo::Config.instance['views_path'] = ::File.join(app_path, 'views')
Olelo::Config.instance['themes_path'] = ::File.join(app_path, 'static', 'themes')
Olelo::Config.instance['rack.session_secret'] = SecureRandom.hex
Olelo::Config.instance.load!(::File.join(app_path, 'config', 'config.yml.default'))
Expand Down
55 changes: 1 addition & 54 deletions lib/olelo/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Application
attr_reader :page
attr_setter :on_error

has_around_hooks :request, :routing, :action, :login_buttons,
has_around_hooks :routing, :action, :login_buttons,
:edit_buttons, :attributes_buttons, :upload_buttons
has_hooks :auto_login, :render, :menu, :head

Expand Down Expand Up @@ -59,18 +59,6 @@ def initialize(app = nil)
edit_menu.item(:move, href: build_path(page, action: :move), rel: 'nofollow')
edit_menu.item(:delete, href: build_path(page, action: :delete), rel: 'nofollow')
end
history_menu = menu.item(:history, href: build_path(page, action: :history), accesskey: 'h')

if @menu_versions
head = !page.head? && (Olelo::Page.find(page.path) rescue nil)
if page.previous_version || head || page.next_version
history_menu.item(:older, href: build_path(page, original_params.merge(version: page.previous_version)),
accesskey: 'o') if page.previous_version
history_menu.item(:head, href: build_path(page.path, original_params), accesskey: 'c') if head
history_menu.item(:newer, href: build_path(page, original_params.merge(version: page.next_version)),
accesskey: 'n') if page.next_version
end
end
end
end

Expand Down Expand Up @@ -139,29 +127,6 @@ def initialize(app = nil)
render :profile
end

get '/changes/:version(/:path)' do
@page = Page.find!(params[:path])
begin
@diff = page.diff(nil, params[:version])
rescue => ex
Olelo.logger.debug ex
raise NotFound
end
@version = @diff.to
cache_control etag: @version.to_s
render :changes
end

get '/history(/:path)' do
per_page = 30
@page = Page.find!(params[:path])
@page_nr = [params[:page].to_i, 1].max
@history = page.history((@page_nr - 1) * per_page, per_page)
@page_count = @page_nr + @history.length / per_page
cache_control etag: page.etag
render :history
end

get '/move/:path' do
@page = Page.find!(params[:path])
render :move
Expand All @@ -184,23 +149,6 @@ def initialize(app = nil)
end
end

get '/compare/:versions(/:path)', versions: '(?:\w+)\.{2,3}(?:\w+)' do
@page = Page.find!(params[:path])
versions = params[:versions].split(/\.{2,3}/)
begin
@diff = page.diff(versions.first, versions.last)
rescue => ex
Olelo.logger.debug ex
raise NotFound
end
render :compare
end

get '/compare(/:path)' do
versions = params[:versions] || []
redirect build_path(params[:path], action: versions.size < 2 ? :history : "compare/#{versions.first}...#{versions.last}")
end

get '/edit(/:path)' do
@page = Page.find!(params[:path])
flash.info!(:info_binary.t(page: page.title, type: "#{page.mime.comment} (#{page.mime})")) unless page.editable?
Expand Down Expand Up @@ -261,7 +209,6 @@ def post_attributes
end

def show_page
@menu_versions = true
render(:show, locals: {content: page.try(:content)})
end

Expand Down
11 changes: 7 additions & 4 deletions lib/olelo/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ def initialize(logger)

def init_locale
Locale.locale = Config['locale']
Locale.load(File.join(File.dirname(__FILE__), 'locale.yml'))
Locale.add(YAML.load_file(File.join(File.dirname(__FILE__), 'locale.yml')))
end

def init_templates
Templates.enable_caching if Config['production']
Templates.loader = proc do |name|
VirtualFS::Union.new(VirtualFS::Native.new(Config['views_path']),
VirtualFS::Union.new(VirtualFS::Native.new(File.join(File.dirname(__FILE__), 'views')),
*Plugin.loaded.map(&:virtual_fs)).read(name)
end
end

def init_plugins
# Load locales provided by plugins
Plugin.after(:load) { Locale.load(File.join(File.dirname(file), 'locale.yml')) }
# Load locale provided by plugin
Plugin.after(:load) do
locale = virtual_fs.read('locale.yml') rescue nil
Locale.add(YAML.load(locale)) if locale
end

# Configure plugin system
Plugin.disabled = Config['disabled_plugins'].to_a
Expand Down
19 changes: 7 additions & 12 deletions lib/olelo/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,22 @@ module Olelo
module Locale
@locale = nil
@translations = Hash.with_indifferent_access
@loaded = []

class << self
attr_accessor :locale

# Load locale from file
# Add locale hash
#
# A locale is a yamlfile which maps
# A locale is a hash which maps
# keys to strings.
#
# @param [String] file name
# @param [Hash] Locale hash
# @return [void]
#
def load(file)
if !@loaded.include?(file) && File.file?(file)
locale = YAML.load_file(file)
@translations.update(locale[$1] || {}) if @locale =~ /^(\w+)(_|-)/
@translations.update(locale[@locale] || {})
@translations.each_value(&:freeze)
@loaded << file
end
def add(locale)
@translations.update(locale[$1] || {}) if @locale =~ /^(\w+)(_|-)/
@translations.update(locale[@locale] || {})
@translations.each_value(&:freeze)
end

# Return translated string for key
Expand Down
36 changes: 0 additions & 36 deletions lib/olelo/locale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ cs_CZ:
attribute_title: 'Titulek'
attributes: 'Atributy'
attributes_edited: 'Atributy stránky %{page} editovány'
author: 'Autor'
binary_file: 'Binární soubor'
cancel: 'Zrušit'
change_password: 'Změnit heslo'
changes: 'Změny'
changes_of: 'Změny stránky %{page}'
changes_saved: 'Změny uloženy'
comment: 'Komentář'
compare: 'Porovnat %{name}: %{from} → %{to}'
confirm_password: 'Potvrdit heslo'
create_page: 'Vytvořit stránku %{page}'
create_redirect: 'Vytvořit přesměrování'
date: 'Datum'
delete: 'Smazat'
delete_page: 'Smazat stránku %{page}'
deleted: 'Smazáno'
Expand All @@ -35,7 +30,6 @@ cs_CZ:
groups: 'Skupiny'
head: 'Nejnovější'
history: 'Historie'
history_of: 'Historie stránky %{page}'
info_binary: 'Stránka %{page} je binární typ %{type} a nemůže být editována jako textový soubor.'
invalid_email: 'e-mail je neplatný'
invalid_mime_type: 'mime-type je neplatný'
Expand All @@ -48,10 +42,6 @@ cs_CZ:
menu_actions_edit_delete: 'Smazat'
menu_actions_edit_move: 'Přesunout'
menu_actions_edit_new: 'Nová stránka'
menu_actions_history: 'Historie'
menu_actions_history_head: 'Aktuální'
menu_actions_history_newer: 'Novější'
menu_actions_history_older: 'Starší'
menu_actions_view: 'Zobrazit'
move: 'Přesunout'
move_page: 'Přesunout stránku %{page}'
Expand All @@ -66,7 +56,6 @@ cs_CZ:
not_found_title: '404 Not found'
page_moved: 'Stránka %{page} přesunuta do %{destination}.'
page_uploaded: 'Stránka %{page} nahrána'
parents: 'Rodiče'
password: 'Heslo'
passwords_do_not_match: 'Hesla se neshodují'
path: 'Cesta'
Expand Down Expand Up @@ -105,19 +94,14 @@ de:
attribute_title: 'Titel'
attributes: 'Attribute'
attributes_edited: 'Attribute von %{page} bearbeitet'
author: 'Autor'
binary_file: 'Binärdatei'
cancel: 'Abbrechen'
change_password: 'Passwort ändern'
changes: 'Änderungen'
changes_of: 'Änderungen von %{page}'
changes_saved: 'Änderungen gespeichert'
comment: 'Kommentar'
compare: 'Vergleiche %{name}: %{from} → %{to}'
confirm_password: 'Bestätige Passwort'
create_page: 'Neue %{page}'
create_redirect: 'Weiterleitung'
date: 'Datum'
delete: 'Löschen'
delete_page: 'Lösche %{page}'
deleted: 'Gelöscht'
Expand All @@ -133,7 +117,6 @@ de:
groups: 'Gruppen'
head: 'Kopf'
history: 'Historie'
history_of: 'Historie von %{page}'
info_binary: '%{page} ist eine Datei mit dem Typ %{type} und kann nicht wie eine Textdatei bearbeitet werden.'
invalid_email: 'E-Mail ist ungültig'
invalid_mime_type: 'Mime-Typ ist ungültig'
Expand All @@ -146,9 +129,6 @@ de:
menu_actions_edit_delete: 'Löschen'
menu_actions_edit_move: 'Verschieben'
menu_actions_edit_new: 'Neue Seite'
menu_actions_history: 'Historie'
menu_actions_history_newer: 'Neuer'
menu_actions_history_older: 'Älter'
menu_actions_view: 'Ansicht'
move: 'Verschieben'
move_page: 'Verschiebe %{page}'
Expand All @@ -163,7 +143,6 @@ de:
page_edited: '%{page} bearbeitet'
page_moved: '%{page} verschoben nach %{destination}.'
page_uploaded: 'Seite %{page} hochgeladen'
parents: 'Eltern'
password: 'Passwort'
passwords_do_not_match: 'Passwörter stimmen nicht überein'
path: 'Pfad'
Expand Down Expand Up @@ -202,19 +181,14 @@ en:
attribute_title: 'Title'
attributes: 'Attributes'
attributes_edited: 'Attributes of %{page} edited'
author: 'Author'
binary_file: 'Binary file'
cancel: 'Cancel'
change_password: 'Change password'
changes: 'Changes'
changes_of: 'Changes of %{page}'
changes_saved: 'Changes saved'
comment: 'Comment'
compare: 'Compare %{name}: %{from} → %{to}'
confirm_password: 'Confirm password'
create_page: 'Create %{page}'
create_redirect: 'Create redirect'
date: 'Date'
delete: 'Delete'
delete_page: 'Delete %{page}'
deleted: 'Deleted'
Expand All @@ -230,7 +204,6 @@ en:
groups: 'Groups'
head: 'Head'
history: 'History'
history_of: 'History of %{page}'
info_binary: '%{page} is a binary %{type} and cannot be edited like a text file.'
invalid_email: 'E-Mail is invalid'
invalid_mime_type: 'Invalid mime type'
Expand All @@ -253,7 +226,6 @@ en:
page_edited: '%{page} edited'
page_moved: '%{page} moved to %{destination}.'
page_uploaded: 'Page %{page} uploaded'
parents: 'Parents'
password: 'Password'
passwords_do_not_match: 'Passwords do not match'
path: 'Path'
Expand Down Expand Up @@ -292,19 +264,14 @@ fr:
attribute_title: "Titre"
attributes: "Attributs"
attributes_edited: "Attributs de %{page} modifiés"
author: "Auteur"
binary_file: "Fichier binaire"
cancel: "Cancel"
change_password: "Changer de mot de passe"
changes: "Changement"
changes_of: "Chamgements de %{page}"
changes_saved: "Changement enregistrés"
comment: "Commentaire"
compare: "Comparer %{name}: %{from} → %{to}"
confirm_password: "Confirmer le mot de passe"
create_page: "Créer %{page}"
create_redirect: "Créer une redirection"
date: "Date"
delete: "Effacer"
delete_page: "Effacer %{page}"
deleted: "Supprimé"
Expand All @@ -320,7 +287,6 @@ fr:
groups: "Groupes"
head: "Tête"
history: "Historique"
history_of: "Historique de %{page}"
info_binary: "%{page} est un binaire %{type} et ne peut pas être édité comme un fichier texte."
invalid_email: "Courriel invalide"
invalid_mime_type: "Type MIME invalide"
Expand All @@ -330,7 +296,6 @@ fr:
login: "Connexion"
logout: "Déconnexion"
menu_actions_edit_new: "Nouvelle page"
menu_actions_history_newer: "Plus récent"
move: "Déplacer"
move_page: "Déplacer %{page}"
name: "Nom"
Expand All @@ -344,7 +309,6 @@ fr:
page_edited: "%{page} éditée"
page_moved: "%{page} déplacer vers %{destination}."
page_uploaded: "Page %{page} téléversé"
parents: "Parents"
password: "Mot de passe"
passwords_do_not_match: "Les mots de passe ne correspondent pas"
path: "Chemin"
Expand Down
2 changes: 1 addition & 1 deletion lib/olelo/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def call!(env)
@original_params.freeze

catch(:forward) do
with_hooks(:request) { perform! }
perform!
status, header, body = response.finish
return [status, header, request.head? ? [] : body]
end
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 3 additions & 5 deletions plugins/aspects/changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ def call(context, page)
end

Application.hook :head do
%{<link rel="alternate" type="application/atom+xml" title="Sitewide Atom Changelog"
result = %{<link rel="alternate" type="application/atom+xml" title="Sitewide Atom Changelog"
href="#{escape_html build_path('/', aspect: 'changelog', format: 'atom')}"/>
<link rel="alternate" type="application/rss+xml" title="Sitewide RSS Changelog"
href="#{escape_html build_path('/', aspect: 'changelog', format: 'rss')}"/>}
end

Application.hook :head do
%{<link rel="alternate" type="application/atom+xml" title="#{escape_html page.path} Atom Changelog"
result << %{<link rel="alternate" type="application/atom+xml" title="#{escape_html page.path} Atom Changelog"
href="#{escape_html(build_path(page.path, aspect: 'changelog', format: 'atom'))}"/>
<link rel="alternate" type="application/rss+xml" title="#{escape_html page.path} RSS Changelog"
href="#{escape_html(build_path(page.path, aspect: 'changelog', format: 'rss'))}"/>} if page && !page.new? && !page.root?
result
end
Loading

0 comments on commit ad572d2

Please sign in to comment.