tweak the code to use the last version of liquid

did committed Oct 07, 2013
commit b44a7a7f35069eea46a9e2cc98ba2a6ac6d7601b
Showing 25 changed files with 268 additions and 80 deletions
Gemfile +4 -1
@@ @@ -5,6 +5,9 @@ gemspec
# Development
# gem 'locomotivecms_solid', path: '../gems/solid', require: false
- # gem 'locomotivecms_mounter', path: '../gems/mounter', require: false
+ gem 'locomotivecms_mounter', path: '../gems/mounter', require: false
+
+ # gem 'locomotivecms-liquid', path: '../gems/liquid', require: false
+ # gem 'locomotivecms-solid', path: '../gems/solid', require: false
gem 'rb-fsevent', '~> 0.9.1'
\ No newline at end of file
locomotive/wagon.rb b/lib/locomotive/wagon.rb +10 -2
@@ @@ -24,12 +24,20 @@ module Locomotive
if reader = self.require_mounter(path, true)
Bundler.require 'misc'
- require 'thin'
require 'locomotive/wagon/server'
+ app = Locomotive::Wagon::Server.new(reader)
- server = Thin::Server.new(options[:host], options[:port], Locomotive::Wagon::Server.new(reader))
+ require 'thin'
+ server = Thin::Server.new(options[:host], options[:port], app)
server.threaded = true # TODO: make it an option ?
server.start
+
+ # require 'unicorn' # TODO: gem 'unicorn'
+ # server = Unicorn::HttpServer.new(app)
+ # server.start
+
+ # require 'rack'
+ # Rack::Handler::WEBrick.run(app, { :'Port' => options[:port], :'Host' => options[:host] })
end
end
locomotive/wagon/exceptions.rb b/lib/locomotive/wagon/exceptions.rb +27 -0
@@ @@ -20,6 +20,33 @@ module Locomotive
end
+ class RendererException < DefaultException
+
+ attr_accessor :name, :template, :liquid_context
+
+ def initialize(exception, name, template, liquid_context)
+ self.name, self.template, self.liquid_context = name, template, liquid_context
+
+ self.log_page_into_backtrace(exception)
+
+ super(exception.message)
+
+ self.set_backtrace(exception.backtrace)
+ end
+
+ def log_page_into_backtrace(exception)
+ line = self.template.line_offset
+ line += (exception.respond_to?(:line) ? exception.line : 0) + 1
+
+ message = "#{self.template.filepath}:#{line}:in `#{self.name}'"
+
+ Locomotive::Wagon::Logger.fatal "[ERROR] #{exception.message} - #{message}\n".red
+
+ exception.backtrace.unshift message
+ end
+
+ end
+
class MounterException < DefaultException
end
locomotive/wagon/liquid/errors.rb b/lib/locomotive/wagon/liquid/errors.rb +4 -0
@@ @@ -8,6 +8,10 @@ module Locomotive
class ContentEntryNotTranslated < ::Liquid::Error; end
class UnknownConditionInScope < ::Liquid::Error; end
+
+ class UnknownConditionInScope < ::Liquid::Error; end
+
+ class ConnectionRefused < ::Liquid::Error; end
end
end
end
\ No newline at end of file
locomotive/wagon/liquid/filters/misc.rb b/lib/locomotive/wagon/liquid/filters/misc.rb +17 -0
@@ @@ -22,6 +22,23 @@ module Locomotive
rand(input.to_i)
end
+ # map/collect on a given property (support to_f, to_i)
+ def map(input, property)
+ flatten_if_necessary(input).map do |e|
+ e = e.call if e.is_a?(Proc)
+
+ if property == "to_liquid"
+ e
+ elsif property == "to_f"
+ e.to_f
+ elsif property == "to_i"
+ e.to_i
+ elsif e.respond_to?(:[])
+ e[property]
+ end
+ end
+ end
+
end
::Liquid::Template.register_filter(Misc)
locomotive/wagon/liquid/patches.rb b/lib/locomotive/wagon/liquid/patches.rb +1 -1
@@ @@ -44,4 +44,4 @@ module Liquid
end
end
- end
\ No newline at end of file
+ end
locomotive/wagon/liquid/tags/consume.rb b/lib/locomotive/wagon/liquid/tags/consume.rb +8 -2
@@ @@ -16,14 +16,14 @@ module Locomotive
Syntax = /(#{::Liquid::VariableSignature}+)\s*from\s*(#{::Liquid::QuotedString}|#{::Liquid::VariableSignature}+)/
- def initialize(tag_name, markup, tokens, context)
+ def initialize(tag_name, markup, tokens, options)
if markup =~ Syntax
@target = $1
self.prepare_url($2)
self.prepare_options(markup)
else
- raise ::Liquid::SyntaxError.new("Syntax Error in 'consume' - Valid syntax: consume <var> from \"<url>\" [username: value, password: value]")
+ raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.consume"), options[:line])
end
@cache_key = Digest::SHA1.hexdigest(@target)
@@ @@ -77,8 +77,14 @@ module Locomotive
begin
context.scopes.last[@target.to_s] = Locomotive::Wagon::Httparty::Webservice.consume(@url, @options.symbolize_keys)
self.cached_response = context.scopes.last[@target.to_s]
+ # rescue Errno::ECONNREFUSED
+ # raise ConnectionRefused.new(@markup)
rescue Timeout::Error
context.scopes.last[@target.to_s] = self.cached_response
+ rescue ::Liquid::Error => e
+ raise e
+ rescue => e
+ raise ::Liquid::Error.new(e.message, line)
end
render_all(@nodelist, context)
locomotive/wagon/liquid/tags/editable/base.rb b/lib/locomotive/wagon/liquid/tags/editable/base.rb +4 -4
@@ @@ -7,13 +7,13 @@ module Locomotive
Syntax = /(#{::Liquid::QuotedFragment})(\s*,\s*#{::Liquid::Expression}+)?/
- def initialize(tag_name, markup, tokens, context)
+ def initialize(tag_name, markup, tokens, options)
if markup =~ Syntax
@slug = $1.gsub(/[\"\']/, '')
- @options = {}
- markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/^'/, '').gsub(/'$/, '') }
+ @_options = {}
+ markup.scan(::Liquid::TagAttributes) { |key, value| @_options[key.to_sym] = value.gsub(/^'/, '').gsub(/'$/, '') }
else
- raise ::Liquid::SyntaxError.new("Syntax Error in 'editable_xxx' - Valid syntax: editable_xxx <slug>(, <options>)")
+ raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.#{tag_name}"), options[:line])
end
super
locomotive/wagon/liquid/tags/extends.rb b/lib/locomotive/wagon/liquid/tags/extends.rb +2 -2
@@ @@ -5,10 +5,10 @@ module Locomotive
class Extends < ::Liquid::Extends
def parse_parent_template
- mounting_point = @context[:mounting_point]
+ mounting_point = @options[:mounting_point]
page = if @template_name == 'parent'
- @context[:page].parent
+ @options[:page].parent
else
mounting_point.pages[@template_name]
end
locomotive/wagon/liquid/tags/google_analytics.rb b/lib/locomotive/wagon/liquid/tags/google_analytics.rb +2 -2
@@ @@ -6,11 +6,11 @@ module Locomotive
Syntax = /(#{::Liquid::Expression}+)?/
- def initialize(tag_name, markup, tokens, context)
+ def initialize(tag_name, markup, tokens, options)
if markup =~ Syntax
@account_id = $1.gsub('\'', '')
else
- raise ::Liquid::SyntaxError.new("Syntax Error in 'google_analytics' - Valid syntax: google_analytics <account_id>")
+ raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.google_analytics"), options[:line])
end
super
locomotive/wagon/liquid/tags/link_to.rb b/lib/locomotive/wagon/liquid/tags/link_to.rb +8 -8
@@ @@ -6,15 +6,15 @@ module Locomotive
Syntax = /(#{::Liquid::Expression}+)(#{::Liquid::TagAttributes}?)/
- def initialize(tag_name, markup, tokens, context)
+ def initialize(tag_name, markup, tokens, options)
if markup =~ Syntax
@handle = $1
- @options = {}
+ @_options = {}
markup.scan(::Liquid::TagAttributes) do |key, value|
- @options[key] = value
+ @_options[key] = value
end
else
- raise SyntaxError.new("Syntax Error in 'link_to' - Valid syntax: link_to page_handle, locale es (locale is optional)")
+ raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.link_to"), options[:line])
end
super
@@ @@ -60,13 +60,13 @@ module Locomotive
end
def fetch_page(mounting_point, handle, templatized = false)
- ::Locomotive::Mounter.with_locale(@options['locale']) do
+ ::Locomotive::Mounter.with_locale(@_options['locale']) do
if templatized
page = mounting_point.pages.values.find do |_page|
_page.templatized? &&
!_page.templatized_from_parent &&
_page.content_type.slug == handle.content_type.slug &&
- (@options['with'].nil? || _page.handle == @options['with'])
+ (@_options['with'].nil? || _page.handle == @_options['with'])
end
page.content_entry = handle if page
@@ @@ -79,7 +79,7 @@ module Locomotive
end
def label_from_page(page)
- ::Locomotive::Mounter.with_locale(@options['locale']) do
+ ::Locomotive::Mounter.with_locale(@_options['locale']) do
if page.templatized?
page.content_entry._label
else
@@ @@ -90,7 +90,7 @@ module Locomotive
def public_page_url(context, page)
mounting_point = context.registers[:mounting_point]
- locale = @options['locale'] || ::I18n.locale
+ locale = @_options['locale'] || ::I18n.locale
if !page.translated_in?(locale)
title = page.title_translations.values.compact.first
locomotive/wagon/liquid/tags/locale_switcher.rb b/lib/locomotive/wagon/liquid/tags/locale_switcher.rb +7 -7
@@ @@ -22,15 +22,15 @@ module Locomotive
Syntax = /(#{::Liquid::Expression}+)?/
- def initialize(tag_name, markup, tokens, context)
- @options = { label: 'iso', sep: ' | ' }
+ def initialize(tag_name, markup, tokens, options)
+ @_options = { label: 'iso', sep: ' | ' }
if markup =~ Syntax
- markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
+ markup.scan(::Liquid::TagAttributes) { |key, value| @_options[key.to_sym] = value.gsub(/"|'/, '') }
- @options[:exclude] = Regexp.new(@options[:exclude]) if @options[:exclude]
+ @_options[:exclude] = Regexp.new(@_options[:exclude]) if @_options[:exclude]
else
- raise ::Liquid::SyntaxError.new("Syntax Error in 'locale_switcher' - Valid syntax: locale_switcher <options>")
+ raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.locale_switcher"), options[:line])
end
super
@@ @@ -60,7 +60,7 @@ module Locomotive
%(<a href="/#{fullpath}" class="#{css}">#{link_label(locale)}</a>)
end
- end.join(@options[:sep])
+ end.join(@_options[:sep])
output += %(</div>)
end
@@ @@ -74,7 +74,7 @@ module Locomotive
end
def link_label(locale)
- case @options[:label]
+ case @_options[:label]
when 'iso' then locale
when 'locale' then I18n.t("locales.#{locale}")
when 'title' then @page.title # FIXME: this returns nil if the page has not been translated in the locale
locomotive/wagon/liquid/tags/nav.rb b/lib/locomotive/wagon/liquid/tags/nav.rb +22 -22
@@ @@ -18,13 +18,13 @@ module Locomotive
attr_accessor :current_page, :mounting_point
- def initialize(tag_name, markup, tokens, context)
+ def initialize(tag_name, markup, tokens, options)
if markup =~ Syntax
@source = ($1 || 'page').gsub(/"|'/, '')
- self.set_options(markup, context)
+ self.set_options(markup, options)
else
- raise ::Liquid::SyntaxError.new("Syntax Error in 'nav' - Valid syntax: nav <site|parent|page|<path to a page>> <options>")
+ raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.nav"), options[:line])
end
super
@@ @@ -39,7 +39,7 @@ module Locomotive
if self.no_wrapper?
output
else
- self.render_tag(:nav, id: @options[:id], css: @options[:class]) do
+ self.render_tag(:nav, id: @_options[:id], css: @_options[:class]) do
self.render_tag(:ul) { output }
end
end
@@ @@ -92,8 +92,8 @@ module Locomotive
def include_page?(page)
if !page.listed? || page.templatized? || !page.published?
false
- elsif @options[:exclude]
- (page.fullpath =~ @options[:exclude]).nil?
+ elsif @_options[:exclude]
+ (page.fullpath =~ @_options[:exclude]).nil?
else
true
end
@@ @@ -118,7 +118,7 @@ module Locomotive
# @return [ Boolean ] True if the children have to be rendered.
#
def render_children_for_page?(page, depth)
- depth.succ <= @options[:depth].to_i &&
+ depth.succ <= @_options[:depth].to_i &&
(page.children || []).select { |child| self.include_page?(child) }.any?
end
@@ @@ -130,12 +130,12 @@ module Locomotive
# @return [ String ] The label in HTML
#
def entry_label(page)
- icon = @options[:icon] ? '<span></span>' : ''
- title = @options[:liquid_render] ? @options[:liquid_render].render('page' => page) : page.title
+ icon = @_options[:icon] ? '<span></span>' : ''
+ title = @_options[:liquid_render] ? @_options[:liquid_render].render('page' => page) : page.title
if icon.blank?
title
- elsif @options[:icon] == 'after'
+ elsif @_options[:icon] == 'after'
"#{title} #{icon}"
else
"#{icon} #{title}"
@@ @@ -165,7 +165,7 @@ module Locomotive
#
def entry_css(page, css = '')
_css = 'link'
- _css += " #{page} #{@options[:active_class]}" if self.page_selected?(page)
+ _css += " #{page} #{@_options[:active_class]}" if self.page_selected?(page)
(_css + " #{css}").strip
end
@@ @@ -192,7 +192,7 @@ module Locomotive
end
self.render_tag(:li, id: "#{page.slug.to_s.dasherize}-link", css: css) do
- children_output = depth.succ <= @options[:depth].to_i ? self.render_entry_children(page, depth.succ) : ''
+ children_output = depth.succ <= @_options[:depth].to_i ? self.render_entry_children(page, depth.succ) : ''
%{<a href="#{url}"#{options}>#{label}</a>} + children_output
end
end
@@ @@ -209,7 +209,7 @@ module Locomotive
css = self.bootstrap? ? 'dropdown-menu' : ''
unless entries.empty?
- self.render_tag(:ul, id: "#{@options[:id]}-#{page.slug.to_s.dasherize}", css: css) do
+ self.render_tag(:ul, id: "#{@_options[:id]}-#{page.slug.to_s.dasherize}", css: css) do
self.build_entries_output(entries, depth)
end
else
@@ @@ -219,16 +219,16 @@ module Locomotive
# Set the value (default or assigned by the tag) of the options.
#
- def set_options(markup, context)
- @options = { id: 'nav', class: '', active_class: 'on', bootstrap: false, no_wrapper: false }
+ def set_options(markup, options)
+ @_options = { id: 'nav', class: '', active_class: 'on', bootstrap: false, no_wrapper: false }
- markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
+ markup.scan(::Liquid::TagAttributes) { |key, value| @_options[key.to_sym] = value.gsub(/"|'/, '') }
- @options[:exclude] = Regexp.new(@options[:exclude]) if @options[:exclude]
+ @_options[:exclude] = Regexp.new(@_options[:exclude]) if @_options[:exclude]
- if @options[:snippet]
- if template = self.parse_snippet_template(context, @options[:snippet])
- @options[:liquid_render] = template
+ if @_options[:snippet]
+ if template = self.parse_snippet_template(options, @_options[:snippet])
+ @_options[:liquid_render] = template
end
end
end
@@ @@ -272,11 +272,11 @@ module Locomotive
end
def bootstrap?
- @options[:bootstrap].to_bool
+ @_options[:bootstrap].to_bool
end
def no_wrapper?
- @options[:no_wrapper].to_bool
+ @_options[:no_wrapper].to_bool
end
::Liquid::Template.register_tag('nav', Nav)
locomotive/wagon/liquid/tags/paginate.rb b/lib/locomotive/wagon/liquid/tags/paginate.rb +2 -2
@@ @@ -18,12 +18,12 @@ module Locomotive
Syntax = /(#{::Liquid::Expression}+)\s+by\s+([0-9]+)/
- def initialize(tag_name, markup, tokens, context)
+ def initialize(tag_name, markup, tokens, options)
if markup =~ Syntax
@collection_name = $1
@per_page = $2.to_i
else
- raise ::Liquid::SyntaxError.new("Syntax Error in 'paginate' - Valid syntax: paginate <collection> by <number>")
+ raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.paginate"), options[:line])
end
super
locomotive/wagon/liquid/tags/session_assign.rb b/lib/locomotive/wagon/liquid/tags/session_assign.rb +2 -2
@@ @@ -14,12 +14,12 @@ module Locomotive
class SessionAssign < ::Liquid::Tag
Syntax = /(#{::Liquid::VariableSignature}+)\s*=\s*(#{::Liquid::QuotedFragment}+)/
- def initialize(tag_name, markup, tokens, context)
+ def initialize(tag_name, markup, tokens, options)
if markup =~ Syntax
@to = $1
@from = $2
else
- raise ::Liquid::SyntaxError.new("Syntax Error in 'session_assign' - Valid syntax: assign [var] = [source]")
+ raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.session_assign"), options[:line])
end
super
locomotive/wagon/liquid/tags/snippet.rb b/lib/locomotive/wagon/liquid/tags/snippet.rb +25 -6
@@ @@ -6,15 +6,14 @@ module Locomotive
class Snippet < ::Liquid::Include
def render(context)
- name = @template_name.gsub(/[\"\']/, '')
+ name = @template_name.gsub(/[\"\']/, '')
+ snippet = context.registers[:mounting_point].snippets[name]
- source = context.registers[:mounting_point].snippets[name].try(:source)
+ raise ::Liquid::StandardError.new("Unknown snippet \"#{name}\"") if snippet.nil?
- Locomotive::Wagon::Logger.info " Rendered snippet #{name}"
+ partial = self.parse_template(snippet)
- partial = ::Liquid::Template.parse(source)
-
- variable = context[@variable_name || @template_name[1..-2]]
+ variable = context[@variable_name || @template_name[1..-2]]
context.stack do
@attributes.each do |key, value|
@@ @@ -31,10 +30,30 @@ module Locomotive
partial.render(context)
end)
+ Locomotive::Wagon::Logger.info " Rendered snippet #{name}"
+
output
end
end
+ protected
+
+ def parse_template(snippet)
+ begin
+ ::Liquid::Template.parse(snippet.source)
+ rescue ::Liquid::Error => e
+ # do it again on the raw source instead so that the error line matches
+ # the source file.
+ begin
+ ::Liquid::Template.parse(snippet.template.raw_source)
+ rescue ::Liquid::Error => e
+ e.backtrace.unshift "#{snippet.template.filepath}:#{e.line + 1}:in `#{snippet.name}'"
+ e.line = self.line - 1
+ raise e
+ end
+ end
+ end
+
end
::Liquid::Template.register_tag('include', Snippet)
locomotive/wagon/liquid/tags/with_scope.rb b/lib/locomotive/wagon/liquid/tags/with_scope.rb +4 -4
@@ @@ -7,17 +7,17 @@ module Locomotive
SlashedString = /\/[^\/]*\//
TagAttributes = /(\w+|\w+\.\w+)\s*\:\s*(#{SlashedString}|#{::Liquid::QuotedFragment})/
- def initialize(tag_name, markup, tokens, context)
- @options = HashWithIndifferentAccess.new
+ def initialize(tag_name, markup, tokens, options)
+ @tag_options = HashWithIndifferentAccess.new
markup.scan(TagAttributes) do |key, value|
- @options[key] = value
+ @tag_options[key] = value
end
super
end
def render(context)
context.stack do
- context['with_scope'] = decode(@options, context)
+ context['with_scope'] = decode(@tag_options, context)
render_all(@nodelist, context)
end
end
locomotive/wagon/misc.rb b/lib/locomotive/wagon/misc.rb +2 -1
@@ @@ -5,4 +5,5 @@ require 'locomotive/wagon/misc/dragonfly.rb'
require 'locomotive/wagon/misc/i18n.rb'
require 'locomotive/wagon/misc/mounter.rb'
require 'locomotive/wagon/misc/markdown.rb'
- require 'locomotive/wagon/misc/haml.rb'
\ No newline at end of file
+ require 'locomotive/wagon/misc/haml.rb'
+ require 'locomotive/wagon/misc/better_errors.rb'
\ No newline at end of file
locomotive/wagon/misc/better_errors.rb b/lib/locomotive/wagon/misc/better_errors.rb +70 -0
@@ @@ -0,0 +1,70 @@
+ require 'ostruct'
+
+ module BetterErrors
+ class MiddlewareWrapper
+
+ def initialize(app)
+ @@middleware ||= BetterErrors::Middleware.new(app)
+ @@middleware.instance_variable_set(:@app, app)
+ end
+
+ def call(env)
+ env['action_dispatch.request.parameters'] = Rack::Request.new(env).params
+
+ @@middleware.call(env)
+ end
+
+ end
+
+ module FrameWithLiquidContext
+
+ extend ActiveSupport::Concern
+
+ included do
+
+ attr_accessor :liquid_context
+
+ alias_method_chain :local_variables, :liquid_context
+
+ class << self
+
+ alias_method_chain :from_exception, :liquid_context
+
+ end
+ end
+
+ def local_variables_with_liquid_context
+ if self.liquid_context
+ scope = self.liquid_context.scopes.last.clone
+
+ scope.delete_if { |k, _| %w(models contents params session).include?(k) }.tap do |_scope|
+ _scope['site'] = _scope['site']._source.to_hash
+ _scope['page'] = _scope['page'].to_hash.delete_if { |k, _| %w(template).include?(k) }
+ end
+ else
+ self.local_variables_without_liquid_context
+ end
+ rescue Exception => e
+ puts "[BetterError] Fatal error: #{e.message}".red
+ puts e.backtrace.join("\n")
+ {}
+ end
+
+ module ClassMethods
+
+ def from_exception_with_liquid_context(exception)
+ from_exception_without_liquid_context(exception).tap do |list|
+ if exception.respond_to?(:liquid_context)
+ list.first.liquid_context = exception.liquid_context
+ end
+ end
+ end
+
+ end
+ end
+
+ class StackFrame
+ include FrameWithLiquidContext
+ end
+
+ end
\ No newline at end of file
locomotive/wagon/misc/mounter.rb b/lib/locomotive/wagon/misc/mounter.rb +17 -5
@@ @@ -4,14 +4,26 @@ module Locomotive
class Page
def render(context)
- mounting_point = context.registers[:mounting_point]
+ self.parse(context).render(context)
+ end
+
+ protected
- template = ::Liquid::Template.parse(self.source, {
+ def parse(context)
+ options = {
page: self,
- mounting_point: mounting_point
- })
+ mounting_point: context.registers[:mounting_point],
+ error_mode: :strict,
+ count_lines: true
+ }
- template.render(context)
+ begin
+ template = ::Liquid::Template.parse(self.source, options)
+ rescue Liquid::SyntaxError => e
+ # do it again on the raw source instead so that the error line matches
+ # the source file.
+ ::Liquid::Template.parse(self.template.raw_source, options)
+ end
end
end
locomotive/wagon/server.rb b/lib/locomotive/wagon/server.rb +4 -2
@@ @@ -30,6 +30,8 @@ module Locomotive::Wagon
unless options[:disable_listen]
Locomotive::Wagon::Listen.instance.start(@reader)
end
+
+ BetterErrors.application_root = reader.mounting_point.path
end
def call(env)
@@ @@ -41,9 +43,10 @@ module Locomotive::Wagon
def create_rack_app(reader)
Rack::Builder.new do
- use BetterErrors::Middleware
use Rack::Lint
+ use BetterErrors::MiddlewareWrapper
+
use Rack::Session::Cookie, {
key: 'wagon.session',
path: '/',
@@ @@ -72,7 +75,6 @@ module Locomotive::Wagon
use Page
use TemplatizedPage
use NotFound
- use Renderer
run Renderer.new
end
locomotive/wagon/server/logging.rb b/lib/locomotive/wagon/server/logging.rb +2 -2
@@ @@ -8,11 +8,11 @@ module Locomotive::Wagon
def call(env)
now = Time.now
- log "Started #{env['REQUEST_METHOD'].upcase} \"#{env['PATH_INFO']}\" at #{now}"
+ log "Started #{env['REQUEST_METHOD'].upcase} \"#{env['PATH_INFO']}\" at #{now}".light_white
app.call(env).tap do |response|
done_in_ms = ((Time.now - now) * 10000).truncate / 10.0
- log "Completed #{code_to_human(response.first)} in #{done_in_ms}ms\n\n"
+ log "Completed #{code_to_human(response.first)} in #{done_in_ms}ms\n\n".green
end
end
locomotive/wagon/server/renderer.rb b/lib/locomotive/wagon/server/renderer.rb +10 -1
@@ @@ -11,7 +11,7 @@ module Locomotive::Wagon
self.redirect_to(self.page.redirect_url, self.page.redirect_type)
else
type = self.page.response_type || 'text/html'
- html = self.page.render(self.locomotive_context)
+ html = self.render_page
self.log " Rendered liquid page template"
@@ @@ -25,6 +25,15 @@ module Locomotive::Wagon
protected
+ def render_page
+ context = self.locomotive_context
+ begin
+ self.page.render(context)
+ rescue Exception => e
+ raise RendererException.new(e, self.page.title, self.page.template, context)
+ end
+ end
+
# Build the Liquid context used to render the Locomotive page. It
# stores both assigns and registers.
#
locales/en.yml +11 -0
@@ @@ -14,6 +14,17 @@ en:
et: Estonian
errors:
+ syntax:
+ editable_text: "Syntax Error in 'editable_text' - Valid syntax: editable_text [slug], [options]"
+ editable_file: "Syntax Error in 'editable_file' - Valid syntax: editable_file [slug], [options]"
+ editable_control: "Syntax Error in 'editable_control' - Valid syntax: editable_control [slug], [options]"
+ consume: "Syntax Error in 'consume' - Valid syntax: consume <var> from [url] [, username: value, password: value]"
+ google_analytics: "Syntax Error in 'google_analytics' - Valid syntax: google_analytics [account_id]"
+ link_to: "Syntax Error in 'link_to' - Valid syntax: link_to [page_handle], locale: es (locale is optional)"
+ locale_switcher: "Syntax Error in 'locale_switcher' - Valid syntax: locale_switcher [options]"
+ nav: "Syntax Error in 'nav' - Valid syntax: nav [site|parent|page|<path to a page>] [options]>"
+ paginate: "Syntax Error in 'paginate' - Valid syntax: paginate <collection> by <number>"
+ session_assign: "Syntax Error in 'session_assign' - Valid syntax: session_assign [var] = [source]"
messages:
blank: "can't not be blank"
locomotivecms_wagon.gemspec +3 -4
@@ @@ -21,21 +21,20 @@ Gem::Specification.new do |gem|
gem.add_dependency 'thor'
gem.add_dependency 'thin', '~> 1.5.1'
gem.add_dependency 'activesupport', '~> 3.2.11'
- gem.add_dependency 'locomotivecms_solid', '~> 0.2.1'
+ gem.add_dependency 'locomotivecms-solid', '~> 0.2.2'
gem.add_dependency 'RedCloth', '~> 4.2.8'
gem.add_dependency 'redcarpet', '~> 3.0.0'
gem.add_dependency 'dragonfly', '~> 0.9.12'
gem.add_dependency 'sprockets', '~> 2.0'
gem.add_dependency 'sprockets-sass', '~> 1.0.1'
gem.add_dependency 'rack-cache', '~> 1.1'
- gem.add_dependency 'better_errors', '~> 0.7.2'
- gem.add_dependency 'tzinfo', '~> 1.0.1'
+ gem.add_dependency 'better_errors', '~> 1.0.1'
gem.add_dependency 'listen', '~> 0.7.0'
gem.add_dependency 'httmultiparty', '0.3.10'
gem.add_dependency 'will_paginate', '~> 3.0.3'
- gem.add_dependency 'locomotivecms_mounter', '~> 1.2.7'
+ # gem.add_dependency 'locomotivecms_mounter', '~> 1.2.7'
gem.add_dependency 'faker', '~> 0.9.5'