From 8196c0a6de138a0769eb85406bb634dabc99731b Mon Sep 17 00:00:00 2001 From: dinedine Date: Sun, 22 Aug 2010 00:58:26 +0200 Subject: [PATCH] handle more liquid errors during page editing --- .gitignore | 1 + app/models/extensions/page/parse.rb | 5 ++++- config/locales/default_en.yml | 3 ++- config/locales/default_fr.yml | 3 ++- lib/locomotive/liquid/errors.rb | 5 +++++ lib/locomotive/liquid/tags/extends.rb | 2 -- 6 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 lib/locomotive/liquid/errors.rb diff --git a/.gitignore b/.gitignore index 1971d097..851f8c32 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ tmp/* .rvmrc Capfile config/deploy.rb +perf/test.rb diff --git a/app/models/extensions/page/parse.rb b/app/models/extensions/page/parse.rb index 2018bccc..190d62ce 100644 --- a/app/models/extensions/page/parse.rb +++ b/app/models/extensions/page/parse.rb @@ -26,8 +26,11 @@ module Models @template.root.context.clear self.serialized_template = BSON::Binary.new(Marshal.dump(@template)) + rescue ::Liquid::SyntaxError => error - self.errors.add :template, :liquid_syntax_error + self.errors.add :template, :liquid_syntax + rescue ::Locomotive::Liquid::PageNotFound => error + self.errors.add :template, :liquid_extend end end end diff --git a/config/locales/default_en.yml b/config/locales/default_en.yml index dadec81c..9c664dc6 100644 --- a/config/locales/default_en.yml +++ b/config/locales/default_en.yml @@ -11,7 +11,8 @@ en: protected_page: "You can not remove index or 404 pages" extname_changed: "New file does not have the original extension" array_too_short: "is too small (minimum element number is %{count})" - liquid_syntax_error: "Syntax error in page parts, please check the syntax" + liquid_syntax: "Liquid Syntax error, please check the syntax" + liquid_extend: "The page extends a template which does not exist" attributes: defaults: diff --git a/config/locales/default_fr.yml b/config/locales/default_fr.yml index 8bf88ee0..76eecc8f 100644 --- a/config/locales/default_fr.yml +++ b/config/locales/default_fr.yml @@ -32,7 +32,8 @@ fr: protected_page: "Vous ne pouvez pas supprimer les pages index et 404" extname_changed: "Nouveau fichier n'a pas l'extension original" array_too_short: "est trop petit (le nombre minimum d'éléments est %{count})" - liquid_syntax_error: "Erreur de syntaxe dans les sections de page, veuillez vérifier la syntaxe" + liquid_syntax: "Erreur de syntaxe dans les sections de page, veuillez vérifier la syntaxe" + liquid_extend: "La page étend le contenu d'une page qui n'existe pas" attributes: defaults: diff --git a/lib/locomotive/liquid/errors.rb b/lib/locomotive/liquid/errors.rb new file mode 100644 index 00000000..0f75090b --- /dev/null +++ b/lib/locomotive/liquid/errors.rb @@ -0,0 +1,5 @@ +module Locomotive + module Liquid + class PageNotFound < ::Liquid::Error; end + end +end \ No newline at end of file diff --git a/lib/locomotive/liquid/tags/extends.rb b/lib/locomotive/liquid/tags/extends.rb index 308e31ee..e12a550e 100644 --- a/lib/locomotive/liquid/tags/extends.rb +++ b/lib/locomotive/liquid/tags/extends.rb @@ -3,8 +3,6 @@ module Locomotive module Tags class Extends < ::Liquid::Extends - class PageNotFound < ::Liquid::Error; end - def parse_parent_template(context) page = context[:site].pages.where(:fullpath => @template_name.gsub("'", '')).first