snippet repository (both works with MongoDB and Filesystem adapters)

did committed Feb 27, 2015
commit a958ec65a5e2a2e76d73bc281c0a6a7566d3e24a
Showing 40 changed files with 1197 additions and 1420 deletions
locomotive/steam.rb b/lib/locomotive/steam.rb +1 -0
@@ @@ -18,6 +18,7 @@ require_relative_all 'steam/entities'
require_relative 'steam/repositories/site_repository'
require_relative 'steam/repositories/page_repository'
require_relative 'steam/repositories/editable_element_repository'
+ require_relative 'steam/repositories/snippet_repository'
require_relative 'steam/services'
locomotive/steam/adapters/filesystem.rb b/lib/locomotive/steam/adapters/filesystem.rb +4 -2
@@ @@ -5,10 +5,12 @@ require_relative 'filesystem/simple_cache_store'
require_relative 'filesystem/yaml_loader'
require_relative 'filesystem/yaml_loaders/site'
require_relative 'filesystem/yaml_loaders/page'
+ require_relative 'filesystem/yaml_loaders/snippet'
require_relative 'filesystem/sanitizer'
require_relative 'filesystem/sanitizers/simple'
require_relative 'filesystem/sanitizers/page'
+ require_relative 'filesystem/sanitizers/snippet'
module Locomotive::Steam
@@ @@ -76,7 +78,7 @@ module Locomotive::Steam
end
def build_yaml_loaders
- %i(sites pages).inject({}) do |memo, name|
+ %i(sites pages snippets).inject({}) do |memo, name|
memo[name] = build_klass('YAMLLoaders', name).new(site_path)
memo
end
@@ @@ -84,7 +86,7 @@ module Locomotive::Steam
def build_sanitizers
hash = Hash.new { build_klass('Sanitizers', :simple).new }
- %i(pages).inject(hash) do |memo, name|
+ %i(pages snippets).inject(hash) do |memo, name|
memo[name] = build_klass('Sanitizers', name).new
memo
end
locomotive/steam/adapters/filesystem/sanitizer.rb b/lib/locomotive/steam/adapters/filesystem/sanitizer.rb +4 -0
@@ @@ -36,6 +36,10 @@ module Locomotive::Steam
entity
end
+ def attach_site_to(entity)
+ entity[:site_id] = scope.site._id if scope.site
+ end
+
alias :current_locale :locale
end
locomotive/steam/adapters/filesystem/sanitizers/page.rb b/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb +1 -1
@@ @@ -16,7 +16,7 @@ module Locomotive::Steam
end
def apply_to_entity(entity)
- entity[:site_id] = scope.site._id if scope.site
+ attach_site_to(entity)
record_id(entity) # required to get the parent_id
locomotive/steam/adapters/filesystem/sanitizers/snippet.rb b/lib/locomotive/steam/adapters/filesystem/sanitizers/snippet.rb +27 -23
@@ @@ -1,28 +1,32 @@
- # module Locomotive
- # module Steam
- # module Repositories
- # module Filesystem
- # module Sanitizers
+ module Locomotive::Steam
+ module Adapters
+ module Filesystem
+ module Sanitizers
- # class Snippet < Struct.new(:default_locale, :locales)
+ class Snippet
- # def apply_to(collection)
- # collection.each do |snippet|
- # # if there a missing template in one of the locales,
- # # then use the one from the default locale
- # default = snippet.template_path[default_locale]
+ include Adapters::Filesystem::Sanitizer
- # locales.each do |locale|
- # next if locale == default_locale
- # snippet.template_path[locale] ||= default
- # end
- # end
- # end
+ def apply_to_entity(entity)
+ attach_site_to(entity)
+ use_default_template_if_missing_locale(entity)
+ end
- # end
+ private
- # end
- # end
- # end
- # end
- # end
+ def use_default_template_if_missing_locale(entity)
+ # if there a missing template in one of the locales,
+ # then use the one from the default locale
+ default = entity.template_path[default_locale]
+ locales.each do |locale|
+ next if locale == default_locale
+ entity.template_path[locale] ||= default
+ end
+ end
+
+ end
+
+ end
+ end
+ end
+ end
locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb b/lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb +68 -42
@@ @@ -1,3 +1,71 @@
+ module Locomotive
+ module Steam
+ module Adapters
+ module Filesystem
+ module YAMLLoaders
+
+ class Snippet
+
+ include Adapters::Filesystem::YAMLLoader
+
+ def load(scope)
+ super
+ load_list
+ end
+
+ private
+
+ def load_list
+ {}.tap do |hash|
+ each_file do |filepath, slug, locale|
+ _locale = locale || default_locale
+
+ if element = hash[slug]
+ update(element, filepath, _locale)
+ else
+ element = build(filepath, slug, _locale)
+ end
+
+ hash[slug] = element
+ end
+ end.values
+ end
+
+ def build(filepath, slug, locale)
+ {
+ name: slug.humanize,
+ slug: slug,
+ template_path: { locale => filepath }
+ }
+ end
+
+ def update(element, filepath, locale)
+ element[:template_path][locale] = filepath
+ end
+
+ def each_file(&block)
+ Dir.glob(File.join(path, "*.{#{template_extensions.join(',')}}")).each do |filepath|
+
+ slug, locale = File.basename(filepath).split('.')[0..1]
+ locale = default_locale if template_extensions.include?(locale)
+
+ yield(filepath, slug.permalink, locale.to_sym)
+ end
+ end
+
+ def path
+ @path ||= File.join(site_path, 'app', 'views', 'snippets')
+ end
+
+ end
+
+ end
+ end
+ end
+ end
+ end
+
+
# module Locomotive
# module Steam
# module Repositories
@@ @@ -12,49 +80,7 @@
# cache.fetch('app/views/snippets') { load_list }
# end
- # private
-
- # def load_list
- # {}.tap do |hash|
- # each_file do |filepath, slug, locale|
- # _locale = locale || default_locale
-
- # if element = hash[slug]
- # update(element, filepath, _locale)
- # else
- # element = build(filepath, slug, _locale)
- # end
-
- # hash[slug] = element
- # end
- # end.values
- # end
-
- # def build(filepath, slug, locale)
- # {
- # name: slug.humanize,
- # slug: slug,
- # template_path: { locale => filepath }
- # }
- # end
- # def update(element, filepath, locale)
- # element[:template_path][locale] = filepath
- # end
-
- # def each_file(&block)
- # Dir.glob(File.join(path, "*.{#{template_extensions.join(',')}}")).each do |filepath|
-
- # slug, locale = File.basename(filepath).split('.')[0..1]
- # locale = default_locale if template_extensions.include?(locale)
-
- # yield(filepath, slug.permalink, locale.to_sym)
- # end
- # end
-
- # def path
- # File.join(root_path, 'app', 'views', 'snippets')
- # end
# end
locomotive/steam/entities/snippet.rb b/lib/locomotive/steam/entities/snippet.rb +40 -0
@@ @@ -0,0 +1,40 @@
+ module Locomotive::Steam
+
+ class Snippet
+
+ include Locomotive::Steam::Models::Entity
+
+ def initialize(attributes = {})
+ super({
+ template: {}
+ }.merge(attributes))
+ end
+
+ end
+
+ end
+
+
+ # module Locomotive
+ # module Steam
+
+ # class SnippetRepository
+ # module Filesystem
+ # module Models
+
+ # class Snippet < Base
+
+ # set_localized_attributes [:template, :template_path]
+
+ # def initialize(attributes)
+ # super({ template: {} }.merge(attributes))
+ # end
+
+ # end
+
+ # end
+ # end
+ # end
+
+ # end
+ # end
locomotive/steam/repositories/filesystem.rb b/lib/locomotive/steam/repositories/filesystem.rb +53 -53
@@ @@ -1,67 +1,67 @@
- require_relative 'filesystem/models/concerns/validation.rb'
- require_relative 'filesystem/models/base'
- require_relative 'filesystem/concerns/queryable.rb'
- require_relative 'filesystem/yaml_loaders/concerns/common.rb'
- require_relative_all %w(memory_adapter yaml_loaders sanitizers models .), 'filesystem'
+ # require_relative 'filesystem/models/concerns/validation.rb'
+ # require_relative 'filesystem/models/base'
+ # require_relative 'filesystem/concerns/queryable.rb'
+ # require_relative 'filesystem/yaml_loaders/concerns/common.rb'
+ # require_relative_all %w(memory_adapter yaml_loaders sanitizers models .), 'filesystem'
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
- def self.build_instance(site = nil, current_locale = nil, path = nil)
- Instance.new(site, current_locale, path)
- end
+ # def self.build_instance(site = nil, current_locale = nil, path = nil)
+ # Instance.new(site, current_locale, path)
+ # end
- class Instance < Struct.new(:current_site, :current_locale, :path)
+ # class Instance < Struct.new(:current_site, :current_locale, :path)
- include Morphine
+ # include Morphine
- register :site do
- Filesystem::Site.new(
- YAMLLoaders::Site.new(path, cache))
- end
+ # register :site do
+ # Filesystem::Site.new(
+ # YAMLLoaders::Site.new(path, cache))
+ # end
- register :page do
- Filesystem::Page.new(
- YAMLLoaders::Page.new(path, current_site.try(:default_locale), cache),
- current_site, current_locale)
- end
+ # register :page do
+ # Filesystem::Page.new(
+ # YAMLLoaders::Page.new(path, current_site.try(:default_locale), cache),
+ # current_site, current_locale)
+ # end
- register :snippet do
- Filesystem::Snippet.new(
- YAMLLoaders::Snippet.new(path, current_site.try(:default_locale), cache),
- current_site, current_locale)
- end
+ # register :snippet do
+ # Filesystem::Snippet.new(
+ # YAMLLoaders::Snippet.new(path, current_site.try(:default_locale), cache),
+ # current_site, current_locale)
+ # end
- register :content_type do
- Filesystem::ContentType.new(
- YAMLLoaders::ContentType.new(path, cache),
- current_site, current_locale)
- end
+ # register :content_type do
+ # Filesystem::ContentType.new(
+ # YAMLLoaders::ContentType.new(path, cache),
+ # current_site, current_locale)
+ # end
- register :content_entry do
- Filesystem::ContentEntry.new(
- YAMLLoaders::ContentEntry.new(path, cache),
- current_site, current_locale, content_type)
- end
+ # register :content_entry do
+ # Filesystem::ContentEntry.new(
+ # YAMLLoaders::ContentEntry.new(path, cache),
+ # current_site, current_locale, content_type)
+ # end
- register :theme_asset do
- Filesystem::ThemeAsset.new(current_site)
- end
+ # register :theme_asset do
+ # Filesystem::ThemeAsset.new(current_site)
+ # end
- register :translation do
- Filesystem::Translation.new(
- YAMLLoaders::Translation.new(path, cache))
- end
+ # register :translation do
+ # Filesystem::Translation.new(
+ # YAMLLoaders::Translation.new(path, cache))
+ # end
- register :cache do
- Filesystem::MemoryAdapter::SimpleCacheStore.new
- end
+ # register :cache do
+ # Filesystem::MemoryAdapter::SimpleCacheStore.new
+ # end
- end
+ # end
- end
- end
- end
- end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/concerns/queryable.rb b/lib/locomotive/steam/repositories/filesystem/concerns/queryable.rb +49 -49
@@ @@ -1,65 +1,65 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module Concerns
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module Concerns
- module Queryable
+ # module Queryable
- extend ActiveSupport::Concern
+ # extend ActiveSupport::Concern
- def query(*args, &block)
- _locale = respond_to?(:current_locale) ? current_locale : nil
- MemoryAdapter::Query.new(memoized_collection(*args), _locale, &block)
- end
+ # def query(*args, &block)
+ # _locale = respond_to?(:current_locale) ? current_locale : nil
+ # MemoryAdapter::Query.new(memoized_collection(*args), _locale, &block)
+ # end
- private
+ # private
- def localized_attribute(object, method)
- if (values = object.send(method)).is_a?(Hash)
- values[current_locale]
- else
- values
- end
- end
+ # def localized_attribute(object, method)
+ # if (values = object.send(method)).is_a?(Hash)
+ # values[current_locale]
+ # else
+ # values
+ # end
+ # end
- def memoized_collection(*args)
- return @collection if @collection
+ # def memoized_collection(*args)
+ # return @collection if @collection
- @collection = collection(*args)
- end
+ # @collection = collection(*args)
+ # end
- def collection(*args)
- _collection = loader.list_of_attributes(*args).map do |attributes|
- collection_options[:model].new(attributes)
- end
+ # def collection(*args)
+ # _collection = loader.list_of_attributes(*args).map do |attributes|
+ # collection_options[:model].new(attributes)
+ # end
- sanitize!(_collection)
- end
+ # sanitize!(_collection)
+ # end
- def sanitize!(collection)
- sanitizer.try(:apply_to, collection) || collection
- end
+ # def sanitize!(collection)
+ # sanitizer.try(:apply_to, collection) || collection
+ # end
- def sanitizer
- return unless (klass = collection_options[:sanitizer])
- klass.new(site.default_locale, site.locales)
- end
+ # def sanitizer
+ # return unless (klass = collection_options[:sanitizer])
+ # klass.new(site.default_locale, site.locales)
+ # end
- module ClassMethods
+ # module ClassMethods
- def set_collection(options = {})
- class_eval do
- define_method(:collection_options) { options }
- end
- end
+ # def set_collection(options = {})
+ # class_eval do
+ # define_method(:collection_options) { options }
+ # end
+ # end
- end
+ # end
- end
+ # end
- end
- end
- end
- end
- end
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/content_entry.rb b/lib/locomotive/steam/repositories/filesystem/content_entry.rb +136 -136
@@ @@ -1,166 +1,166 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
- class ContentEntry < Struct.new(:loader, :site, :current_locale, :content_type_repository)
+ # class ContentEntry < Struct.new(:loader, :site, :current_locale, :content_type_repository)
- include Concerns::Queryable
+ # include Concerns::Queryable
- set_collection model: Filesystem::Models::ContentEntry, sanitizer: Filesystem::Sanitizers::ContentEntry
+ # set_collection model: Filesystem::Models::ContentEntry, sanitizer: Filesystem::Sanitizers::ContentEntry
- # Engine: ???
- def all(type, conditions = {})
- conditions = { _visible: true }.merge(conditions || {})
+ # # Engine: ???
+ # def all(type, conditions = {})
+ # conditions = { _visible: true }.merge(conditions || {})
- # priority:
- # 1/ order_by passed in the conditions parameter
- # 2/ the default order (_position) defined in the content type
- order_by = conditions.delete(:order_by)|| conditions.delete('order_by') || type.order_by
-
- query(type) do
- where(conditions).order_by(order_by)
- end.all
- end
-
- # Engine: content_type.entries.build(attributes)
- def build(type, attributes = {})
- collection_options[:model].new(attributes).tap do |entry|
- # set the reference to the content type
- entry.content_type = type
- end
- end
-
- # Engine: entry.save
- def persist(entry)
- return nil if entry.nil?
-
- collection = memoized_collection(entry.content_type)
-
- # slugify entry
- sanitizer.set_slug(entry, collection)
-
- collection << entry # immediate result
-
- # make sure we write it back to the data source
- loader.write(entry.content_type, entry.attributes)
- end
-
- # Engine: all(conditions).count > 0
- def exists?(type, conditions = {})
- query(type) { where(conditions) }.all.size > 0
- end
+ # # priority:
+ # # 1/ order_by passed in the conditions parameter
+ # # 2/ the default order (_position) defined in the content type
+ # order_by = conditions.delete(:order_by)|| conditions.delete('order_by') || type.order_by
+
+ # query(type) do
+ # where(conditions).order_by(order_by)
+ # end.all
+ # end
+
+ # # Engine: content_type.entries.build(attributes)
+ # def build(type, attributes = {})
+ # collection_options[:model].new(attributes).tap do |entry|
+ # # set the reference to the content type
+ # entry.content_type = type
+ # end
+ # end
+
+ # # Engine: entry.save
+ # def persist(entry)
+ # return nil if entry.nil?
+
+ # collection = memoized_collection(entry.content_type)
+
+ # # slugify entry
+ # sanitizer.set_slug(entry, collection)
+
+ # collection << entry # immediate result
+
+ # # make sure we write it back to the data source
+ # loader.write(entry.content_type, entry.attributes)
+ # end
+
+ # # Engine: all(conditions).count > 0
+ # def exists?(type, conditions = {})
+ # query(type) { where(conditions) }.all.size > 0
+ # end
- # Engine: not necessary
- def by_slug(type, slug)
- query(type) { where(_slug: slug) }.first
- end
+ # # Engine: not necessary
+ # def by_slug(type, slug)
+ # query(type) { where(_slug: slug) }.first
+ # end
- # Engine: entry.name :-)
- def value_for(name, entry, conditions = {})
- value = entry.send(name)
+ # # Engine: entry.name :-)
+ # def value_for(name, entry, conditions = {})
+ # value = entry.send(name)
- if value.respond_to?(:association)
- association(value, conditions || {})
- else
- value
- end
- end
+ # if value.respond_to?(:association)
+ # association(value, conditions || {})
+ # else
+ # value
+ # end
+ # end
- # Engine: entry.next
- def next(entry)
- next_or_previous(entry, 'gt', 'lt')
- end
+ # # Engine: entry.next
+ # def next(entry)
+ # next_or_previous(entry, 'gt', 'lt')
+ # end
- # Engine: entry.previous
- def previous(entry)
- next_or_previous(entry, 'lt', 'gt')
- end
+ # # Engine: entry.previous
+ # def previous(entry)
+ # next_or_previous(entry, 'lt', 'gt')
+ # end
- # Engine: content_type.entries.klass.send(:group_by_select_option, name, content_type.order_by_definition)
- def group_by_select_option(type, name)
- return {} if type.nil? || name.nil? || type.fields_by_name[name].type != :select
+ # # Engine: content_type.entries.klass.send(:group_by_select_option, name, content_type.order_by_definition)
+ # def group_by_select_option(type, name)
+ # return {} if type.nil? || name.nil? || type.fields_by_name[name].type != :select
- _groups = all(type).group_by(&name)
+ # _groups = all(type).group_by(&name)
- groups = content_type_repository.select_options(type, name).map do |option|
- { name: option, entries: _groups.delete(option) || [] }
- end
+ # groups = content_type_repository.select_options(type, name).map do |option|
+ # { name: option, entries: _groups.delete(option) || [] }
+ # end
- unless _groups.blank?
- groups << (empty = { name: nil, entries: [] })
- _groups.values.each { |list| empty[:entries] += list }
- end
+ # unless _groups.blank?
+ # groups << (empty = { name: nil, entries: [] })
+ # _groups.values.each { |list| empty[:entries] += list }
+ # end
- groups
- end
+ # groups
+ # end
- private
+ # private
- def type_from(slug)
- content_type_repository.by_slug(slug)
- end
+ # def type_from(slug)
+ # content_type_repository.by_slug(slug)
+ # end
- def localized_slug(entry)
- localized_attribute(entry, :_slug)
- end
+ # def localized_slug(entry)
+ # localized_attribute(entry, :_slug)
+ # end
- def association(metadata, conditions = {})
- case metadata.type
- when :belongs_to then belongs_to_association(metadata)
- when :has_many then has_many_association(metadata, conditions)
- when :many_to_many then many_to_many_association(metadata, conditions)
- end
- end
-
- def belongs_to_association(metadata)
- type = type_from(metadata.target_class_slug)
- by_slug(type, metadata.target_slugs.first)
- end
+ # def association(metadata, conditions = {})
+ # case metadata.type
+ # when :belongs_to then belongs_to_association(metadata)
+ # when :has_many then has_many_association(metadata, conditions)
+ # when :many_to_many then many_to_many_association(metadata, conditions)
+ # end
+ # end
+
+ # def belongs_to_association(metadata)
+ # type = type_from(metadata.target_class_slug)
+ # by_slug(type, metadata.target_slugs.first)
+ # end
- def has_many_association(metadata, conditions)
- many_association(metadata,
- { metadata.target_field => localized_slug(metadata.source) }.merge(conditions))
- end
+ # def has_many_association(metadata, conditions)
+ # many_association(metadata,
+ # { metadata.target_field => localized_slug(metadata.source) }.merge(conditions))
+ # end
- def many_to_many_association(metadata, conditions)
- many_association(metadata,
- { '_slug.in' => metadata.target_slugs }.merge(conditions))
- end
+ # def many_to_many_association(metadata, conditions)
+ # many_association(metadata,
+ # { '_slug.in' => metadata.target_slugs }.merge(conditions))
+ # end
- def many_association(metadata, conditions)
- type = type_from(metadata.target_class_slug)
+ # def many_association(metadata, conditions)
+ # type = type_from(metadata.target_class_slug)
- if order_by = metadata.order_by
- conditions = { order_by: order_by }.merge(conditions)
- end
+ # if order_by = metadata.order_by
+ # conditions = { order_by: order_by }.merge(conditions)
+ # end
- all(type, conditions)
- end
+ # all(type, conditions)
+ # end
- def memoized_collection(content_type)
- slug = content_type.slug
- @collections ||= {}
+ # def memoized_collection(content_type)
+ # slug = content_type.slug
+ # @collections ||= {}
- return @collections[slug] if @collections[slug]
-
- @collections[slug] = collection(content_type)
- end
-
- def next_or_previous(entry, asc_op, desc_op)
- return nil if entry.nil?
+ # return @collections[slug] if @collections[slug]
+
+ # @collections[slug] = collection(content_type)
+ # end
+
+ # def next_or_previous(entry, asc_op, desc_op)
+ # return nil if entry.nil?
- type = entry.content_type
- column, direction = type.order_by.split
- operator = direction == 'asc' ? asc_op : desc_op
- value = localized_attribute(entry, column)
+ # type = entry.content_type
+ # column, direction = type.order_by.split
+ # operator = direction == 'asc' ? asc_op : desc_op
+ # value = localized_attribute(entry, column)
- query(type) { where("#{column}.#{operator}" => value) }.first
- end
+ # query(type) { where("#{column}.#{operator}" => value) }.first
+ # end
- end
+ # end
- end
- end
- end
- end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/content_type.rb b/lib/locomotive/steam/repositories/filesystem/content_type.rb +57 -57
@@ @@ -1,57 +1,57 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
-
- class ContentType < Struct.new(:loader, :site, :current_locale)
-
- include Concerns::Queryable
-
- set_collection model: Filesystem::Models::ContentType, sanitizer: Filesystem::Sanitizers::ContentType
-
- # Engine: site.where(slug: slug_or_content_type).first
- def by_slug(slug_or_content_type)
- if slug_or_content_type.is_a?(String)
- query { where(slug: slug_or_content_type) }.first
- else
- slug_or_content_type
- end
- end
-
- # Engine: content_type.entries_custom_fields.where(unique: true)
- def look_for_unique_fields(content_type)
- return nil if content_type.nil?
-
- {}.tap do |hash|
- content_type.query_fields { where(unique: true) }.each do |field|
- hash[field.name] = field
- end
- end
- end
-
- # Engine: content_type.entries_custom_fields
- def fields_for(content_type)
- return nil if content_type.nil?
-
- content_type.fields
- end
-
- # Engine: content_type.entries.klass.send(:"#{name}_options").map { |option| option['name'] }
- def select_options(content_type, name)
- return nil if content_type.nil? || name.nil?
-
- field = content_type.fields_by_name[name]
-
- if field.type == :select
- localized_attribute(field, :select_options)
- else
- nil
- end
- end
-
- end
-
- end
- end
- end
- end
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+
+ # class ContentType < Struct.new(:loader, :site, :current_locale)
+
+ # include Concerns::Queryable
+
+ # set_collection model: Filesystem::Models::ContentType, sanitizer: Filesystem::Sanitizers::ContentType
+
+ # # Engine: site.where(slug: slug_or_content_type).first
+ # def by_slug(slug_or_content_type)
+ # if slug_or_content_type.is_a?(String)
+ # query { where(slug: slug_or_content_type) }.first
+ # else
+ # slug_or_content_type
+ # end
+ # end
+
+ # # Engine: content_type.entries_custom_fields.where(unique: true)
+ # def look_for_unique_fields(content_type)
+ # return nil if content_type.nil?
+
+ # {}.tap do |hash|
+ # content_type.query_fields { where(unique: true) }.each do |field|
+ # hash[field.name] = field
+ # end
+ # end
+ # end
+
+ # # Engine: content_type.entries_custom_fields
+ # def fields_for(content_type)
+ # return nil if content_type.nil?
+
+ # content_type.fields
+ # end
+
+ # # Engine: content_type.entries.klass.send(:"#{name}_options").map { |option| option['name'] }
+ # def select_options(content_type, name)
+ # return nil if content_type.nil? || name.nil?
+
+ # field = content_type.fields_by_name[name]
+
+ # if field.type == :select
+ # localized_attribute(field, :select_options)
+ # else
+ # nil
+ # end
+ # end
+
+ # end
+
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/memory_adapter/condition.rb b/lib/locomotive/steam/repositories/filesystem/memory_adapter/condition.rb +101 -101
@@ @@ -1,101 +1,101 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module MemoryAdapter
- class Condition
-
- class UnsupportedOperator < StandardError; end
-
- OPERATORS = %i(== eq ne neq matches gt gte lt lte size all in nin).freeze
-
- attr_reader :field, :operator, :value
-
- def initialize(operator_and_field, value, locale)
- @locale = locale.try(:to_sym)
- @operator_and_field, @value = operator_and_field, value
- @operator, @field = :==, operator_and_field
-
- decode_operator_and_field!
- end
-
- def matches?(entry)
- entry_value = entry_value(entry)
-
- adapt_operator!(entry_value)
- case @operator
- when :== then entry_value == @value
- when :eq then entry_value == @value
- when :ne then entry_value != @value
- when :neq then entry_value != @value
- when :matches then @value =~ entry_value
- when :gt then entry_value > @value
- when :gte then entry_value >= @value
- when :lt then entry_value < @value
- when :lte then entry_value <= @value
- when :size then entry_value.size == @value
- when :all then array_contains?([*@value], entry_value)
- when :in, :nin then value_is_in_entry_value?(entry_value)
- else
- raise UnknownConditionInScope.new("#{@operator} is unknown or not implemented.")
- end
- end
-
- def to_s
- "#{field} #{operator} #{@value.to_s}"
- end
-
- protected
-
- def entry_value(entry)
- case (value = entry.send(@field))
- when Hash
- value.fetch(@locale) { nil }
- else
- value
- end
- end
-
- def decode_operator_and_field!
- if match = @operator_and_field.match(/^(?<field>[a-z0-9_-]+)\.(?<operator>.*)$/)
- @field = match[:field].to_sym
- @operator = match[:operator].to_sym
- check_operator!
- end
-
- @operator = :matches if @value.is_a?(Regexp)
- end
-
- def adapt_operator!(value)
- case value
- when Array
- @operator = :in if @operator == :==
- end
- end
-
- def value_is_in_entry_value?(value)
- _matches = if value.is_a?(Array)
- array_contains?([*value], [*@value])
- else
- [*@value].include?(value)
- end
- @operator == :in ? _matches : !_matches
- end
-
- private
-
- def check_operator!
- raise UnsupportedOperator.new unless OPERATORS.include?(@operator)
- end
-
- def array_contains?(source, target)
- source & target == target
- end
-
- end
-
- end
- end
- end
- end
- end
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module MemoryAdapter
+ # class Condition
+
+ # class UnsupportedOperator < StandardError; end
+
+ # OPERATORS = %i(== eq ne neq matches gt gte lt lte size all in nin).freeze
+
+ # attr_reader :field, :operator, :value
+
+ # def initialize(operator_and_field, value, locale)
+ # @locale = locale.try(:to_sym)
+ # @operator_and_field, @value = operator_and_field, value
+ # @operator, @field = :==, operator_and_field
+
+ # decode_operator_and_field!
+ # end
+
+ # def matches?(entry)
+ # entry_value = entry_value(entry)
+
+ # adapt_operator!(entry_value)
+ # case @operator
+ # when :== then entry_value == @value
+ # when :eq then entry_value == @value
+ # when :ne then entry_value != @value
+ # when :neq then entry_value != @value
+ # when :matches then @value =~ entry_value
+ # when :gt then entry_value > @value
+ # when :gte then entry_value >= @value
+ # when :lt then entry_value < @value
+ # when :lte then entry_value <= @value
+ # when :size then entry_value.size == @value
+ # when :all then array_contains?([*@value], entry_value)
+ # when :in, :nin then value_is_in_entry_value?(entry_value)
+ # else
+ # raise UnknownConditionInScope.new("#{@operator} is unknown or not implemented.")
+ # end
+ # end
+
+ # def to_s
+ # "#{field} #{operator} #{@value.to_s}"
+ # end
+
+ # protected
+
+ # def entry_value(entry)
+ # case (value = entry.send(@field))
+ # when Hash
+ # value.fetch(@locale) { nil }
+ # else
+ # value
+ # end
+ # end
+
+ # def decode_operator_and_field!
+ # if match = @operator_and_field.match(/^(?<field>[a-z0-9_-]+)\.(?<operator>.*)$/)
+ # @field = match[:field].to_sym
+ # @operator = match[:operator].to_sym
+ # check_operator!
+ # end
+
+ # @operator = :matches if @value.is_a?(Regexp)
+ # end
+
+ # def adapt_operator!(value)
+ # case value
+ # when Array
+ # @operator = :in if @operator == :==
+ # end
+ # end
+
+ # def value_is_in_entry_value?(value)
+ # _matches = if value.is_a?(Array)
+ # array_contains?([*value], [*@value])
+ # else
+ # [*@value].include?(value)
+ # end
+ # @operator == :in ? _matches : !_matches
+ # end
+
+ # private
+
+ # def check_operator!
+ # raise UnsupportedOperator.new unless OPERATORS.include?(@operator)
+ # end
+
+ # def array_contains?(source, target)
+ # source & target == target
+ # end
+
+ # end
+
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/memory_adapter/query.rb b/lib/locomotive/steam/repositories/filesystem/memory_adapter/query.rb +113 -113
@@ @@ -1,113 +1,113 @@
- require 'forwardable'
-
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module MemoryAdapter
-
- class Query
-
- include Enumerable
- extend Forwardable
-
- def_delegators :all, :each, :to_s, :to_a, :empty?, :size
-
- alias :length :size
- alias :count :size
-
- attr_reader :conditions
-
- def initialize(dataset, locale=nil, &block)
- @dataset = dataset
- @conditions = []
- @sorting = nil
- @limit = nil
- @offset = 0
- @locale = locale
- instance_eval(&block) if block_given?
- end
-
- def where(conditions = {})
- @conditions += conditions.map { |name, value| Condition.new(name, value, @locale) }
- self
- end
-
- def +(query)
- @conditions += query.conditions
- self
- end
-
- def order_by(order_string)
- unless order_string.blank?
- pattern = order_string.include?('.') ? '.' : ' '
- @sorting = order_string.downcase.split(pattern).map(&:to_sym)
- end
- self
- end
-
- def limit(num)
- @limit = num
- self
- end
-
- def offset(num)
- @offset = num
- self
- end
-
- def ==(other)
- if other.kind_of? Array
- all == other
- else
- super
- end
- end
-
- def all
- limited sorted(filtered)
- end
-
- def sorted(entries)
- return entries if @sorting.nil?
-
- name, direction = @sorting.first, (@sorting.last || :asc)
- if direction == :asc
- entries.sort { |a, b| a.send(name) <=> b.send(name) }
- else
- entries.sort { |a, b| b.send(name) <=> a.send(name) }
- end
- end
-
- def limited(entries)
- return [] if @limit == 0
- return entries if @offset == 0 && @limit.nil?
-
- subentries = entries.drop(@offset || 0)
- if @limit.kind_of? Integer
- subentries.take(@limit)
- else
- subentries
- end
- end
-
- def filtered
- @dataset.to_a.dup.find_all do |entry|
- accepted = true
-
- @conditions.each do |_condition|
- unless _condition.matches?(entry)
- accepted = false
- break # no to go further
- end
- end
- accepted
- end
- end # filtered
-
- end
- end
- end
- end
- end
- end
+ # require 'forwardable'
+
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module MemoryAdapter
+
+ # class Query
+
+ # include Enumerable
+ # extend Forwardable
+
+ # def_delegators :all, :each, :to_s, :to_a, :empty?, :size
+
+ # alias :length :size
+ # alias :count :size
+
+ # attr_reader :conditions
+
+ # def initialize(dataset, locale=nil, &block)
+ # @dataset = dataset
+ # @conditions = []
+ # @sorting = nil
+ # @limit = nil
+ # @offset = 0
+ # @locale = locale
+ # instance_eval(&block) if block_given?
+ # end
+
+ # def where(conditions = {})
+ # @conditions += conditions.map { |name, value| Condition.new(name, value, @locale) }
+ # self
+ # end
+
+ # def +(query)
+ # @conditions += query.conditions
+ # self
+ # end
+
+ # def order_by(order_string)
+ # unless order_string.blank?
+ # pattern = order_string.include?('.') ? '.' : ' '
+ # @sorting = order_string.downcase.split(pattern).map(&:to_sym)
+ # end
+ # self
+ # end
+
+ # def limit(num)
+ # @limit = num
+ # self
+ # end
+
+ # def offset(num)
+ # @offset = num
+ # self
+ # end
+
+ # def ==(other)
+ # if other.kind_of? Array
+ # all == other
+ # else
+ # super
+ # end
+ # end
+
+ # def all
+ # limited sorted(filtered)
+ # end
+
+ # def sorted(entries)
+ # return entries if @sorting.nil?
+
+ # name, direction = @sorting.first, (@sorting.last || :asc)
+ # if direction == :asc
+ # entries.sort { |a, b| a.send(name) <=> b.send(name) }
+ # else
+ # entries.sort { |a, b| b.send(name) <=> a.send(name) }
+ # end
+ # end
+
+ # def limited(entries)
+ # return [] if @limit == 0
+ # return entries if @offset == 0 && @limit.nil?
+
+ # subentries = entries.drop(@offset || 0)
+ # if @limit.kind_of? Integer
+ # subentries.take(@limit)
+ # else
+ # subentries
+ # end
+ # end
+
+ # def filtered
+ # @dataset.to_a.dup.find_all do |entry|
+ # accepted = true
+
+ # @conditions.each do |_condition|
+ # unless _condition.matches?(entry)
+ # accepted = false
+ # break # no to go further
+ # end
+ # end
+ # accepted
+ # end
+ # end # filtered
+
+ # end
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/memory_adapter/simple_cache_store.rb b/lib/locomotive/steam/repositories/filesystem/memory_adapter/simple_cache_store.rb +42 -42
@@ @@ -1,42 +1,42 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module MemoryAdapter
-
- class SimpleCacheStore
-
- @@store = {}
-
- def fetch(name, options = nil, &block)
- if block_given?
- read(name) || write(name, yield)
- else
- read(name)
- end
- end
-
- def read(name, options = nil)
- @@store[name]
- end
-
- def write(name, value, options = nil)
- @@store[name] = value
- end
-
- def clear
- @@store.clear
- end
-
- #:nocov:
- def _store
- @@store
- end
-
- end
-
- end
- end
- end
- end
- end
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module MemoryAdapter
+
+ # class SimpleCacheStore
+
+ # @@store = {}
+
+ # def fetch(name, options = nil, &block)
+ # if block_given?
+ # read(name) || write(name, yield)
+ # else
+ # read(name)
+ # end
+ # end
+
+ # def read(name, options = nil)
+ # @@store[name]
+ # end
+
+ # def write(name, value, options = nil)
+ # @@store[name] = value
+ # end
+
+ # def clear
+ # @@store.clear
+ # end
+
+ # #:nocov:
+ # def _store
+ # @@store
+ # end
+
+ # end
+
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/models/page.rb b/lib/locomotive/steam/repositories/filesystem/models/page.rb +56 -56
@@ @@ -1,56 +1,56 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module Models
-
- class Page < Base
-
- set_localized_attributes [:title, :slug, :permalink, :editable_elements, :template, :template_path, :redirect_url, :fullpath, :seo_title, :meta_description, :meta_keywords]
-
- attr_accessor :depth, :_fullpath, :content_entry
-
- def initialize(attributes)
- super({
- handle: nil,
- listed: false,
- published: true,
- fullpath: {},
- content_type: nil,
- position: 99,
- template: {},
- editable_elements: {},
- redirect_url: {}
- }.merge(attributes))
- end
-
- def listed?; !!listed; end
- def published?; !!published; end
-
- def templatized?
- !!content_type
- end
-
- def depth_and_position
- depth * 100 + position
- end
-
- def index?
- attributes[:fullpath].values.first == 'index'
- end
-
- def not_found?
- attributes[:fullpath].values.first == '404'
- end
-
- def to_liquid
- Steam::Liquid::Drops::Page.new(self)
- end
-
- end
-
- end
- end
- end
- end
- end
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module Models
+
+ # class Page < Base
+
+ # set_localized_attributes [:title, :slug, :permalink, :editable_elements, :template, :template_path, :redirect_url, :fullpath, :seo_title, :meta_description, :meta_keywords]
+
+ # attr_accessor :depth, :_fullpath, :content_entry
+
+ # def initialize(attributes)
+ # super({
+ # handle: nil,
+ # listed: false,
+ # published: true,
+ # fullpath: {},
+ # content_type: nil,
+ # position: 99,
+ # template: {},
+ # editable_elements: {},
+ # redirect_url: {}
+ # }.merge(attributes))
+ # end
+
+ # def listed?; !!listed; end
+ # def published?; !!published; end
+
+ # def templatized?
+ # !!content_type
+ # end
+
+ # def depth_and_position
+ # depth * 100 + position
+ # end
+
+ # def index?
+ # attributes[:fullpath].values.first == 'index'
+ # end
+
+ # def not_found?
+ # attributes[:fullpath].values.first == '404'
+ # end
+
+ # def to_liquid
+ # Steam::Liquid::Drops::Page.new(self)
+ # end
+
+ # end
+
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/models/site.rb b/lib/locomotive/steam/repositories/filesystem/models/site.rb +29 -29
@@ @@ -1,38 +1,38 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module Models
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module Models
- class Site < Base
+ # class Site < Base
- set_localized_attributes [:seo_title, :meta_description, :meta_keywords]
+ # set_localized_attributes [:seo_title, :meta_description, :meta_keywords]
- attr_accessor :root_path
+ # attr_accessor :root_path
- def initialize(attributes = {})
- super({
- timezone: 'UTC',
- prefix_default_locale: false
- }.merge(attributes))
- end
+ # def initialize(attributes = {})
+ # super({
+ # timezone: 'UTC',
+ # prefix_default_locale: false
+ # }.merge(attributes))
+ # end
- def default_locale
- self.locales.try(:first) || :en
- end
+ # def default_locale
+ # self.locales.try(:first) || :en
+ # end
- def locales
- attributes[:locales].map(&:to_sym)
- end
+ # def locales
+ # attributes[:locales].map(&:to_sym)
+ # end
- def to_liquid
- Steam::Liquid::Drops::Site.new(self)
- end
+ # def to_liquid
+ # Steam::Liquid::Drops::Site.new(self)
+ # end
- end
+ # end
- end
- end
- end
- end
- end
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/models/snippet.rb b/lib/locomotive/steam/repositories/filesystem/models/snippet.rb +16 -16
@@ @@ -1,21 +1,21 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module Models
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module Models
- class Snippet < Base
+ # class Snippet < Base
- set_localized_attributes [:template, :template_path]
+ # set_localized_attributes [:template, :template_path]
- def initialize(attributes)
- super({ template: {} }.merge(attributes))
- end
+ # def initialize(attributes)
+ # super({ template: {} }.merge(attributes))
+ # end
- end
+ # end
- end
- end
- end
- end
- end
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/page.rb b/lib/locomotive/steam/repositories/filesystem/page.rb +0 -106
@@ @@ -1,106 +0,0 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
-
- class Page < Struct.new(:loader, :site, :current_locale)
-
- include Concerns::Queryable
-
- set_collection model: Filesystem::Models::Page, sanitizer: Filesystem::Sanitizers::Page
-
- # Engine: site.pages.ordered_pages(conditions)
- def all(conditions = {})
- default_order = 'depth_and_position asc'
- query { where(conditions || {}).order_by(default_order) }.all
- end
-
- # Engine: site.pages.where(handle: handle).first
- def by_handle(handle)
- query { where(handle: handle) }.first
- end
-
- def by_fullpath(path)
- query { where(fullpath: path) }.first
- end
-
- def matching_fullpath(list)
- all('fullpath.in' => list)
- end
-
- # Engine: ???
- def template_for(entry, handle = nil)
- conditions = { templatized?: true, content_type: entry.try(:content_type_slug) }
-
- conditions[:handle] = handle if handle
-
- query { where(conditions) }.first.tap do |page|
- page.content_entry = entry if page
- end
- end
-
- def root
- query { where(fullpath: 'index') }.first
- end
-
- # Engine: page.parent
- def parent_of(page)
- return nil if page.nil? || page.index?
-
- # TODO: parent_id property
- segments = localized_attribute(page, :fullpath).split('/')
- path = segments[0..-2].join('/')
- path = 'index' if path.blank?
-
- by_fullpath(path)
- end
-
- # Engine: page.ancestors_and_self
- def ancestors_of(page)
- return [] if page.nil?
-
- # Example: foo/bar/test
- # ['foo', 'foo/bar', 'foo/bar/test']
- segments = localized_attribute(page, :fullpath).split('/')
- paths = 0.upto(segments.size - 1).map { |i| segments[0..i].join('/') }
-
- all('fullpath.in' => ['index'] + paths)
- end
-
- # Engine: page.children
- def children_of(page)
- return [] if page.nil?
-
- conditions = { 'slug.ne' => nil, depth: page.depth + 1 }
-
- unless page.index?
- conditions[:fullpath] = /^#{localized_attribute(page, :fullpath)}\//
- end
-
- all(conditions)
- end
-
- # Engine: page.editable_elements
- def editable_elements_of(page)
- return nil if page.nil?
- localized_attribute(page, :editable_elements).values
- end
-
- # Engine: page.editable_elements.where(block: block, slug: slug).first
- def editable_element_for(page, block, slug)
- return nil if page.nil?
-
- if elements = localized_attribute(page, :editable_elements)
- name = [block, slug].compact.join('/')
- elements[name]
- else
- nil
- end
- end
-
- end
-
- end
- end
- end
- end
locomotive/steam/repositories/filesystem/sanitizers/content_entry.rb b/lib/locomotive/steam/repositories/filesystem/sanitizers/content_entry.rb +54 -54
@@ @@ -1,66 +1,66 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module Sanitizers
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module Sanitizers
- class ContentEntry < Struct.new(:default_locale, :locales)
+ # class ContentEntry < Struct.new(:default_locale, :locales)
- def apply_to(collection)
- collection.each do |entry|
- set_content_type(entry)
- add_label(entry)
- set_slug(entry, collection)
- end
- end
+ # def apply_to(collection)
+ # collection.each do |entry|
+ # set_content_type(entry)
+ # add_label(entry)
+ # set_slug(entry, collection)
+ # end
+ # end
- def set_slug(entry, collection)
- if entry._label.is_a?(Hash)
- entry[:_slug] ||= {}
- entry._label.each do |locale, label|
- entry[:_slug][locale] ||= slugify(label, collection, locale)
- end
- else
- entry[:_slug] ||= slugify(entry._label, collection)
- end
- end
+ # def set_slug(entry, collection)
+ # if entry._label.is_a?(Hash)
+ # entry[:_slug] ||= {}
+ # entry._label.each do |locale, label|
+ # entry[:_slug][locale] ||= slugify(label, collection, locale)
+ # end
+ # else
+ # entry[:_slug] ||= slugify(entry._label, collection)
+ # end
+ # end
- def slugify(label, collection, locale = nil)
- base, index = label.permalink(false), nil
- _slugify = -> (i) { [base, i].compact.join('-') }
+ # def slugify(label, collection, locale = nil)
+ # base, index = label.permalink(false), nil
+ # _slugify = -> (i) { [base, i].compact.join('-') }
- while !is_slug_unique?(_slugify.call(index), collection, locale)
- index = index ? index + 1 : 1
- end
+ # while !is_slug_unique?(_slugify.call(index), collection, locale)
+ # index = index ? index + 1 : 1
+ # end
- _slugify.call(index)
- end
+ # _slugify.call(index)
+ # end
- def is_slug_unique?(slug, collection, locale)
- Filesystem::MemoryAdapter::Query.new(collection, locale) do
- where(_slug: slug)
- end.first.nil?
- end
+ # def is_slug_unique?(slug, collection, locale)
+ # Filesystem::MemoryAdapter::Query.new(collection, locale) do
+ # where(_slug: slug)
+ # end.first.nil?
+ # end
- def set_content_type(entry)
- entry.content_type = entry.attributes.delete(:content_type)
- end
+ # def set_content_type(entry)
+ # entry.content_type = entry.attributes.delete(:content_type)
+ # end
- def add_label(entry)
- value = entry.attributes.delete(:_label)
- name = entry.content_type.label_field_name
+ # def add_label(entry)
+ # value = entry.attributes.delete(:_label)
+ # name = entry.content_type.label_field_name
- if entry.attributes[name].is_a?(Hash) # localized?
- entry.attributes[name][default_locale] = value
- else
- entry.attributes[name] ||= value
- end
- end
+ # if entry.attributes[name].is_a?(Hash) # localized?
+ # entry.attributes[name][default_locale] = value
+ # else
+ # entry.attributes[name] ||= value
+ # end
+ # end
- end
+ # end
- end
- end
- end
- end
- end
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/sanitizers/content_type.rb b/lib/locomotive/steam/repositories/filesystem/sanitizers/content_type.rb +49 -49
@@ @@ -1,49 +1,49 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module Sanitizers
-
- class ContentType < Struct.new(:default_locale, :locales)
-
- def apply_to(collection)
- collection.each do |content_type|
- if list = content_type.attributes[:fields]
- content_type[:slug] = content_type[:slug].to_s
- content_type.fields = build_fields(list)
- end
- build_fields_by_name_shortcut(content_type)
- end
- end
-
- def build_fields(list)
- list.map do |attributes|
- name, _attributes = attributes.keys.first, attributes.values.first
-
- _attributes[:name] = name.to_sym
-
- if _attributes[:label].blank?
- _attributes[:label] = name.to_s.humanize
- end
-
- _attributes[:type] = _attributes[:type].try(:to_sym)
-
- Filesystem::Models::ContentTypeField.new(_attributes)
- end
- end
-
- def build_fields_by_name_shortcut(content_type)
- content_type.fields_by_name = {}
-
- (content_type.fields || []).each do |field|
- content_type.fields_by_name[field.name] = field
- end
- end
-
- end
-
- end
- end
- end
- end
- end
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module Sanitizers
+
+ # class ContentType < Struct.new(:default_locale, :locales)
+
+ # def apply_to(collection)
+ # collection.each do |content_type|
+ # if list = content_type.attributes[:fields]
+ # content_type[:slug] = content_type[:slug].to_s
+ # content_type.fields = build_fields(list)
+ # end
+ # build_fields_by_name_shortcut(content_type)
+ # end
+ # end
+
+ # def build_fields(list)
+ # list.map do |attributes|
+ # name, _attributes = attributes.keys.first, attributes.values.first
+
+ # _attributes[:name] = name.to_sym
+
+ # if _attributes[:label].blank?
+ # _attributes[:label] = name.to_s.humanize
+ # end
+
+ # _attributes[:type] = _attributes[:type].try(:to_sym)
+
+ # Filesystem::Models::ContentTypeField.new(_attributes)
+ # end
+ # end
+
+ # def build_fields_by_name_shortcut(content_type)
+ # content_type.fields_by_name = {}
+
+ # (content_type.fields || []).each do |field|
+ # content_type.fields_by_name[field.name] = field
+ # end
+ # end
+
+ # end
+
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/sanitizers/snippet.rb b/lib/locomotive/steam/repositories/filesystem/sanitizers/snippet.rb +0 -28
@@ @@ -1,28 +0,0 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module Sanitizers
-
- class Snippet < Struct.new(:default_locale, :locales)
-
- def apply_to(collection)
- collection.each do |snippet|
- # if there a missing template in one of the locales,
- # then use the one from the default locale
- default = snippet.template_path[default_locale]
-
- locales.each do |locale|
- next if locale == default_locale
- snippet.template_path[locale] ||= default
- end
- end
- end
-
- end
-
- end
- end
- end
- end
- end
locomotive/steam/repositories/filesystem/site.rb b/lib/locomotive/steam/repositories/filesystem/site.rb +0 -17
@@ @@ -1,17 +0,0 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
-
- class Site < Struct.new(:loader)
-
- def by_host(host, options = {})
- Filesystem::Models::Site.new(loader.attributes)
- end
-
- end
-
- end
- end
- end
- end
locomotive/steam/repositories/filesystem/snippet.rb b/lib/locomotive/steam/repositories/filesystem/snippet.rb +0 -21
@@ @@ -1,21 +0,0 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
-
- class Snippet < Struct.new(:loader, :site, :current_locale)
-
- include Concerns::Queryable
-
- set_collection model: Filesystem::Models::Snippet, sanitizer: Filesystem::Sanitizers::Snippet
-
- def by_slug(slug)
- query { where(slug: slug) }.first
- end
-
- end
-
- end
- end
- end
- end
locomotive/steam/repositories/filesystem/theme_asset.rb b/lib/locomotive/steam/repositories/filesystem/theme_asset.rb +18 -18
@@ @@ -1,23 +1,23 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
- class ThemeAsset < Struct.new(:site)
+ # class ThemeAsset < Struct.new(:site)
- # Engine: ['', 'sites', site._id.to_s, 'theme', path].join('/')
- def url_for(path)
- '/' + path
- end
+ # # Engine: ['', 'sites', site._id.to_s, 'theme', path].join('/')
+ # def url_for(path)
+ # '/' + path
+ # end
- # Engine: site.theme_assets.checksums
- def checksums
- {}
- end
+ # # Engine: site.theme_assets.checksums
+ # def checksums
+ # {}
+ # end
- end
+ # end
- end
- end
- end
- end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/translation.rb b/lib/locomotive/steam/repositories/filesystem/translation.rb +16 -16
@@ @@ -1,22 +1,22 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
- class Translation < Struct.new(:loader)
+ # class Translation < Struct.new(:loader)
- include Concerns::Queryable
+ # include Concerns::Queryable
- set_collection model: Filesystem::Models::Translation
+ # set_collection model: Filesystem::Models::Translation
- # Engine: site.translations.where(key: key).first
- def find(key)
- query { where(key: key) }.first
- end
+ # # Engine: site.translations.where(key: key).first
+ # def find(key)
+ # query { where(key: key) }.first
+ # end
- end
+ # end
- end
- end
- end
- end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/yaml_loaders/concerns/common.rb b/lib/locomotive/steam/repositories/filesystem/yaml_loaders/concerns/common.rb +32 -32
@@ @@ -1,39 +1,39 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module YAMLLoaders
- module Concerns
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module YAMLLoaders
+ # module Concerns
- module Common
+ # module Common
- def load(path, frontmatter = false, &block)
- if File.exists?(path)
- yaml = File.open(path).read.force_encoding('utf-8')
- template = nil
+ # def load(path, frontmatter = false, &block)
+ # if File.exists?(path)
+ # yaml = File.open(path).read.force_encoding('utf-8')
+ # template = nil
- if frontmatter && match = yaml.match(FRONTMATTER_REGEXP)
- yaml, template = match[:yaml], match[:template]
- end
+ # if frontmatter && match = yaml.match(FRONTMATTER_REGEXP)
+ # yaml, template = match[:yaml], match[:template]
+ # end
- HashConverter.to_sym(YAML.load(yaml)).tap do |attributes|
- block.call(attributes, template) if block_given?
- end
- else
- Locomotive::Common::Logger.error "No #{path} file found"
- {}
- end
- end
+ # HashConverter.to_sym(YAML.load(yaml)).tap do |attributes|
+ # block.call(attributes, template) if block_given?
+ # end
+ # else
+ # Locomotive::Common::Logger.error "No #{path} file found"
+ # {}
+ # end
+ # end
- def template_extensions
- @extensions ||= %w(liquid haml)
- end
+ # def template_extensions
+ # @extensions ||= %w(liquid haml)
+ # end
- end
+ # end
- end
- end
- end
- end
- end
- end
+ # end
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/yaml_loaders/content_entry.rb b/lib/locomotive/steam/repositories/filesystem/yaml_loaders/content_entry.rb +51 -51
@@ @@ -1,51 +1,51 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module YAMLLoaders
-
- class ContentEntry < Struct.new(:root_path, :cache)
-
- include YAMLLoaders::Concerns::Common
-
- def list_of_attributes(content_type)
- cache.fetch("data/#{content_type.slug}") { load_list(content_type) }
- end
-
- def write(content_type, attributes)
- list = cache.read("data/#{content_type.slug}")
-
- list << attributes.merge(content_type: content_type)
- end
-
- private
-
- def load_list(content_type)
- [].tap do |list|
- each(content_type.slug) do |label, attributes, position|
- default = { content_type: content_type, _position: position, _label: label.to_s }
- list << default.merge(attributes)
- end
- end
- end
-
- def each(slug, &block)
- position = 0
- load(File.join(path, "#{slug}.yml")).each do |element|
- label, attributes = element.keys.first, element.values.first
- yield(label, attributes, position)
- position += 1
- end
- end
-
- def path
- File.join(root_path, 'data')
- end
-
- end
-
- end
- end
- end
- end
- end
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module YAMLLoaders
+
+ # class ContentEntry < Struct.new(:root_path, :cache)
+
+ # include YAMLLoaders::Concerns::Common
+
+ # def list_of_attributes(content_type)
+ # cache.fetch("data/#{content_type.slug}") { load_list(content_type) }
+ # end
+
+ # def write(content_type, attributes)
+ # list = cache.read("data/#{content_type.slug}")
+
+ # list << attributes.merge(content_type: content_type)
+ # end
+
+ # private
+
+ # def load_list(content_type)
+ # [].tap do |list|
+ # each(content_type.slug) do |label, attributes, position|
+ # default = { content_type: content_type, _position: position, _label: label.to_s }
+ # list << default.merge(attributes)
+ # end
+ # end
+ # end
+
+ # def each(slug, &block)
+ # position = 0
+ # load(File.join(path, "#{slug}.yml")).each do |element|
+ # label, attributes = element.keys.first, element.values.first
+ # yield(label, attributes, position)
+ # position += 1
+ # end
+ # end
+
+ # def path
+ # File.join(root_path, 'data')
+ # end
+
+ # end
+
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/yaml_loaders/content_type.rb b/lib/locomotive/steam/repositories/filesystem/yaml_loaders/content_type.rb +42 -42
@@ @@ -1,42 +1,42 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module YAMLLoaders
-
- class ContentType < Struct.new(:root_path, :cache)
-
- include YAMLLoaders::Concerns::Common
-
- def list_of_attributes
- cache.fetch('app/content_types') { load_list }
- end
-
- private
-
- def load_list
- [].tap do |array|
- each_file do |filepath, slug|
- array << { slug: slug }.merge(load(filepath))
- end
- end
- end
-
- def each_file(&block)
- Dir.glob(File.join(path, "*.yml")).each do |filepath|
- slug = File.basename(filepath, '.yml')
- yield(filepath, slug)
- end
- end
-
- def path
- File.join(root_path, 'app', 'content_types')
- end
-
- end
-
- end
- end
- end
- end
- end
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module YAMLLoaders
+
+ # class ContentType < Struct.new(:root_path, :cache)
+
+ # include YAMLLoaders::Concerns::Common
+
+ # def list_of_attributes
+ # cache.fetch('app/content_types') { load_list }
+ # end
+
+ # private
+
+ # def load_list
+ # [].tap do |array|
+ # each_file do |filepath, slug|
+ # array << { slug: slug }.merge(load(filepath))
+ # end
+ # end
+ # end
+
+ # def each_file(&block)
+ # Dir.glob(File.join(path, "*.yml")).each do |filepath|
+ # slug = File.basename(filepath, '.yml')
+ # yield(filepath, slug)
+ # end
+ # end
+
+ # def path
+ # File.join(root_path, 'app', 'content_types')
+ # end
+
+ # end
+
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/filesystem/yaml_loaders/page.rb b/lib/locomotive/steam/repositories/filesystem/yaml_loaders/page.rb +0 -108
@@ @@ -1,108 +0,0 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module YAMLLoaders
-
- class Page < Struct.new(:root_path, :default_locale, :cache)
-
- include YAMLLoaders::Concerns::Common
-
- def list_of_attributes
- cache.fetch('app/views/pages') { load_tree }
- end
-
- private
-
- def path
- @path ||= File.join(root_path, 'app', 'views', 'pages')
- end
-
- def load_tree
- {}.tap do |hash|
- each_file do |filepath, relative_path, fullpath, locale|
-
- if leaf = hash[fullpath]
- update(leaf, filepath, fullpath, locale)
- else
- leaf = build(filepath, fullpath, locale)
- end
-
- hash[fullpath] = leaf
- end
- end.values
- end
-
- def build(filepath, fullpath, locale)
- slug = fullpath.split('/').last
- attributes = get_attributes(filepath, fullpath)
-
- {
- title: { locale => attributes.delete(:title) || (default_locale == locale ? slug.humanize : nil) },
- slug: { locale => attributes.delete(:slug) || slug },
- editable_elements: { locale => attributes.delete(:editable_elements) },
- template_path: { locale => template_path(filepath, attributes, locale) },
- redirect_url: { locale => attributes.delete(:redirect_url) },
- _fullpath: fullpath
- }.merge(attributes)
- end
-
- def update(leaf, filepath, fullpath, locale)
- slug = fullpath.split('/').last
- attributes = get_attributes(filepath, fullpath)
-
- leaf[:title][locale] = attributes.delete(:title) || slug.humanize
- leaf[:slug][locale] = attributes.delete(:slug) || slug
- leaf[:editable_elements][locale] = attributes.delete(:editable_elements)
- leaf[:template_path][locale] = template_path(filepath, attributes, locale)
- leaf[:redirect_url][locale] = attributes.delete(:redirect_url)
-
- leaf.merge!(attributes)
- end
-
- def get_attributes(filepath, fullpath)
- load(filepath, true) do |attributes, template|
- # make sure index/404 are the slugs of the index/404 pages
- attributes.delete(:slug) if %w(index 404).include?(fullpath)
-
- # trick to use the template of the default locale (if available)
- attributes[:template_path] = false if template.blank?
- end
- end
-
- def each_file(&block)
- Dir.glob(File.join(path, '**', '*')).each do |filepath|
- next unless is_liquid_file?(filepath)
-
- relative_path = get_relative_path(filepath)
-
- fullpath, locale = relative_path.split('.')[0..1]
- locale = default_locale if template_extensions.include?(locale)
-
- yield(filepath, relative_path, fullpath, locale.to_sym)
- end
- end
-
- def is_liquid_file?(filepath)
- filepath =~ /\.(#{template_extensions.join('|')})$/
- end
-
- def template_path(filepath, attributes, locale)
- if attributes.delete(:template_path) == false && locale != default_locale
- false
- else
- filepath
- end
- end
-
- def get_relative_path(filepath)
- filepath.gsub(path, '').gsub(/^\//, '')
- end
-
- end
-
- end
- end
- end
- end
- end
locomotive/steam/repositories/filesystem/yaml_loaders/site.rb b/lib/locomotive/steam/repositories/filesystem/yaml_loaders/site.rb +0 -23
@@ @@ -1,23 +0,0 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module YAMLLoaders
-
- class Site < Struct.new(:root_path, :cache)
-
- include YAMLLoaders::Concerns::Common
-
- def attributes
- cache.fetch('config/site') do
- load(File.join(root_path, 'config', 'site.yml'))
- end
- end
-
- end
-
- end
- end
- end
- end
- end
locomotive/steam/repositories/filesystem/yaml_loaders/snippet.rb b/lib/locomotive/steam/repositories/filesystem/yaml_loaders/snippet.rb +0 -65
@@ @@ -1,65 +0,0 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module YAMLLoaders
-
- class Snippet < Struct.new(:root_path, :default_locale, :cache)
-
- include YAMLLoaders::Concerns::Common
-
- def list_of_attributes
- cache.fetch('app/views/snippets') { load_list }
- end
-
- private
-
- def load_list
- {}.tap do |hash|
- each_file do |filepath, slug, locale|
- _locale = locale || default_locale
-
- if element = hash[slug]
- update(element, filepath, _locale)
- else
- element = build(filepath, slug, _locale)
- end
-
- hash[slug] = element
- end
- end.values
- end
-
- def build(filepath, slug, locale)
- {
- name: slug.humanize,
- slug: slug,
- template_path: { locale => filepath }
- }
- end
-
- def update(element, filepath, locale)
- element[:template_path][locale] = filepath
- end
-
- def each_file(&block)
- Dir.glob(File.join(path, "*.{#{template_extensions.join(',')}}")).each do |filepath|
-
- slug, locale = File.basename(filepath).split('.')[0..1]
- locale = default_locale if template_extensions.include?(locale)
-
- yield(filepath, slug.permalink, locale.to_sym)
- end
- end
-
- def path
- File.join(root_path, 'app', 'views', 'snippets')
- end
-
- end
-
- end
- end
- end
- end
- end
locomotive/steam/repositories/filesystem/yaml_loaders/translation.rb b/lib/locomotive/steam/repositories/filesystem/yaml_loaders/translation.rb +27 -27
@@ @@ -1,35 +1,35 @@
- module Locomotive
- module Steam
- module Repositories
- module Filesystem
- module YAMLLoaders
+ # module Locomotive
+ # module Steam
+ # module Repositories
+ # module Filesystem
+ # module YAMLLoaders
- class Translation < Struct.new(:root_path, :cache)
+ # class Translation < Struct.new(:root_path, :cache)
- include YAMLLoaders::Concerns::Common
+ # include YAMLLoaders::Concerns::Common
- def list_of_attributes
- cache.fetch('config/translations') { load_array }
- end
+ # def list_of_attributes
+ # cache.fetch('config/translations') { load_array }
+ # end
- private
+ # private
- def load_array
- [].tap do |array|
- load(path).each do |key, values|
- array << { key: key.to_s, values: HashConverter.to_string(values) }
- end
- end
- end
+ # def load_array
+ # [].tap do |array|
+ # load(path).each do |key, values|
+ # array << { key: key.to_s, values: HashConverter.to_string(values) }
+ # end
+ # end
+ # end
- def path
- File.join(root_path, 'config', 'translations.yml')
- end
+ # def path
+ # File.join(root_path, 'config', 'translations.yml')
+ # end
- end
+ # end
- end
- end
- end
- end
- end
+ # end
+ # end
+ # end
+ # end
+ # end
locomotive/steam/repositories/snippet_repository.rb b/lib/locomotive/steam/repositories/snippet_repository.rb +20 -0
@@ @@ -0,0 +1,20 @@
+ module Locomotive
+ module Steam
+
+ class SnippetRepository
+
+ include Models::Repository
+
+ # set_collection model: Filesystem::Models::Snippet, sanitizer: Filesystem::Sanitizers::Snippet
+
+ mapping :snippets, entity: Snippet do
+ localized_attributes :template_path, :template
+ end
+
+ def by_slug(slug)
+ query { where(slug: slug) }.first
+ end
+
+ end
+ end
+ end
spec/integration/repositories/page_repository_spec.rb +1 -1
@@ @@ -9,7 +9,7 @@ describe Locomotive::Steam::PageRepository do
let(:site) { Locomotive::Steam::Site.new(_id: site_id, locales: %w(en fr nb)) }
let(:locale) { :en }
- let(:repository) { Locomotive::Steam::PageRepository.new(adapter, site, locale) }
+ let(:repository) { described_class.new(adapter, site, locale) }
describe '#all' do
subject { repository.all }
spec/integration/repositories/site_repository_spec.rb +1 -1
@@ @@ -5,7 +5,7 @@ require_relative '../../../lib/locomotive/steam/adapters/mongodb.rb'
describe Locomotive::Steam::SiteRepository do
- let(:repository) { Locomotive::Steam::SiteRepository.new(adapter) }
+ let(:repository) { described_class.new(adapter) }
shared_examples_for 'site repository' do
spec/integration/repositories/snippet_repository_spec.rb +50 -0
@@ @@ -0,0 +1,50 @@
+ require File.join(File.dirname(__FILE__), '..', 'mongodb_helper')
+
+ require_relative '../../../lib/locomotive/steam/adapters/filesystem.rb'
+ require_relative '../../../lib/locomotive/steam/adapters/mongodb.rb'
+
+ describe Locomotive::Steam::SnippetRepository do
+
+ shared_examples_for 'snippet repository' do
+
+ let(:site) { Locomotive::Steam::Site.new(_id: site_id, locales: %w(en fr nb)) }
+ let(:locale) { :en }
+ let(:repository) { described_class.new(adapter, site, locale) }
+
+ describe '#all' do
+ subject { repository.all }
+ it { expect(subject.size).to eq 4 }
+ end
+
+ describe '#by_slug' do
+ subject { repository.by_slug('a_complicated-one') }
+ it { expect(subject).not_to eq nil }
+ end
+
+ end
+
+ context 'MongoDB' do
+
+ it_should_behave_like 'snippet repository' do
+
+ let(:site_id) { BSON::ObjectId.from_string('54eb49c12475804b2b000002') }
+ let(:adapter) { Locomotive::Steam::MongoDBAdapter.new('steam_test', ['127.0.0.1:27017']) }
+
+ end
+
+ end
+
+ context 'Filesystem' do
+
+ it_should_behave_like 'snippet repository' do
+
+ let(:site_id) { 1 }
+ let(:adapter) { Locomotive::Steam::FilesystemAdapter.new(default_fixture_site_path) }
+
+ after(:all) { Locomotive::Steam::Adapters::Filesystem::SimpleCacheStore.new.clear }
+
+ end
+
+ end
+
+ end
spec/unit/repositories/filesystem/snippet_spec.rb +0 -39
@@ @@ -1,39 +0,0 @@
- # require 'spec_helper'
-
- # describe Locomotive::Steam::Repositories::Filesystem::Snippet do
-
- # let(:loader) { instance_double('Loader', list_of_attributes: [{ name: 'Simple', slug: 'simple', template_path: { en: 'simple.yml' } }]) }
- # let(:site) { instance_double('Site', default_locale: :en, locales: [:en, :fr]) }
- # let(:locale) { :en }
-
- # let(:repository) { Locomotive::Steam::Repositories::Filesystem::Snippet.new(loader, site, locale) }
-
- # describe '#collection' do
-
- # subject { repository.send(:collection).first }
-
- # it { expect(subject.class).to eq Locomotive::Steam::Repositories::Filesystem::Models::Snippet }
-
- # it 'applies the sanitizer' do
- # expect(subject[:template_path]).to eq({ en: 'simple.yml', fr: 'simple.yml' })
- # end
-
- # end
-
- # describe '#by_slug' do
-
- # let(:name) { nil }
- # subject { repository.by_slug(name) }
-
- # it { is_expected.to eq nil }
-
- # context 'existing snippet' do
-
- # let(:name) { 'simple' }
- # it { expect(subject.name).to eq 'Simple' }
-
- # end
-
- # end
-
- # end
spec/unit/repositories/page_repository_spec.rb +1 -1
@@ @@ -9,7 +9,7 @@ describe Locomotive::Steam::PageRepository do
let(:locale) { :en }
let(:site) { instance_double('Site', _id: 1, default_locale: :en, locales: %i(en fr)) }
let(:adapter) { Locomotive::Steam::FilesystemAdapter.new(nil) }
- let(:repository) { Locomotive::Steam::PageRepository.new(adapter, site, locale) }
+ let(:repository) { described_class.new(adapter, site, locale) }
before do
allow(adapter).to receive(:collection).and_return(pages)
spec/unit/repositories/site_repository_spec.rb +1 -1
@@ @@ -5,7 +5,7 @@ require_relative '../../../lib/locomotive/steam/adapters/filesystem.rb'
describe Locomotive::Steam::SiteRepository do
let(:adapter) { Locomotive::Steam::FilesystemAdapter.new(nil) }
- let(:repository) { Locomotive::Steam::SiteRepository.new(adapter) }
+ let(:repository) { described_class.new(adapter) }
before do
allow(adapter).to receive(:collection).and_return([{ name: 'Acme', handle: 'acme', domains: ['example.org'] }])
spec/unit/repositories/snippet_repository_spec.rb +37 -0
@@ @@ -0,0 +1,37 @@
+ require 'spec_helper'
+
+ require_relative '../../../lib/locomotive/steam/adapters/filesystem.rb'
+
+ describe Locomotive::Steam::SnippetRepository do
+
+ let(:snippets) { [{ name: 'Simple', slug: 'simple', template_path: { en: 'simple.yml' } }] }
+ let(:locale) { :en }
+ let(:site) { instance_double('Site', _id: 1, default_locale: :en, locales: [:en, :fr]) }
+ let(:adapter) { Locomotive::Steam::FilesystemAdapter.new(nil) }
+ let(:repository) { described_class.new(adapter, site, locale) }
+
+ before do
+ allow(adapter).to receive(:collection).and_return(snippets)
+ adapter.cache = NoCacheStore.new
+ end
+
+ describe '#by_slug' do
+
+ let(:name) { nil }
+ subject { repository.by_slug(name) }
+
+ it { is_expected.to eq nil }
+
+ context 'existing snippet' do
+
+ let(:name) { 'simple' }
+ it { expect(subject.class).to eq Locomotive::Steam::Snippet }
+ it { expect(subject.name).to eq 'Simple' }
+ it { expect(subject[:template_path][:en]).to eq 'simple.yml' }
+ it { expect(subject[:template_path][:fr]).to eq 'simple.yml' }
+
+ end
+
+ end
+
+ end