Class: Jenner::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/jenner/asset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, site) ⇒ Asset

Returns a new instance of Asset.



4
5
6
7
# File 'lib/jenner/asset.rb', line 4

def initialize(path, site)
  @path = path
  @site = site
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/jenner/asset.rb', line 3

def path
  @path
end

Instance Method Details

#filenameObject



9
10
11
# File 'lib/jenner/asset.rb', line 9

def filename
  File.basename(@path)
end

#generate!Object



43
44
45
46
47
48
49
50
# File 'lib/jenner/asset.rb', line 43

def generate!
  if sass?
    engine = Sass::Engine.new(File.read(source_path), syntax: :scss)
    File.write(public_path, engine.render)
  else
    FileUtils.cp source_path, public_path
  end
end

#output_filenameObject



17
18
19
# File 'lib/jenner/asset.rb', line 17

def output_filename
  sass? ? filename.sub(".scss",".css") : filename
end

#output_pathObject



25
26
27
# File 'lib/jenner/asset.rb', line 25

def output_path
  @path.sub(filename, output_filename)
end

#public_pathObject



33
34
35
# File 'lib/jenner/asset.rb', line 33

def public_path
  File.join(@site.root,"public", output_path)
end

#sass?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/jenner/asset.rb', line 13

def sass?
  File.extname(filename) == ".scss"
end

#source_pathObject



21
22
23
# File 'lib/jenner/asset.rb', line 21

def source_path
  File.join(@site.root,"_site",@path)
end

#to_liquidObject



37
38
39
40
41
# File 'lib/jenner/asset.rb', line 37

def to_liquid
  {
    'url' => url
  }
end

#urlObject



29
30
31
# File 'lib/jenner/asset.rb', line 29

def url
  "/#{output_path}"
end