Class: MakeBook::Formats::HTML::Stylesheet

Inherits:
Asset
  • Object
show all
Defined in:
lib/makebook/formats/html.rb

Overview

Stylesheet asset

Constant Summary collapse

TYPES =
{
  'eot'  => 'application/vnd.ms-fontobject',
  'otf'  => 'application/font-sfnt',
  'ttf'  => 'application/font-sfnt',
  'woff' => 'application/font-woff',
  'png' => 'image/png',
  'jpg'  => 'image/jpg',
  'jpeg' => 'image/jpg',
  'svg'  => 'image/svg+xml',
  'gif'  => 'image/gif',
}.freeze

Instance Attribute Summary

Attributes inherited from Asset

#mime, #source

Instance Method Summary collapse

Methods inherited from Asset

#base64, #build_name, #data_uri, #digest

Constructor Details

#initialize(source, mime: 'text/css') ⇒ Stylesheet

Returns a new instance of Stylesheet.



74
75
76
# File 'lib/makebook/formats/html.rb', line 74

def initialize(source, mime: 'text/css')
  super
end

Instance Method Details

#assetsObject



78
79
80
81
82
83
84
85
# File 'lib/makebook/formats/html.rb', line 78

def assets
  scan(/url\("([^"]+\.(#{TYPES.keys.join('|')}))"\)/).map do |path, ext|
    [
      Asset.new(source.dirname + path, mime: TYPES[ext]),
      wrap(Regexp.last_match.begin(1)...Regexp.last_match.end(1)),
    ]
  end
end

#readObject



91
92
93
# File 'lib/makebook/formats/html.rb', line 91

def read
  @read ||= super
end

#to_cssObject



87
88
89
# File 'lib/makebook/formats/html.rb', line 87

def to_css
  read
end