Class: IS::StaticFile

Inherits:
Jekyll::StaticFile
  • Object
show all
Defined in:
lib/is/static_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, target, name, source: nil, content: nil) ⇒ StaticFile

Returns a new instance of StaticFile.



12
13
14
15
16
17
18
19
20
# File 'lib/is/static_file.rb', line 12

def initialize site, target, name, source: nil, content: nil
  @site = site
  @target = target
  @name = name
  @source = source
  @content = content
  @base = File.dirname(@source || "/")
  super @site, @base, "", @name
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



10
11
12
# File 'lib/is/static_file.rb', line 10

def base
  @base
end

#contentObject

Returns the value of attribute content.



9
10
11
# File 'lib/is/static_file.rb', line 9

def content
  @content
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/is/static_file.rb', line 10

def name
  @name
end

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/is/static_file.rb', line 10

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'lib/is/static_file.rb', line 10

def target
  @target
end

Instance Method Details

#destination(dest) ⇒ Object



26
27
28
# File 'lib/is/static_file.rb', line 26

def destination dest
  File.join dest, @target, @name
end

#modified?Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/is/static_file.rb', line 46

def modified?
  return super if @source
  !!@content
end

#pathObject



22
23
24
# File 'lib/is/static_file.rb', line 22

def path
  @source
end

#relative_pathObject



30
31
32
# File 'lib/is/static_file.rb', line 30

def relative_path 
  File.join @target, @name
end

#write(dest) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/is/static_file.rb', line 34

def write dest
  return super(dest) if @source
  return false unless @content

  dest_path = destination dest
  FileUtils.mkdir_p(File.dirname(dest_path))
  File.open dest_path, 'wb' do |io|
    io.write(@content || '')
  end
  true
end