Class: Potion::StaticFile
- Inherits:
-
Object
- Object
- Potion::StaticFile
- Defined in:
- lib/potion/static_file.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#path ⇒ Object
Returns the value of attribute path.
-
#relative_output_path ⇒ Object
Returns the value of attribute relative_output_path.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(path, site) ⇒ StaticFile
constructor
A new instance of StaticFile.
- #render ⇒ Object
- #write ⇒ Object
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
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/potion/static_file.rb', line 3 def content @content end |
#output_path ⇒ Object
Returns the value of attribute output_path.
3 4 5 |
# File 'lib/potion/static_file.rb', line 3 def output_path @output_path end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/potion/static_file.rb', line 3 def path @path end |
#relative_output_path ⇒ Object
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 |
#site ⇒ Object
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 |
#render ⇒ Object
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 |
#write ⇒ Object
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 |