Class: Hyde::Decap::GeneratedFile

Inherits:
Jekyll::StaticFile
  • Object
show all
Defined in:
lib/hyde/decap/generated_file.rb

Overview

Alternative class for jekyll’s static files this allows the creation of files without a source file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, dir, name) ⇒ GeneratedFile

Returns a new instance of GeneratedFile.



12
13
14
15
16
17
18
19
20
# File 'lib/hyde/decap/generated_file.rb', line 12

def initialize(site, dir, name)
  @site = site
  @dir = dir
  @name = name
  @relative_path = File.join(*[@dir, @name].compact)
  @extname = File.extname(@name)
  @type = @collection&.label&.to_sym
  @generator = "hyde-decap"
end

Instance Attribute Details

#file_contentsObject

Returns the value of attribute file_contents.



9
10
11
# File 'lib/hyde/decap/generated_file.rb', line 9

def file_contents
  @file_contents
end

#generatorObject (readonly)

Returns the value of attribute generator.



10
11
12
# File 'lib/hyde/decap/generated_file.rb', line 10

def generator
  @generator
end

Instance Method Details

#write(dest) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hyde/decap/generated_file.rb', line 22

def write(dest)
  dest_path = destination(dest)
  return false if File.exist?(dest_path)

  FileUtils.mkdir_p(File.dirname(dest_path))
  FileUtils.rm(dest_path) if File.exist?(dest_path)

  File.open(dest_path, "w") do |output_file|
    output_file << file_contents
  end

  true
end