class Wpxf::DataFile
Represents a data file found in the data directory.
Attributes
content[RW]
@return the content of the file.
Public Class Methods
new(*path_parts)
click to toggle source
Initialize a new instance of {DataFile}. @param path_parts the path to the file, relative to the data directory.
# File lib/wpxf/core/data_file.rb, line 8 def initialize(*path_parts) self.content = File.read(File.join(Wpxf.data_directory, path_parts)) end
Public Instance Methods
content_with_named_vars(vars)
click to toggle source
@return [String] the contents of the data file with variable replacements.
# File lib/wpxf/core/data_file.rb, line 19 def content_with_named_vars(vars) matcher = /#{vars.keys.map { |k| Regexp.escape(k) }.join('|')}/ content.gsub(matcher, vars) end
php_content()
click to toggle source
@return [String] the contents of a PHP data file without the surrounding
<?php ?> tags.
# File lib/wpxf/core/data_file.rb, line 14 def php_content content.strip.sub(/^<\?php/i, '').sub(/\?>$/i, '') end