trip to green spec

arnaud sellenet committed Jun 03, 2014
commit 6dfb083901d6369e9e9d9b947f2b19e188fcc790
Showing 6 changed files with 29 additions and 30 deletions
locomotive/steam.rb b/lib/locomotive/steam.rb +6 -0
@@ @@ -8,3 +8,9 @@ require 'compass'
require 'httmultiparty'
require 'mime/types'
+
+ module Locomotive
+ module Steam
+ TEMPLATE_EXTENSIONS = %w(liquid haml)
+ end
+ end
locomotive/steam/liquid/patches.rb b/lib/locomotive/steam/liquid/patches.rb +0 -4
@@ @@ -2,10 +2,6 @@ module Liquid
class Drop
- def mounting_point
- @context.registers[:mounting_point]
- end
-
def site
@context.registers[:site]
end
locomotive/steam/middlewares/base.rb b/lib/locomotive/steam/middlewares/base.rb +5 -9
@@ @@ -5,7 +5,7 @@ module Locomotive::Steam
attr_accessor :app, :request, :path
attr_accessor :liquid_assigns, :services
- attr_accessor :mounting_point, :page, :content_entry
+ attr_accessor :site, :page, :content_entry, :locale
def initialize(app = nil)
@app = app
@@ @@ -22,16 +22,12 @@ module Locomotive::Steam
protected
def set_accessors(env)
- %w(path request mounting_point page content_entry services).each do |name|
- self.send(:"#{name}=", env["steam.#{name}"])
+ %w(path site request page content_entry services locale).each do |name|
+ self.send(:"#{name}=", env.fetch("steam.#{name}", nil))
end
env['steam.liquid_assigns'] ||= {}
- self.liquid_assigns = env['steam.liquid_assigns']
- end
-
- def site
- self.mounting_point.site
+ self.liquid_assigns = env.fetch('steam.liquid_assigns')
end
def params
@@ @@ -60,4 +56,4 @@ module Locomotive::Steam
end
end
- end
\ No newline at end of file
+ end
locomotive/steam/middlewares/locale.rb b/lib/locomotive/steam/middlewares/locale.rb +3 -4
@@ @@ -20,15 +20,14 @@ module Locomotive::Steam
protected
def set_locale!(env)
- locale = self.mounting_point.default_locale
+ locale = site.default_locale
- if self.path =~ /^(#{self.mounting_point.locales.join('|')})+(\/|$)/
+ if self.path =~ /^(#{self.site.locales.join('|')})+(\/|$)/
locale = $1
self.path = self.path.gsub($1 + $2, '')
self.path = 'index' if self.path.blank?
end
- Locomotive::Mounter.locale = locale
::I18n.locale = locale
self.log "Detecting locale #{locale.upcase}"
@@ @@ -39,4 +38,4 @@ module Locomotive::Steam
end
end
- end
\ No newline at end of file
+ end
locomotive/steam/middlewares/page.rb b/lib/locomotive/steam/middlewares/page.rb +2 -5
@@ @@ -29,10 +29,7 @@ module Locomotive::Steam
def fetch_page
matchers = self.path_combinations(self.path)
- pages = self.mounting_point.pages.values.find_all do |_page|
- matchers.include?(_page.safe_fullpath) ||
- matchers.include?(_page.safe_fullpath.try(:underscore))
- end.sort_by { |p| p.position || Float::INFINITY }
+ pages = Locomotive::Models[:pages].matching_paths(matchers)
if pages.size > 1
self.log "Found multiple pages: #{pages.collect(&:title).join(', ')}"
@@ @@ -53,7 +50,7 @@ module Locomotive::Steam
(can_include_template ? [segment, '*'] : [segment]).map do |_segment|
if (_combinations = _path_combinations(segments.clone, can_include_template && _segment != '*'))
[*_combinations].map do |_combination|
- File.join(_segment, _combination)
+ URI.join(_segment, _combination)
end
else
[_segment]
locomotive/steam/server.rb b/lib/locomotive/steam/server.rb +13 -8
@@ @@ -4,13 +4,14 @@ require_relative 'liquid'
require_relative 'services'
require_relative 'middlewares'
+ require 'locomotive/models'
+
module Locomotive::Steam
class Server
- attr_reader :datastore, :app, :options
+ attr_reader :app, :options
- def initialize(datastore, options = {})
- @datastore = datastore
+ def initialize(options = {})
@options = options
stack = Middlewares::Stack.new(options)
@@ @@ -24,7 +25,9 @@ module Locomotive::Steam
def _call(env)
set_request(env)
- set_mounting_point(env)
+ set_path(env)
+
+ fetch_site(env)
set_services(env)
@@ @@ -33,20 +36,22 @@ module Locomotive::Steam
protected
+ def set_path(env)
+ env['steam.path'] = options.fetch(:path)
+ end
def set_request(env)
@request = Rack::Request.new(env)
env['steam.request'] = @request
end
- def set_mounting_point(env)
+ def fetch_site(env)
# one single mounting point per site
- @mounting_point = @datastore.build_mounting_point(@request.host)
- env['steam.mounting_point'] = @mounting_point
+ env['steam.site'] = Locomotive::Models[:sites].find_by_host(@request.host)
end
def set_services(env)
env['steam.services'] = {
- dragonfly: Locomotive::Steam::Services::Dragonfly.new(@mounting_point.path),
+ dragonfly: Locomotive::Steam::Services::Dragonfly.new(options.fetch(:path)),
markdown: Locomotive::Steam::Services::Markdown.new,
external_api: Locomotive::Steam::Services::ExternalAPI.new
}