Class: Crush::Engine
- Inherits:
-
Tilt::Template
- Object
- Tilt::Template
- Crush::Engine
- Defined in:
- lib/crush/engine.rb
Overview
Crush::Engine is an abstract class like Tilt::Template, which adds methods common to compression library APIs.
Direct Known Subclasses
CSSMin, Closure::Compiler, JSMin, Packr, Rainpress, Sass::Engine, Uglifier, YUI::CssCompressor, YUI::JavaScriptCompressor
Class Method Summary collapse
-
.compile ⇒ String
Convenience method of initializing an engine and immediately compressing the given data.
-
.compress(data, options = {}) ⇒ String
Convenience method of initializing an engine and immediately compressing the given data.
Instance Method Summary collapse
-
#compress(data = nil) ⇒ String
(also: #compile)
Compresses the given data.
-
#initialize(file = nil, *args, &block) ⇒ Engine
constructor
Override Tilt::Template#initialize so that it does not require a file or block.
-
#render(*args) ⇒ Object
Override Tilt::Template#render to check for data and raise an error if there isn’t any.
Constructor Details
#initialize(file = nil, *args, &block) ⇒ Engine
Override Tilt::Template#initialize so that it does not require a file or block. This is done so that Crush::Engines can follow the usual compressor API convention of having an instance method, #compress, which accepts the data to compress as an argument.
(see Tilt::Template#initialize)
30 31 32 33 34 35 |
# File 'lib/crush/engine.rb', line 30 def initialize(file = nil, *args, &block) unless block_given? or args[0].respond_to?(:to_str) block = Proc.new {} end super file, *args, &block end |
Class Method Details
.compile ⇒ String
Convenience method of initializing an engine and immediately compressing the given data.
19 20 21 |
# File 'lib/crush/engine.rb', line 19 def compress(data, = {}) self.new().compress(data) end |
.compress(data, options = {}) ⇒ String
Convenience method of initializing an engine and immediately compressing the given data.
16 17 18 |
# File 'lib/crush/engine.rb', line 16 def compress(data, = {}) self.new().compress(data) end |
Instance Method Details
#compress(data = nil) ⇒ String Also known as: compile
Compresses the given data.
41 42 43 44 |
# File 'lib/crush/engine.rb', line 41 def compress(data = nil) @data = data.to_s unless data.nil? render end |
#render(*args) ⇒ Object
Override Tilt::Template#render to check for data and raise an error if there isn’t any.
(see Tilt::Template#render)
51 52 53 54 |
# File 'lib/crush/engine.rb', line 51 def render(*args) raise ArgumentError, "data must be set before rendering" if @data.nil? super end |