class Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentEntry
Public Instance Methods
load(scope)
click to toggle source
Calls superclass method
Locomotive::Steam::Adapters::Filesystem::YAMLLoader#load
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 11 def load(scope) super load_list end
Private Instance Methods
content_type()
click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 120 def content_type @scope.context[:content_type] end
content_type_slug()
click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 124 def content_type_slug content_type.slug end
each(slug) { |label, attributes, position| ... }
click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 99 def each(slug, &block) position = 0 _load(File.join(path, "#{slug}.yml")).each do |element| label, attributes = if element.respond_to?(:keys) [element.keys.first, element.values.first] else [element, {}] end yield(label, attributes, position) position += 1 end end
file_size(path)
click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 68 def file_size(path) return nil if path.blank? _path = File.join(site_path, 'public', path) File.exists?(_path) ? File.size(_path) : nil end
load_list()
click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 18 def load_list [].tap do |list| each(content_type_slug) do |label, attributes, position| _attributes = { _position: position, _label: label.to_s }.merge(attributes || {}) modify_for_selects(_attributes) modify_for_associations(_attributes) modify_for_files(_attributes) modify_for_passwords(_attributes) list << _attributes end end end
modify_belongs_to_association(field, attributes)
click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 87 def modify_belongs_to_association(field, attributes) # <name>_id attributes[:"#{field.name}_id"] = attributes.delete(field.name.to_sym) # _position_in_<name> attributes[:"position_in_#{field.name}"] = attributes[:_position] end
modify_for_associations(attributes)
click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 76 def modify_for_associations(attributes) content_type.association_fields.each do |field| case field.type when :belongs_to modify_belongs_to_association(field, attributes) when :many_to_many modify_many_to_many_association(field, attributes) end end end
modify_for_files(attributes)
click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 48 def modify_for_files(attributes) content_type.file_fields.each do |field| attributes[:"#{field.name}_size"] ||= {} value = attributes[:"#{field.name}_size"] if (path = attributes[field.name.to_sym]).is_a?(Hash) path.each { |locale, path| value[locale.to_s] = file_size(path) } else value['default'] = file_size(path) end end end
modify_for_passwords(attributes)
click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 61 def modify_for_passwords(attributes) content_type.password_fields.each do |field| uncrypted_password = attributes.delete(field.name.to_sym) attributes[:"#{field.name}_hash"] = BCrypt::Password.create(uncrypted_password) end end
modify_for_selects(attributes)
click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 33 def modify_for_selects(attributes) content_type.select_fields.each do |field| if (option = attributes.delete(field.name.to_sym)).is_a?(Hash) attributes[:"#{field.name}_id"] = option.inject({}) do |memo, (locale, name)| field.select_options.scope.with_locale(locale) do memo[locale] = field.select_options.by_name(name).try(:_id) end memo end else attributes[:"#{field.name}_id"] = field.select_options.by_name(option).try(:_id) end end end
modify_many_to_many_association(field, attributes)
click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 95 def modify_many_to_many_association(field, attributes) attributes[:"#{field.name.to_s.singularize}_ids"] = attributes.delete(field.name.to_sym) end
path()
click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb, line 112 def path return @path if @path # memoization path = File.join(site_path, 'data', env.to_s, 'content_entries') @path = File.exists?(path) ? path : File.join(site_path, 'data') # allow the legacy folder end