Module: Locomotive::Steam::Adapters::Filesystem::YAMLLoader
- Included in:
- Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentEntry, Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentType, Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Page, Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Site, Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Snippet, Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ThemeAsset, Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Translation
- Defined in:
- lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
Instance Attribute Summary collapse
-
#site_path ⇒ Object
readonly
Returns the value of attribute site_path.
Instance Method Summary collapse
- #_load(path, frontmatter = false, &block) ⇒ Object
- #default_locale ⇒ Object
- #initialize(site_path) ⇒ Object
- #load(scope = nil) ⇒ Object
- #safe_yaml_load(yaml, template, path, &block) ⇒ Object
- #template_extensions ⇒ Object
Instance Attribute Details
#site_path ⇒ Object (readonly)
Returns the value of attribute site_path.
7 8 9 |
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 7 def site_path @site_path end |
Instance Method Details
#_load(path, frontmatter = false, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 21 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 safe_yaml_load(yaml, template, path, &block) else Locomotive::Common::Logger.error "No #{path} file found" {} end end |
#default_locale ⇒ Object
17 18 19 |
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 17 def default_locale @scope.default_locale end |
#initialize(site_path) ⇒ Object
9 10 11 |
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 9 def initialize(site_path) @site_path = site_path end |
#load(scope = nil) ⇒ Object
13 14 15 |
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 13 def load(scope = nil) @scope = scope end |
#safe_yaml_load(yaml, template, path, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 37 def safe_yaml_load(yaml, template, path, &block) return {} if yaml.blank? begin HashConverter.to_sym(YAML.load(yaml)).tap do |attributes| block.call(attributes, template) if block_given? end rescue Exception => e raise "Malformed YAML in this file #{path}, error: #{e.}" end end |
#template_extensions ⇒ Object
49 50 51 |
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 49 def template_extensions @extensions ||= %w(liquid haml) end |