Class: Hyde::Page::GeneratedJsFile

Inherits:
Jekyll::StaticFile
  • Object
show all
Defined in:
lib/hyde-page-js.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, dir, name) ⇒ GeneratedJsFile

Returns a new instance of GeneratedJsFile.



19
20
21
22
23
24
25
26
27
# File 'lib/hyde-page-js.rb', line 19

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-page-js"
end

Instance Attribute Details

#file_contentsObject

Returns the value of attribute file_contents.



16
17
18
# File 'lib/hyde-page-js.rb', line 16

def file_contents
  @file_contents
end

#generatorObject (readonly)

Returns the value of attribute generator.



17
18
19
# File 'lib/hyde-page-js.rb', line 17

def generator
  @generator
end

Instance Method Details

#write(dest) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hyde-page-js.rb', line 29

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