Class: Regenerate::PageObject

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/regenerate/web-page.rb

Instance Method Summary collapse

Methods included from Utils

#ensureDirectoryExists, #makeBackupFile

Instance Method Details

#erb(templateFileName) ⇒ Object



469
470
471
472
473
474
475
476
477
# File 'lib/regenerate/web-page.rb', line 469

def erb(templateFileName)
  @binding = binding
  File.open(relative_path(templateFileName), "r") do |input|
    templateText = input.read
    template = ERB.new(templateText, nil, nil)
    template.filename = templateFileName
    result = template.result(@binding)
  end
end

#erbFromString(templateString) ⇒ Object



479
480
481
482
483
# File 'lib/regenerate/web-page.rb', line 479

def erbFromString(templateString)
  @binding = binding
  template = ERB.new(templateString, nil, nil)
  template.result(@binding)
end

#relative_path(path) ⇒ Object



486
487
488
# File 'lib/regenerate/web-page.rb', line 486

def relative_path(path)
  File.expand_path(File.join(@baseDir, path.to_str))
end

#require_relative(path) ⇒ Object



490
491
492
# File 'lib/regenerate/web-page.rb', line 490

def require_relative(path)
  require relative_path(path)
end

#savePropertiesObject



494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/regenerate/web-page.rb', line 494

def saveProperties
  properties = {}
  for property in propertiesToSave
    value = instance_variable_get("@" + property.to_s)
    properties[property] = value
  end
  propertiesFileName = relative_path(self.class.propertiesFileName(@baseFileName))
  puts "Saving properties #{properties.inspect} to #{propertiesFileName}"
  ensureDirectoryExists(File.dirname(propertiesFileName))
  File.open(propertiesFileName,"w") do |f|
    f.write(JSON.pretty_generate(properties))
  end
end