Class: Potion::StaticFile

Inherits:
Object
  • Object
show all
Defined in:
lib/potion/static_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, site) ⇒ StaticFile

Returns a new instance of StaticFile.



5
6
7
8
9
10
11
# File 'lib/potion/static_file.rb', line 5

def initialize(path, site)
  @path = path
  @site = site
  @content = File.open(path) {|stream| stream.read }
  @relative_output_path = @path.gsub(@site.base_path, "").gsub("_posts/", "")
  @output_path = File.join(@site.destination_path, @relative_output_path)
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/potion/static_file.rb', line 3

def content
  @content
end

#output_pathObject

Returns the value of attribute output_path.



3
4
5
# File 'lib/potion/static_file.rb', line 3

def output_path
  @output_path
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/potion/static_file.rb', line 3

def path
  @path
end

#relative_output_pathObject

Returns the value of attribute relative_output_path.



3
4
5
# File 'lib/potion/static_file.rb', line 3

def relative_output_path
  @relative_output_path
end

#siteObject

Returns the value of attribute site.



3
4
5
# File 'lib/potion/static_file.rb', line 3

def site
  @site
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
16
17
# File 'lib/potion/static_file.rb', line 13

def ==(other)
  self.class.name == other.class.name &&
  @path == other.path && 
  @site == other.site
end

#renderObject



19
20
21
22
23
24
25
# File 'lib/potion/static_file.rb', line 19

def render
  @site.class.extensions.each do |extension|
    extension.new.process(self)
  end
  
  @content
end

#writeObject



27
28
29
30
31
32
# File 'lib/potion/static_file.rb', line 27

def write
  FileUtils.mkdir_p(File.split(@output_path)[0])
  File.open(@output_path, "w+") do |stream|
    stream.puts self.render
  end
end