please codeclimate + force the order of pages and snippets when testing them (yaml_loader)
did
committed Feb 12, 2015
commit 0836ef0e24f9c3cf8a134f8ccc71fc1337fcd09a
Showing 11
changed files with
70 additions
and 43 deletions
locomotive/steam/core_ext.rb b/lib/locomotive/steam/core_ext.rb
+2
-1
| @@ | @@ -2,4 +2,5 @@ require_relative 'core_ext/hash' |
| require_relative 'core_ext/string' | |
| require_relative 'core_ext/array' | |
| require_relative 'core_ext/boolean/true' | |
| - | require_relative 'core_ext/boolean/false' |
| \ No newline at end of file | |
| + | require_relative 'core_ext/boolean/false' |
| + | require_relative 'core_ext/kernel' |
locomotive/steam/core_ext/kernel.rb b/lib/locomotive/steam/core_ext/kernel.rb
+14
-0
| @@ | @@ -0,0 +1,14 @@ |
| + | module Kernel |
| + | |
| + | def require_relative_all(paths, sub = nil) |
| + | main_path = File.dirname(caller.first.sub(/:\d+$/, '')) |
| + | main_path = File.join(main_path, sub) if sub |
| + | |
| + | paths.each do |path| |
| + | Dir[File.join(main_path, path, '*.rb')].each { |file| require file } |
| + | end |
| + | end |
| + | |
| + | end |
| + | |
| + | |
locomotive/steam/liquid.rb b/lib/locomotive/steam/liquid.rb
+1
-4
| @@ | @@ -6,7 +6,4 @@ require_relative 'liquid/drops/base' |
| require_relative 'liquid/drops/i18n_base' | |
| require_relative 'liquid/drops/proxy_collection' | |
| require_relative 'liquid/tags/hybrid' | |
| - | |
| - | %w{. drops filters tags/concerns tags}.each do |dir| |
| - | Dir[File.join(File.dirname(__FILE__), 'liquid', dir, '*.rb')].each { |lib| require lib } |
| - | end |
| + | require_relative_all %w(. drops filters tags/concerns tags), 'liquid' |
locomotive/steam/middlewares/renderer.rb b/lib/locomotive/steam/middlewares/renderer.rb
+38
-16
| @@ | @@ -50,26 +50,48 @@ module Locomotive::Steam |
| end | |
| def liquid_assigns | |
| + | _default_liquid_assigns.merge( |
| + | _locale_liquid_assigns.merge( |
| + | _request_liquid_assigns.merge( |
| + | _steam_liquid_assigns))) |
| + | end |
| + | |
| + | def _default_liquid_assigns |
| { | |
| - | 'site' => site.to_liquid, |
| - | 'page' => page.to_liquid, |
| - | 'models' => Locomotive::Steam::Liquid::Drops::ContentTypes.new, |
| - | 'contents' => Locomotive::Steam::Liquid::Drops::ContentTypes.new, |
| 'current_page' => params[:page], | |
| 'params' => params.stringify_keys, | |
| - | 'path' => request.path, |
| - | 'fullpath' => request.fullpath, |
| - | 'url' => request.url, |
| - | 'ip_address' => request.ip, |
| - | 'post?' => request.post?, |
| - | 'host' => request.host_with_port, |
| 'now' => Time.zone.now, | |
| - | 'today' => Date.today, |
| - | 'locale' => locale, |
| - | 'default_locale' => site.default_locale.to_s, |
| - | 'locales' => site.locales.map(&:to_s), |
| - | 'current_user' => {}, |
| - | 'session' => Locomotive::Steam::Liquid::Drops::SessionProxy.new, |
| + | 'today' => Date.today |
| + | } |
| + | end |
| + | |
| + | def _steam_liquid_assigns |
| + | { |
| + | 'site' => site.to_liquid, |
| + | 'page' => page.to_liquid, |
| + | 'models' => Locomotive::Steam::Liquid::Drops::ContentTypes.new, |
| + | 'contents' => Locomotive::Steam::Liquid::Drops::ContentTypes.new, |
| + | 'current_user' => {}, |
| + | 'session' => Locomotive::Steam::Liquid::Drops::SessionProxy.new, |
| + | } |
| + | end |
| + | |
| + | def _locale_liquid_assigns |
| + | { |
| + | 'locale' => locale, |
| + | 'default_locale' => site.default_locale.to_s, |
| + | 'locales' => site.locales.map(&:to_s) |
| + | } |
| + | end |
| + | |
| + | def _request_liquid_assigns |
| + | { |
| + | 'path' => request.path, |
| + | 'fullpath' => request.fullpath, |
| + | 'url' => request.url, |
| + | 'ip_address' => request.ip, |
| + | 'post?' => request.post?, |
| + | 'host' => request.host_with_port |
| } | |
| end | |
locomotive/steam/repositories/filesystem.rb b/lib/locomotive/steam/repositories/filesystem.rb
+8
-10
| @@ | @@ -1,10 +1,7 @@ |
| require_relative 'filesystem/models/base' | |
| require_relative 'filesystem/concerns/queryable.rb' | |
| require_relative 'filesystem/yaml_loaders/concerns/common.rb' | |
| - | |
| - | %w(memory_adapter yaml_loaders sanitizers models .).each do |name| |
| - | Dir[File.join(File.dirname(__FILE__), 'filesystem', name, '*.rb')].each { |lib| require lib } |
| - | end |
| + | require_relative_all %w(memory_adapter yaml_loaders sanitizers models .), 'filesystem' |
| module Locomotive | |
| module Steam | |
| @@ | @@ -20,13 +17,14 @@ module Locomotive |
| include Morphine | |
| register :site do | |
| - | loader = YAMLLoaders::Site.new(options[:path], cache) |
| - | Filesystem::Site.new(loader) |
| + | Filesystem::Site.new( |
| + | YAMLLoaders::Site.new(options[:path], cache)) |
| end | |
| register :page do | |
| - | loader = YAMLLoaders::Page.new(options[:path], current_site.try(:default_locale), cache) |
| - | Filesystem::Page.new(loader, current_site, current_locale) |
| + | Filesystem::Page.new( |
| + | YAMLLoaders::Page.new(options[:path], current_site.try(:default_locale), cache), |
| + | current_site, current_locale) |
| end | |
| register :snippet do | |
| @@ | @@ -47,8 +45,8 @@ module Locomotive |
| end | |
| register :translation do | |
| - | loader = YAMLLoaders::Translation.new(options[:path], cache) |
| - | Filesystem::Translation.new(loader, current_site) |
| + | Filesystem::Translation.new( |
| + | YAMLLoaders::Translation.new(options[:path], cache)) |
| end | |
| register :cache do | |
locomotive/steam/repositories/filesystem/translation.rb b/lib/locomotive/steam/repositories/filesystem/translation.rb
+1
-1
| @@ | @@ -3,7 +3,7 @@ module Locomotive |
| module Repositories | |
| module Filesystem | |
| - | class Translation < Struct.new(:loader, :site) |
| + | class Translation < Struct.new(:loader) |
| include Concerns::Queryable | |
locomotive/steam/services.rb b/lib/locomotive/steam/services.rb
+2
-4
| @@ | @@ -1,9 +1,7 @@ |
| - | %w(concerns .).each do |name| |
| - | Dir[File.join(File.dirname(__FILE__), 'services', name, '*.rb')].each { |lib| require lib } |
| - | end |
| - | |
| require 'morphine' | |
| + | require_relative_all %w(concerns .), 'services' |
| + | |
| module Locomotive | |
| module Steam | |
| module Services | |
locomotivecms_steam.gemspec
+1
-3
| @@ | @@ -24,7 +24,6 @@ Gem::Specification.new do |spec| |
| spec.add_dependency 'morphine', '~> 0.1.1' | |
| spec.add_dependency 'httparty', '~> 0.13.3' | |
| - | # spec.add_dependency 'httmultiparty', '~> 0.3.10' |
| spec.add_dependency 'rack-cache', '~> 1.2' | |
| spec.add_dependency 'dragonfly', '~> 1.0.7' | |
| spec.add_dependency 'moneta', '~> 0.8.0' | |
| @@ | @@ -43,9 +42,8 @@ Gem::Specification.new do |spec| |
| spec.add_dependency 'mime-types', '~> 2.4.3' | |
| - | # spec.add_dependency 'locomotivecms_models', '~> 0.0.1.pre.alpha' |
| spec.add_dependency 'locomotivecms-solid', '~> 4.0.0.alpha2' | |
| spec.add_dependency 'locomotivecms_common', '~> 0.0.2' | |
| - | # spec.required_ruby_version = '~> 2.0' |
| + | spec.required_ruby_version = '>= 2.0' |
| end | |
spec/unit/repositories/filesystem/translation_spec.rb
+1
-2
| @@ | @@ -3,10 +3,9 @@ require 'spec_helper' |
| describe Locomotive::Steam::Repositories::Filesystem::Translation do | |
| let(:loader) { instance_double('Loader', list_of_attributes: [{ key: 'powered_by', values: { en: 'Powered by Steam', fr: 'Propulsé par Steam' } }]) } | |
| - | let(:site) { instance_double('Site', default_locale: :en, locales: [:en, :fr]) } |
| let(:locale) { :en } | |
| - | let(:repository) { Locomotive::Steam::Repositories::Filesystem::Translation.new(loader, site) } |
| + | let(:repository) { Locomotive::Steam::Repositories::Filesystem::Translation.new(loader) } |
| describe '#collection' do | |
spec/unit/repositories/filesystem/yaml_loaders/page_spec.rb
+1
-1
| @@ | @@ -9,7 +9,7 @@ describe Locomotive::Steam::Repositories::Filesystem::YAMLLoaders::Page do |
| describe '#list_of_attributes' do | |
| - | subject { loader.list_of_attributes } |
| + | subject { loader.list_of_attributes.sort { |a, b| a[:_fullpath] <=> b[:_fullpath] } } |
| it 'tests various stuff' do | |
| expect(subject.size).to eq 20 | |
spec/unit/repositories/filesystem/yaml_loaders/snippet_spec.rb
+1
-1
| @@ | @@ -9,7 +9,7 @@ describe Locomotive::Steam::Repositories::Filesystem::YAMLLoaders::Snippet do |
| describe '#list_of_attributes' do | |
| - | subject { loader.list_of_attributes } |
| + | subject { loader.list_of_attributes.sort { |a, b| a[:_fullpath] <=> b[:_fullpath] } } |
| it 'tests various stuff' do | |
| expect(subject.size).to eq 4 | |