Class: SiteFuel::Processor::JavaScriptProcessor
- Inherits:
-
AbstractStringBasedProcessor
- Object
- AbstractProcessor
- AbstractStringBasedProcessor
- SiteFuel::Processor::JavaScriptProcessor
- Defined in:
- lib/sitefuel/processors/JavaScriptProcessor.rb
Constant Summary collapse
- CDATA_START =
'//<![CDATA['
- CDATA_END =
'//]]>'
Instance Attribute Summary
Attributes inherited from AbstractStringBasedProcessor
Attributes inherited from AbstractProcessor
#execution_list, #original_size, #processed_size, #resource_name
Class Method Summary collapse
- .default_filterset ⇒ Object
- .file_patterns ⇒ Object
- .filterset_minify ⇒ Object
-
.processor_name ⇒ Object
override AbstractProcessor#processor_name so output shows up as
JS
instead ofJavaScript
.
Instance Method Summary collapse
Methods inherited from AbstractStringBasedProcessor
filter_string, #generate, #generate_string, #open_file, #open_string, process_file, process_string, #processor_symbol, processor_type, #save
Methods inherited from AbstractProcessor
#add_filter, #add_filterset, #clear_filters, #create_file, #drop_filter, #execute, file_pattern_match?, #filter?, filter?, filters, filters_in_filterset, filterset?, filterset_ignore, filtersets, find_processors, #finish_filters, #initialize, processes_file?, #processor_symbol, processor_type, #run_filter, #run_filterset, #save, #setup_filters
Methods included from ClassLogging
#debug, #error, #fatal, #info, #warn
Methods included from Configurable
#configuration_options, #configure, #ensure_configurable_option, #post_configuration, #pre_configuration, #set_configuration
Methods included from Logging
#debug, #error, #fatal, #info, #logger=, #warn
Constructor Details
This class inherits a constructor from SiteFuel::Processor::AbstractProcessor
Class Method Details
.default_filterset ⇒ Object
27 28 29 |
# File 'lib/sitefuel/processors/JavaScriptProcessor.rb', line 27 def self.default_filterset :minify end |
.file_patterns ⇒ Object
17 18 19 |
# File 'lib/sitefuel/processors/JavaScriptProcessor.rb', line 17 def self.file_patterns ['.js'] end |
.filterset_minify ⇒ Object
31 32 33 |
# File 'lib/sitefuel/processors/JavaScriptProcessor.rb', line 31 def self.filterset_minify [:minify] end |
.processor_name ⇒ Object
override AbstractProcessor#processor_name so output shows up as JS
instead of JavaScript
.
23 24 25 |
# File 'lib/sitefuel/processors/JavaScriptProcessor.rb', line 23 def self.processor_name "JS" end |
Instance Method Details
#filter_minify ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sitefuel/processors/JavaScriptProcessor.rb', line 37 def filter_minify return nil if @document == nil return nil if @document.length == 0 # JSMin doesn't like having files without any newlines @document << "\n" # put in CDATA placeholders @document.gsub!(CDATA_START, '[[CDATA_START]]') @document.gsub!(CDATA_END, '[[CDATA_END]]') # run the minification @document = JSMin.minify(@document).strip # put back CDATA @document.gsub!('[[CDATA_START]]', CDATA_START) @document.gsub!('[[CDATA_END]]', CDATA_END) end |