the theme_asset repository returns all the assets for the filesystem adapter

did committed Apr 18, 2015
commit 22e9de685727cff7da719cd172baa62d7a6e944f
Showing 6 changed files with 57 additions and 2 deletions
locomotive/steam.rb b/lib/locomotive/steam.rb +6 -0
@@ @@ -36,6 +36,12 @@ module Locomotive
require_relative 'steam/initializers'
end
+ # Shortcut to build the Rack stack
+ def self.to_app
+ require_relative 'steam/server'
+ Server.to_app
+ end
+
# FIXME: not sure it will ever be needed
# class << self
# def method_missing(name, *args, &block)
locomotive/steam/adapters/filesystem/yaml_loaders/theme_asset.rb b/lib/locomotive/steam/adapters/filesystem/yaml_loaders/theme_asset.rb +31 -1
@@ @@ -9,7 +9,37 @@ module Locomotive
include Adapters::Filesystem::YAMLLoader
def load(scope)
- []
+ super
+ [].tap do |list|
+ each_file do |filepath, folder|
+ list << { source: filepath, folder: folder }
+ end
+ end
+ end
+
+ private
+
+ def each_file(&block)
+ # Follows symlinks and makes sure subdirectories are handled
+ pattern = ['**', '*', '**', '*']
+
+ Dir.glob(File.join(path, *pattern)).each do |file|
+ next if exclude?(file)
+
+ folder = File.dirname(file.gsub(File.join(path, ''), ''))
+
+ yield(file, folder)
+ end
+ end
+
+ def exclude?(file)
+ File.directory?(file) ||
+ file.starts_with?(File.join(path, 'samples')) ||
+ File.basename(file).starts_with?('_')
+ end
+
+ def path
+ @path ||= File.join(site_path, 'public')
end
end
locomotive/steam/decorators/template_decorator.rb b/lib/locomotive/steam/decorators/template_decorator.rb +1 -0
@@ @@ -1,3 +1,4 @@
+ require 'haml'
require_relative 'i18n_decorator'
module Locomotive
locomotive/steam/entities/theme_asset.rb b/lib/locomotive/steam/entities/theme_asset.rb +8 -0
@@ @@ -4,6 +4,14 @@ module Locomotive::Steam
include Locomotive::Steam::Models::Entity
+ def initialize(attributes = {})
+ super({
+ local_path: nil,
+ checksum: nil
+ }.merge(attributes))
+ end
+
+
end
end
locomotive/steam/repositories/theme_asset_repository.rb b/lib/locomotive/steam/repositories/theme_asset_repository.rb +1 -1
@@ @@ -14,7 +14,7 @@ module Locomotive
def checksums
query { only(:checksum, :local_path) }.all.inject({}) do |memo, asset|
- memo[asset.local_path] = asset.checksum
+ memo[asset.local_path] = asset.checksum if asset.checksum
memo
end
end
spec/integration/repositories/theme_asset_repository_spec.rb +10 -0
@@ @@ -13,6 +13,11 @@ describe Locomotive::Steam::ThemeAssetRepository do
let(:site_id) { BSON::ObjectId.from_string('54eb49c12475804b2b000002') }
let(:adapter) { Locomotive::Steam::MongoDBAdapter.new(database: 'steam_test', hosts: ['127.0.0.1:27017']) }
+ describe '#all' do
+ subject { repository.all }
+ it { expect(subject.size).to eq 16 }
+ end
+
describe '#url_for' do
subject { repository.url_for('stylesheets/application.css') }
it { is_expected.to eq '/sites/54eb49c12475804b2b000002/theme/stylesheets/application.css' }
@@ @@ -31,6 +36,11 @@ describe Locomotive::Steam::ThemeAssetRepository do
let(:site_id) { 1 }
let(:adapter) { Locomotive::Steam::FilesystemAdapter.new(default_fixture_site_path) }
+ describe '#all' do
+ subject { repository.all }
+ it { expect(subject.size).to eq 16 }
+ end
+
describe '#url_for' do
subject { repository.url_for('stylesheets/application.css') }
it { is_expected.to eq '/stylesheets/application.css' }