Class: Crush::Engine
- Inherits:
-
Object
- Object
- Crush::Engine
- Defined in:
- lib/crush/engine.rb
Direct Known Subclasses
CSSMin, Closure::Compiler, JSMin, Packr, Rainpress, Uglifier, YUI::CssCompressor, YUI::JavaScriptCompressor
Class Attribute Summary collapse
-
.engine_initialized ⇒ Object
(also: engine_initialized?)
Returns the value of attribute engine_initialized.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
The data to cmopress; loaded from a file or given directly.
-
#file ⇒ Object
readonly
The name of the file to be compressed.
-
#options ⇒ Object
readonly
A Hash of compression engine specific options.
Class Method Summary collapse
-
.engine_name ⇒ Object
Returns a lowercase, underscored name for the engine.
Instance Method Summary collapse
-
#initialize(file = nil, options = nil) ⇒ Engine
constructor
Create a new engine with the file and options specified.
-
#render(data = nil) ⇒ Object
(also: #compress, #compile)
Compresses the data.
Constructor Details
#initialize(file = nil, options = nil) ⇒ Engine
Create a new engine with the file and options specified. By default, the data to compress is read from the file. When a block is given, it should read data and return as a String.
All arguments are optional.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/crush/engine.rb', line 37 def initialize(file = nil, = nil) if file.respond_to?(:to_hash) @options = file.to_hash else @file = file @options = || {} end unless self.class.engine_initialized? initialize_engine self.class.engine_initialized = true end @data = if block_given? yield elsif @file File.respond_to?(:binread) ? File.binread(@file) : File.read(@file) end prepare end |
Class Attribute Details
.engine_initialized ⇒ Object Also known as: engine_initialized?
Returns the value of attribute engine_initialized.
17 18 19 |
# File 'lib/crush/engine.rb', line 17 def engine_initialized @engine_initialized end |
Instance Attribute Details
#data ⇒ Object (readonly)
The data to cmopress; loaded from a file or given directly.
11 12 13 |
# File 'lib/crush/engine.rb', line 11 def data @data end |
#file ⇒ Object (readonly)
The name of the file to be compressed
4 5 6 |
# File 'lib/crush/engine.rb', line 4 def file @file end |
#options ⇒ Object (readonly)
A Hash of compression engine specific options. This is passed directly to the underlying engine and is not used by the generic interface.
8 9 10 |
# File 'lib/crush/engine.rb', line 8 def @options end |
Class Method Details
.engine_name ⇒ Object
Returns a lowercase, underscored name for the engine.
21 22 23 24 25 26 27 28 29 |
# File 'lib/crush/engine.rb', line 21 def engine_name engine_name = name.to_s.dup engine_name.sub! /^.*::/ , "" engine_name.gsub! /([A-Z]+)([A-Z][a-z])/, '\1_\2' engine_name.gsub! /([a-z\d])([A-Z])/, '\1_\2' engine_name.tr! "-", "_" engine_name.downcase! engine_name end |
Instance Method Details
#render(data = nil) ⇒ Object Also known as: compress, compile
Compresses the data. Data can be read through the file or the block given at initialization, or through passing it here directly.
61 62 63 64 |
# File 'lib/crush/engine.rb', line 61 def render(data = nil) @data = data unless data.nil? evaluate end |