require "prez/files" require "sass" require "uglifier" module Prez module Assets class Tagged attr_reader :name, :contents def initialize(name, options = {}) @name = name @contents = Prez::Files.contents name, extension @dev = options.fetch :dev, false end def dev? @dev end def minified_contents minify contents end def minify(contents) contents end def to_tag if dev? "#{open}\n#{contents}#{close}" else "#{open}#{minified_contents}#{close}" end end end class Javascript < Prez::Assets::Tagged def extension "js" end def open %{} end def minify(contents) Uglifier.compile contents end end class Stylesheet < Prez::Assets::Tagged def extension "css" end def open %{} end def minify(contents) Sass::Engine.new(contents, syntax: :scss, style: :compressed).render end end class << self def javascript(name, options = {}) Prez::Assets::Javascript.new(name, options).to_tag end def stylesheet(name, options = {}) Prez::Assets::Stylesheet.new(name, options).to_tag end end end end