Class: Jenner::Asset
- Inherits:
-
Object
- Object
- Jenner::Asset
- Defined in:
- lib/jenner/asset.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #filename ⇒ Object
- #generate! ⇒ Object
-
#initialize(path, site) ⇒ Asset
constructor
A new instance of Asset.
- #output_filename ⇒ Object
- #output_path ⇒ Object
- #public_path ⇒ Object
- #sass? ⇒ Boolean
- #source_path ⇒ Object
- #to_liquid ⇒ Object
- #url ⇒ Object
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
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/jenner/asset.rb', line 3 def path @path end |
Instance Method Details
#filename ⇒ Object
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_filename ⇒ Object
17 18 19 |
# File 'lib/jenner/asset.rb', line 17 def output_filename sass? ? filename.sub(".scss",".css") : filename end |
#output_path ⇒ Object
25 26 27 |
# File 'lib/jenner/asset.rb', line 25 def output_path @path.sub(filename, output_filename) end |
#public_path ⇒ Object
33 34 35 |
# File 'lib/jenner/asset.rb', line 33 def public_path File.join(@site.root,"public", output_path) end |
#sass? ⇒ Boolean
13 14 15 |
# File 'lib/jenner/asset.rb', line 13 def sass? File.extname(filename) == ".scss" end |
#source_path ⇒ Object
21 22 23 |
# File 'lib/jenner/asset.rb', line 21 def source_path File.join(@site.root,"_site",@path) end |
#to_liquid ⇒ Object
37 38 39 40 41 |
# File 'lib/jenner/asset.rb', line 37 def to_liquid { 'url' => url } end |
#url ⇒ Object
29 30 31 |
# File 'lib/jenner/asset.rb', line 29 def url "/#{output_path}" end |