class SycLink::Designer

Creates a designer that acts as a proxy between the user and the website. The designer will create a website with the provided title.

Creates a designer that acts as a proxy between the user and the website. The designer will create a website with the provided title.

Attributes

website[RW]

The website the designer is working on

Public Instance Methods

create_website(directory, template_filename) click to toggle source

Creates the html representation of the website. The website is saved to the directory with websites title and needs an erb-template where the links are integrated to. An example template can be found at templates/syclink.html.erb

# File lib/syclink/designer.rb, line 152
def create_website(directory, template_filename)
  template = File.read(template_filename)
  File.open(html_file(directory, website.title), 'w') do |f|
    f.puts website.to_html(template)
  end 
end
delete_website(directory) click to toggle source

Deletes the website if it already exists

# File lib/syclink/designer.rb, line 142
def delete_website(directory)
  if File.exists? yaml_file(directory, website.title)
    FileUtils.rm(yaml_file(directory, website.title)) 
  end
end
export(format) click to toggle source

Export links to specified format

# File lib/syclink/designer.rb, line 51
def export(format)
  message = "to_#{format.downcase}"
  if website.respond_to? message
    website.send(message)
  else
    raise "cannot export to #{format}"
  end
end
load_website(website) click to toggle source

Loads a website based on the provided YAML-file and asigns it to the designer to operate on

# File lib/syclink/designer.rb, line 137
def load_website(website)
  @website = YAML.load_file(website)
end
new_website(title = "SYC LINK") click to toggle source

Creates a new website where designer can operate on

# File lib/syclink/designer.rb, line 22
def new_website(title = "SYC LINK")
  @website = Website.new(title)
end
save_website(directory) click to toggle source

Saves the website to the specified directory with the downcased name of the website and the extension 'website'. The website is save as YAML

# File lib/syclink/designer.rb, line 129
def save_website(directory)
  File.open(yaml_file(directory, website.title), 'w') do |f|
    YAML.dump(website, f)
  end
end