Class: Projects::Website

Inherits:
Object
  • Object
show all
Defined in:
lib/reparcs/projects.rb

Overview

A Website, a good starting point for larger projects, that require other files, etc.

Direct Known Subclasses

WebsiteWithScript

Instance Method Summary collapse

Constructor Details

#initializeWebsite

Create a new Project.



88
89
90
91
92
93
# File 'lib/reparcs/projects.rb', line 88

def initialize
  @javascript_files = []
  @image_files = []
  @css_files = []
  @pages = []
end

Instance Method Details

#add_css_file(file) ⇒ Object

Adds a css stylsheet file to the project Once the website has been published the file will be accesible via the relative path of css/



111
112
113
# File 'lib/reparcs/projects.rb', line 111

def add_css_file(file)
  @css_files << file
end

#add_image_file(file) ⇒ Object

Adds a image file to the project Once the website has been published the file will be accesible via the relative path of image/



117
118
119
# File 'lib/reparcs/projects.rb', line 117

def add_image_file(file)
  @image_files << file
end

#add_javascript_file(file) ⇒ Object

Adds a javascript file to the project Once the website has been published the file will be accesible via the relative path of javascript/



105
106
107
# File 'lib/reparcs/projects.rb', line 105

def add_javascript_file(file)
  @javascript_files << file
end

#append(name, page) ⇒ Object

Adds a page to the website, takes thre page object, and a name for the page as parameters. If you specify ‘index’ for the name, the file produced by the publish method will be index.html.



123
124
125
# File 'lib/reparcs/projects.rb', line 123

def append(name, page)
  @pages << [name, page]
end

#include_scriptaculous_filesObject

Automatically includes the required javascript files, for the effects.



95
96
97
98
99
100
101
# File 'lib/reparcs/projects.rb', line 95

def include_scriptaculous_files
  Dir.foreach(JAVASCRIPT_LIB_PATH) { |f| 
    unless f[0,1] == "."
      @javascript_files << "#{JAVASCRIPT_LIB_PATH}/#{f}"
    end
  }
end

#publish(directory) ⇒ Object

Publishes the entire website to the given directory.



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/reparcs/projects.rb', line 127

def publish(directory)
  root = directory
  unless @javascript_files.length == 0
    FileUtils.mkdir "#{root}/javascript"
    @javascript_files.each do |f|
      FileUtils.cp(f, "#{root}/javascript")
    end
  end
  unless @image_files.length == 0
    FileUtils.mkdir "#{root}/image"
    @image_files.each do |f|
      FileUtils.cp(f, "#{root}/image")
    end
  end
  unless @css_files.length == 0
    FileUtils.mkdir "#{root}/css"
    @css_files.each do |f|
      FileUtils.cp(f, "#{root}/css")
    end
  end
  unless @pages.length == 0
    @pages.each do |p|
      f = File.new("#{root}/#{p[0]}.html", "w")
      f.write(p[1].to_html)
      f.close
    end
  end
end