module WaxIiif::Utilities::Helpers
Module Helpers
provides helper functions. Which seems logical.
Note that these functions require an @config object to exist on the mixed-in class.
@author David Newbury <david.newbury@gmail.com>
Public Instance Methods
# File lib/wax_iiif/utilities/helpers.rb, line 61 def escape_yaml(str) str.gsub(/\A---(.|\n)*?---/, '') end
Given an id, generate a path on disk for that id, based on the config file
@param [String] id the path to the unique key for the object @return [String] a path within the output dir, with the prefix included
# File lib/wax_iiif/utilities/helpers.rb, line 34 def generate_build_location(id) "#{@config.output_dir}#{@config.prefix}/#{id}" end
This will generate a valid, escaped URI for an object.
This will prepend the standard path and prefix, and will append .json if enabled.
@param [String] path The desired ID string @return [String] The generated URI
# File lib/wax_iiif/utilities/helpers.rb, line 24 def generate_id(path) val = "#{@config.base_url}#{@config.prefix}/#{path}" val += '.json' if @config.use_extensions val end
Given an id and a page number, generate a path on disk for an image The path will be based on the config file.
@param [String] id the unique key for the object @return [String] a path for the image
# File lib/wax_iiif/utilities/helpers.rb, line 43 def generate_image_location(id) generate_build_location "#{@config.image_directory_name}/#{id}" end
# File lib/wax_iiif/utilities/helpers.rb, line 47 def get_data_path(data) data['@id'].gsub(@config.base_url, @config.output_dir) end
# File lib/wax_iiif/utilities/helpers.rb, line 51 def save_to_disk(data) path = get_data_path(data) data['@context'] ||= WaxIiif::PRESENTATION_CONTEXT puts "writing #{path}" if @config.verbose? FileUtils.mkdir_p File.dirname(path) File.open(path, 'w') do |file| file.puts JSON.pretty_generate(data) end end